diff --git a/pages/verification/index.tsx b/pages/verification/index.tsx index 3636fed..664fa57 100644 --- a/pages/verification/index.tsx +++ b/pages/verification/index.tsx @@ -59,9 +59,8 @@ import Axios from "axios"; import { BackButton } from "../../components/back-button"; import { FinalCheckModal } from "../../components/final-check-modal"; import { ErrorModal } from "../../components/error-modal"; -import * as process from "process"; -export default function VerificationPage(props: { blockList: string[] }) { +export default function VerificationPage() { const router = useRouter(); const [twitterAuthInfo, setTwitterAuthInfo] = useState(); @@ -240,15 +239,33 @@ export default function VerificationPage(props: { blockList: string[] }) { }; const fetchChainList = async (wallet: KeplrWallet) => { - const chainIds = (await wallet.getChainInfosWithoutEndpoints()).map( - (c) => c.chainId, - ); - const chainKeys = await Promise.allSettled( - chainIds.map((chainId) => wallet.getKey(chainId)), - ); + const needAllowList = + process.env.NEXT_PUBLIC_CHAIN_ALLOWLIST != null && + process.env.NEXT_PUBLIC_CHAIN_ALLOWLIST.trim().length !== 0; + const chainAllowList = (process.env.NEXT_PUBLIC_CHAIN_ALLOWLIST || "") + .split(",") + .map((str) => str.trim()) + .filter((str) => str.length > 0) + .map((str) => ChainIdHelper.parse(str).identifier); - const chainInfos = (await wallet.getChainInfosWithoutEndpoints()).map( - (chainInfo) => { + const chainAllowListMap = new Map(); + for (const allow of chainAllowList) { + chainAllowListMap.set(allow, true); + } + + const chainInfos = (await wallet.getChainInfosWithoutEndpoints()) + .filter((chainInfo) => { + if (!needAllowList) { + return true; + } + + const chainIdentifier = ChainIdHelper.parse( + chainInfo.chainId, + ).identifier; + + return chainAllowListMap.get(chainIdentifier) === true; + }) + .map((chainInfo) => { return { chainId: chainInfo.chainId, chainName: chainInfo.chainName, @@ -258,15 +275,15 @@ export default function VerificationPage(props: { blockList: string[] }) { }/chain.png`, isEthermintLike: chainInfo.isEthermintLike, }; - }, + }); + + const chainIds = chainInfos.map((c) => c.chainId); + const chainKeys = await Promise.allSettled( + chainIds.map((chainId) => wallet.getKey(chainId)), ); const chainArray = []; for (let i = 0; i < chainKeys.length; i++) { - if (props.blockList.includes(chainInfos[i].prefix)) { - continue; - } - const chainKey = chainKeys[i]; if (chainKey.status !== "fulfilled") { console.log("Failed to get key from wallet", chainKey); @@ -522,15 +539,6 @@ export default function VerificationPage(props: { blockList: string[] }) { ); } -export async function getStaticProps() { - let blockList: string[] = []; - if (process.env.NEXT_PUBLIC_BLOCK_LIST) { - blockList = process.env.NEXT_PUBLIC_BLOCK_LIST.trim().split(","); - } - - return { props: { blockList } }; -} - const Container = styled.div` width: 100vw; height: 100vh;