Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Feb 3, 2025
1 parent 082735b commit 39dad34
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions packages/multichain/src/caip25Permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down
21 changes: 10 additions & 11 deletions packages/multichain/src/handlers/wallet-invokeMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ 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.
* @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.
* @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,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/multichain/src/scope/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
CaipChainId,
type CaipChainId,
hasProperty,
isCaipAccountId,
isCaipChainId,
Expand Down
2 changes: 1 addition & 1 deletion packages/multichain/src/scope/filter.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
10 changes: 5 additions & 5 deletions packages/multichain/src/scope/supported.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
Expand Down Expand Up @@ -404,7 +404,7 @@ describe('Scope Support', () => {
isSupportedAccount('foo:bar:0xdeadbeef', {
getEvmInternalAccounts,
getNonEvmAccountAddresses
}),
})

expect(getNonEvmAccountAddresses).toHaveBeenCalledWith('foo:bar')
});
Expand Down
12 changes: 4 additions & 8 deletions packages/multichain/src/scope/supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
};

/**
Expand Down

0 comments on commit 39dad34

Please sign in to comment.