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: add network picker to AssetPicker #26559

Merged
merged 20 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fcee6ad
feat: add network picker to asset-picker
micaelae Jul 30, 2024
9c16831
fix: show correct network icon when selected network !== active network
micaelae Aug 1, 2024
9831a41
fix: override native token details in AssetList
micaelae Aug 9, 2024
c32c6d8
refactor: split up token sorting and filtering
micaelae Aug 8, 2024
246195d
feat: pass in custom filteredTokensGenerator function to asset-picker
micaelae Aug 8, 2024
858425b
chore: pass filter predicate to filteredTokensGenerator
micaelae Aug 8, 2024
fb0a4f6
chore: add AssetPicker fallback text
micaelae Aug 23, 2024
6a9e5ec
fix: lint and unit tests
micaelae Sep 5, 2024
a4a6914
fix: show network picker button only if networkProps are present
micaelae Sep 25, 2024
f5e0adc
fix: use NetworkConfiguration instead of ProviderConfig/RPCEndpoint
micaelae Sep 25, 2024
af477a5
test: add asset-picker-modal-network tests
micaelae Sep 25, 2024
abb5d7f
refactor: remove nested ternary
micaelae Sep 26, 2024
00b1601
fix: asset-picker should open network selection tab if network is und…
micaelae Sep 18, 2024
7537c51
fix: hide token suffix when balance is shown in fiat
micaelae Oct 1, 2024
737da46
fix: always show fiat value as primary
micaelae Oct 1, 2024
b4fc740
fix: replace hardcoded currency
micaelae Oct 1, 2024
54a1e14
chore: display token value before fiat
micaelae Oct 2, 2024
7b05ddc
fix: asset-picker-send e2e test
micaelae Oct 2, 2024
bf57b5c
chore: destructure chainId from networkConfig
micaelae Oct 8, 2024
2309fa5
chore: trim searchQuery before checking for symbol match
micaelae 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
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.

4 changes: 2 additions & 2 deletions test/e2e/tests/multichain/asset-picker-send.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ describe('AssetPickerSendFlow @no-mmi', function () {
)
).getText();

assert.equal(tokenListValue, '25 ETH');
assert.equal(tokenListValue, '$250,000.00');

const tokenListSecondaryValue = await (
await driver.findElement(
'[data-testid="multichain-token-list-item-secondary-value"]',
)
).getText();

assert.equal(tokenListSecondaryValue, '$250,000.00');
assert.equal(tokenListSecondaryValue, '25 ETH');

// Search for CHZ
const searchInputField = await driver.waitForSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ describe('Asset', () => {
expect.objectContaining({
tokenSymbol: 'WETH',
tokenImage: 'token-icon-url',
primary: '10',
secondary: '$10.10',
primary: '$10.10',
secondary: '10 WETH',
title: 'Token',
tooltipText: 'tooltip',
isPrimaryTokenSymbolHidden: true,
}),
{},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ export default function Asset({
{},
true,
);
const formattedAmount = decimalTokenAmount
? `${formatAmount(
locale,
new BigNumber(decimalTokenAmount || '0', 10),
)} ${symbol}`
: undefined;

return (
<TokenListItem
tokenSymbol={symbol}
tokenImage={tokenImage}
primary={formatAmount(
locale,
new BigNumber(decimalTokenAmount || '0', 10),
)}
secondary={formattedFiat}
secondary={formattedAmount}
primary={formattedFiat}
title={title}
tooltipText={tooltipText}
isPrimaryTokenSymbolHidden
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { useSelector } from 'react-redux';
import classnames from 'classnames';
import { getSelectedAccountCachedBalance } from '../../../../selectors';
import {
getCurrentCurrency,
getSelectedAccountCachedBalance,
} from '../../../../selectors';
import { getNativeCurrency } from '../../../../ducks/metamask/metamask';
import { useUserPreferencedCurrency } from '../../../../hooks/useUserPreferencedCurrency';
import { PRIMARY, SECONDARY } from '../../../../helpers/constants/common';
import { useCurrencyDisplay } from '../../../../hooks/useCurrencyDisplay';
import { AssetType } from '../../../../../shared/constants/transaction';
import { Box } from '../../../component-library';
Expand Down Expand Up @@ -43,35 +44,24 @@ export default function AssetList({

const nativeCurrency = useSelector(getNativeCurrency);
const balanceValue = useSelector(getSelectedAccountCachedBalance);
const currentCurrency = useSelector(getCurrentCurrency);

const {
currency: primaryCurrency,
numberOfDecimals: primaryNumberOfDecimals,
} = useUserPreferencedCurrency(PRIMARY, { ethNumberOfDecimals: 4 });

const {
currency: secondaryCurrency,
numberOfDecimals: secondaryNumberOfDecimals,
} = useUserPreferencedCurrency(SECONDARY, { ethNumberOfDecimals: 4 });

const [, primaryCurrencyProperties] = useCurrencyDisplay(balanceValue, {
numberOfDecimals: primaryNumberOfDecimals,
currency: primaryCurrency,
const [primaryCurrencyValue] = useCurrencyDisplay(balanceValue, {
currency: currentCurrency,
hideLabel: true,
});
micaelae marked this conversation as resolved.
Show resolved Hide resolved

const [secondaryCurrencyDisplay, secondaryCurrencyProperties] =
useCurrencyDisplay(balanceValue, {
numberOfDecimals: secondaryNumberOfDecimals,
currency: secondaryCurrency,
hideLabel: true,
});
const [secondaryCurrencyValue] = useCurrencyDisplay(balanceValue, {
currency: nativeCurrency,
});

return (
<Box className="tokens-main-view-modal">
{tokenList.map((token) => {
const tokenAddress = token.address?.toLowerCase();
const isSelected = tokenAddress === selectedToken?.toLowerCase();
const isDisabled = isTokenDisabled?.(token) ?? false;

return (
<Box
padding={0}
Expand Down Expand Up @@ -112,15 +102,13 @@ export default function AssetList({
<Box marginInlineStart={2}>
{token.type === AssetType.native ? (
<TokenListItem
title={nativeCurrency}
primary={
primaryCurrencyProperties.value ??
secondaryCurrencyProperties.value
}
tokenSymbol={primaryCurrency}
secondary={secondaryCurrencyDisplay}
title={token.symbol}
primary={primaryCurrencyValue}
tokenSymbol={token.symbol}
secondary={secondaryCurrencyValue}
tokenImage={token.image}
isOriginalTokenSymbol
isOriginalTokenSymbol={token.symbol === nativeCurrency}
isPrimaryTokenSymbolHidden
/>
) : (
<AssetComponent
Expand Down
Loading