From 39dad3431a0c27821bcf0a411fd9c50b9164e386 Mon Sep 17 00:00:00 2001 From: Jiexi Luan Date: Mon, 3 Feb 2025 14:45:52 -0800 Subject: [PATCH] lint --- .../caip-permission-adapter-session-scopes.ts | 2 +- packages/multichain/src/caip25Permission.ts | 2 ++ .../src/handlers/wallet-invokeMethod.ts | 21 +++++++++---------- packages/multichain/src/scope/assert.ts | 2 +- packages/multichain/src/scope/filter.ts | 2 +- .../multichain/src/scope/supported.test.ts | 10 ++++----- packages/multichain/src/scope/supported.ts | 12 ++++------- 7 files changed, 24 insertions(+), 27 deletions(-) diff --git a/packages/multichain/src/adapters/caip-permission-adapter-session-scopes.ts b/packages/multichain/src/adapters/caip-permission-adapter-session-scopes.ts index febcb57f3c0..902e84bb0dd 100644 --- a/packages/multichain/src/adapters/caip-permission-adapter-session-scopes.ts +++ b/packages/multichain/src/adapters/caip-permission-adapter-session-scopes.ts @@ -1,4 +1,4 @@ -import { CaipChainId, isCaipChainId, KnownCaipNamespace } from '@metamask/utils'; +import { type CaipChainId, isCaipChainId, KnownCaipNamespace } from '@metamask/utils'; import type { Caip25CaveatValue } from '../caip25Permission'; import { diff --git a/packages/multichain/src/caip25Permission.ts b/packages/multichain/src/caip25Permission.ts index 3da93ee5abf..d8c82cd13c3 100644 --- a/packages/multichain/src/caip25Permission.ts +++ b/packages/multichain/src/caip25Permission.ts @@ -80,6 +80,8 @@ type Caip25EndowmentCaveatSpecificationBuilderOptions = { * @param options - The specification builder options. * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId. * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts. + * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported. + * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope. * @returns The specification for the `caip25` caveat. */ export const caip25CaveatBuilder = ({ diff --git a/packages/multichain/src/handlers/wallet-invokeMethod.ts b/packages/multichain/src/handlers/wallet-invokeMethod.ts index a1187903f3f..603124278f0 100644 --- a/packages/multichain/src/handlers/wallet-invokeMethod.ts +++ b/packages/multichain/src/handlers/wallet-invokeMethod.ts @@ -35,7 +35,7 @@ export type WalletInvokeMethodRequest = JsonRpcRequest & { * and instead uses the singular session for the origin if available. * * @param request - The request object. - * @param _response - The response object. Unused. + * @param response - The response object. Unused. * @param next - The next middleware function. * @param end - The end function. * @param hooks - The hooks object. @@ -43,6 +43,7 @@ export type WalletInvokeMethodRequest = JsonRpcRequest & { * @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId. * @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId. * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope. + * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing. */ async function walletInvokeMethodHandler( request: WalletInvokeMethodRequest, @@ -100,17 +101,15 @@ async function walletInvokeMethodHandler( if (isEvmRequest) { let networkClientId; - switch (namespace) { - case 'wallet': + if (namespace === KnownCaipNamespace.Wallet) { networkClientId = hooks.getSelectedNetworkClientId(); - break; - case 'eip155': - if (reference) { - networkClientId = hooks.findNetworkClientIdByChainId( - numberToHex(parseInt(reference, 10)), - ); - } - break; + } + else if (namespace === KnownCaipNamespace.Eip155) { + if (reference) { + networkClientId = hooks.findNetworkClientIdByChainId( + numberToHex(parseInt(reference, 10)), + ); + } } if (!networkClientId) { diff --git a/packages/multichain/src/scope/assert.ts b/packages/multichain/src/scope/assert.ts index d6b9ec22fa9..7bccb569f1b 100644 --- a/packages/multichain/src/scope/assert.ts +++ b/packages/multichain/src/scope/assert.ts @@ -1,5 +1,5 @@ import { - CaipChainId, + type CaipChainId, hasProperty, isCaipAccountId, isCaipChainId, diff --git a/packages/multichain/src/scope/filter.ts b/packages/multichain/src/scope/filter.ts index 65a9ed72a54..04bd3eef8f5 100644 --- a/packages/multichain/src/scope/filter.ts +++ b/packages/multichain/src/scope/filter.ts @@ -1,4 +1,4 @@ -import { CaipChainId, type Hex } from '@metamask/utils'; +import type { CaipChainId, Hex } from '@metamask/utils'; import { assertIsInternalScopeString, assertScopeSupported } from './assert'; import { isSupportedMethod, isSupportedNotification } from './supported'; diff --git a/packages/multichain/src/scope/supported.test.ts b/packages/multichain/src/scope/supported.test.ts index 25a1e553b70..a0b9e16a7aa 100644 --- a/packages/multichain/src/scope/supported.test.ts +++ b/packages/multichain/src/scope/supported.test.ts @@ -372,10 +372,10 @@ describe('Scope Support', () => { }); it('gets the non-evm account addresses for the scope if wallet namespace with non-evm reference', () => { - isSupportedAccount('wallet:nonevm:0xdeadbeef', { - getEvmInternalAccounts, - getNonEvmAccountAddresses - }), + isSupportedAccount('wallet:nonevm:0xdeadbeef', { + getEvmInternalAccounts, + getNonEvmAccountAddresses + }) expect(getNonEvmAccountAddresses).toHaveBeenCalledWith('wallet:nonevm') }); @@ -404,7 +404,7 @@ describe('Scope Support', () => { isSupportedAccount('foo:bar:0xdeadbeef', { getEvmInternalAccounts, getNonEvmAccountAddresses - }), + }) expect(getNonEvmAccountAddresses).toHaveBeenCalledWith('foo:bar') }); diff --git a/packages/multichain/src/scope/supported.ts b/packages/multichain/src/scope/supported.ts index 3a18aee8497..fd5078a75ab 100644 --- a/packages/multichain/src/scope/supported.ts +++ b/packages/multichain/src/scope/supported.ts @@ -34,9 +34,8 @@ export const isSupportedScopeString = ( case KnownCaipNamespace.Wallet: if (!reference || reference === KnownCaipNamespace.Eip155) { return true - } else { - return isCaipChainId(scopeString) ? isNonEvmScopeSupported(scopeString) : false } + return isCaipChainId(scopeString) ? isNonEvmScopeSupported(scopeString) : false case KnownCaipNamespace.Eip155: return ( !reference || @@ -86,9 +85,8 @@ export const isSupportedAccount = ( case KnownCaipNamespace.Wallet: if(reference === KnownCaipNamespace.Eip155) { return isSupportedEip155Account() - } else { - return isSupportedNonEvmAccount() } + return isSupportedNonEvmAccount() case KnownCaipNamespace.Eip155: return isSupportedEip155Account(); default: @@ -127,17 +125,15 @@ export const isSupportedMethod = ( if (reference) { if (reference === KnownCaipNamespace.Eip155) { return KnownWalletNamespaceRpcMethods[reference].includes(method); - } else { - return isSupportedNonEvmMethod() } + return isSupportedNonEvmMethod() } return KnownWalletRpcMethods.includes(method); } else if ( namespace === KnownCaipNamespace.Eip155) { return KnownRpcMethods[namespace].includes(method); - } else { - return isSupportedNonEvmMethod() } + return isSupportedNonEvmMethod() }; /**