Files
js/components/selects/SupportedNetworkSelect.tsx
T
Nacho IacovinoandJonas Daniels fcba9f7bc1 Add all new chains (#191)
* Add all new chains

* Import from SDK

* Add RPC urls

* Fix type error

* Fix currency map

* Fix build

* Fix imports

* Add faucets, fix stuff

* Rename

* Add Optimism/Arbitrum icons

* Disable arbitrum/optimism

* Fix build

* Fix build again

* Update SDK

* Update TypeScript SDK

* Add registry

* Fix faucets

* Update embeds

* slight changes

* Update embeds

* Filter gnosis, update optimism kovan alchemy url

* Simplify transfer modal

* Remove console.logs

* Fix embeds

Co-authored-by: Jonas Daniels <[email protected]>
2022-06-14 17:02:21 -07:00

69 lines
2.1 KiB
TypeScript

import { useWeb3 } from "@3rdweb-sdk/react";
import { Select, SelectProps, forwardRef } from "@chakra-ui/react";
import { ChainId, SUPPORTED_CHAIN_IDS } from "@thirdweb-dev/sdk";
import { useMemo } from "react";
export interface SupportedNetworkSelectProps
extends Omit<SelectProps, "children"> {
disabledChainIds?: ChainId[];
disabledChainIdText?: string;
}
export const SupportedNetworkSelect = forwardRef<
SupportedNetworkSelectProps,
"select"
>(
(
{ disabledChainIds, disabledChainIdText = "Unsupported", ...selectProps },
ref,
) => {
const { getNetworkMetadata } = useWeb3();
const testnets = useMemo(() => {
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
return getNetworkMetadata(supportedChain);
}).filter((n) => n.isTestnet);
}, [getNetworkMetadata]);
const mainnets = useMemo(() => {
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
return getNetworkMetadata(supportedChain);
}).filter((n) => !n.isTestnet);
}, [getNetworkMetadata]);
return (
<Select {...selectProps} ref={ref}>
<option disabled value={-1}>
Select Network
</option>
<optgroup label="Mainnets">
{mainnets.map((mn) => (
<option
key={mn.chainId}
value={mn.chainId}
disabled={disabledChainIds?.includes(mn.chainId)}
>
{mn.chainName} ({mn.symbol})
{disabledChainIds?.includes(mn.chainId)
? ` - ${disabledChainIdText}`
: ""}
</option>
))}
</optgroup>
<optgroup label="Testnets">
{testnets.map((tn) => (
<option
key={tn.chainId}
value={tn.chainId}
disabled={disabledChainIds?.includes(tn.chainId)}
>
{tn.chainName} ({tn.symbol})
{disabledChainIds?.includes(tn.chainId)
? ` - ${disabledChainIdText}`
: ""}
</option>
))}
</optgroup>
</Select>
);
},
);