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

feat: Sort/Import Tokens in Extension #27184

Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
da7a49d
Convert js files to ts
gambinish Sep 5, 2024
ede7e00
Update to non-deprecated modal
gambinish Sep 5, 2024
7d8aee9
Update snapshots
gambinish Sep 5, 2024
24026bc
Use types instead of interfaces
gambinish Sep 5, 2024
b787923
Prefer object destructuring
gambinish Sep 5, 2024
168b32e
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 5, 2024
2e688f2
Init sortAssets logic
gambinish Sep 5, 2024
159622c
Working
gambinish Sep 6, 2024
3052a92
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 6, 2024
a902a3f
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 6, 2024
094fecb
Merge branch 'feat/mmassets-356_sort-import-tokens-extension' of gith…
gambinish Sep 6, 2024
e348b10
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 9, 2024
5055394
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 10, 2024
95881ef
Temporary fix to sorting logic
gambinish Sep 10, 2024
d424655
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 10, 2024
3a7c669
Merge branch 'feat/mmassets-356_sort-import-tokens-extension' of gith…
gambinish Sep 10, 2024
6fad3b2
Init dropdown styles
gambinish Sep 11, 2024
b7d6e47
Init css for SelectableListItem
gambinish Sep 11, 2024
0d7c10e
Polish controlbar styles
gambinish Sep 11, 2024
313af19
Cleanup
gambinish Sep 11, 2024
4a45990
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 12, 2024
43d3c3b
Merge branch 'feat/mmassets-356_sort-import-tokens-extension' of gith…
gambinish Sep 12, 2024
0f7b5ac
Use tsignore for string variable in token-cell
gambinish Sep 12, 2024
41f528a
Remove unecessary ts-ignores, and unskip unit tests
gambinish Sep 12, 2024
6dd32e4
Merge main, address conflicts in asset-list.tsx
gambinish Sep 12, 2024
5c5b22e
Update snapshots
gambinish Sep 12, 2024
aeee661
Remove foo
gambinish Sep 13, 2024
0c93057
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 13, 2024
2bdb02f
Convert asset-list.test to ts
gambinish Sep 13, 2024
692001c
Update token-cell tests to ts
gambinish Sep 13, 2024
0aab9fc
Lint
gambinish Sep 13, 2024
431583b
Update snapshots
gambinish Sep 13, 2024
46b557c
Merge feat/mmassets-356_sort-import-tokens-extension, address conflicts
gambinish Sep 13, 2024
9f6a228
Begin linting ts
gambinish Sep 13, 2024
0ea31d0
Add refinements to sorting logic
gambinish Sep 13, 2024
94d0dd8
Cleanup mocks
gambinish Sep 13, 2024
66d9da1
Init native token inclusion
gambinish Sep 16, 2024
e4179b1
Include native token in sorting logic
gambinish Sep 16, 2024
3512d69
Address merge conflicts
gambinish Sep 16, 2024
34b8c62
Fix merge conflict
gambinish Sep 16, 2024
8dd7e75
Lint
gambinish Sep 16, 2024
7d35d44
More linting
gambinish Sep 16, 2024
3647fdf
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 16, 2024
24becef
More liting to fix e2e
gambinish Sep 16, 2024
c51d4bb
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--ui' of …
gambinish Sep 16, 2024
70cb82d
Unskip test
gambinish Sep 16, 2024
4b1c44c
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 16, 2024
13ee970
Allow undefined value for Native balance while fetching
gambinish Sep 16, 2024
d8815a2
Add tokenSortCriteria to appState
gambinish Sep 16, 2024
91cb3c6
setTokenSortConfig works
gambinish Sep 17, 2024
663e0ae
Subscribe to tokenSortConfig to sort assets
gambinish Sep 17, 2024
77b9515
Sort order persisting, need to include nativeToken
gambinish Sep 17, 2024
a9d4bd3
Fully functional
gambinish Sep 17, 2024
c8b4526
Clean up hooks logic computation into utility files
gambinish Sep 17, 2024
9e3961e
Cleanup
gambinish Sep 17, 2024
6f64365
Cleanup
gambinish Sep 17, 2024
b12fb4a
Fix lint errors
gambinish Sep 17, 2024
48ca7f9
Move useNativeTokenBalance outside of mmi codefence
gambinish Sep 17, 2024
45fb807
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--ui' int…
gambinish Sep 17, 2024
8ee6bd0
Move components out of mmi code fence
gambinish Sep 17, 2024
6b3e580
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--persist…
gambinish Sep 17, 2024
8d8baca
Cleanup loader
gambinish Sep 17, 2024
85337c2
Remove uneeded ducks changes
gambinish Sep 17, 2024
d7f4cc2
More cleanup
gambinish Sep 17, 2024
e7424ee
Add tokenSortConfig to e2e fixtureBuilder
gambinish Sep 17, 2024
eb23bfb
Integrate import controls
gambinish Sep 17, 2024
95caf84
Remove existing import token link
gambinish Sep 17, 2024
07766a1
Cleanup
gambinish Sep 17, 2024
c3551dd
Add telemetry to sort
gambinish Sep 17, 2024
fbd60c6
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 17, 2024
d5ae8fe
Update metametrics unit test
gambinish Sep 17, 2024
03737b9
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--ui' int…
gambinish Sep 17, 2024
ed2aba1
update account-overview-btc.test.tsx
gambinish Sep 18, 2024
c5a3366
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--persist…
gambinish Sep 18, 2024
8862beb
Fix unit tests and update snapshots
gambinish Sep 18, 2024
0de2f55
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 18, 2024
d4b7a71
Update more snapshots
gambinish Sep 18, 2024
ef46288
More snapshot updates
gambinish Sep 18, 2024
9b3e95a
Merge ui branch
gambinish Sep 18, 2024
d36dee0
Update coverage snapshots
gambinish Sep 18, 2024
d8e2303
Subscribe to loading to trigger asset rendering correctly
gambinish Sep 18, 2024
e3f0ad2
Fix: test/e2e/tests/transaction/change-assets.spec.js
gambinish Sep 18, 2024
6c3ecc2
Add native token to default sort
gambinish Sep 18, 2024
4b30c0c
Fix ui/pages/confirmations/components/confirm/header/header-info.tsx
gambinish Sep 18, 2024
fbf0285
Use React.cloneElement to pass unique key
gambinish Sep 18, 2024
c0c60dc
Fix: test/e2e/tests/tokens/custom-token-add-approve.spec.js
gambinish Sep 18, 2024
1eba098
Fix Import token e2e selector bc its now Import
gambinish Sep 18, 2024
02c227a
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 18, 2024
1ca77b7
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--ui' int…
gambinish Sep 18, 2024
93828aa
Update test/e2e/tests/tokens/custom-token-send-transfer.spec.js with …
gambinish Sep 18, 2024
e680f43
Fix: ui/components/app/assets/asset-list/asset-list-control-bar/asset…
gambinish Sep 18, 2024
6fc7bfc
Add showLoader boolean to setPreferences
gambinish Sep 18, 2024
0a4488f
Cleanup
gambinish Sep 18, 2024
dccebb3
Consolidate logic to useAccountTotalFiatBalance
gambinish Sep 18, 2024
86c43a9
Typecast return of useAccountTotalFiatBalance
gambinish Sep 18, 2024
b89da7d
Update unit tests
gambinish Sep 18, 2024
6e91c8b
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 18, 2024
4df54e5
Consolidate more tokenWithBalance changes into useAccountTotalFiatBal…
gambinish Sep 18, 2024
38597e1
Reuse nativeTokenWithBalance within hook
gambinish Sep 18, 2024
b7b8847
Update unit test
gambinish Sep 18, 2024
4baa9ad
Touch up styles to use Design System props
gambinish Sep 18, 2024
106cc43
Add margin and padding from design system props
gambinish Sep 18, 2024
a0987a5
Merge UI branch
gambinish Sep 18, 2024
8b8f05d
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 18, 2024
fe07229
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 19, 2024
f38d164
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 20, 2024
514a8b8
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 20, 2024
58ef0a6
Migrate tokenSortConfig in state
gambinish Sep 20, 2024
899c571
Debug preferences state
gambinish Sep 20, 2024
c9cecf2
Add migration file
gambinish Sep 20, 2024
c229c32
Add unit tests, begin migration tests
gambinish Sep 20, 2024
2a0957d
Handle case where primaryCurrency preference is toggled between Fiat …
gambinish Sep 20, 2024
3e0ba18
Add unit tests to sort-control.test.tsx
gambinish Sep 21, 2024
dcb236d
Update comment
gambinish Sep 21, 2024
249fc58
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 23, 2024
82bf9f6
Lint
gambinish Sep 23, 2024
390d85c
Fix undefined error
gambinish Sep 23, 2024
8c555a1
Fix e2e
gambinish Sep 23, 2024
304e079
Provide default sort order to handle edge case where tokenSortConfig …
gambinish Sep 23, 2024
fa47e1e
Add delay to debug flaky test that queries tokens from screen after l…
gambinish Sep 23, 2024
663518d
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 23, 2024
16bf4e2
Fix: test/e2e/tests/tokens/token-details.spec.ts token order default …
gambinish Sep 24, 2024
deca597
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--persist…
gambinish Sep 24, 2024
45ab85c
Fix: test/e2e/tests/tokens/add-hide-token.spec.js default sort order …
gambinish Sep 24, 2024
a5213b1
Remove exclusive test
gambinish Sep 24, 2024
9c891f1
Update snapshots
gambinish Sep 24, 2024
adda9b7
Fix: Add metrics log test
gambinish Sep 24, 2024
b6a2e93
Debug buggy migration
gambinish Sep 24, 2024
3bb7e9a
Debug bug in migration file
gambinish Sep 24, 2024
9b7c5f5
More cleanup
gambinish Sep 24, 2024
9beb092
Update migration number
gambinish Sep 24, 2024
1f71edc
Update unit tests
gambinish Sep 24, 2024
5447e13
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 24, 2024
99bc3a2
Fix: test token ordering
gambinish Sep 24, 2024
fa8a13c
Fix token ordering token-details
gambinish Sep 24, 2024
b34c389
Lint
gambinish Sep 24, 2024
e8619af
Fix token order in block-explorer.spec.js
gambinish Sep 24, 2024
263bafb
Revert previously skipped test and re-update snapshots
gambinish Sep 24, 2024
2cbba97
Fix: Add boolean chain to fix storybook test
gambinish Sep 24, 2024
e1d6cea
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 24, 2024
7b8045f
Remove exclusive test
gambinish Sep 24, 2024
3107aa3
Add localization
gambinish Sep 24, 2024
943ee72
Use padding shorthand property
gambinish Sep 24, 2024
d9ef11a
Remove console log from actions.ts
gambinish Sep 24, 2024
0aa750e
Add onClickOutside handler
gambinish Sep 24, 2024
196fb77
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 24, 2024
84e1127
Use testId in jest unit tests for robustness and reliability
gambinish Sep 25, 2024
7c9e039
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--persist…
gambinish Sep 25, 2024
7d2c2c6
Fix: test/e2e/tests/account/import-flow.spec.js
gambinish Sep 25, 2024
35cbc24
Revert fix
gambinish Sep 25, 2024
81f62a4
Remove exclusive test
gambinish Sep 25, 2024
59c5d2f
Query predefined delay selector for custom-token-send-transfer.spec.js
gambinish Sep 25, 2024
27b96aa
Remove uneccessary delay
gambinish Sep 25, 2024
b1266e7
Wait for confirmed selector to prevent flakiness, rather than delay t…
gambinish Sep 25, 2024
6155e2a
Remove exclusive test
gambinish Sep 25, 2024
794f41d
Fix typos: sortCriteria -> sortCallback
gambinish Sep 25, 2024
6764dae
Add another migration test
gambinish Sep 25, 2024
f6621c6
Add confirmed selector to custom token send transfer spec
gambinish Sep 25, 2024
9a68d5e
Add token-sort.spec.ts e2e
gambinish Sep 25, 2024
51aea64
Add data-testid to asset-list-control-bar
gambinish Sep 25, 2024
3ba8165
Remove exclusive only in test case
gambinish Sep 25, 2024
f89b06e
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 25, 2024
4362780
chore: UX feedback, popover should close after select, font weight tw…
gambinish Sep 25, 2024
196aa34
Trigger CI/CD pipeline
gambinish Sep 25, 2024
a0ad07a
Fix: font color improperly imported
gambinish Sep 25, 2024
a6d153a
fix: unformat to raw fiat value for sorting purposes
gambinish Sep 25, 2024
42e5667
Refactor useAccountTotalFiatBalance to use checkSum lookup
gambinish Sep 26, 2024
e6310ad
Lint: Ignore restricted import path like rest of TODO in app, remove …
gambinish Sep 26, 2024
4201cd8
Fix: token-sort-spec e2e no longer needs to click out of token sort c…
gambinish Sep 26, 2024
6b7084b
Lint: add additional line before nested rule
gambinish Sep 26, 2024
4483afd
chore: Remove uneccesary migration files
gambinish Sep 26, 2024
bda74e9
fix: Paramaterize sortByDecliningBalance localized string to include …
gambinish Sep 26, 2024
707d4cb
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 26, 2024
97f6333
fix: Update state snapshot to include tokenSortConfig e2e
gambinish Sep 26, 2024
dee8bf0
Merge main
gambinish Sep 26, 2024
b893bb2
chore: Update asset list to have ramps card below token list, update css
gambinish Sep 26, 2024
41ad686
Merge develop
gambinish Sep 26, 2024
6a522e0
nit: Remove whitespace diff from block-explorer.spec.js
gambinish Sep 26, 2024
af90edd
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 26, 2024
5c29b73
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 27, 2024
614c338
fix: Fix flakey permit-spec.ts. Upstream change here: https://github.…
gambinish Sep 27, 2024
0d02930
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--persist…
gambinish Sep 27, 2024
1f51ec2
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 27, 2024
f9b2a48
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Sep 30, 2024
5985667
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Oct 1, 2024
e1962a3
fix: Remove tokenSortConfig mocks from tests where they are not needed
gambinish Oct 1, 2024
84b215d
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--persist…
gambinish Oct 1, 2024
db0e071
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Oct 2, 2024
2dcc38c
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Oct 2, 2024
8f78bb6
Merge branch 'feat/mmassets-356_sort-import-tokens-extension--persist…
gambinish Oct 2, 2024
896521a
chore: Merge develop, address conflicts, noticed bug in sorting while…
gambinish Oct 2, 2024
eb914ff
fix: Race condition: Account switching doesnt respect tokenSort until…
gambinish Oct 2, 2024
a085dd0
chore: Merge develop, fix conflicts
gambinish Oct 2, 2024
63b8a0e
fix: Merge conflict in preferences-controller
gambinish Oct 2, 2024
411f860
fix: Merge conflict in metametrics.test.js
gambinish Oct 2, 2024
79171bd
fix: Update mockstate for routes.component.test to include tokenSortC…
gambinish Oct 2, 2024
06ebe0a
fix: Subscribe to market data on update. simplify effect
gambinish Oct 2, 2024
f53e30b
fix: Add tokeSortConfig to storybook test data
gambinish Oct 3, 2024
a2537d4
chore: Memoize sorting logic, and move responsibility to token-list. …
gambinish Oct 3, 2024
2583bfc
chore: Merge develop, address merge conflicts
gambinish Oct 4, 2024
77c7c73
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Oct 7, 2024
2a13515
chore: Add migration file to set default tokenSortConfig
gambinish Oct 7, 2024
eca6987
chore: Add unit tests for tokenSortConfig migration file
gambinish Oct 7, 2024
ba1e3d9
fix: Update correct file imports for migration test file
gambinish Oct 7, 2024
60f33ac
fix: Lint migration files
gambinish Oct 7, 2024
00477d5
chore: fix sonar cloud issues
gambinish Oct 7, 2024
e7a879e
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Oct 7, 2024
f4ef0da
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Oct 7, 2024
0cd3e25
fix: Remove useNativeCurrencyAsPrimaryCurrency
gambinish Oct 7, 2024
c8467f6
Merge branch 'develop' into feat/mmassets-356_sort-import-tokens-exte…
gambinish Oct 8, 2024
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
2 changes: 2 additions & 0 deletions app/scripts/controllers/metametrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ export default class MetaMetricsController {
metamaskState.participateInMetaMetrics,
[MetaMetricsUserTrait.HasMarketingConsent]:
metamaskState.dataCollectionForMarketing,
[MetaMetricsUserTrait.TokenSortPreference]:
metamaskState.tokenSortConfig?.key || '',
};

if (!previousUserTraits) {
Expand Down
26 changes: 26 additions & 0 deletions app/scripts/controllers/metametrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,11 @@ describe('MetaMetricsController', function () {
},
},
},
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCriteria: 'stringNumeric',
},
});

expect(traits).toStrictEqual({
Expand Down Expand Up @@ -1121,6 +1126,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(petnames)
[MetaMetricsUserTrait.PetnameAddressCount]: 3,
///: END:ONLY_INCLUDE_IF
[MetaMetricsUserTrait.TokenSortPreference]: 'token-sort-key',
});
});

Expand Down Expand Up @@ -1150,6 +1156,11 @@ describe('MetaMetricsController', function () {
theme: 'default',
useTokenDetection: true,
useNativeCurrencyAsPrimaryCurrency: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCriteria: 'stringNumeric',
},
});

const updatedTraits = metaMetricsController._buildUserTraitsObject({
Expand Down Expand Up @@ -1177,6 +1188,11 @@ describe('MetaMetricsController', function () {
theme: 'default',
useTokenDetection: true,
useNativeCurrencyAsPrimaryCurrency: false,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCriteria: 'stringNumeric',
},
});

expect(updatedTraits).toStrictEqual({
Expand Down Expand Up @@ -1214,6 +1230,11 @@ describe('MetaMetricsController', function () {
theme: 'default',
useTokenDetection: true,
useNativeCurrencyAsPrimaryCurrency: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCriteria: 'stringNumeric',
},
});

const updatedTraits = metaMetricsController._buildUserTraitsObject({
Expand All @@ -1236,6 +1257,11 @@ describe('MetaMetricsController', function () {
theme: 'default',
useTokenDetection: true,
useNativeCurrencyAsPrimaryCurrency: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCriteria: 'stringNumeric',
},
});
expect(updatedTraits).toStrictEqual(null);
});
Expand Down
5 changes: 5 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ export enum MetaMetricsUserTrait {
* Identified when the user selects a currency from settings
*/
CurrentCurrency = 'current_currency',
/**
* Identified when the user changes token sort order on asset-list
*/
TokenSortPreference = 'token_sort_preference',
}

/**
Expand Down Expand Up @@ -622,6 +626,7 @@ export enum MetaMetricsEventName {
TokenScreenOpened = 'Token Screen Opened',
TokenAdded = 'Token Added',
TokenRemoved = 'Token Removed',
TokenSortPreference = 'Token Sort Preference',
NFTRemoved = 'NFT Removed',
TokenDetected = 'Token Detected',
TokenHidden = 'Token Hidden',
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ function onboardingFixture() {
petnamesEnabled: true,
isRedesignedConfirmationsDeveloperEnabled: false,
showConfirmationAdvancedDetails: false,
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCriteria: 'stringNumeric',
},
},
useExternalServices: true,
theme: 'light',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/tokens/add-hide-token.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('Add existing token using search', function () {
async ({ driver }) => {
await unlockWallet(driver);

await driver.clickElement({ text: 'Import tokens', tag: 'button' });
await driver.clickElement({ text: 'Import', tag: 'button' });
await driver.fill('input[placeholder="Search tokens"]', 'BAT');
await driver.clickElement({
text: 'BAT',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/tokens/custom-token-add-approve.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Create token, approve token and approve token without gas', function (
);
await clickNestedButton(driver, 'Tokens');

await driver.clickElement({ text: 'Import tokens', tag: 'button' });
await driver.clickElement({ text: 'Import', tag: 'button' });
await clickNestedButton(driver, 'Custom token');
await driver.fill(
'[data-testid="import-tokens-modal-custom-address"]',
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/tests/tokens/custom-token-send-transfer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ describe('Transfer custom tokens @no-mmi', function () {
text: '-1.5 TST',
});

// this delay helps prevent flakiness. it allows driver to wait until send transer is "confirmed"
await driver.delay(5000);
gambinish marked this conversation as resolved.
Show resolved Hide resolved

// check token amount is correct after transaction
await clickNestedButton(driver, 'Tokens');
const tokenAmount = await driver.findElement(
Expand Down Expand Up @@ -192,6 +195,9 @@ describe('Transfer custom tokens @no-mmi', function () {
text: 'Send TST',
});

// this delay helps prevent flakiness. it allows driver to wait until send transer is "confirmed"
await driver.delay(5000);

// check token amount is correct after transaction
await clickNestedButton(driver, 'Tokens');
const tokenAmount = await driver.findElement(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/tokens/token-details.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Token Details', function () {
};

const importToken = async (driver: Driver) => {
await driver.clickElement({ text: 'Import tokens', tag: 'button' });
await driver.clickElement({ text: 'Import', tag: 'button' });
await clickNestedButton(driver, 'Custom token');
await driver.fill(
'[data-testid="import-tokens-modal-custom-address"]',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/tokens/token-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Token List', function () {
};

const importToken = async (driver: Driver) => {
await driver.clickElement({ text: 'Import tokens', tag: 'button' });
await driver.clickElement({ text: 'Import', tag: 'button' });
await clickNestedButton(driver, 'Custom token');
await driver.fill(
'[data-testid="import-tokens-modal-custom-address"]',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/transaction/change-assets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ describe('Change assets', function () {

// Make sure gas is updated by resetting amount and hex data
// Note: this is needed until the race condition is fixed on the wallet level (issue #25243)
await driver.fill('[data-testid="currency-input"]', '2');
await driver.fill('[data-testid="currency-input"]', '2.000042');
gambinish marked this conversation as resolved.
Show resolved Hide resolved
await hexDataLocator.fill('0x');
await hexDataLocator.fill('');

Expand Down
2 changes: 2 additions & 0 deletions ui/components/app/app-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
@import 'srp-input/srp-input';
@import 'snaps/snap-privacy-warning/index';
@import 'tab-bar/index';
@import 'assets/asset-list/asset-list-control-bar/index';
@import 'assets/asset-list/sort-control/index';
@import 'assets/token-cell/token-cell';
@import 'assets/token-list-display/token-list-display';
@import 'transaction-activity-log/index';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import React, { useEffect, useRef, useState } from 'react';
import { useSelector } from 'react-redux';
import {
Box,
ButtonBase,
ButtonBaseSize,
IconName,
Popover,
PopoverPosition,
} from '../../../../component-library';
import { TokenWithBalance } from '../asset-list';
import { getCurrentCurrency } from '../../../../../selectors';
import { roundToDecimalPlacesRemovingExtraZeroes } from '../../../../../helpers/utils/util';
import { isEqualCaseInsensitive } from '../../../../../../shared/modules/string-utils';
import { getConversionRate } from '../../../../../ducks/metamask/metamask';
import { getTokenFiatAmount } from '../../../../../helpers/utils/token-util';
import SortControl from '../sort-control';
import {
BackgroundColor,
BorderColor,
BorderStyle,
TextColor,
} from '../../../../../helpers/constants/design-system';
import { sortAssets } from '../../util/sort';
import { useNativeTokenBalance } from '../native-token/use-native-token-balance';
import ImportControl from '../import-control';
import { useAccountTotalFiatBalancesHook } from './use-account-total-fiat-balances';

type AssetListControlBarProps = {
tokenList: TokenWithBalance[];
setTokenList: (arg: TokenWithBalance[]) => void;
sorted: boolean;
setSorted: (arg: boolean) => void;
showTokensLinks?: boolean;
};

const AssetListControlBar = ({
tokenList,
setTokenList,
sorted,
setSorted,
showTokensLinks,
}: AssetListControlBarProps) => {
const controlBarRef = useRef<HTMLDivElement>(null); // Create a ref
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const conversionRate = useSelector(getConversionRate);
const currentCurrency = useSelector(getCurrentCurrency);
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
gambinish marked this conversation as resolved.
Show resolved Hide resolved
const tokenSortConfig = useSelector((state: any) => {
return state.metamask.preferences.tokenSortConfig;
gambinish marked this conversation as resolved.
Show resolved Hide resolved
});
const { accountTotalFiatBalance, mergedRates, loading } =
useAccountTotalFiatBalancesHook();

const { primaryBalance, secondaryBalance, tokenSymbol, primaryTokenImage } =
useNativeTokenBalance();

const nativeTokenWithBalance: TokenWithBalance = {
address: '',
symbol: tokenSymbol || '',
string: primaryBalance,
image: primaryTokenImage,
tokenFiatAmount: secondaryBalance,
isNative: true,
};

const handleSort = () => {
if (!sorted) {
const tokensWithBalances =
accountTotalFiatBalance.tokensWithBalances as TokenWithBalance[];

tokensWithBalances.forEach((token) => {
// token.string is the balance displayed in the TokenList UI
token.string = roundToDecimalPlacesRemovingExtraZeroes(
token.string,
5,
) as string;
});

// to sort by fiat balance, we need to compute this at this level
// should this get passed down as props to token-cell as props, rather than recomputing there?
tokensWithBalances.forEach((token) => {
const contractExchangeTokenKey = Object.keys(mergedRates).find((key) =>
isEqualCaseInsensitive(key, token.address),
);

const tokenExchangeRate =
contractExchangeTokenKey && mergedRates[contractExchangeTokenKey];

token.tokenFiatAmount =
getTokenFiatAmount(
tokenExchangeRate,
conversionRate,
currentCurrency,
token.string, // tokenAmount
token.symbol, // tokenSymbol
false, // no currency symbol prefix
false, // no ticker symbol suffix
) || '0';
});

if (tokenSortConfig) {
const sortedTokenList = sortAssets(
[nativeTokenWithBalance, ...tokensWithBalances],
tokenSortConfig,
);
setTokenList(sortedTokenList);
} else {
setTokenList([nativeTokenWithBalance, ...tokensWithBalances]);
}
}
};

useEffect(() => {
handleSort();
}, [
tokenSortConfig,
loading,
accountTotalFiatBalance.tokensWithBalances.length,
]);

const handleOpenPopover = () => {
setIsPopoverOpen(!isPopoverOpen);
};

return (
<>
<Box className="asset-list-control-bar" ref={controlBarRef}>
<ButtonBase
onClick={handleOpenPopover}
size={ButtonBaseSize.Sm}
endIconName={IconName.ArrowDown}
backgroundColor={
isPopoverOpen
? BackgroundColor.backgroundPressed
: BackgroundColor.backgroundDefault
}
borderColor={BorderColor.borderMuted}
borderStyle={BorderStyle.solid}
color={TextColor.textDefault}
>
Sort By
gambinish marked this conversation as resolved.
Show resolved Hide resolved
</ButtonBase>
<ImportControl showTokensLinks={showTokensLinks} />
<Popover
gambinish marked this conversation as resolved.
Show resolved Hide resolved
isOpen={isPopoverOpen}
position={PopoverPosition.BottomStart}
referenceElement={controlBarRef.current}
matchWidth={true}
style={{
zIndex: 10,
display: 'flex',
flexDirection: 'column',
padding: 0,
}}
>
<SortControl
tokenList={tokenList}
setTokenList={setTokenList}
setSorted={setSorted}
sorted={sorted}
/>
</Popover>
</Box>
</>
);
};

export default AssetListControlBar;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.asset-list-control-bar {
display: flex;
justify-content: space-between;
cursor: pointer;
padding-top: 16px;
margin-left: 16px;
margin-right: 16px;

button:hover {
background-color: var(--color-background-hover);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './asset-list-control-bar';
Loading