Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
},
"packages/assets-controllers/src/TokenListController.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will fix the lint complaining about --prune-suppressions paratmeter, but when we put that parameter to run yarn lint it still complain. the only way is to change the count here to pass the error, if your guys know some better way to fix this issue, i am happy to change it back here.

"count": 1
},
"no-restricted-syntax": {
"count": 7
Expand Down
11 changes: 8 additions & 3 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
const tokensWithBalance: Token[] = [];
const eventTokensDetails: string[] = [];
for (const nonZeroTokenAddress of Object.keys(balances)) {
const { decimals, symbol, aggregators, iconUrl, name } =
const { decimals, symbol, aggregators, iconUrl, name, rwaData } =
this.#tokensChainsCache[chainId].data[nonZeroTokenAddress];
eventTokensDetails.push(`${symbol} - ${nonZeroTokenAddress}`);
tokensWithBalance.push({
Expand All @@ -763,6 +763,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
image: iconUrl,
isERC721: false,
name,
...(rwaData && { rwaData }),
});
}

Expand Down Expand Up @@ -843,7 +844,8 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
continue;
}

const { decimals, symbol, aggregators, iconUrl, name } = tokenData;
const { decimals, symbol, aggregators, iconUrl, name, rwaData } =
tokenData;

// Push to lists with checksummed address (for allTokens storage)
eventTokensDetails.push(`${symbol} - ${checksummedTokenAddress}`);
Expand All @@ -855,6 +857,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
image: iconUrl,
isERC721: false,
name,
...(rwaData && { rwaData }),
});
}

Expand Down Expand Up @@ -964,7 +967,8 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
continue;
}

const { decimals, symbol, aggregators, iconUrl, name } = tokenData;
const { decimals, symbol, aggregators, iconUrl, name, rwaData } =
tokenData;

eventTokensDetails.push(`${symbol} - ${checksummedTokenAddress}`);
tokensWithBalance.push({
Expand All @@ -975,6 +979,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
image: iconUrl,
isERC721: false,
name,
...(rwaData && { rwaData }),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1366,5 +1366,5 @@ describe('TokenListController', () => {
function getTokensPath(chainId: Hex) {
return `/tokens/${convertHexToDecimal(
chainId,
)}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`;
)}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`;
}
24 changes: 19 additions & 5 deletions packages/assets-controllers/src/TokenListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export type TokenListToken = {
occurrences: number;
aggregators: string[];
iconUrl: string;
rwaData?: {
instrumentType: string;
ticker: string;
market: {
nextOpen: string;
nextClose: string;
};
nextPause: {
start: string;
end: string;
};
};
};

export type TokenListMap = Record<string, TokenListToken>;
Expand Down Expand Up @@ -189,7 +201,9 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
*
* @param networkControllerState - The updated network controller state.
*/
async #onNetworkControllerStateChange(networkControllerState: NetworkState) {
async #onNetworkControllerStateChange(
networkControllerState: NetworkState,
): Promise<void> {
const selectedNetworkClient = this.messenger.call(
'NetworkController:getNetworkClientById',
networkControllerState.selectedNetworkClientId,
Expand All @@ -214,7 +228,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
* @deprecated This method is deprecated and will be removed in the future.
* Consider using the new polling approach instead
*/
async start() {
async start(): Promise<void> {
if (!isTokenListSupportedForNetwork(this.chainId)) {
return;
}
Expand All @@ -227,7 +241,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
* @deprecated This method is deprecated and will be removed in the future.
* Consider using the new polling approach instead
*/
async restart() {
async restart(): Promise<void> {
this.stopPolling();
await this.#startDeprecatedPolling();
}
Expand All @@ -238,7 +252,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
* @deprecated This method is deprecated and will be removed in the future.
* Consider using the new polling approach instead
*/
stop() {
stop(): void {
this.stopPolling();
}

Expand All @@ -248,7 +262,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
* @deprecated This method is deprecated and will be removed in the future.
* Consider using the new polling approach instead
*/
override destroy() {
override destroy(): void {
super.destroy();
this.stopPolling();
}
Expand Down
12 changes: 12 additions & 0 deletions packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ export type Token = {
hasBalanceError?: boolean;
isERC721?: boolean;
name?: string;
rwaData?: {
instrumentType: string;
ticker: string;
market: {
nextOpen: string;
nextClose: string;
};
nextPause: {
start: string;
end: string;
};
};
};

const DEFAULT_INTERVAL = 180000;
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ describe('TokensController', () => {
.get(
`/token/${convertHexToDecimal(
chainId,
)}?address=${dummyTokenAddress}`,
)}?address=${dummyTokenAddress}&includeRwaData=true`,
)
.reply(200, { error })
.persist();
Expand Down
6 changes: 5 additions & 1 deletion packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ export class TokensController extends BaseController<
isERC721,
aggregators: formatAggregatorNames(tokenMetadata?.aggregators || []),
name,
...(tokenMetadata?.rwaData && { rwaData: tokenMetadata.rwaData }),
};
const previousIndex = newTokens.findIndex(
(token) => token.address.toLowerCase() === address.toLowerCase(),
Expand Down Expand Up @@ -525,7 +526,7 @@ export class TokensController extends BaseController<
}, {});
try {
tokensToImport.forEach((tokenToAdd) => {
const { address, symbol, decimals, image, aggregators, name } =
const { address, symbol, decimals, image, aggregators, name, rwaData } =
tokenToAdd;
const checksumAddress = toChecksumHexAddress(address);
const formattedToken: Token = {
Expand All @@ -535,6 +536,7 @@ export class TokensController extends BaseController<
image,
aggregators,
name,
...(rwaData && { rwaData }),
};
newTokensMap[checksumAddress] = formattedToken;
importedTokensMap[address.toLowerCase()] = true;
Expand Down Expand Up @@ -664,6 +666,7 @@ export class TokensController extends BaseController<
aggregators,
isERC721,
name,
rwaData,
} = tokenToAdd;
const checksumAddress = toChecksumHexAddress(address);
const newEntry: Token = {
Expand All @@ -674,6 +677,7 @@ export class TokensController extends BaseController<
isERC721,
aggregators,
name,
...(rwaData && { rwaData }),
};

const previousImportedIndex = newTokens.findIndex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { NetworkState } from '@metamask/network-controller';
import { hexToBigInt, parseCaipAssetType } from '@metamask/utils';
import type { Hex } from '@metamask/utils';
import { createSelector, weakMapMemoize } from 'reselect';
import { TokenRwaData } from 'src/token-service';

import {
parseBalanceWithDecimals,
Expand Down Expand Up @@ -84,6 +85,7 @@ export type Asset = (
conversionRate: number;
}
| undefined;
rwaData?: TokenRwaData;
};

export type AssetListState = {
Expand Down
Loading
Loading