Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add RWA data to asset fetching endpoints ([#7548](https://github.com/MetaMask/core/pull/7548))
- Add Rootstock (0x1e) mapping to eip155:30/erc20:0x542fda317318ebf1d3deaf76e0b632741a7e677d for RBTC ([#7601](https://github.com/MetaMask/core/pull/7601))

### Changed
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
12 changes: 7 additions & 5 deletions packages/assets-controllers/src/TokenListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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 @@ -216,7 +218,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 @@ -229,7 +231,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 @@ -240,7 +242,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 @@ -250,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
*/
override destroy() {
override destroy(): void {
super.destroy();
this.stopPolling();
}
Expand Down
2 changes: 2 additions & 0 deletions packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { isEqual } from 'lodash';
import { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from './assetsUtil';
import type { AbstractTokenPricesService } from './token-prices-service/abstract-token-prices-service';
import { getNativeTokenAddress } from './token-prices-service/codefi-v2';
import { TokenRwaData } from './token-service';
import type {
TokensControllerGetStateAction,
TokensControllerStateChangeEvent,
Expand Down Expand Up @@ -45,6 +46,7 @@ export type Token = {
hasBalanceError?: boolean;
isERC721?: boolean;
name?: string;
rwaData?: TokenRwaData;
};

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 }),
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm okay so rwaData is also needed on the TokensController? Nice.

};
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 Expand Up @@ -325,6 +327,7 @@ const selectAllEvmAssets = createAssetListSelector(
}
: undefined,
chainId,
...(token.rwaData && { rwaData: token.rwaData }),
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay fair.

});
}
}
Expand Down
Loading
Loading