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 all 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
5 changes: 5 additions & 0 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ const state = {
currentLocale: 'en',
preferences: {
showNativeTokenAsMainBalance: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCallback: 'stringNumeric',
},
},
incomingTransactionsPreferences: {
[CHAIN_IDS.MAINNET]: true,
Expand Down
10 changes: 10 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/scripts/controllers/metametrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,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 @@ -1122,6 +1122,11 @@ describe('MetaMetricsController', function () {
},
},
},
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCallback: 'stringNumeric',
},
});

expect(traits).toStrictEqual({
Expand Down Expand Up @@ -1153,6 +1158,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 @@ -1181,6 +1187,11 @@ describe('MetaMetricsController', function () {
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCallback: 'stringNumeric',
},
showNativeTokenAsMainBalance: true,
});

Expand Down Expand Up @@ -1208,6 +1219,11 @@ describe('MetaMetricsController', function () {
useNftDetection: false,
theme: 'default',
useTokenDetection: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCallback: 'stringNumeric',
},
showNativeTokenAsMainBalance: false,
});

Expand Down Expand Up @@ -1245,6 +1261,11 @@ describe('MetaMetricsController', function () {
useNftDetection: true,
theme: 'default',
useTokenDetection: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCallback: 'stringNumeric',
},
showNativeTokenAsMainBalance: true,
});

Expand All @@ -1267,6 +1288,11 @@ describe('MetaMetricsController', function () {
useNftDetection: true,
theme: 'default',
useTokenDetection: true,
tokenSortConfig: {
key: 'token-sort-key',
order: 'dsc',
sortCallback: 'stringNumeric',
},
showNativeTokenAsMainBalance: true,
});
expect(updatedTraits).toStrictEqual(null);
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/controllers/preferences-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export type Preferences = {
showMultiRpcModal: boolean;
isRedesignedConfirmationsDeveloperEnabled: boolean;
showConfirmationAdvancedDetails: boolean;
tokenSortConfig: {
key: string;
order: string;
sortCallback: string;
};
shouldShowAggregatedBalancePopover: boolean;
};

Expand Down Expand Up @@ -237,6 +242,11 @@ export default class PreferencesController {
showMultiRpcModal: false,
isRedesignedConfirmationsDeveloperEnabled: false,
showConfirmationAdvancedDetails: false,
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCallback: 'stringNumeric',
},
shouldShowAggregatedBalancePopover: true, // by default user should see popover;
},
// ENS decentralized website resolution
Expand Down
91 changes: 91 additions & 0 deletions app/scripts/migrations/130.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { migrate, version } from './130';

const oldVersion = 129;

describe(`migration #${version}`, () => {
it('updates the version metadata', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {},
};
const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({ version });
});
describe(`migration #${version}`, () => {
it('updates the preferences with a default tokenSortConfig', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {
PreferencesController: {
preferences: {},
},
},
};
const expectedData = {
PreferencesController: {
preferences: {
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCallback: 'stringNumeric',
},
},
},
};
const newStorage = await migrate(oldStorage);

expect(newStorage.data).toStrictEqual(expectedData);
});

it('does nothing if the preferences already has a tokenSortConfig', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {
PreferencesController: {
preferences: {
tokenSortConfig: {
key: 'fooKey',
order: 'foo',
sortCallback: 'fooCallback',
},
},
},
},
};

const newStorage = await migrate(oldStorage);

expect(newStorage.data).toStrictEqual(oldStorage.data);
});

it('does nothing to other preferences if they exist without a tokenSortConfig', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {
PreferencesController: {
preferences: {
existingPreference: true,
},
},
},
};

const expectedData = {
PreferencesController: {
preferences: {
existingPreference: true,
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCallback: 'stringNumeric',
},
},
},
};

const newStorage = await migrate(oldStorage);

expect(newStorage.data).toStrictEqual(expectedData);
});
});
});
44 changes: 44 additions & 0 deletions app/scripts/migrations/130.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { hasProperty, isObject } from '@metamask/utils';
import { cloneDeep } from 'lodash';

type VersionedData = {
meta: { version: number };
data: Record<string, unknown>;
};
export const version = 130;
/**
* This migration adds a tokenSortConfig to the user's preferences
*
*
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
* @param originalVersionedData.meta - State metadata.
* @param originalVersionedData.meta.version - The current state version.
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller.
* @returns Updated versioned MetaMask extension state.
*/
export async function migrate(
originalVersionedData: VersionedData,
): Promise<VersionedData> {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
transformState(versionedData.data);
return versionedData;
}
function transformState(
state: Record<string, unknown>,
): Record<string, unknown> {
if (
hasProperty(state, 'PreferencesController') &&
isObject(state.PreferencesController) &&
hasProperty(state.PreferencesController, 'preferences') &&
isObject(state.PreferencesController.preferences) &&
!state.PreferencesController.preferences.tokenSortConfig
) {
state.PreferencesController.preferences.tokenSortConfig = {
key: 'tokenFiatAmount',
order: 'dsc',
sortCallback: 'stringNumeric',
};
}
return state;
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const migrations = [
require('./127'),
require('./128'),
require('./129'),
require('./130'),
];

export default migrations;
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 @@ -630,6 +634,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
7 changes: 6 additions & 1 deletion test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,12 @@
"showFiatInTestnets": false,
"showNativeTokenAsMainBalance": true,
"showTestNetworks": true,
"smartTransactionsOptInStatus": false
"smartTransactionsOptInStatus": false,
"tokenSortConfig": {
"key": "tokenFiatAmount",
"order": "dsc",
"sortCallback": "stringNumeric"
}
},
"ensResolutionsByAddress": {},
"isAccountMenuOpen": false,
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/default-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) {
showMultiRpcModal: false,
isRedesignedConfirmationsDeveloperEnabled: false,
showConfirmationAdvancedDetails: false,
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCallback: 'stringNumeric',
},
shouldShowAggregatedBalancePopover: true,
},
selectedAddress: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
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 @@ -77,6 +77,11 @@ function onboardingFixture() {
showMultiRpcModal: false,
isRedesignedConfirmationsDeveloperEnabled: false,
showConfirmationAdvancedDetails: false,
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCallback: 'stringNumeric',
},
shouldShowAggregatedBalancePopover: true,
},
useExternalServices: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
"isRedesignedConfirmationsDeveloperEnabled": "boolean",
"redesignedConfirmationsEnabled": true,
"redesignedTransactionsEnabled": "boolean",
"showMultiRpcModal": "boolean",
"tokenSortConfig": "object",
"shouldShowAggregatedBalancePopover": "boolean"
},
"ipfsGateway": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"isRedesignedConfirmationsDeveloperEnabled": "boolean",
"redesignedConfirmationsEnabled": true,
"redesignedTransactionsEnabled": "boolean",
"tokenSortConfig": "object",
"showMultiRpcModal": "boolean",
"shouldShowAggregatedBalancePopover": "boolean"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
},
"NetworkController": {
"selectedNetworkClientId": "string",
"networkConfigurations": "object",
"networksMetadata": {
"networkConfigurationId": { "EIPS": {}, "status": "available" }
},
"providerConfig": "object",
"networkConfigurations": "object"
"providerConfig": "object"
},
"OnboardingController": {
"completedOnboarding": true,
Expand Down Expand Up @@ -114,8 +114,9 @@
"smartTransactionsOptInStatus": false,
"showNativeTokenAsMainBalance": true,
"petnamesEnabled": true,
"showConfirmationAdvancedDetails": false,
"isRedesignedConfirmationsDeveloperEnabled": "boolean",
"showConfirmationAdvancedDetails": false,
"tokenSortConfig": "object",
"showMultiRpcModal": "boolean",
"shouldShowAggregatedBalancePopover": "boolean"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
},
"NetworkController": {
"selectedNetworkClientId": "string",
"networkConfigurations": "object",
"networksMetadata": {
"networkConfigurationId": { "EIPS": {}, "status": "available" }
},
"providerConfig": "object",
"networkConfigurations": "object"
"providerConfig": "object"
},
"OnboardingController": {
"completedOnboarding": true,
Expand Down Expand Up @@ -114,8 +114,9 @@
"smartTransactionsOptInStatus": false,
"showNativeTokenAsMainBalance": true,
"petnamesEnabled": true,
"showConfirmationAdvancedDetails": false,
"isRedesignedConfirmationsDeveloperEnabled": "boolean",
"showConfirmationAdvancedDetails": false,
"tokenSortConfig": "object",
"showMultiRpcModal": "boolean",
"shouldShowAggregatedBalancePopover": "boolean"
},
Expand Down
Loading