Skip to content

Commit

Permalink
EIP-5792 Updates (#1148)
Browse files Browse the repository at this point in the history
* naming, param update

* lint

* stronger typing on walletCapabilities

stronger typing on walletCapabilities

* ts
  • Loading branch information
nateReiners authored Apr 1, 2024
1 parent 3cfbc1c commit afb24ac
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 45 deletions.
22 changes: 8 additions & 14 deletions apps/testapp/src/components/RpcMethods/method/walletTxMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,30 @@ const walletGetCapabilities: RpcRequestInput = {
params: [],
};

const walletSendTransaction: RpcRequestInput = {
method: 'wallet_sendTransaction',
const walletSendCalls: RpcRequestInput = {
method: 'wallet_sendCalls',
params: [
{ key: 'version', required: true },
{ key: 'chainId', required: true },
{ key: 'sender', required: true },
{ key: 'from', required: true },
{ key: 'calls', required: true },
{ key: 'version', required: true },
{ key: 'gas', required: false },
{ key: 'capabilities', required: false },
{ key: 'capabilities', required: true },
],
format: (data: Record<string, string>) => [
{
chainId: data.chainId,
sender: data.sender,
calls: data.calls,
version: data.version,
gas: data.gas,
capabilities: parseMessage(data.capabilities),
},
],
};

const walletGetTransactionStatus: RpcRequestInput = {
method: 'wallet_getTransactionStatus',
const walletGetCallsStatus: RpcRequestInput = {
method: 'wallet_getCallsStatus',
params: [{ key: 'params', required: true }],
format: (data: Record<string, string>) => [data.params],
};

export const walletTxMethods = [
walletGetCapabilities,
walletGetTransactionStatus,
walletSendTransaction,
];
export const walletTxMethods = [walletGetCapabilities, walletGetCallsStatus, walletSendCalls];
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ADDR_TO_FILL } from './const';
import { ShortcutType } from './ShortcutType';

const walletSendTransactionShortcuts: ShortcutType[] = [
const walletSendCallsShortcuts: ShortcutType[] = [
{
key: 'wallet_sendTransaction',
key: 'wallet_sendCalls',
data: {
chainId: '84532',
sender: ADDR_TO_FILL,
Expand All @@ -19,5 +19,5 @@ const walletSendTransactionShortcuts: ShortcutType[] = [
];

export const walletTxShortcutsMap = {
wallet_sendTransaction: walletSendTransactionShortcuts,
wallet_sendCalls: walletSendCallsShortcuts,
};
4 changes: 2 additions & 2 deletions packages/wallet-sdk/src/sign/SignRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class SignRequestHandler implements RequestHandler {
'wallet_switchEthereumChain',
'wallet_watchAsset',
'wallet_getCapabilities',
'wallet_sendTransaction',
'wallet_getTransactionStatus',
'wallet_sendCalls',
'wallet_getCallsStatus',
];

return methodsThatRequireSigning.includes(request.method);
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-sdk/src/sign/scw/SCWSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class SCWSigner implements Signer {

private async tryBackendHandling<T>(request: RequestArguments): Promise<T | undefined> {
switch (request.method) {
case SupportedEthereumMethods.WalletGetTransactionStatus: {
case SupportedEthereumMethods.WalletGetCallsStatus: {
const requestBody = {
...request,
jsonrpc: '2.0',
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet-sdk/src/sign/scw/SCWStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class SCWStateManager {
private updateListener: StateUpdateListener;

private availableChains?: Chain[];
private _walletCapabilities?: Record<string, object>;
private _walletCapabilities?: Record<`0x${string}`, Record<string, unknown>>;
private _accounts: AddressString[];
private _activeChain: Chain;
get accounts() {
Expand Down Expand Up @@ -83,7 +83,7 @@ export class SCWStateManager {
this.switchChain(this._activeChain.id);
}

updateWalletCapabilities(capabilities: Record<string, object>) {
updateWalletCapabilities(capabilities: Record<`0x${string}`, Record<string, unknown>>) {
this._walletCapabilities = capabilities;
this.storeItemToStorage(WALLET_CAPABILITIES_STORAGE_KEY, capabilities);
}
Expand Down
45 changes: 23 additions & 22 deletions packages/wallet-sdk/src/sign/scw/message/type/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export enum SupportedEthereumMethods {
WalletSwitchEthereumChain = 'wallet_switchEthereumChain',
WalletAddEthereumChain = 'wallet_addEthereumChain',
WalletGetCapabilities = 'wallet_getCapabilities',
WalletSendTransaction = 'wallet_sendTransaction',
WalletGetTransactionStatus = 'wallet_getTransactionStatus',
WalletSendCalls = 'wallet_sendCalls',
WalletGetCallsStatus = 'wallet_getCallsStatus',
}

export type RequestAccountsAction = {
Expand Down Expand Up @@ -109,8 +109,8 @@ export type SwitchEthereumChainAction = {
method: SupportedEthereumMethods.WalletSwitchEthereumChain;
params: [
{
chainId: string;
}
chainId: `0x${string}`; // Hex chain id
},
];
};

Expand All @@ -134,24 +134,25 @@ export type GetCapabilitiesAction = {
method: SupportedEthereumMethods.WalletGetCapabilities;
};

export type WalletSendTransactionAction = {
method: SupportedEthereumMethods.WalletSendTransaction;
params: {
chainId: string;
sender: string;
version: string;
gas?: string;
calls: {
target: string;
value: string;
data: string;
}[];
capabilities: object;
};
type WalletSendCallsParams = {
version: string;
chainId: `0x${string}`; // Hex chain id
from: `0x${string}`;
calls: {
to: `0x${string}`;
data: `0x${string}`;
value: `0x${string}`; // Hex value
}[];
capabilities: Record<string, unknown>;
};

export type WalletSendCallsAction = {
method: SupportedEthereumMethods.WalletSendCalls;
params: WalletSendCallsParams;
};

export type GetTransactionStatusAction = {
method: SupportedEthereumMethods.WalletGetTransactionStatus;
export type GetCallsStatusAction = {
method: SupportedEthereumMethods.WalletGetCallsStatus;
params: [string];
};

Expand All @@ -168,8 +169,8 @@ export type AllAction =
| SwitchEthereumChainAction
| AddEthereumChainAction
| GetCapabilitiesAction
| WalletSendTransactionAction
| GetTransactionStatusAction;
| WalletSendCallsAction
| GetCallsStatusAction;

export type Action = {
method: SupportedEthereumMethods;
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-sdk/src/sign/scw/message/type/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export type SCWResponse<T> = {
data?: {
// optional data
chains?: { [key: number]: string };
capabilities?: Record<string, object>;
capabilities?: Record<`0x${string}`, Record<string, unknown>>;
};
};

0 comments on commit afb24ac

Please sign in to comment.