-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite): show zero balance tokens (#13572)
- Loading branch information
1 parent
9f2a159
commit 29a03df
Showing
14 changed files
with
801 additions
and
529 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
packages/suite/src/utils/wallet/__fixtures__/tokenUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { EnhancedTokenInfo, TokenDefinition } from '@suite-common/token-definitions'; | ||
import { NetworkSymbol } from '@suite-common/wallet-config'; | ||
|
||
export const getTokensFixtures = [ | ||
{ | ||
testName: 'tokens with definitions and balance', | ||
tokens: [ | ||
{ contract: '0x1', balance: '100' } as EnhancedTokenInfo, | ||
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo, | ||
], | ||
symbol: 'eth' as NetworkSymbol, | ||
coinDefinitions: { | ||
error: false, | ||
isLoading: false, | ||
data: ['0x1', '0x2'], | ||
hide: [], | ||
show: [], | ||
} as TokenDefinition, | ||
searchQuery: '', | ||
result: { | ||
shownWithBalance: [ | ||
{ contract: '0x1', balance: '100' } as EnhancedTokenInfo, | ||
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo, | ||
], | ||
shownWithoutBalance: [], | ||
hiddenWithBalance: [], | ||
hiddenWithoutBalance: [], | ||
unverifiedWithBalance: [], | ||
unverifiedWithoutBalance: [], | ||
}, | ||
}, | ||
{ | ||
testName: 'hidden token with legit tokens', | ||
tokens: [ | ||
{ contract: '0x1', balance: '100' } as EnhancedTokenInfo, | ||
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo, | ||
{ contract: '0x3', balance: '0' } as EnhancedTokenInfo, | ||
], | ||
symbol: 'eth' as NetworkSymbol, | ||
coinDefinitions: { | ||
error: false, | ||
isLoading: false, | ||
data: ['0x1', '0x2', '0x3'], | ||
hide: ['0x2'], | ||
show: [], | ||
} as TokenDefinition, | ||
searchQuery: '', | ||
result: { | ||
shownWithBalance: [{ contract: '0x1', balance: '100' } as EnhancedTokenInfo], | ||
shownWithoutBalance: [{ contract: '0x3', balance: '0' } as EnhancedTokenInfo], | ||
hiddenWithBalance: [{ contract: '0x2', balance: '200' } as EnhancedTokenInfo], | ||
hiddenWithoutBalance: [], | ||
unverifiedWithBalance: [], | ||
unverifiedWithoutBalance: [], | ||
}, | ||
}, | ||
{ | ||
testName: 'unverified tokens with legit token', | ||
tokens: [ | ||
{ contract: '0x1', balance: '100' } as EnhancedTokenInfo, | ||
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo, | ||
{ contract: '0x3', balance: '0' } as EnhancedTokenInfo, | ||
], | ||
symbol: 'eth' as NetworkSymbol, | ||
coinDefinitions: { | ||
error: false, | ||
isLoading: false, | ||
data: ['0x1'], | ||
hide: [], | ||
show: [], | ||
} as TokenDefinition, | ||
searchQuery: '', | ||
result: { | ||
shownWithBalance: [{ contract: '0x1', balance: '100' } as EnhancedTokenInfo], | ||
shownWithoutBalance: [], | ||
hiddenWithBalance: [], | ||
hiddenWithoutBalance: [], | ||
unverifiedWithBalance: [{ contract: '0x2', balance: '200' } as EnhancedTokenInfo], | ||
unverifiedWithoutBalance: [{ contract: '0x3', balance: '0' } as EnhancedTokenInfo], | ||
}, | ||
}, | ||
{ | ||
testName: 'mix of shown, hidden, and unverified tokens', | ||
tokens: [ | ||
{ contract: '0x1', balance: '100' } as EnhancedTokenInfo, | ||
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo, | ||
{ contract: '0x3', balance: '300' } as EnhancedTokenInfo, | ||
{ contract: '0x4', balance: '0' } as EnhancedTokenInfo, | ||
{ contract: '0x5', balance: '0' } as EnhancedTokenInfo, | ||
], | ||
symbol: 'eth' as NetworkSymbol, | ||
coinDefinitions: { | ||
error: false, | ||
isLoading: false, | ||
data: ['0x1', '0x2', '0x3'], | ||
hide: ['0x2'], | ||
show: ['0x3'], | ||
} as TokenDefinition, | ||
searchQuery: '', | ||
result: { | ||
shownWithBalance: [ | ||
{ contract: '0x1', balance: '100' } as EnhancedTokenInfo, | ||
{ contract: '0x3', balance: '300' } as EnhancedTokenInfo, | ||
], | ||
shownWithoutBalance: [], | ||
hiddenWithBalance: [{ contract: '0x2', balance: '200' } as EnhancedTokenInfo], | ||
hiddenWithoutBalance: [], | ||
unverifiedWithBalance: [], | ||
unverifiedWithoutBalance: [ | ||
{ contract: '0x4', balance: '0' } as EnhancedTokenInfo, | ||
{ contract: '0x5', balance: '0' } as EnhancedTokenInfo, | ||
], | ||
}, | ||
}, | ||
{ | ||
testName: 'legitokens search', | ||
tokens: [ | ||
{ contract: '0x1', balance: '100', symbol: 'ABC' } as EnhancedTokenInfo, | ||
{ contract: '0x2', balance: '200', symbol: 'DEF' } as EnhancedTokenInfo, | ||
{ contract: '0x3', balance: '0', symbol: 'GHI' } as EnhancedTokenInfo, | ||
], | ||
symbol: 'eth' as NetworkSymbol, | ||
coinDefinitions: { | ||
error: false, | ||
isLoading: false, | ||
data: ['0x1', '0x2', '0x3'], | ||
hide: [], | ||
show: [], | ||
} as TokenDefinition, | ||
searchQuery: 'AB', | ||
result: { | ||
shownWithBalance: [ | ||
{ contract: '0x1', balance: '100', symbol: 'ABC' } as EnhancedTokenInfo, | ||
], | ||
shownWithoutBalance: [], | ||
hiddenWithBalance: [], | ||
hiddenWithoutBalance: [], | ||
unverifiedWithBalance: [], | ||
unverifiedWithoutBalance: [], | ||
}, | ||
}, | ||
]; |
14 changes: 14 additions & 0 deletions
14
packages/suite/src/utils/wallet/__tests__/tokenUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getTokensFixtures } from '../__fixtures__/tokenUtils'; | ||
import { getTokens } from '../tokenUtils'; | ||
|
||
describe('getTokens', () => { | ||
getTokensFixtures.forEach( | ||
({ testName, tokens, symbol, coinDefinitions, searchQuery, result }) => { | ||
test(testName, () => { | ||
expect(getTokens(tokens, symbol, coinDefinitions, searchQuery)).toStrictEqual( | ||
result, | ||
); | ||
}); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.