Skip to content

Commit 57bb0e5

Browse files
committed
Fix linting problems
1 parent e2585f1 commit 57bb0e5

23 files changed

Lines changed: 119 additions & 100 deletions

File tree

packages/gator-permissions-snap/images/networks/not-found.svg

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/gator-permissions-snap/images/tokens/not-found.svg

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/gator-permissions-snap/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snap-7715-permissions.git"
88
},
99
"source": {
10-
"shasum": "k3y7TRsPdHuDrL9r1SbxdLYSK2tdbbWT0C4xdUa2EhU=",
10+
"shasum": "m4LWlKnvQMfH2OgdfZzvNn7L97UX+7pyHXCd7C0TRlA=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/gator-permissions-snap/src/accountController/baseAccountController.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { logger } from '@metamask/7715-permissions-shared/utils';
22
import { CHAIN_ID as ChainsWithDelegatorDeployed } from '@metamask/delegation-toolkit';
33
import type { SnapsProvider } from '@metamask/snaps-sdk';
4-
import * as chains from 'viem/chains';
54
import type { Address } from 'viem';
5+
import * as chains from 'viem/chains';
66

77
import type { AccountApiClient } from '../clients/accountApiClient';
88
import type {
@@ -183,18 +183,19 @@ export abstract class BaseAccountController {
183183
* Gets the appropriate token metadata client for the given chain ID.
184184
* Uses the account API client for mainnet (chain ID 1) and the blockchain client for other chains.
185185
*
186-
* @param params - The parameters object
187-
* @param params.chainId - The chain ID to get the client for
188-
* @returns The appropriate token metadata client
186+
* @param config - The configuration object.
187+
* @param config.chainId - The chain ID to get the client for.
188+
* @returns The appropriate token metadata client.
189189
*/
190-
#getTokenMetadataClientForChainId({
191-
chainId,
192-
}: {
190+
#getTokenMetadataClientForChainId(config: {
193191
chainId: number;
194192
}): TokenMetadataClient {
195-
if (this.#accountApiClient.isChainIdSupported({ chainId })) {
193+
console.log('getTokenMetadataClientForChainId', config);
194+
if (this.#accountApiClient.isChainIdSupported(config)) {
195+
console.log('Returning account api client', config);
196196
return this.#accountApiClient;
197197
}
198+
console.log('Returning tokenMetadataClient');
198199

199200
return this.#tokenMetadataClient;
200201
}

packages/gator-permissions-snap/src/accountController/eoaAccountController.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import {
55
type DeleGatorEnvironment,
66
} from '@metamask/delegation-toolkit';
77
import type { SnapsEthereumProvider, SnapsProvider } from '@metamask/snaps-sdk';
8-
import { Hex, type Address } from 'viem';
8+
import type { Hex } from 'viem';
9+
import { type Address } from 'viem';
910

10-
import { AccountApiClient } from '../clients/accountApiClient';
11+
import type { AccountApiClient } from '../clients/accountApiClient';
12+
import type { TokenMetadataClient } from '../core/types';
1113
import type { SupportedChains } from './baseAccountController';
1214
import { BaseAccountController } from './baseAccountController';
1315
import type {
@@ -16,7 +18,6 @@ import type {
1618
SignDelegationOptions,
1719
FactoryArgs,
1820
} from './types';
19-
import type { TokenMetadataClient } from '../core/types';
2021

2122
/**
2223
* Controls EOA account operations including address retrieval, delegation signing, and balance queries.
@@ -36,6 +37,7 @@ export class EoaAccountController
3637
* @param config.ethereumProvider - The provider for interacting with Ethereum.
3738
* @param config.supportedChains - Optional list of supported blockchain chains.
3839
* @param config.accountApiClient - The client for interacting with the account API.
40+
* @param config.tokenMetadataClient - The client for interacting with the token metadata.
3941
*/
4042
constructor(config: {
4143
snapsProvider: SnapsProvider;

packages/gator-permissions-snap/src/accountController/smartAccountController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type MetaMaskSmartAccount,
88
} from '@metamask/delegation-toolkit';
99
import type { SnapsProvider } from '@metamask/snaps-sdk';
10+
import type { TokenMetadataClient } from 'src/core/types';
1011
import {
1112
createClient,
1213
custom,
@@ -16,7 +17,7 @@ import {
1617
} from 'viem';
1718
import { privateKeyToAccount } from 'viem/accounts';
1819

19-
import { AccountApiClient } from '../clients/accountApiClient';
20+
import type { AccountApiClient } from '../clients/accountApiClient';
2021
import type { SupportedChains } from './baseAccountController';
2122
import { BaseAccountController } from './baseAccountController';
2223
import type {
@@ -25,7 +26,6 @@ import type {
2526
SignDelegationOptions,
2627
FactoryArgs,
2728
} from './types';
28-
import { TokenMetadataClient } from 'src/core/types';
2929

3030
const GET_ENTROPY_SALT = '7715_permissions_provider_snap';
3131
const MULTISIG_THRESHOLD = 1n;
@@ -56,6 +56,7 @@ export class SmartAccountController
5656
* @param config.supportedChains - The supported blockchain chains.
5757
* @param config.deploymentSalt - The hex salt for smart account deployment.
5858
* @param config.accountApiClient - The client for interacting with the account API.
59+
* @param config.tokenMetadataClient - The client for interacting with the token metadata.
5960
*/
6061
constructor(config: {
6162
snapsProvider: SnapsProvider;

packages/gator-permissions-snap/src/accountController/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
DeleGatorEnvironment,
44
} from '@metamask/delegation-toolkit';
55
import type { Address, Hex } from 'viem';
6+
67
import type { TokenBalanceAndMetadata } from '../core/types';
78

89
/**

packages/gator-permissions-snap/src/clients/accountApiClient.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { logger } from '@metamask/7715-permissions-shared/utils';
22
import { isAddressEqual, zeroAddress, type Address } from 'viem';
3+
34
import type { TokenBalanceAndMetadata } from '../core/types';
45

56
/**
@@ -53,9 +54,9 @@ export class AccountApiClient {
5354
* Checks if a chain ID is supported by the account API.
5455
* Currently only mainnet (chain ID 1) is supported.
5556
*
56-
* @param params - The parameters object
57-
* @param params.chainId - The chain ID to check
58-
* @returns True if the chain ID is supported, false otherwise
57+
* @param params - The parameters object.
58+
* @param params.chainId - The chain ID to check.
59+
* @returns True if the chain ID is supported, false otherwise.
5960
*/
6061
public isChainIdSupported({ chainId }: { chainId: number }): boolean {
6162
return chainId === 1;
@@ -64,11 +65,11 @@ export class AccountApiClient {
6465
/**
6566
* Fetch the token balance and metadata for a given account and token.
6667
*
67-
* @param params - The parameters for fetching the token balance
68-
* @param params.chainId - The chain ID to fetch the balance from
69-
* @param params.assetAddress - The token address to fetch the balance for. If not provided, fetches native token balance
70-
* @param params.account - The account address to fetch the balance for
71-
* @returns The token balance and metadata
68+
* @param params - The parameters for fetching the token balance.
69+
* @param params.chainId - The chain ID to fetch the balance from.
70+
* @param params.assetAddress - The token address to fetch the balance for. If not provided, fetches native token balance.
71+
* @param params.account - The account address to fetch the balance for.
72+
* @returns The token balance and metadata.
7273
*/
7374
public async getTokenBalanceAndMetadata({
7475
chainId,
@@ -79,18 +80,15 @@ export class AccountApiClient {
7980
account: Address;
8081
assetAddress?: Address | undefined;
8182
}): Promise<TokenBalanceAndMetadata> {
82-
console.log('getTokenBalanceAndMetadata', chainId, assetAddress, account);
8383
if (!chainId) {
8484
const message = 'No chainId provided to fetch token balance';
85-
console.log(message);
8685
logger.error(message);
8786

8887
throw new Error(message);
8988
}
9089

9190
if (!account) {
9291
const message = 'No account address provided to fetch token balance';
93-
console.log(message);
9492
logger.error(message);
9593

9694
throw new Error(message);
@@ -99,12 +97,8 @@ export class AccountApiClient {
9997
// zeroAddress is the native token on the specified chain
10098
const tokenAddress = assetAddress ?? zeroAddress;
10199

102-
console.log(
103-
`${this.#baseUrl}/tokens/${tokenAddress}?accountAddresses=${account}&chainId=${1}`,
104-
);
105-
// todo: chainId is hardcoded to mainnet, because the account api does not support sepolia.
106100
const response = await this.#fetch(
107-
`${this.#baseUrl}/tokens/${tokenAddress}?accountAddresses=${account}&chainId=${1}`,
101+
`${this.#baseUrl}/tokens/${tokenAddress}?accountAddresses=${account}&chainId=${chainId}`,
108102
);
109103

110104
if (!response.ok) {
@@ -127,9 +121,7 @@ export class AccountApiClient {
127121
throw new Error(message);
128122
}
129123

130-
if (
131-
AccountApiClient.#supportedTokenTypes.indexOf(balanceData.type) === -1
132-
) {
124+
if (!AccountApiClient.#supportedTokenTypes.includes(balanceData.type)) {
133125
const message = `Unsupported token type: ${balanceData.type}`;
134126
logger.error(message);
135127

packages/gator-permissions-snap/src/clients/tokenMetadataClient.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { logger } from '@metamask/7715-permissions-shared/utils';
2-
import type {
3-
TokenMetadataClient,
4-
TokenBalanceAndMetadata,
5-
} from '../core/types';
2+
import type { SnapsEthereumProvider } from '@metamask/snaps-sdk';
63
import type { AbiFunction, AbiParameter, Address, Hex } from 'viem';
74
import {
85
decodeAbiParameters,
@@ -11,7 +8,11 @@ import {
118
zeroAddress,
129
} from 'viem';
1310
import { sepolia, mainnet } from 'viem/chains';
14-
import { SnapsEthereumProvider } from '@metamask/snaps-sdk';
11+
12+
import type {
13+
TokenMetadataClient,
14+
TokenBalanceAndMetadata,
15+
} from '../core/types';
1516

1617
const BALANCEOF_ABI: AbiFunction = {
1718
constant: true,
@@ -59,11 +60,11 @@ export class BlockchainTokenMetadataClient implements TokenMetadataClient {
5960
/**
6061
* Fetch the token balance and metadata for a given account and token.
6162
*
62-
* @param params - The parameters for fetching the token balance
63-
* @param params.chainId - The chain ID to fetch the balance from
64-
* @param params.assetAddress - The token address to fetch the balance for. If not provided, fetches native token balance
65-
* @param params.account - The account address to fetch the balance for
66-
* @returns The token balance and metadata
63+
* @param args - The parameters for fetching the token balance.
64+
* @param args.chainId - The chain ID to fetch the balance from.
65+
* @param args.assetAddress - The token address to fetch the balance for. If not provided, fetches native token balance.
66+
* @param args.account - The account address to fetch the balance for.
67+
* @returns The token balance and metadata.
6768
*/
6869
public async getTokenBalanceAndMetadata({
6970
chainId,

packages/gator-permissions-snap/src/core/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export type TokenBalanceAndMetadata = {
318318
/**
319319
* Interface for token metadata clients that can fetch token balance and metadata
320320
*/
321-
export interface TokenMetadataClient {
321+
export type TokenMetadataClient = {
322322
/**
323323
* Fetch the token balance and metadata for a given account and token.
324324
*
@@ -333,4 +333,4 @@ export interface TokenMetadataClient {
333333
account: Address;
334334
assetAddress?: Address | undefined;
335335
}): Promise<TokenBalanceAndMetadata>;
336-
}
336+
};

0 commit comments

Comments
 (0)