-
-
Notifications
You must be signed in to change notification settings - Fork 273
feat: add rwa data to tokens in tokens controller #7804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
994090c
7378e26
23b6620
d00e8ab
fca7da2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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 | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stale
|
||
| } | ||
| } | ||
| } | ||
|
|
@@ -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({ | ||
|
|
@@ -426,6 +431,7 @@ export class TokensController extends BaseController< | |
| image, | ||
| interactingAddress, | ||
| networkClientId, | ||
| rwaData, | ||
| }: { | ||
| address: string; | ||
| symbol: string; | ||
|
|
@@ -434,6 +440,7 @@ export class TokensController extends BaseController< | |
| image?: string; | ||
| interactingAddress?: string; | ||
| networkClientId: NetworkClientId; | ||
| rwaData?: TokenRwaData; | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }): Promise<Token[]> { | ||
| const releaseLock = await this.#mutex.acquire(); | ||
| const { allTokens, allIgnoredTokens, allDetectedTokens } = this.state; | ||
|
|
@@ -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(), | ||
|
|
@@ -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, | ||
|
|
@@ -995,6 +1002,7 @@ export class TokensController extends BaseController< | |
| image, | ||
| interactingAddress: suggestedAssetMeta.interactingAddress, | ||
| networkClientId, | ||
| rwaData, | ||
| }); | ||
| } | ||
|
|
||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache unconditionally overwrites user-provided
rwaDataunlikenameMedium Severity
The cache propagation logic for
rwaDataunconditionally overwrites existing token data whencachedToken.rwaDataexists, unlike thenamehandling which only updates when!token.name. This means user-providedrwaData(set viawatchAssetoraddToken) will be lost when theTokenListController:stateChangeevent fires with cached data. The conditionif (cachedToken?.rwaData)is missing the!token.rwaDatacheck that would preserve user-provided values.