Files
js/components/selects/SupportedNetworkSelect.tsx
T
752b2c2634 Refactor for react/sdk v3 (#457)
* Refactor claim conditions

* Add util function

* Full NFT pages refactor

* Improve onDashboard

* Token refactor fun

* Fix some logic

* Make token drop use custom contract pages

* Remove all the things

* Fix checks

* Fix delayed reveal

* Fix marketplace embed

* Fix lgtm

* Change detection strategy

* Improve some checks

* Reduce use of actualContract

* Fix lgtm

* Fix build

* Some renamings and some more cleanup

* Default sources to release source if found

* Fix lgtm

* Rename multiwrap

* Use useTokenDecimals hook

* Fix token forms not accepting decimals

* Check decimals for inputs

* Fix logic

* Update packages

* update SDK + add Optimism/Arbitrum goerli testnets

* Add goerli l2s to disabled chains of gnosis

* Add comment

* Fix todo

* Rename detection

* Fix code tab on multiwrap and pack

* Add deprecated text

* Add faucet links

* Prettier comments

* Check isDirty for all forms

* add latest nightly

* upgrade nightly and use stable for storage

Co-authored-by: Joaquim Verges <[email protected]>
Co-authored-by: Jonas Daniels <[email protected]>
2022-09-09 18:16:09 -07:00

77 lines
2.3 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]);
const deprecatedChains = [
ChainId.Rinkeby,
ChainId.OptimismKovan,
ChainId.ArbitrumRinkeby,
];
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})
{deprecatedChains.includes(tn.chainId) && " - Deprecated"}
{disabledChainIds?.includes(tn.chainId)
? ` - ${disabledChainIdText}`
: ""}
</option>
))}
</optgroup>
</Select>
);
},
);