Skip to content
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

DetectedTokens getting reloaded from allDetectedTokens even after the tokens are imported for a chain and selectedAddress #1015

Merged
merged 6 commits into from
Dec 16, 2022
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
17 changes: 16 additions & 1 deletion packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,14 +756,14 @@ describe('TokensController', () => {
[DETECTED_CHAINID]: {
[DETECTED_ADDRESS]: [detectedToken],
},
'4': { '0xabc': [] },
});

expect(tokensController.state.allTokens).toStrictEqual({
[NetworksChainId[CONFIGURED_NETWORK]]: {
[CONFIGURED_ADDRESS]: [directlyAddedToken],
},
});

stub.restore();
});
});
Expand Down Expand Up @@ -852,6 +852,21 @@ describe('TokensController', () => {
).toStrictEqual(dummyTokens);
});

it('should nest detectedTokens under chain ID and selected address when detectedTokens provided is an empty list', () => {
tokensController.configure({
selectedAddress: dummySelectedAddress,
chainId: NetworksChainId.mainnet,
});
const processedTokens = tokensController._getNewAllTokensState({
newDetectedTokens: [],
});
expect(
processedTokens.newAllDetectedTokens[NetworksChainId.mainnet][
dummySelectedAddress
],
).toStrictEqual([]);
});

it('should nest ignoredTokens under chain ID and selected address when provided with ignoredTokens as input', () => {
tokensController.configure({
selectedAddress: dummySelectedAddress,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ export class TokensController extends BaseController<
}

let newAllDetectedTokens = allDetectedTokens;
if (newDetectedTokens?.length) {
if (newDetectedTokens !== undefined) {
NiranjanaBinoy marked this conversation as resolved.
Show resolved Hide resolved
const networkDetectedTokens = allDetectedTokens[chainIdToAddTokens];
const newDetectedNetworkTokens = {
...networkDetectedTokens,
Expand Down