@@ -149,7 +149,10 @@ const Home: NextPage = () => {
149
149
} ) ;
150
150
}
151
151
152
- const getEthereumActions = ( chainId :string , address :string ) : AccountAction [ ] => {
152
+ const getEthereumActions = (
153
+ chainId : string ,
154
+ address : string
155
+ ) : AccountAction [ ] => {
153
156
const actions = {
154
157
[ DEFAULT_EIP155_METHODS . ETH_SEND_TRANSACTION ] : {
155
158
method : DEFAULT_EIP155_METHODS . ETH_SEND_TRANSACTION ,
@@ -217,35 +220,52 @@ const Home: NextPage = () => {
217
220
} ;
218
221
219
222
let availableActions : AccountAction [ ] = [ ] ;
220
- const chainIdAsHex = `0x${ numberToHex ( parseInt ( chainId ) ) } `
221
- const capabilitiesJson = session ?. sessionProperties ?. [ ' capabilities' ]
222
- const walletCapabilities = capabilitiesJson && JSON . parse ( capabilitiesJson )
223
+ const chainIdAsHex = `0x${ numberToHex ( parseInt ( chainId ) ) } ` ;
224
+ const capabilitiesJson = session ?. sessionProperties ?. [ " capabilities" ] ;
225
+ const walletCapabilities = capabilitiesJson && JSON . parse ( capabilitiesJson ) ;
223
226
session ?. namespaces ?. [ "eip155" ] . methods . forEach ( ( methodName ) => {
224
- const action : AccountAction | undefined = actions [ methodName as keyof typeof actions ] ;
225
- // Determine if the method requires additional capability checks
226
- const requiresCapabilityCheck = [ "wallet_sendCalls" , "wallet_getCallsStatus" ] . includes ( methodName ) ;
227
- // Check capabilities only if the method requires it
228
- if ( ! requiresCapabilityCheck || hasEIP7592RequiredCapabilities ( address , chainIdAsHex , walletCapabilities ) ) {
229
- availableActions . push ( action ) ;
230
- }
227
+ const action : AccountAction | undefined =
228
+ actions [ methodName as keyof typeof actions ] ;
229
+ // Determine if the method requires additional capability checks
230
+ const requiresCapabilityCheck = [
231
+ "wallet_sendCalls" ,
232
+ "wallet_getCallsStatus" ,
233
+ ] . includes ( methodName ) ;
234
+ // Check capabilities only if the method requires it
235
+ if (
236
+ ! requiresCapabilityCheck ||
237
+ hasEIP7592RequiredCapabilities (
238
+ address ,
239
+ chainIdAsHex ,
240
+ walletCapabilities
241
+ )
242
+ ) {
243
+ availableActions . push ( action ) ;
231
244
}
232
- ) ;
245
+ } ) ;
233
246
234
- return availableActions ;
247
+ // if a method is approved in the session thats not supported by the app, it will result in an undefined item in the array
248
+ return availableActions . filter ( ( action ) => action !== undefined ) ;
235
249
} ;
236
250
237
- const hasEIP7592RequiredCapabilities = ( address : string , chainId : string , walletCapabilities : any ) : boolean => {
238
- if ( ! walletCapabilities ) return false ;
239
- const addressCapabilities : GetCapabilitiesResult | undefined = walletCapabilities [ address ] ;
251
+ const hasEIP7592RequiredCapabilities = (
252
+ address : string ,
253
+ chainId : string ,
254
+ walletCapabilities : any
255
+ ) : boolean => {
256
+ if ( ! walletCapabilities ) return false ;
257
+ const addressCapabilities : GetCapabilitiesResult | undefined =
258
+ walletCapabilities [ address ] ;
240
259
if (
241
260
addressCapabilities &&
242
261
addressCapabilities [ chainId ] &&
243
- ( addressCapabilities [ chainId ] [ 'atomicBatch' ] ?. supported ||
244
- addressCapabilities [ chainId ] [ 'paymasterService' ] ?. supported ||
245
- addressCapabilities [ chainId ] [ 'sessionKey' ] ?. supported )
246
- ) return true ; // Capabilities are supported
262
+ ( addressCapabilities [ chainId ] [ "atomicBatch" ] ?. supported ||
263
+ addressCapabilities [ chainId ] [ "paymasterService" ] ?. supported ||
264
+ addressCapabilities [ chainId ] [ "sessionKey" ] ?. supported )
265
+ )
266
+ return true ; // Capabilities are supported
247
267
return false ; // Capabilities are not supported or not defined
248
- }
268
+ } ;
249
269
250
270
const getCosmosActions = ( ) : AccountAction [ ] => {
251
271
const onSignDirect = async ( chainId : string , address : string ) => {
@@ -447,11 +467,11 @@ const Home: NextPage = () => {
447
467
] ;
448
468
} ;
449
469
450
- const getBlockchainActions = ( account :string ) => {
470
+ const getBlockchainActions = ( account : string ) => {
451
471
const [ namespace , chainId , address ] = account . split ( ":" ) ;
452
472
switch ( namespace ) {
453
473
case "eip155" :
454
- return getEthereumActions ( chainId , address ) ;
474
+ return getEthereumActions ( chainId , address ) ;
455
475
case "cosmos" :
456
476
return getCosmosActions ( ) ;
457
477
case "solana" :
@@ -503,7 +523,12 @@ const Home: NextPage = () => {
503
523
case "ping" :
504
524
return < PingModal pending = { isRpcRequestPending } result = { rpcResult } /> ;
505
525
case "requestLoader" :
506
- return < RequestLoaderModal pending = { isRpcRequestPending } result = { rpcResult } /> ;
526
+ return (
527
+ < RequestLoaderModal
528
+ pending = { isRpcRequestPending }
529
+ result = { rpcResult }
530
+ />
531
+ ) ;
507
532
case "disconnect" :
508
533
return < LoaderModal title = { "Disconnecting..." } /> ;
509
534
default :
0 commit comments