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

[Token Detection V2] 6 of 7 - Introduce Detected Tokens #808

Merged
merged 52 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a9a7e32
Introduce detected tokens and update other relevant controllers.
Cal-L Apr 27, 2022
7342d78
Update preferences controller with useTokenDetection
Cal-L Apr 27, 2022
be42418
Set token detection to be true by default
Cal-L Apr 27, 2022
bf95ef9
Merge branch 'main' of https://github.com/MetaMask/controllers into t…
Cal-L May 17, 2022
6ad5496
Fix linting issues
Cal-L May 18, 2022
373de69
Fix ComposableController test
Cal-L Apr 27, 2022
76e45b0
Update ComposableController test
Cal-L May 18, 2022
032bc17
Use named export with AbortController
Cal-L May 18, 2022
0e0645a
Remove typecasting as any on error
Cal-L May 18, 2022
70bb6d0
Reintroduce override keyword. Remove typecast any on error.
Cal-L May 20, 2022
a692352
Clean up token list messenger in token detection controller.
Cal-L May 20, 2022
dd1a80d
Refine token detection tests
Cal-L May 20, 2022
1e81923
Remove unnecessary abort controller from TokenDetectionController
Cal-L May 20, 2022
b37ed9c
Change importTokens back to addTokens. Rename hex to decimal util fun…
Cal-L May 23, 2022
b1ff426
Merge branch 'main' of https://github.com/MetaMask/controllers into t…
Cal-L May 24, 2022
ebfaf6f
Remove redundant comment
Cal-L May 25, 2022
254b64f
Do not mutate token states directly on TokensController. Update fetch…
Cal-L May 25, 2022
5a1ee26
Remove check for hexadecimal chainId on TokensController
Cal-L May 27, 2022
f7b1a1e
Rename isTokenDetectionEnabledForNetwork to isTokenDetectionSupported…
Cal-L May 27, 2022
ef37fac
Throw error for fetchTokenMetadata when fetching from non supported n…
Cal-L May 27, 2022
c4d92a0
Update imports on TokenListController
Cal-L May 27, 2022
518afff
Make fetchTokenMetadata on TokensController private. Only return null…
Cal-L May 27, 2022
e0de5fb
Update TokenDetectionController import + clean up tests.
Cal-L May 27, 2022
638eead
Add TokensController test for switching networks while adding token
Cal-L May 28, 2022
f8b3e62
Clean up token service tests
Cal-L May 28, 2022
198cd87
Fix linting
Cal-L May 28, 2022
dc5fefa
Return undefined instead of throwing for token metadata when no respo…
Cal-L May 29, 2022
b42cb15
Merge branch 'main' of https://github.com/MetaMask/controllers into t…
Cal-L May 29, 2022
97a5438
Fix TokensController test
Cal-L May 29, 2022
73f67cf
Make token detection restart method private
Cal-L May 31, 2022
fc120f8
Remove unused networkType from TokenDetectionController
Cal-L May 31, 2022
0c5e0fe
Populate tokens with image property, which uses proxied url
Cal-L May 31, 2022
ff1b944
Remove removeAndIgnore method from TokensController. Update TokensCon…
Cal-L May 31, 2022
f934a6c
Update fetchTokenMetadata @returns doc
Cal-L Jun 1, 2022
a08717d
Update TokenListMessenger type
Cal-L Jun 1, 2022
85fe537
Test onTokensStateChange after introducing detected tokens for TokenR…
Cal-L Jun 1, 2022
d95bf6f
Test onTokensStateChange for detected tokens on TokenBalancesController
Cal-L Jun 1, 2022
d0d9005
Clean up addToken doc
Cal-L Jun 2, 2022
3455b91
Update TokenDetectionController to respect disable property from config
Cal-L Jun 2, 2022
ba10f37
Fix TokensController tes
Cal-L Jun 2, 2022
73a07d2
Merge branch 'main' of https://github.com/MetaMask/controllers into t…
Cal-L Jun 2, 2022
3a17032
Deprecate onTokensStateChange from TokenDetectionController
Cal-L Jun 2, 2022
94c6777
Fix formatting proxy token images. Re-introduce ability to provide im…
Cal-L Jun 2, 2022
61d91cb
Fix tests
Cal-L Jun 2, 2022
cb6cb9e
Update formatIconUrlWithProxy tokenAddress input to state mixed or lo…
Cal-L Jun 3, 2022
1b0c3ac
Increase test coverage for AssetsContractController
Cal-L Jun 3, 2022
09e484a
Increase branch coverage for AssetsContractController
Cal-L Jun 3, 2022
e6ed4fb
Increase test coverage for TokensController and TokenDetectionController
Cal-L Jun 3, 2022
db23ad6
Merge branch 'main' of https://github.com/MetaMask/controllers into t…
Cal-L Jun 6, 2022
ed74f85
Improve token detection test to check for getBalancesInSingle call
Cal-L Jun 6, 2022
91d5efb
Update comments on TokenDetectionController
Cal-L Jun 6, 2022
629e0c3
Update TokenDetectionController tests to check for getBalancesInSingl…
Cal-L Jun 6, 2022
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
Next Next commit
Introduce detected tokens and update other relevant controllers.
  • Loading branch information
Cal-L committed Apr 27, 2022
commit a9a7e3211c50be3ea0df425621decc83b35df82c
13 changes: 10 additions & 3 deletions src/assets/TokenBalancesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ describe('TokenBalancesController', () => {
getSelectedAddress: () => preferences.state.selectedAddress,
getERC20BalanceOf: sinon.stub().returns(new BN(1)),
},
{ interval: 1337, tokens: [{ address, decimals: 18, symbol: 'EOS' }] },
{
interval: 1337,
tokens: [{ address, decimals: 18, symbol: 'EOS', aggregators: [] }],
},
);
expect(tokenBalances.state.contractBalances).toStrictEqual({});

Expand Down Expand Up @@ -155,7 +158,10 @@ describe('TokenBalancesController', () => {
getSelectedAddress: () => preferences.state.selectedAddress,
getERC20BalanceOf: getERC20BalanceOfStub,
},
{ interval: 1337, tokens: [{ address, decimals: 18, symbol: 'EOS' }] },
{
interval: 1337,
tokens: [{ address, decimals: 18, symbol: 'EOS', aggregators: [] }],
},
);

expect(tokenBalances.state.contractBalances).toStrictEqual({});
Expand All @@ -180,11 +186,12 @@ describe('TokenBalancesController', () => {
});

it('should subscribe to new sibling assets controllers', async () => {
const network = new NetworkController();
const preferences = new PreferencesController();
const assetsContract = new AssetsContractController({
onPreferencesStateChange: (listener) => preferences.subscribe(listener),
onNetworkStateChange: (listener) => network.subscribe(listener),
});
const network = new NetworkController();
const tokensController = new TokensController({
onPreferencesStateChange: (listener) => preferences.subscribe(listener),
onNetworkStateChange: (listener) => network.subscribe(listener),
Expand Down
6 changes: 3 additions & 3 deletions src/assets/TokenBalancesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class TokenBalancesController extends BaseController<
};
this.defaultState = { contractBalances: {} };
this.initialize();
onTokensStateChange(({ tokens }) => {
this.configure({ tokens });
onTokensStateChange(({ tokens, detectedTokens }) => {
this.configure({ tokens: [...tokens, ...detectedTokens] });
this.updateBalances();
});
this.getSelectedAddress = getSelectedAddress;
Expand Down Expand Up @@ -122,7 +122,7 @@ export class TokenBalancesController extends BaseController<
this.getSelectedAddress(),
);
tokens[i].balanceError = null;
} catch (error) {
} catch (error: any) {
newContractBalances[address] = new BN(0);
tokens[i].balanceError = error;
}
Expand Down
Loading