Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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 optional `rwaData` support when adding tokens in `TokensController` ([#7804](https://github.com/MetaMask/core/pull/7804)).
- Add `HYPEREVM` support ([#7790](https://github.com/MetaMask/core/pull/7790))
- Add `HYPEREVM` in `SupportedTokenDetectionNetworks`
- Add `HYPEREVM` in `SUPPORTED_NETWORKS_ACCOUNTS_API_V4`
Expand Down
3 changes: 3 additions & 0 deletions packages/assets-controllers/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ module.exports = merge(baseConfig, {

// We rely on `window` to make requests
testEnvironment: '<rootDir>/jest.environment.js',

// Watchman isn't available in some environments (e.g. sandboxed CI/containers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should this be in its own PR? It doesn't seem to be related to the changes here and might get buried. It would also be good to understand what you were doing when you encountered the problem that this fixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just codex that added this, good catch, will get rid of it :)

watchman: false,
});
12 changes: 10 additions & 2 deletions packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { ERC1155Standard } from './Standards/NftStandards/ERC1155/ERC1155Standar
import {
fetchTokenMetadata,
TOKEN_METADATA_NO_SUPPORT_ERROR,
TokenRwaData,
} from './token-service';
import type {
TokenListStateChange,
Expand Down Expand Up @@ -288,6 +289,9 @@ export class TokensController extends BaseController<
if (cachedToken && cachedToken.name && !token.name) {
token.name = cachedToken.name; // Update the token name
}
if (cachedToken?.rwaData) {
token.rwaData = cachedToken.rwaData; // Update the token RWA data
}
}
}
}
Expand Down Expand Up @@ -416,6 +420,7 @@ export class TokensController extends BaseController<
* @param options.image - Image of the token.
* @param options.interactingAddress - The address of the account to add a token to.
* @param options.networkClientId - Network Client ID.
* @param options.rwaData - Optional RWA data for the token.
* @returns Current token list.
*/
async addToken({
Expand All @@ -426,6 +431,7 @@ export class TokensController extends BaseController<
image,
interactingAddress,
networkClientId,
rwaData,
}: {
address: string;
symbol: string;
Expand All @@ -434,6 +440,7 @@ export class TokensController extends BaseController<
image?: string;
interactingAddress?: string;
networkClientId: NetworkClientId;
rwaData?: TokenRwaData;
}): Promise<Token[]> {
const releaseLock = await this.#mutex.acquire();
const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state;
Expand Down Expand Up @@ -473,7 +480,7 @@ export class TokensController extends BaseController<
isERC721,
aggregators: formatAggregatorNames(tokenMetadata?.aggregators ?? []),
name,
...(tokenMetadata?.rwaData && { rwaData: tokenMetadata.rwaData }),
...(rwaData !== undefined && { rwaData }),
};
const previousIndex = newTokens.findIndex(
(token) => token.address.toLowerCase() === address.toLowerCase(),
Expand Down Expand Up @@ -986,7 +993,7 @@ export class TokensController extends BaseController<

await this.#requestApproval(suggestedAssetMeta);

const { address, symbol, decimals, name, image } = asset;
const { address, symbol, decimals, name, image, rwaData } = asset;
await this.addToken({
address,
symbol,
Expand All @@ -995,6 +1002,7 @@ export class TokensController extends BaseController<
image,
interactingAddress: suggestedAssetMeta.interactingAddress,
networkClientId,
rwaData,
});
}

Expand Down