-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MetaMask Snap services and types for account management and netwo…
…rk interactions
- Loading branch information
Showing
22 changed files
with
588 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { MetaMaskInpageProvider } from '@metamask/providers'; | ||
import { MASSA_SNAP_ID } from '../config'; | ||
import type { AccountToken } from '../types/account-token'; | ||
|
||
export type AddTokenParams = { | ||
address: string; | ||
}; | ||
|
||
export type AddTokenResponse = AccountToken; | ||
|
||
/** | ||
* Function that calls the MetaMask provider to add a token | ||
* @param provider - The MetaMask provider | ||
* @param params - The add token parameters (address of the token) | ||
* @returns The response of the operation | ||
*/ | ||
export const addToken = async ( | ||
provider: MetaMaskInpageProvider, | ||
params: AddTokenParams, | ||
): Promise<AddTokenResponse | undefined> => { | ||
return provider.request({ | ||
method: 'wallet_invokeSnap', | ||
params: { | ||
snapId: MASSA_SNAP_ID, | ||
request: { | ||
method: 'account.addToken', | ||
params, | ||
}, | ||
}, | ||
}) as Promise<AddTokenResponse>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { MetaMaskInpageProvider } from '@metamask/providers'; | ||
import { MASSA_SNAP_ID } from '../config'; | ||
|
||
export type BuyRollsParams = { | ||
fee: string; | ||
amount: string; | ||
}; | ||
|
||
export type BuyRollsResponse = { | ||
operationId: string; | ||
}; | ||
|
||
/** | ||
* Function that calls the MetaMask provider to buy rolls | ||
* @param provider - The MetaMask provider | ||
* @param params - The buy rolls parameters (fee and amount) | ||
* @returns The operationId of the operation | ||
*/ | ||
export const buyRolls = async ( | ||
provider: MetaMaskInpageProvider, | ||
params: BuyRollsParams, | ||
): Promise<BuyRollsResponse | undefined> => { | ||
return provider.request({ | ||
method: 'wallet_invokeSnap', | ||
params: { | ||
snapId: MASSA_SNAP_ID, | ||
request: { | ||
method: 'account.buyRolls', | ||
params, | ||
}, | ||
}, | ||
}) as Promise<BuyRollsResponse>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { MetaMaskInpageProvider } from '@metamask/providers'; | ||
import { MASSA_SNAP_ID } from '../config'; | ||
|
||
export type CallSCParams = { | ||
fee: string; | ||
functionName: string; | ||
at: string; | ||
args: number[]; | ||
coins: string; | ||
maxGas?: string; | ||
}; | ||
|
||
export type CallSCResponse = { | ||
operationId: string; | ||
}; | ||
|
||
/** | ||
* Function that calls the MetaMask provider to call a smart contract | ||
* @param provider - The MetaMask provider | ||
* @param params - The call smart contract parameters (see massa standard) | ||
* @returns The response of the operation | ||
*/ | ||
export const callSC = async ( | ||
provider: MetaMaskInpageProvider, | ||
params: CallSCParams, | ||
): Promise<CallSCResponse | undefined> => { | ||
return provider.request({ | ||
method: 'wallet_invokeSnap', | ||
params: { | ||
snapId: MASSA_SNAP_ID, | ||
request: { | ||
method: 'account.callSC', | ||
params, | ||
}, | ||
}, | ||
}) as Promise<CallSCResponse>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { MetaMaskInpageProvider } from '@metamask/providers'; | ||
import { MASSA_SNAP_ID } from '../config'; | ||
|
||
export type ClearOperationsResponse = { | ||
response: 'OK' | 'ERROR' | 'REFUSED'; | ||
message?: string; | ||
}; | ||
|
||
/** | ||
* Function that calls the MetaMask provider to clear the operations of an account | ||
* @param provider - The MetaMask provider | ||
* @returns The response of the operation | ||
*/ | ||
export const clearOperations = async ( | ||
provider: MetaMaskInpageProvider, | ||
): Promise<ClearOperationsResponse | undefined> => { | ||
return provider.request({ | ||
method: 'wallet_invokeSnap', | ||
params: { | ||
snapId: MASSA_SNAP_ID, | ||
request: { | ||
method: 'account.clearOperations', | ||
}, | ||
}, | ||
}) as Promise<ClearOperationsResponse>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { MetaMaskInpageProvider } from '@metamask/providers'; | ||
import { MASSA_SNAP_ID } from '../config'; | ||
|
||
export type DeleteTokenParams = { | ||
address: string; | ||
}; | ||
|
||
export type DeleteTokenResponse = { | ||
response: 'OK' | 'ERROR'; | ||
message?: string; | ||
}; | ||
|
||
/** | ||
* Function that calls the MetaMask provider to delete a token | ||
* @param provider - The MetaMask provider | ||
* @param params - The delete token parameters (address of the token) | ||
* @returns The response of the operation | ||
*/ | ||
export const deleteToken = async ( | ||
provider: MetaMaskInpageProvider, | ||
params: DeleteTokenParams, | ||
): Promise<DeleteTokenResponse | undefined> => { | ||
return provider.request({ | ||
method: 'wallet_invokeSnap', | ||
params: { | ||
snapId: MASSA_SNAP_ID, | ||
request: { | ||
method: 'account.deleteToken', | ||
params, | ||
}, | ||
}, | ||
}) as Promise<DeleteTokenResponse>; | ||
}; |
Oops, something went wrong.