Skip to content

Commit

Permalink
fix: display other currency conversion for btc
Browse files Browse the repository at this point in the history
  • Loading branch information
montelaidev committed Dec 5, 2024
1 parent 9d4120e commit e42e7bd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
getMultichainSelectedAccountCachedBalance,
getMultichainShouldShowFiat,
} from '../../../../../selectors/multichain';
import { getCurrentCurrency, getPreferences } from '../../../../../selectors';
import {
getCurrentCurrency,
getPreferences,
getSelectedInternalAccount,
} from '../../../../../selectors';
import { useIsOriginalNativeTokenSymbol } from '../../../../../hooks/useIsOriginalNativeTokenSymbol';
import { PRIMARY, SECONDARY } from '../../../../../helpers/constants/common';
import { useUserPreferencedCurrency } from '../../../../../hooks/useUserPreferencedCurrency';
Expand All @@ -16,6 +20,7 @@ import { TokenWithBalance } from '../asset-list';

export const useNativeTokenBalance = () => {
const showFiat = useSelector(getMultichainShouldShowFiat);
const account = useSelector(getSelectedInternalAccount);
const primaryTokenImage = useSelector(getMultichainCurrencyImage);
const { showNativeTokenAsMainBalance } = useSelector(getPreferences);
const { chainId, ticker, type, rpcUrl } = useSelector(
Expand Down Expand Up @@ -46,12 +51,14 @@ export const useNativeTokenBalance = () => {

const [primaryCurrencyDisplay, primaryCurrencyProperties] =
useCurrencyDisplay(balance, {
account,
numberOfDecimals: primaryNumberOfDecimals,
currency: primaryCurrency,
});

const [secondaryCurrencyDisplay, secondaryCurrencyProperties] =
useCurrencyDisplay(balance, {
account,
numberOfDecimals: secondaryNumberOfDecimals,
currency: secondaryCurrency,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,7 @@ const AccountListItem = ({
{shortenAddress(normalizeSafeAddress(account.address))}
</Text>
</Box>
{/* For non-EVM networks we always want to show tokens */}
{mappedOrderedTokenList.length > 1 || !isEvmNetwork ? (
{mappedOrderedTokenList.length > 1 ? (
<AvatarGroup members={mappedOrderedTokenList} limit={4} />
) : (
<Box
Expand Down
1 change: 1 addition & 0 deletions ui/hooks/useCurrencyDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function formatNonEvmAssetCurrencyDisplay({
* @property {string} [denomination] - Denomination (wei, gwei) to convert to for display
* @property {string} [currency] - Currency type to convert to. Will override nativeCurrency
* @property {boolean} [hideLabel] – hide the currency label
* @property {object} [account] - The account object
*/

/**
Expand Down
23 changes: 8 additions & 15 deletions ui/selectors/multichain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,10 @@ export function getMultichainNativeCurrency(

export function getMultichainCurrentCurrency(
state: MultichainState,
account?: InternalAccount,
_account?: InternalAccount,
) {
const currentCurrency = getCurrentCurrency(state);

if (getMultichainIsEvm(state, account)) {
return currentCurrency;
}

// For non-EVM:
// To mimic `getCurrentCurrency` we only consider fiat values, otherwise we
// fallback to the current ticker symbol value
return currentCurrency && currentCurrency.toLowerCase() === 'usd'
? 'usd'
: getMultichainProviderConfig(state, account).ticker;
return currentCurrency;
}

export function getMultichainCurrencyImage(
Expand Down Expand Up @@ -375,9 +365,12 @@ export const getMultichainCoinRates = (state: MultichainState) => {
return state.metamask.rates;
};

function getNonEvmCachedBalance(state: MultichainState) {
function getNonEvmCachedBalance(
state: MultichainState,
account?: InternalAccount,
) {
const balances = getMultichainBalances(state);
const account = getSelectedInternalAccount(state);
const selectedAccount = account ?? getSelectedInternalAccount(state);
const network = getMultichainCurrentNetwork(state);

// We assume that there's at least one asset type in and that is the native
Expand All @@ -387,7 +380,7 @@ function getNonEvmCachedBalance(state: MultichainState) {
network.chainId as MultichainNetworks
]?.[0];

return balances?.[account.id]?.[asset]?.amount;
return balances?.[selectedAccount.id]?.[asset]?.amount ?? 0;
}

export function getImageForChainId(chainId: string) {
Expand Down
4 changes: 2 additions & 2 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import {
import { BackgroundColor } from '../helpers/constants/design-system';
import { NOTIFICATION_DROP_LEDGER_FIREFOX } from '../../shared/notifications';
import { ENVIRONMENT_TYPE_POPUP } from '../../shared/constants/app';
import { MultichainNativeAssets } from '../../shared/constants/multichain/assets';
import { MULTICHAIN_NETWORK_TO_ASSET_TYPES } from '../../shared/constants/multichain/assets';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { BridgeFeatureFlagsKey } from '../../app/scripts/controllers/bridge/types';
Expand Down Expand Up @@ -291,7 +291,7 @@ export const getMetaMaskAccounts = createSelector(
...account,
balance:
multichainBalances?.[internalAccount.id]?.[
MultichainNativeAssets[multichainNetwork.chainId]
MULTICHAIN_NETWORK_TO_ASSET_TYPES[multichainNetwork.chainId]
]?.amount ?? '0',
};
}
Expand Down

0 comments on commit e42e7bd

Please sign in to comment.