Skip to content

Commit aa521c8

Browse files
chakra-guyjiexiadonesky1
authored
refactor: Better RPC handling (#1373)
* feat: proper rpc handling * fix tests * refactor strategy * remove describe in client test * remove wallet_getPermissions from SDK_HANDLED_METHODS * Update packages/sdk-multichain/src/multichain/rpc/strategy.ts Co-authored-by: Alex Donesky <[email protected]> --------- Co-authored-by: Jiexi Luan <[email protected]> Co-authored-by: Alex Donesky <[email protected]>
1 parent 7fb2175 commit aa521c8

File tree

5 files changed

+232
-432
lines changed

5 files changed

+232
-432
lines changed

packages/sdk-multichain/src/domain/multichain/api/constants.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -64,88 +64,3 @@ export const infuraRpcUrls: RPC_URLS_MAP = {
6464
'eip155:44787': 'https://celo-alfajores.infura.io/v3/',
6565
};
6666

67-
/**
68-
* Standard RPC method names used in the MetaMask ecosystem.
69-
*
70-
* This constant provides a centralized registry of all supported
71-
* RPC methods, making it easier to reference them consistently
72-
* throughout the codebase.
73-
*/
74-
export const RPC_METHODS = {
75-
/** Get the current provider state */
76-
METAMASK_GETPROVIDERSTATE: 'metamask_getProviderState',
77-
/** Connect and sign in a single operation */
78-
METAMASK_CONNECTSIGN: 'metamask_connectSign',
79-
/** Connect with specific parameters */
80-
METAMASK_CONNECTWITH: 'metamask_connectWith',
81-
/** Open MetaMask interface */
82-
METAMASK_OPEN: 'metamask_open',
83-
/** Execute multiple operations in a batch */
84-
METAMASK_BATCH: 'metamask_batch',
85-
/** Sign a message with personal_sign */
86-
PERSONAL_SIGN: 'personal_sign',
87-
/** Request wallet permissions */
88-
WALLET_REQUESTPERMISSIONS: 'wallet_requestPermissions',
89-
/** Revoke wallet permissions */
90-
WALLET_REVOKEPERMISSIONS: 'wallet_revokePermissions',
91-
/** Get current wallet permissions */
92-
WALLET_GETPERMISSIONS: 'wallet_getPermissions',
93-
/** Watch/add a token to the wallet */
94-
WALLET_WATCHASSET: 'wallet_watchAsset',
95-
/** Add a new Ethereum chain */
96-
WALLET_ADDETHEREUMCHAIN: 'wallet_addEthereumChain',
97-
/** Switch to a different Ethereum chain */
98-
WALLET_SWITCHETHEREUMCHAIN: 'wallet_switchEthereumChain',
99-
/** Request account access */
100-
ETH_REQUESTACCOUNTS: 'eth_requestAccounts',
101-
/** Get available accounts */
102-
ETH_ACCOUNTS: 'eth_accounts',
103-
/** Get current chain ID */
104-
ETH_CHAINID: 'eth_chainId',
105-
/** Send a transaction */
106-
ETH_SENDTRANSACTION: 'eth_sendTransaction',
107-
/** Sign typed data */
108-
ETH_SIGNTYPEDDATA: 'eth_signTypedData',
109-
/** Sign typed data v3 */
110-
ETH_SIGNTYPEDDATA_V3: 'eth_signTypedData_v3',
111-
/** Sign typed data v4 */
112-
ETH_SIGNTYPEDDATA_V4: 'eth_signTypedData_v4',
113-
/** Sign a transaction */
114-
ETH_SIGNTRANSACTION: 'eth_signTransaction',
115-
/** Sign arbitrary data */
116-
ETH_SIGN: 'eth_sign',
117-
/** Recover address from signature */
118-
PERSONAL_EC_RECOVER: 'personal_ecRecover',
119-
};
120-
121-
/**
122-
* Configuration mapping for RPC methods that should be redirected to the wallet.
123-
*
124-
* This constant defines which RPC methods require user interaction through
125-
* the wallet interface (true) versus those that can be handled locally (false).
126-
* Methods marked as true will redirect to the wallet for user approval.
127-
*/
128-
export const METHODS_TO_REDIRECT: { [method: string]: boolean } = {
129-
[RPC_METHODS.ETH_REQUESTACCOUNTS]: true,
130-
[RPC_METHODS.ETH_SENDTRANSACTION]: true,
131-
[RPC_METHODS.ETH_SIGNTRANSACTION]: true,
132-
[RPC_METHODS.ETH_SIGN]: true,
133-
[RPC_METHODS.PERSONAL_SIGN]: true,
134-
// stop redirecting these as we are caching values in the provider
135-
[RPC_METHODS.ETH_ACCOUNTS]: false,
136-
[RPC_METHODS.ETH_CHAINID]: false,
137-
//
138-
[RPC_METHODS.ETH_SIGNTYPEDDATA]: true,
139-
[RPC_METHODS.ETH_SIGNTYPEDDATA_V3]: true,
140-
[RPC_METHODS.ETH_SIGNTYPEDDATA_V4]: true,
141-
[RPC_METHODS.WALLET_REQUESTPERMISSIONS]: true,
142-
[RPC_METHODS.WALLET_GETPERMISSIONS]: true,
143-
[RPC_METHODS.WALLET_WATCHASSET]: true,
144-
[RPC_METHODS.WALLET_ADDETHEREUMCHAIN]: true,
145-
[RPC_METHODS.WALLET_SWITCHETHEREUMCHAIN]: true,
146-
[RPC_METHODS.METAMASK_CONNECTSIGN]: true,
147-
[RPC_METHODS.METAMASK_CONNECTWITH]: true,
148-
[RPC_METHODS.PERSONAL_EC_RECOVER]: true,
149-
[RPC_METHODS.METAMASK_BATCH]: true,
150-
[RPC_METHODS.METAMASK_OPEN]: true,
151-
};

packages/sdk-multichain/src/invoke.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ function testSuite<T extends MultichainOptions>({ platform, createSDK, options:
167167
{ timeout: 100000 },
168168
);
169169

170-
t.it(`${platform} should invoke readonly method successfully from client if infuraAPIKey exists`, async () => {
170+
// TODO: Re-enable this test once we handle RPC node routing (INTERCEPT_AND_ROUTE_TO_RPC_NODE strategy)
171+
t.it.skip(`${platform} should invoke readonly method successfully from client if infuraAPIKey exists`, async () => {
171172
const scopes = ['eip155:1'] as Scope[];
172173
const caipAccountIds = ['eip155:1:0x1234567890abcdef1234567890abcdef12345678'] as any;
173174

0 commit comments

Comments
 (0)