Skip to content

Commit

Permalink
Fix typing, excess properties from legacy token list
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Feb 20, 2024
1 parent c5709b8 commit ea4c5b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
11 changes: 3 additions & 8 deletions packages/assets-controllers/src/TokenDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1845,17 +1845,12 @@ describe('TokenDetectionController', () => {
expect(callActionSpy).toHaveBeenLastCalledWith(
'TokensController:addDetectedTokens',
Object.values(STATIC_MAINNET_TOKEN_LIST).map((token) => {
const newToken = {
...token,
const { iconUrl, ...tokenMetadata } = token;
return {
...tokenMetadata,
image: token.iconUrl,
isERC721: false,
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (newToken as any).erc20;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (newToken as any).erc721;
delete newToken.iconUrl;
return newToken;
}),
{
selectedAddress,
Expand Down
26 changes: 13 additions & 13 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import type { AssetsContractController } from './AssetsContractController';
import { isTokenDetectionSupportedForNetwork } from './assetsUtil';
import type {
GetTokenListState,
TokenListMap,
TokenListStateChange,
TokenListToken,
} from './TokenListController';
import type { Token } from './TokenRatesController';
import type {
Expand Down Expand Up @@ -63,25 +63,23 @@ export function isEqualCaseInsensitive(
return value1.toLowerCase() === value2.toLowerCase();
}

type LegacyToken = Omit<
Token,
'aggregators' | 'image' | 'balanceError' | 'isERC721'
> & {
type LegacyToken = {
name: string;
logo: string;
logo: `${string}.svg`;
symbol: string;
decimals: number;
erc20?: boolean;
erc721?: boolean;
};

type TokenDetectionMap = {
[P in keyof TokenListMap]: Omit<TokenListMap[P], 'occurrences'>;
};

export const STATIC_MAINNET_TOKEN_LIST = Object.entries<LegacyToken>(
contractMap,
).reduce<
Record<
string,
Partial<TokenListToken> & Pick<Token, 'address' | 'symbol' | 'decimals'>
>
>((acc, [base, contract]) => {
const { logo, ...tokenMetadata } = contract;
).reduce<TokenDetectionMap>((acc, [base, contract]) => {
const { logo, erc20, erc721, ...tokenMetadata } = contract;
return {
...acc,
[base.toLowerCase()]: {
Expand Down Expand Up @@ -168,6 +166,8 @@ export class TokenDetectionController extends StaticIntervalPollingController<

#networkClientIdAgainstWhichToDetect: NetworkClientId;

#tokenList: TokenDetectionMap = {};

#disabled: boolean;

#isUnlocked: boolean;
Expand Down

0 comments on commit ea4c5b8

Please sign in to comment.