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: Multichain AssetList #28386

Closed
Show file tree
Hide file tree
Changes from 118 commits
Commits
Show all changes
259 commits
Select commit Hold shift + click to select a range
6ec980b
chore: Merge main, address conflicts
gambinish Oct 17, 2024
3b6d223
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 17, 2024
d670862
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 21, 2024
bf5913c
fix: Update unit tests in preferences-controller
gambinish Oct 21, 2024
85d5161
feat: Add filterAssets function
gambinish Oct 21, 2024
72ea2cf
chore: Polish filters to be layerable in order of importance, allowin…
gambinish Oct 21, 2024
8b52780
fix: Lint tsc, specifiy chain indication rather than arbitrary number
gambinish Oct 21, 2024
4349f4f
chore: Localize strings
gambinish Oct 21, 2024
8b83df4
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 22, 2024
bc82cb4
chore: Add localized Network string
gambinish Oct 22, 2024
42ad7d4
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 22, 2024
c4ce6c7
chore: Add FILTER_TOKENS_TOGGLE feature flag
gambinish Oct 22, 2024
5be0713
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 22, 2024
023b0ca
fix: Show current selection on Network filter, and ellipsize when ove…
gambinish Oct 22, 2024
c9a2d8d
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 22, 2024
ae96cea
fix: Lint
gambinish Oct 22, 2024
5b40705
fix: Remove duplicate locale string
gambinish Oct 22, 2024
f7f09da
fix: Cleanup
gambinish Oct 22, 2024
85fe12d
bump asset controllers to 39
bergeron Oct 22, 2024
0f3cd64
update ConfirmTransaction
bergeron Oct 22, 2024
bdf921b
fix useGasFeeEstimates unit test
bergeron Oct 22, 2024
9bc4ecf
fix usePolling tests
bergeron Oct 23, 2024
c6a408d
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 23, 2024
9b1529b
bump controller utils
bergeron Oct 23, 2024
c8bcc0b
remove patch
bergeron Oct 23, 2024
d1a3782
Merge branch 'develop' into brian/asset-controller-39
bergeron Oct 23, 2024
05fd6ef
Update LavaMoat policies
metamaskbot Oct 23, 2024
9dfdfa8
lint
bergeron Oct 23, 2024
04ea3d6
Merge branch 'brian/asset-controller-39' of github.com:MetaMask/metam…
bergeron Oct 23, 2024
cf66072
Merge branch 'develop' into brian/asset-controller-39
bergeron Oct 24, 2024
6934434
fix: Clean up filterAssets logic
gambinish Oct 24, 2024
15e4e47
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 24, 2024
a2074cd
fix: Update network-filter Avatar rendering logic
gambinish Oct 24, 2024
6e80b34
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 24, 2024
836a11b
fix: Duplicate chainId
gambinish Oct 24, 2024
441d4cf
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 24, 2024
d18d25a
chore: Aggregate token listings across chains, per account
gambinish Oct 24, 2024
dd0b3f5
chore: Cleanup variables and logs
gambinish Oct 24, 2024
1e461ee
Merge branch 'brian/asset-controller-39' into feat/mmassets-432_netwo…
gambinish Oct 24, 2024
a51fec4
chore: Update yarn resolution to provide marketData across chains
gambinish Oct 24, 2024
0d637fb
chore: get balances for tokens via TokenTracker
gambinish Oct 25, 2024
c923dfe
feat: poc of consolidated asset view across chains. balances are mocked
gambinish Oct 25, 2024
6a394a2
chore: Integrate filtering logic, to be improved
gambinish Oct 25, 2024
785de28
initial multi chain polling for currency and token rates
bergeron Oct 29, 2024
f461767
fix testnets
bergeron Oct 29, 2024
f1da818
only refetch prices on chains whose tokens changed
bergeron Oct 29, 2024
878f407
poll multiple native currencies
bergeron Oct 30, 2024
e8a9d6a
fix test
bergeron Oct 30, 2024
245f8d3
yarn dedupe
bergeron Oct 30, 2024
1afebee
Update LavaMoat policies
metamaskbot Oct 30, 2024
e99e2ef
Merge branch 'develop' into brian/currency-rate-multichain-polling2
bergeron Oct 30, 2024
ca590ec
fix e2e test mocks
bergeron Oct 30, 2024
d2191ac
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
bergeron Oct 30, 2024
70c0db4
fix e2e test
bergeron Oct 30, 2024
6b7df4d
.
bergeron Oct 30, 2024
4e816c2
lint
bergeron Oct 30, 2024
aaef377
fix e2e test
bergeron Oct 30, 2024
48bff46
Merge branch 'brian/currency-rate-multichain-polling2' of github.com:…
bergeron Oct 31, 2024
0450b04
package.json
bergeron Oct 31, 2024
fdc04ad
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
bergeron Oct 31, 2024
3ec3574
bump controller preview version
bergeron Oct 31, 2024
dcc8a64
Merge branch 'develop' into brian/multiexchangerate
bergeron Oct 31, 2024
0e7a872
fix: fix lint
sahar-fehri Oct 31, 2024
ea95aca
fix: update js file to tsx
sahar-fehri Oct 31, 2024
3bf7b78
Merge branch 'develop' into brian/multiexchangerate
sahar-fehri Nov 1, 2024
bb1f278
make polling input a chain id
bergeron Nov 1, 2024
14dc84b
Merge branch 'develop' into brian/multiexchangerate
bergeron Nov 1, 2024
ef3ef10
bump to asset controller v42
bergeron Nov 1, 2024
ab6e7cc
.
bergeron Nov 1, 2024
44861d9
Merge branch 'brian/multiexchangerate' of github.com:MetaMask/metamas…
bergeron Nov 1, 2024
0b543e0
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
bergeron Nov 4, 2024
411fc1c
initial token balances controller
bergeron Nov 4, 2024
c2b6afe
Update metamask-controller.js
bergeron Nov 4, 2024
69404a5
Merge branch 'develop' into brian/token-balances-controller
bergeron Nov 4, 2024
bb1d6bf
cleanup
bergeron Nov 4, 2024
f6e56b3
Merge branch 'brian/token-balances-controller' of github.com:MetaMask…
bergeron Nov 4, 2024
8e752a1
yarn
bergeron Nov 4, 2024
6fac24b
feat: add native tokens to multichain token list (#28193)
jonybur Nov 5, 2024
12570a5
chore: Merge develop, address conflicts
gambinish Nov 5, 2024
39a1285
fix: Missed merge conflict in filter funciton
gambinish Nov 5, 2024
95ce7de
fix: Address conflicts in lavamoat policies
gambinish Nov 5, 2024
f3a679b
fix: Address conflict in main lavamoat policy
gambinish Nov 5, 2024
b0c07c1
fix: Update selectors and various discrepancies after merge conflict …
gambinish Nov 5, 2024
03e047d
fix: Incorrect selector for marketData
gambinish Nov 5, 2024
3612b58
fix: Cleanup
gambinish Nov 5, 2024
776c63b
fix: conversionRate undefined error on network switch
gambinish Nov 5, 2024
9482953
fix: Get native token image from mapping
gambinish Nov 5, 2024
bd035f3
fix: Ethereum mainnet should be called Ethereum
gambinish Nov 5, 2024
23747ed
fix: Changing selected network should reset filters to all networks
gambinish Nov 5, 2024
14c9b57
fix: Cleanup selector console log
gambinish Nov 5, 2024
c308609
Styling changes
jonybur Nov 6, 2024
3c9049c
fix: Add percentage change for native currency
gambinish Nov 6, 2024
f81cbbc
fix: Multichain scam warning should not appear on native tokens, othe…
gambinish Nov 6, 2024
93cd913
fix: Network selector should also update network filter
gambinish Nov 7, 2024
f290926
fix: On mount, set the filters to show all networks by default
gambinish Nov 7, 2024
919faf5
fix: Temporarily stub out showScamWarning boolean. To improve on mult…
gambinish Nov 7, 2024
1710bc7
fix: pricePercentChange1d can be undefined, use optional chaining
gambinish Nov 7, 2024
ffe9e5f
fix: Tweak useEffect in asset-list-control-bar
gambinish Nov 7, 2024
46bc93c
fix: Use tokenChainId not cached chainId from selected network
gambinish Nov 7, 2024
5f0e632
Add auto switching for network on Send
jonybur Nov 7, 2024
f48e734
Merge branch 'feat/mmassets-432_network-filter-extension--integration…
jonybur Nov 7, 2024
25c8a90
Bugfixing, add tooltips
jonybur Nov 7, 2024
06112af
chore: Temporarily link preview build of assets-controllers package
gambinish Nov 7, 2024
56470ad
refactor: Init token balance integration
gambinish Nov 7, 2024
42ce9be
Padding fixes
jonybur Nov 7, 2024
6de2f95
UI fixes
jonybur Nov 7, 2024
ecb8508
Reduce size of selector
jonybur Nov 7, 2024
a241f5e
Fix native token clicking
jonybur Nov 7, 2024
9509d36
chore: format currency and token values
gambinish Nov 8, 2024
b5a0642
chore: Handle native token balances
gambinish Nov 8, 2024
41f19f2
refactor: Handle balance calculation higher up to respect sorting
gambinish Nov 8, 2024
ffa995b
fix: Include AssetsController patch
gambinish Nov 8, 2024
a58da57
chore: Cleanup
gambinish Nov 8, 2024
65e2c18
chore: Tidy up some types on token-list
gambinish Nov 8, 2024
3edf269
Fix toast for network switching
jonybur Nov 10, 2024
2dc23d3
Fix asset page for offchain native tokens
jonybur Nov 10, 2024
d778834
Filter out zero-value tokens on asset list picker
jonybur Nov 10, 2024
6537cb6
Design changes
jonybur Nov 11, 2024
ae73a3b
Fix: Consolidate type for AdressTokenMapping
gambinish Nov 11, 2024
6397e30
Merge branch 'feat/mmassets-432_network-filter-extension--integration…
gambinish Nov 11, 2024
74f2b8e
chore: Fix calculated balances on asset details
gambinish Nov 11, 2024
82d4c4e
chore: Render chart data for native token
gambinish Nov 11, 2024
3cc8773
chore: Key market details on chainId
gambinish Nov 11, 2024
f73c8f4
chore: Cleanup market details
gambinish Nov 11, 2024
eea519f
chore: Cleanup types on token-list
gambinish Nov 11, 2024
ac3c389
Fix: small bug related to native token image
gambinish Nov 11, 2024
3c2bc6b
fix: Remove console.log
gambinish Nov 11, 2024
21bd89a
Fix: Include string in type
gambinish Nov 11, 2024
3ff6b40
fix: Persist cross chain balances on detail view
gambinish Nov 11, 2024
e55852e
chore: formatWithThreshold
gambinish Nov 11, 2024
929f406
chore: calculateTokenBalance utility
gambinish Nov 11, 2024
5d06829
Create utilities for calculating tokenBalance and tokenFiatAmount
gambinish Nov 11, 2024
39ec4e7
fix: Memoized token listing should update after new tokens are imported
gambinish Nov 11, 2024
1d747e6
fix: Missing import
gambinish Nov 12, 2024
9fe2f23
Add chain network switching for swaps and send on native tokens
jonybur Nov 12, 2024
2691cb7
Fix toast on swap
jonybur Nov 12, 2024
01c51de
Fix NaN value on new tokens
jonybur Nov 12, 2024
e82bb27
Remove console log
jonybur Nov 12, 2024
f1077cf
NFT fixes for multichain
jonybur Nov 12, 2024
9b4b058
fix: Init zero balance bug
gambinish Nov 12, 2024
9defc73
chore: Merge main, address conflicts
gambinish Nov 12, 2024
ed8cd61
fix: All networks filter should only show the chains for mainnet that…
gambinish Nov 12, 2024
994b363
fix: Remove console.log
gambinish Nov 12, 2024
c5ddc71
fix: yarn lint
gambinish Nov 12, 2024
d5e56ec
fix: yarn lint:tsc
gambinish Nov 12, 2024
776cecf
fix: Cleanup
gambinish Nov 12, 2024
6a663a8
fix: If network icons doesn't exist, we should not fallback to the cu…
gambinish Nov 13, 2024
7e2b157
fix: Show ETH as Ethereum on non ETH mainnet chains when allNetworks …
gambinish Nov 13, 2024
5d07e03
fix: Lint
gambinish Nov 13, 2024
a7e2a77
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 13, 2024
156482a
chore: Style updates to asset-list-control-bar
gambinish Nov 13, 2024
cd49ad1
chore: Update localization string in prep for multichain asset list
gambinish Nov 13, 2024
b4e4ba7
chore: Update import button to import icon in preparation for Multich…
gambinish Nov 13, 2024
d49824f
chore: Update sort control styles
gambinish Nov 13, 2024
5c3d4d3
chore: Consider chainId when navigating from main asset list
gambinish Nov 13, 2024
031e8e3
chore: Begin incorporating concept of chainId to support multichain a…
gambinish Nov 13, 2024
40b36f5
fix: Tweak unit test
gambinish Nov 13, 2024
b24e25a
fix: Tweak unit test
gambinish Nov 13, 2024
18aa7e8
chore: Add low risk selectors to prepare for multichain asset list
gambinish Nov 13, 2024
e127f07
fix: Add unit testable utility in preperation for unified asset list
gambinish Nov 13, 2024
7307904
fix: Revert changes to locales, can't do this in advance
gambinish Nov 13, 2024
b5da71e
fix: Update test id in custom-token-add-approve.spec.js
gambinish Nov 13, 2024
e939574
chore: Remove console.log
gambinish Nov 13, 2024
c71bee0
fix: Update token-sort.spec.ts testid
gambinish Nov 13, 2024
f9fa8da
fix: Update other instances of testid Import
gambinish Nov 13, 2024
1a1737a
chore: Add new unit test for findAssetByAddress util
gambinish Nov 13, 2024
41adb56
fix: Update nullish search bug in chainSupprotsPricing
gambinish Nov 13, 2024
aa3063f
fix: Lint error in util.test.ts
gambinish Nov 13, 2024
57f8af1
test: [POM] Migrate autodetect and import nft e2e tests to use Page O…
chloeYue Nov 13, 2024
01652f5
test: fix state fixtures race condition (#28421)
seaona Nov 13, 2024
02dba24
feat: btc send flow e2e (#28340)
montelaidev Nov 13, 2024
bc5f345
fix: Default to dApp suggested fees only when user selects the option…
pedronfigueiredo Nov 13, 2024
0055289
Revert "fix: Lint error in util.test.ts"
gambinish Nov 13, 2024
c006bb6
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 13, 2024
25c27ea
fix: @metamask/assets-controllers should be imported before local fil…
gambinish Nov 13, 2024
ce6f520
chore: Merge main, address conflicts
gambinish Nov 13, 2024
6ceb087
chore: Merge in prep updates to reduces file size diff
gambinish Nov 13, 2024
dcf39fd
fix: Remove duplicate import entry for getCurrentChainId
gambinish Nov 13, 2024
0ffa5d0
fix: Revert component library change to ButtonBase
gambinish Nov 13, 2024
89b9ffc
fix: Revert margin update to ButtonBase
gambinish Nov 13, 2024
8739893
fix: Continue using optional chaining in useFiatTokenBalance hook
gambinish Nov 13, 2024
572f998
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 13, 2024
82e1ddd
fix: Update token cell test, by tweaking primary formatWithThreshold …
gambinish Nov 13, 2024
5ebc8e4
chore: tweak formatWithThreshold for primary token balance value
gambinish Nov 13, 2024
5b684ad
fix: Update snapshot in token cell unit test
gambinish Nov 13, 2024
21aa0c4
chore: Replace scam token warning logic in token-list-item
gambinish Nov 13, 2024
11c51aa
chore: Tweak token-list-item isOriginalToken symbol prop
gambinish Nov 13, 2024
bc2f132
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 13, 2024
f474448
chore: Merge develop
gambinish Nov 14, 2024
a29b211
chore: Update legacy gas display unit test
gambinish Nov 14, 2024
71c8879
fix: Remove suffix constraint
gambinish Nov 14, 2024
4947aba
fix: Update snapshot
gambinish Nov 14, 2024
5fa2984
fix: chore fix otudated snapshot
gambinish Nov 14, 2024
fc0722c
fix: Revert change to token cell snap
gambinish Nov 14, 2024
bf61b33
fix: Tweak snap
gambinish Nov 14, 2024
04c3e3f
fix: troubleshoot whitespace diff
gambinish Nov 14, 2024
ae00656
fix: Troubleshoot whitespace diff
gambinish Nov 14, 2024
d18e085
fix: Troubleshoot whitespace diff
gambinish Nov 14, 2024
43b0cfe
fix: Update showScamWarning to not scam native tokens on multichain t…
gambinish Nov 14, 2024
c147b3a
fix: Fix behavior of native token click
gambinish Nov 14, 2024
ae01bfc
chore: Merge develop, address conflicts
gambinish Nov 14, 2024
9252c18
chore: Fix undefined bug during token import process causing crash
gambinish Nov 14, 2024
35f6287
fix: When hex balance is 0x0, return zero value
gambinish Nov 14, 2024
8e57813
fix: Cleanup console.log
gambinish Nov 14, 2024
e0b49ed
fix: Do not prematurely return from calculateTokenBalance function
gambinish Nov 14, 2024
0a72a62
chore: Merge develop, address conflicts
gambinish Nov 15, 2024
0bee071
fix: Patch updates and NetworkController:state change subscription
gambinish Nov 15, 2024
2df22cb
refactor: Integrate useTokenBalances hook
gambinish Nov 15, 2024
5c4c9b4
chore: Merge develop, address conflicts
gambinish Nov 16, 2024
0e2c013
fix: Address inconsistencies after merge
gambinish Nov 16, 2024
8bf9eaf
Style fixes
jonybur Nov 18, 2024
1df49df
fix: Issue 28509 - when navigating to send/swap form a token from a c…
gambinish Nov 19, 2024
bc459c2
fix: Issue 28511 - Show native token symbol in token-list
gambinish Nov 19, 2024
1fff579
fix: Issue 28513 - WHen a network is added, and the network is switch…
gambinish Nov 19, 2024
5980212
fix: Issue 28513: Adding networks should toggle network filter
gambinish Nov 19, 2024
758fa6a
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 19, 2024
3b42f0c
Move refresh list to asset control bar
jonybur Nov 19, 2024
2338fcc
Merge branch 'feat/mmassets-432_network-filter-extension--integration…
jonybur Nov 19, 2024
a8364ff
Style fix
jonybur Nov 19, 2024
4f70ccd
Filter tokens by test-nontest networks
jonybur Nov 19, 2024
da79b45
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 19, 2024
836c2f5
fix: Dedupde controller polling init
gambinish Nov 19, 2024
704fd6f
fix: typo in test id
gambinish Nov 19, 2024
85546a0
fix: When new tokens are imported, rerender the token list
gambinish Nov 19, 2024
3273dba
fix: On network change, include newly added network to tokenNetworkFi…
gambinish Nov 20, 2024
1bdaf8d
fix: Format currency with same format as previous implementation to a…
gambinish Nov 20, 2024
817c9ba
fix: Map Arbitrum, Linea, and Base native token to ETH logo
gambinish Nov 20, 2024
ce01c11
fix: Lint token-cell.tsx
gambinish Nov 20, 2024
e55b50d
chore: Merge develop, address conflicts
gambinish Nov 20, 2024
a9b16e2
fix: Remove fake loading boolean
gambinish Nov 20, 2024
675780e
fix: Lint
gambinish Nov 20, 2024
614b5ff
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 20, 2024
0bbaeb5
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 20, 2024
2c458c5
fix: Typo
gambinish Nov 20, 2024
6e92ee4
chore: Rebase with develop
gambinish Nov 21, 2024
e6b33f5
fix: Revert removal of NativeToken in order to support flask build
gambinish Nov 21, 2024
838e4a1
fix: Include nativeToken in props
gambinish Nov 21, 2024
00c07aa
chore: Remove patch resolution
gambinish Nov 21, 2024
5b7ea11
fix: Dont remove chokidar
gambinish Nov 21, 2024
0d77e0b
fix: Dedupe controller method
gambinish Nov 21, 2024
d4880c7
fix: Align asset-list-control-bar styles
gambinish Nov 21, 2024
f0d722f
fix: component import
gambinish Nov 21, 2024
035fb5c
fix: Revert token-cell test. Should be fixed in unit test branch, not…
gambinish Nov 21, 2024
0867b5c
chore: Cleanup useAccountTotalFiatBalance hook
gambinish Nov 21, 2024
7f29e11
Merge branch 'develop' into feat/mmassets-432_network-filter-extensio…
gambinish Nov 21, 2024
a610400
fix: Dont override suffix label
gambinish Nov 21, 2024
650aec5
fix: Lint unused var
gambinish Nov 21, 2024
b34ce81
fix: React.CloneElement tells react to return an element in the tree
gambinish Nov 21, 2024
006f12c
fix: Update en locale, loadingTokens no longer needed
gambinish Nov 21, 2024
4d3aeba
fix: Temporarily log locale string to remove
gambinish Nov 21, 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
3 changes: 3 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.

3 changes: 3 additions & 0 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ export const SENTRY_BACKGROUND_STATE = {
[AllProperties]: false,
},
},
TokenBalancesController: {
tokenBalances: false,
},
TokenRatesController: {
marketData: false,
},
Expand Down
34 changes: 34 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CodefiTokenPricesServiceV2,
RatesController,
fetchMultiExchangeRate,
TokenBalancesController,
} from '@metamask/assets-controllers';
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
import { createEngineStream } from '@metamask/json-rpc-middleware-stream';
Expand Down Expand Up @@ -891,6 +892,27 @@ export default class MetamaskController extends EventEmitter {
};
};

const tokenBalancesMessenger = this.controllerMessenger.getRestricted({
name: 'TokenBalancesController',
allowedActions: [
'NetworkController:getState',
'NetworkController:getNetworkClientById',
'TokensController:getState',
'PreferencesController:getState',
'AccountsController:getSelectedAccount',
],
allowedEvents: [
'PreferencesController:stateChange',
'TokensController:stateChange',
],
});

this.tokenBalancesController = new TokenBalancesController({
messenger: tokenBalancesMessenger,
state: initState.TokenBalancesController,
interval: 30000,
});

const phishingControllerMessenger = this.controllerMessenger.getRestricted({
name: 'PhishingController',
});
Expand Down Expand Up @@ -2397,6 +2419,7 @@ export default class MetamaskController extends EventEmitter {
GasFeeController: this.gasFeeController,
TokenListController: this.tokenListController,
TokensController: this.tokensController,
TokenBalancesController: this.tokenBalancesController,
SmartTransactionsController: this.smartTransactionsController,
NftController: this.nftController,
PhishingController: this.phishingController,
Expand Down Expand Up @@ -2452,6 +2475,7 @@ export default class MetamaskController extends EventEmitter {
GasFeeController: this.gasFeeController,
TokenListController: this.tokenListController,
TokensController: this.tokensController,
TokenBalancesController: this.tokenBalancesController,
SmartTransactionsController: this.smartTransactionsController,
NftController: this.nftController,
SelectedNetworkController: this.selectedNetworkController,
Expand Down Expand Up @@ -3225,6 +3249,7 @@ export default class MetamaskController extends EventEmitter {
nftController,
nftDetectionController,
currencyRateController,
tokenBalancesController,
tokenDetectionController,
ensController,
gasFeeController,
Expand Down Expand Up @@ -4019,6 +4044,14 @@ export default class MetamaskController extends EventEmitter {
tokenRatesController,
),

tokenBalancesStartPolling: tokenBalancesController.startPolling.bind(
tokenBalancesController,
),
tokenBalancesStopPollingByPollingToken:
tokenBalancesController.stopPollingByPollingToken.bind(
tokenBalancesController,
),

// GasFeeController
gasFeeStartPollingByNetworkClientId:
gasFeeController.startPollingByNetworkClientId.bind(gasFeeController),
Expand Down Expand Up @@ -6652,6 +6685,7 @@ export default class MetamaskController extends EventEmitter {
this.currencyRateController.stopAllPolling();
this.tokenRatesController.stopAllPolling();
this.appStateController.clearPollingTokens();
this.tokenBalancesController.stopAllPolling();
} catch (error) {
console.error(error);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"attributions:generate": "./development/generate-attributions.sh"
gambinish marked this conversation as resolved.
Show resolved Hide resolved
},
"resolutions": {
"@metamask/assets-controllers": "patch:@metamask-previews/[email protected]#./.yarn/patches/@metamask-assets-controllers-npm-42.0.0-57b3d695bb.patch",
"chokidar": "^3.6.0",
"gridplus-sdk/elliptic": "^6.5.7",
"gridplus-sdk/secp256k1": "^5.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { useRef, useState } from 'react';
import { useSelector } from 'react-redux';
import { getCurrentNetwork, getPreferences } from '../../../../../selectors';
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
getCurrentNetwork,
getNetworkConfigurationsByChainId,
getPreferences,
} from '../../../../../selectors';
import {
Box,
ButtonBase,
Expand All @@ -12,8 +16,6 @@ import {
import SortControl from '../sort-control';
import {
BackgroundColor,
BorderColor,
BorderStyle,
Display,
JustifyContent,
TextColor,
Expand All @@ -28,21 +30,40 @@ import {
ENVIRONMENT_TYPE_POPUP,
} from '../../../../../../shared/constants/app';
import NetworkFilter from '../network-filter';
import { setTokenNetworkFilter } from '../../../../../store/actions';
import Tooltip from '../../../../ui/tooltip';

type AssetListControlBarProps = {
showTokensLinks?: boolean;
};

const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
const t = useI18nContext();
const dispatch = useDispatch();
const popoverRef = useRef<HTMLDivElement>(null);
const currentNetwork = useSelector(getCurrentNetwork);
const allNetworks = useSelector(getNetworkConfigurationsByChainId);
const { tokenNetworkFilter } = useSelector(getPreferences);
const [isTokenSortPopoverOpen, setIsTokenSortPopoverOpen] = useState(false);
const [isNetworkFilterPopoverOpen, setIsNetworkFilterPopoverOpen] =
useState(false);

const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length;
const allOpts: Record<string, boolean> = {};
Object.keys(allNetworks).forEach((chainId) => {
allOpts[chainId] = true;
});

const allNetworksFilterShown =
Object.keys(tokenNetworkFilter).length !== Object.keys(allOpts).length;

// TODO: This useEffect should be a migration
// We need to set the default filter for all users to be all included networks, rather than defaulting to empty object
// This effect is to unblock and derisk in the short-term
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still true?

Copy link
Contributor Author

@gambinish gambinish Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a perfect world, I think we should have a migration that runs and updates everyone's default network filter to all their networkConfigurationByChainId, rather than updating them on the fly in the UI.

I'm not sure if it's totally necessary to be feature complete however. I can remove this comment if it's confusing.

if (Object.keys(tokenNetworkFilter).length === 0) {
dispatch(setTokenNetworkFilter(allOpts));
}
}, []);

const windowType = getEnvironmentType();
const isFullScreen =
Expand All @@ -67,21 +88,16 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
return (
<Box
className="asset-list-control-bar"
marginLeft={4}
marginRight={4}
marginLeft={2}
marginRight={2}
paddingTop={4}
ref={popoverRef}
>
<Box
display={Display.Flex}
justifyContent={
isFullScreen ? JustifyContent.flexStart : JustifyContent.spaceBetween
}
>
<Box display={Display.Flex} justifyContent={JustifyContent.spaceBetween}>
{process.env.FILTER_TOKENS_TOGGLE && (
<ButtonBase
data-testid="sort-by-popover-toggle"
className="asset-list-control-bar__button"
className="asset-list-control-bar__button asset-list-control-bar__network_control"
onClick={toggleNetworkFilterPopover}
size={ButtonBaseSize.Sm}
endIconName={IconName.ArrowDown}
Expand All @@ -90,8 +106,6 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
? BackgroundColor.backgroundPressed
: BackgroundColor.backgroundDefault
}
borderColor={BorderColor.borderMuted}
borderStyle={BorderStyle.solid}
color={TextColor.textDefault}
marginRight={isFullScreen ? 2 : null}
ellipsis
Expand All @@ -102,26 +116,28 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
</ButtonBase>
)}

<ButtonBase
data-testid="sort-by-popover-toggle"
className="asset-list-control-bar__button"
onClick={toggleTokenSortPopover}
size={ButtonBaseSize.Sm}
endIconName={IconName.ArrowDown}
backgroundColor={
isTokenSortPopoverOpen
? BackgroundColor.backgroundPressed
: BackgroundColor.backgroundDefault
}
borderColor={BorderColor.borderMuted}
borderStyle={BorderStyle.solid}
color={TextColor.textDefault}
marginRight={isFullScreen ? 2 : null}
>
{t('sortBy')}
</ButtonBase>
<Box display={Display.Flex} justifyContent={JustifyContent.flexEnd}>
<Tooltip title={t('sortBy')} position="bottom" distance={20}>
<ButtonBase
data-testid="sort-by-popover-toggle"
className="asset-list-control-bar__button"
onClick={toggleTokenSortPopover}
size={ButtonBaseSize.Sm}
endIconName={IconName.SwapVertical}
backgroundColor={
isTokenSortPopoverOpen
? BackgroundColor.backgroundPressed
: BackgroundColor.backgroundDefault
}
color={TextColor.textDefault}
marginRight={isFullScreen ? 2 : null}
/>
</Tooltip>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use ButtonIcon?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we probably should. I'll make this change ty for pointing this out.


<ImportControl showTokensLinks={showTokensLinks} />
<Tooltip title={t('importTokens')} position="bottom" distance={20}>
<ImportControl showTokensLinks={showTokensLinks} />
</Tooltip>
</Box>
</Box>

<Popover
Expand All @@ -143,7 +159,7 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
<Popover
onClickOutside={closePopover}
isOpen={isTokenSortPopoverOpen}
position={PopoverPosition.BottomStart}
position={PopoverPosition.BottomEnd}
referenceElement={popoverRef.current}
matchWidth={!isFullScreen}
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
max-width: 35%;
}

&__network_control {
justify-content: space-between;
min-width: 180px;
}

&__button:hover {
background-color: var(--color-background-hover);
}
Expand Down
2 changes: 0 additions & 2 deletions ui/components/app/assets/asset-list/asset-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
import { getIsNativeTokenBuyable } from '../../../../ducks/ramps';
///: END:ONLY_INCLUDE_IF
import AssetListControlBar from './asset-list-control-bar';
import NativeToken from './native-token';

export type TokenWithBalance = {
address: string;
Expand Down Expand Up @@ -115,7 +114,6 @@ const AssetList = ({ onClickAsset, showTokensLinks }: AssetListProps) => {
)}
<AssetListControlBar showTokensLinks={showTokensLinks} />
<TokenList
nativeToken={<NativeToken onClickAsset={onClickAsset} />}
onTokenClick={(tokenAddress: string) => {
onClickAsset(tokenAddress);
trackEvent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
} from '../../../../component-library';
import {
BackgroundColor,
BorderColor,
BorderStyle,
TextColor,
} from '../../../../../helpers/constants/design-system';
import { showImportTokensModal } from '../../../../../store/actions';
Expand All @@ -18,7 +16,6 @@ import {
MetaMetricsEventName,
} from '../../../../../../shared/constants/metametrics';
import { getMultichainIsEvm } from '../../../../../selectors/multichain';
import { useI18nContext } from '../../../../../hooks/useI18nContext';

type AssetListControlBarProps = {
showTokensLinks?: boolean;
Expand All @@ -27,7 +24,6 @@ type AssetListControlBarProps = {
const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
const dispatch = useDispatch();
const trackEvent = useContext(MetaMetricsContext);
const t = useI18nContext();
const isEvm = useSelector(getMultichainIsEvm);
// NOTE: Since we can parametrize it now, we keep the original behavior
// for EVM assets
Expand All @@ -41,8 +37,6 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
size={ButtonBaseSize.Sm}
startIconName={IconName.Add}
backgroundColor={BackgroundColor.backgroundDefault}
borderColor={BorderColor.borderMuted}
borderStyle={BorderStyle.solid}
color={TextColor.textDefault}
onClick={() => {
dispatch(showImportTokensModal());
Expand All @@ -54,9 +48,7 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
},
});
}}
>
{t('import')}
</ButtonBase>
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
getShouldHideZeroBalanceTokens,
);

const { totalFiatBalance: selectedAccountBalance } =
useAccountTotalFiatBalance(selectedAccount, shouldHideZeroBalanceTokens);
// const { totalFiatBalance: selectedAccountBalance } =
// useAccountTotalFiatBalance(selectedAccount, shouldHideZeroBalanceTokens);

const selectedAccountBalance = 100;

// TODO: fetch balances across networks
// const multiNetworkAccountBalance = useMultichainAccountBalance()
Expand All @@ -56,11 +58,19 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
handleClose();
};

const allOpts: Record<string, boolean> = {};
Object.keys(allNetworks).forEach((chainId) => {
allOpts[chainId] = true;
});

return (
<>
<SelectableListItem
isSelected={!Object.keys(tokenNetworkFilter).length}
onClick={() => handleFilter({})}
isSelected={
Object.keys(tokenNetworkFilter).length ===
Object.keys(allNetworks).length
}
onClick={() => handleFilter(allOpts)}
>
<Box
display={Display.Flex}
Expand Down Expand Up @@ -106,7 +116,10 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
</Box>
</SelectableListItem>
<SelectableListItem
isSelected={tokenNetworkFilter[chainId]}
isSelected={
tokenNetworkFilter[chainId] &&
Object.keys(tokenNetworkFilter).length === 1
}
onClick={() => handleFilter({ [chainId]: true })}
>
<Box
Expand Down
Loading
Loading