Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1e319a0
refactor: selectedAddress to selectedAccountId
montelaidev Jun 5, 2024
c8ac590
fix: add more tests
montelaidev Jun 5, 2024
87b6a32
fix: lower branch coverage
montelaidev Jun 5, 2024
b58e44c
Merge branch 'main' into fix/ap381/update-tokens-controllers-to-use-i…
montelaidev Jun 5, 2024
b853f09
Merge remote-tracking branch 'origin/main' into fix/ap381/update-toke…
montelaidev Jun 7, 2024
22ee782
refactor: token detection test
montelaidev Jun 12, 2024
f8d1303
refactor: token balances test
montelaidev Jun 12, 2024
5800381
refactor: token rates tests
montelaidev Jun 12, 2024
9253b27
Merge remote-tracking branch 'origin/main' into fix/ap381/update-toke…
montelaidev Jun 12, 2024
d38c696
fix: test
montelaidev Jun 12, 2024
03aac22
refactor: TokensController to not require selectedAccountId in constr…
montelaidev Jun 13, 2024
5f3f15b
fix: lint
montelaidev Jun 13, 2024
b0f09ea
fix: test names
montelaidev Jun 13, 2024
3539272
revert: coverage
montelaidev Jun 13, 2024
f92a0a0
fix: lint
montelaidev Jun 14, 2024
fd652a3
refactor: create new helper
montelaidev Jun 14, 2024
e3d389b
fix: remove empty line
montelaidev Jun 18, 2024
63c2b82
refactor: variable names and helper method
montelaidev Jun 18, 2024
8882ab2
refactor: use helper
montelaidev Jun 18, 2024
e7f0888
Merge remote-tracking branch 'origin/main' into fix/ap381/update-toke…
montelaidev Jun 18, 2024
8ab89f2
fix: test
montelaidev Jun 18, 2024
12814e7
fix: test name
montelaidev Jun 20, 2024
1c40133
feat: add #getSelectedAddress helper
montelaidev Jun 20, 2024
58d8a42
refactor: create const to be used in getTOkenAddresses
montelaidev Jun 20, 2024
c7805b9
fix: reduce getAccountHandler calls
montelaidev Jun 20, 2024
692d1c2
fix: refactor test vars
montelaidev Jun 20, 2024
82cf639
Merge branch 'main' into fix/ap381/update-tokens-controllers-to-use-i…
montelaidev Jun 20, 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
309 changes: 172 additions & 137 deletions packages/assets-controllers/src/TokenBalancesController.test.ts

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions packages/assets-controllers/src/TokenBalancesController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';
import {
type RestrictedControllerMessenger,
type ControllerGetStateAction,
type ControllerStateChangeEvent,
BaseController,
} from '@metamask/base-controller';
import { safelyExecute, toHex } from '@metamask/controller-utils';
import type { PreferencesControllerGetStateAction } from '@metamask/preferences-controller';

import type { AssetsContractController } from './AssetsContractController';
import type { Token } from './TokenRatesController';
Expand Down Expand Up @@ -56,7 +56,7 @@ export type TokenBalancesControllerGetStateAction = ControllerGetStateAction<
export type TokenBalancesControllerActions =
TokenBalancesControllerGetStateAction;

export type AllowedActions = PreferencesControllerGetStateAction;
export type AllowedActions = AccountsControllerGetSelectedAccountAction;

export type TokenBalancesControllerStateChangeEvent =
ControllerStateChangeEvent<
Expand Down Expand Up @@ -201,16 +201,18 @@ export class TokenBalancesController extends BaseController<
if (this.#disabled) {
return;
}

const { selectedAddress } = this.messagingSystem.call(
'PreferencesController:getState',
const selectedInternalAccount = this.messagingSystem.call(
'AccountsController:getSelectedAccount',
);

const newContractBalances: ContractBalances = {};
for (const token of this.#tokens) {
const { address } = token;
try {
const balance = await this.#getERC20BalanceOf(address, selectedAddress);
const balance = await this.#getERC20BalanceOf(
address,
selectedInternalAccount.address,
);
newContractBalances[address] = toHex(balance);
token.hasBalanceError = false;
} catch (error) {
Expand Down
Loading