Skip to content

Commit

Permalink
start fetching balance
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Dec 13, 2024
1 parent 373bf9e commit 6de9d8b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
10 changes: 10 additions & 0 deletions app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
import { InternalAccount } from '@metamask/keyring-api';
import { getChainIdsToPoll } from '../../../../../selectors/tokensController';
import AggregatedPercentageCrossChains from '../../../../../component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentageCrossChains';
import { selectMultichainSelectedAccountCachedBalance } from '../../../../../selectors/multichain';

export const PortfolioBalance = () => {
const { PreferencesController } = Engine.context;
Expand Down Expand Up @@ -102,6 +103,15 @@ export const PortfolioBalance = () => {
const browserTabs = useSelector((state: RootState) => state.browser.tabs);
const privacyMode = useSelector(selectPrivacyMode);

const multichainSelectedAccountCachedBalance = useSelector(
selectMultichainSelectedAccountCachedBalance,
);

console.log(

Check failure on line 110 in app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx

View workflow job for this annotation

GitHub Actions / scripts (lint)

Unexpected console statement
'multichainSelectedAccountCachedBalance',
multichainSelectedAccountCachedBalance,
);

const isOriginalNativeTokenSymbol = useIsOriginalNativeTokenSymbol(
chainId,
ticker,
Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ const Wallet = ({
</View>
) : null}
<>
{accountBalanceByChainId && <PortfolioBalance />}
<PortfolioBalance />
<ScrollableTabView
renderTabBar={renderTabBar}
// eslint-disable-next-line react/jsx-no-bind
Expand Down
18 changes: 13 additions & 5 deletions app/core/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ export class Engine {

return Boolean(
hasProperty(showIncomingTransactions, currentChainId) &&
showIncomingTransactions?.[currentHexChainId],
showIncomingTransactions?.[currentHexChainId],
);
},
updateTransactions: true,
Expand Down Expand Up @@ -1827,7 +1827,7 @@ export class Engine {

const tokenBalances =
allTokenBalances?.[selectedInternalAccount.address as Hex]?.[
chainId
chainId
] ?? {};
tokens.forEach(
(item: { address: string; balance?: string; decimals: number }) => {
Expand All @@ -1838,9 +1838,9 @@ export class Engine {
item.balance ||
(item.address in tokenBalances
? renderFromTokenMinimalUnit(
tokenBalances[item.address as Hex],
item.decimals,
)
tokenBalances[item.address as Hex],
item.decimals,
)
: undefined);
const tokenBalanceFiat = balanceToFiatNumber(
// TODO: Fix this by handling or eliminating the undefined case
Expand Down Expand Up @@ -2143,6 +2143,10 @@ export default {
ApprovalController,
LoggingController,
AccountsController,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
MultichainBalancesController,
RatesController,
///: END:ONLY_INCLUDE_IF
} = instance.datamodel.state;

return {
Expand Down Expand Up @@ -2177,6 +2181,10 @@ export default {
ApprovalController,
LoggingController,
AccountsController,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
MultichainBalancesController,
RatesController,
///: END:ONLY_INCLUDE_IF
};
},

Expand Down
29 changes: 18 additions & 11 deletions app/selectors/multichain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { selectTokenMarketData } from './tokenRatesController';
import { isMainNet } from '../util/networks';
import { isEvmAccountType } from '@metamask/keyring-api';
import { createDeepEqualSelector } from './util';
import Engine from '../core/Engine/Engine';

Check failure on line 36 in app/selectors/multichain.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

'Engine' is defined but never used

interface NativeTokenBalance {
balance: string;
Expand Down Expand Up @@ -300,8 +301,13 @@ export const selectMultichainIsMainnet = createSelector(
* @param state - Root redux state
* @returns - MultichainBalancesController state
*/
const selectMultichainBalancesControllerState = (state: RootState) =>
state.engine.backgroundState.MultichainBalancesController;
const selectMultichainBalancesControllerState = (state: RootState) => {
console.log(

Check failure on line 305 in app/selectors/multichain.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Unexpected console statement
'selectMultichainBalancesControllerState',
JSON.stringify(state.engine.backgroundState.MultichainBalancesController),
);
return state.engine.backgroundState.MultichainBalancesController;
};

export const selectMultichainBalances = createDeepEqualSelector(
selectMultichainBalancesControllerState,
Expand All @@ -322,16 +328,17 @@ const selectBtcCachedBalance = createDeepEqualSelector(
},
);

export const selectMultichainSelectedAccountCachedBalance = createSelector(
selectMultichainIsEvm,
selectAccountBalanceByChainId,
selectBtcCachedBalance,
(isEvm, accountBalanceByChainId, btcCachedBalance) =>
isEvm ? accountBalanceByChainId?.balance ?? '0x0' : btcCachedBalance,
);
export const selectMultichainSelectedAccountCachedBalance =
createDeepEqualSelector(
selectMultichainIsEvm,
selectAccountBalanceByChainId,
selectBtcCachedBalance,
(isEvm, accountBalanceByChainId, btcCachedBalance) =>
isEvm ? accountBalanceByChainId?.balance ?? '0x0' : btcCachedBalance,
);

export const selectMultichainSelectedAccountCachedBalanceIsZero =
createSelector(
createDeepEqualSelector(
selectMultichainSelectedAccountCachedBalance,
selectMultichainIsEvm,
(balance, isEvm) => {
Expand All @@ -341,7 +348,7 @@ export const selectMultichainSelectedAccountCachedBalanceIsZero =
},
);

export const selectMultichainConversionRate = createSelector(
export const selectMultichainConversionRate = createDeepEqualSelector(
selectMultichainIsEvm,
selectConversionRate,
selectCurrencyRates,
Expand Down

0 comments on commit 6de9d8b

Please sign in to comment.