Skip to content

Commit

Permalink
Fix Network dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
rustam-cb committed Feb 28, 2025
1 parent f5db892 commit 47ca9d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
6 changes: 5 additions & 1 deletion components/FundForm/FundForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const FundForm = memo(({ walletAddress }: FundFormProps) => {
purchaseCurrencies,
dataLoading,
setAppLoading,
allNetworks,
} = useApp();

const foregroundMuted = useThemeColor({}, "foregroundMuted");
Expand All @@ -70,7 +71,10 @@ export const FundForm = memo(({ walletAddress }: FundFormProps) => {

handleFiatChange(fiatAmount, exchangeRate);

setNetwork(asset.networks[0]);
// Check if the asset is supported on the current network. If not, set the network to the first network that supports the asset
if (!asset.networks.some((n) => n.name === network?.name)) {
setNetwork(asset.networks[0]);
}

setExchangeRate(exchangeRate);

Expand Down
26 changes: 15 additions & 11 deletions components/NetworkDropdown/NetworkDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OnrampNetwork } from "@/constants/types";
import { useApp } from "@/context/AppContext";
import { fetchExchangeRate } from "@/utils/fetchExchangeRate";
import { getNetworkIcon } from "@/utils/getNetworkIcon";
import React, { memo, useCallback } from "react";
import React, { memo, useCallback, useMemo } from "react";
import { useAmountInput } from "../FundForm/hooks/useAmountInput";

export const NetworkDropdown = memo(() => {
Expand Down Expand Up @@ -82,22 +82,26 @@ export const NetworkDropdown = memo(() => {
]
);

const networkList = useMemo(() => {
return allNetworks
?.filter((n) => asset?.networks.some((n) => n.name === n.name))
.map((network) => ({
id: network.chainId,
name: network.name,
label: network.displayName,
value: network,
iconUrl: getNetworkIcon(network.name),
Icon: getNetworkIconComponent(network.name),
}));
}, [allNetworks, asset]);

return (
<Dropdown
title="Select network"
value={network}
onValueChange={handleChangeNetwork}
isSelected={(option) => option.value === network}
options={
allNetworks?.map((network) => ({
id: network.chainId,
name: network.name,
label: network.displayName,
value: network,
iconUrl: getNetworkIcon(network.chainId),
Icon: getNetworkIconComponent(network.name),
})) ?? []
}
options={networkList ?? []}
/>
);
});

0 comments on commit 47ca9d3

Please sign in to comment.