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(suite): show just receiving network in add account #16023

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const AddAccountModal = ({
const [enabledNetworks, disabledNetworks] = arrayPartition(supportedNetworks, network =>
enabledNetworkSymbols.includes(network.symbol),
);
const [disabledMainnetNetworks, disabledTestnetNetworks] = arrayPartition(
const [, disabledTestnetNetworks] = arrayPartition(
disabledNetworks,
network => !network?.testnet,
);
Expand All @@ -99,6 +99,15 @@ export const AddAccountModal = ({
)
: [];

const filterNetworksBySymbol = (networks: Network[], symbol?: NetworkSymbol) =>
symbol ? networks.filter(network => network.symbol === symbol) : networks;

const filteredDisabledNetworks = filterNetworksBySymbol(disabledNetworks, symbol);
const filteredEnabledNetworks = filterNetworksBySymbol(enabledNetworks, symbol);

const visibleNetworks =
emptyAccounts.length > 0 ? filteredEnabledNetworks : filteredDisabledNetworks;

const isCoinjoinVisible = (isCoinjoinPublic || isDebug) && !isCoinjoinDisabled;

const getAvailableAccountTypes = (network: Network) => {
Expand Down Expand Up @@ -208,20 +217,22 @@ export const AddAccountModal = ({
children: (
<>
<NetworksWrapper>
<SelectNetwork
heading={<Translation id="TR_ACTIVATED_COINS" />}
networks={enabledNetworks}
selectedNetworks={selectedNetworks}
handleNetworkSelection={selectNetwork}
/>
{!symbol && (
<SelectNetwork
heading={<Translation id="TR_ACTIVATED_COINS" />}
networks={enabledNetworks}
selectedNetworks={selectedNetworks}
handleNetworkSelection={selectNetwork}
/>
)}
<SelectNetwork
heading={<Translation id="TR_INACTIVE_COINS" />}
networks={disabledMainnetNetworks}
networks={visibleNetworks}
selectedNetworks={selectedNetworks}
handleNetworkSelection={selectNetwork}
/>
</NetworksWrapper>
{!!disabledTestnetNetworks.length && (
{!symbol && !!disabledTestnetNetworks.length && (
<CollapsibleBox
heading={
<Tooltip
Expand All @@ -243,7 +254,7 @@ export const AddAccountModal = ({
/>
</CollapsibleBox>
)}
{showUnsupportedCoins && (
{!symbol && showUnsupportedCoins && (
<CollapsibleBox
heading={
<Tooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const getTranslationIds = (
};

const useCoinmarketVerifyAccount = ({
currency,
cryptoId,
}: CoinmarketVerifyAccountProps): CoinmarketVerifyAccountReturnProps => {
const selectedAccount = useSelector(state => state.wallet.selectedAccount);
const accounts = useSelector(state => state.wallet.accounts);
Expand All @@ -82,15 +82,15 @@ const useCoinmarketVerifyAccount = ({
CoinmarketVerifyFormAccountOptionProps | undefined
>();

const networkId = currency && parseCryptoId(currency).networkId;
const symbol = currency && cryptoIdToSymbol(currency);
const networkId = cryptoId && parseCryptoId(cryptoId).networkId;
const symbol = cryptoId && cryptoIdToSymbol(cryptoId);

const isSupportedNetwork = [...supportedMainnets, ...supportedTestnets].some(
network => network.symbol === symbol,
);

const suiteReceiveAccounts = useMemo(() => {
if (currency) {
if (cryptoId) {
return filterReceiveAccounts({
accounts,
deviceState: device?.state?.staticSessionId,
Expand All @@ -100,7 +100,7 @@ const useCoinmarketVerifyAccount = ({
}

return undefined;
}, [accounts, currency, device, isDebug, symbol]);
}, [accounts, cryptoId, device, isDebug, symbol]);

const selectAccountOptions = useMemo(
() => getSelectAccountOptions(suiteReceiveAccounts, device, isSupportedNetwork),
Expand Down
2 changes: 1 addition & 1 deletion packages/suite/src/types/coinmarket/coinmarketVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface CoinmarketVerifyFormAccountOptionProps {
}

export interface CoinmarketVerifyAccountProps {
currency: CryptoId | undefined;
cryptoId: CryptoId | undefined;
}

export interface CoinmarketGetTranslationIdsProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export const CoinmarketOfferBuy = ({
paymentMethod,
paymentMethodName,
}: CoinmarketOfferBuyProps) => {
const currency = selectedQuote?.receiveCurrency;
const coinmarketVerifyAccount = useCoinmarketVerifyAccount({ currency });
const cryptoId = selectedQuote?.receiveCurrency;
const coinmarketVerifyAccount = useCoinmarketVerifyAccount({ cryptoId });

return (
<>
<Card>
{currency && (
{cryptoId && (
<CoinmarketVerify
coinmarketVerifyAccount={coinmarketVerifyAccount}
currency={currency}
cryptoId={cryptoId}
/>
)}
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export const CoinmarketOfferExchange = ({
quoteAmounts,
}: CoinmarketOfferExchangeProps) => {
const { exchangeStep } = useCoinmarketFormContext<CoinmarketTradeExchangeType>();
const currency = selectedQuote?.receive;
const coinmarketVerifyAccount = useCoinmarketVerifyAccount({ currency });
const cryptoId = selectedQuote?.receive;
const coinmarketVerifyAccount = useCoinmarketVerifyAccount({ cryptoId });

const steps: CoinmarketSelectedOfferStepperItemProps[] = [
{
step: 'RECEIVING_ADDRESS',
translationId: 'TR_EXCHANGE_VERIFY_ADDRESS_STEP',
isActive: exchangeStep === 'RECEIVING_ADDRESS',
component: currency ? (
component: cryptoId ? (
<CoinmarketVerify
coinmarketVerifyAccount={coinmarketVerifyAccount}
currency={currency}
cryptoId={cryptoId}
/>
) : null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import { getCoinmarketNetworkDisplaySymbol } from 'src/utils/wallet/coinmarket/c

interface CoinmarketVerifyProps {
coinmarketVerifyAccount: CoinmarketVerifyAccountReturnProps;
currency: CryptoId;
cryptoId: CryptoId;
}

export const CoinmarketVerify = ({ coinmarketVerifyAccount, currency }: CoinmarketVerifyProps) => {
export const CoinmarketVerify = ({ coinmarketVerifyAccount, cryptoId }: CoinmarketVerifyProps) => {
const dispatch = useDispatch();
const { translationString } = useTranslation();
const { cryptoIdToCoinSymbol, cryptoIdToNativeCoinSymbol } = useCoinmarketInfo();
Expand Down Expand Up @@ -60,13 +60,13 @@ export const CoinmarketVerify = ({ coinmarketVerifyAccount, currency }: Coinmark
const { accountTooltipTranslationId, addressTooltipTranslationId } = getTranslationIds(
selectedAccountOption?.type,
);
const coinSymbol = getCoinmarketNetworkDisplaySymbol(cryptoIdToCoinSymbol(currency) ?? '');
const coinSymbol = getCoinmarketNetworkDisplaySymbol(cryptoIdToCoinSymbol(cryptoId) ?? '');

const { ref: networkRef, ...networkField } = form.register('address', {
required: translationString('TR_EXCHANGE_RECEIVING_ADDRESS_REQUIRED'),
validate: value => {
if (selectedAccountOption?.type === 'NON_SUITE' && currency) {
const symbol = cryptoIdToNativeCoinSymbol(currency);
if (selectedAccountOption?.type === 'NON_SUITE' && cryptoId) {
const symbol = cryptoIdToNativeCoinSymbol(cryptoId);
if (value && !addressValidator.validate(value, symbol)) {
return translationString('TR_EXCHANGE_RECEIVING_ADDRESS_INVALID');
}
Expand Down Expand Up @@ -111,7 +111,7 @@ export const CoinmarketVerify = ({ coinmarketVerifyAccount, currency }: Coinmark
/>
</Paragraph>
<CoinmarketVerifyOptions
receiveNetwork={currency}
receiveNetwork={cryptoId}
selectedAccountOption={selectedAccountOption}
selectAccountOptions={selectAccountOptions}
isMenuOpen={isMenuOpen}
Expand All @@ -129,7 +129,7 @@ export const CoinmarketVerify = ({ coinmarketVerifyAccount, currency }: Coinmark
account={selectedAccountOption?.account}
address={address}
control={form.control}
receiveSymbol={currency}
receiveSymbol={cryptoId}
setValue={form.setValue}
label={
<Tooltip
Expand Down
Loading