From 26c95bfbe55efbebcdc3530257e8f7d591250d25 Mon Sep 17 00:00:00 2001 From: Thunnini Date: Mon, 19 Dec 2022 16:00:10 +0900 Subject: [PATCH 1/2] Revert "Add block list" This reverts commit 40e3522c2a4c9f5b289458399ee94caa5a2d478a. --- pages/verification/index.tsx | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pages/verification/index.tsx b/pages/verification/index.tsx index 252975c..b2f6048 100644 --- a/pages/verification/index.tsx +++ b/pages/verification/index.tsx @@ -50,6 +50,7 @@ import { queryRegisteredTwitterId, verifyTwitterAccount, } from "../../queries"; +import { ErrorHandler } from "../../utils/error"; import { KEPLR_NOT_FOUND_ERROR, TWITTER_LOGIN_ERROR, @@ -59,9 +60,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(); @@ -263,10 +263,6 @@ export default function VerificationPage(props: { blockList: string[] }) { 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 +518,6 @@ export default function VerificationPage(props: { blockList: string[] }) { ); } -export async function getStaticProps() { - let blockList: string[] = []; - if (process.env.BLOCK_LIST) { - blockList = process.env.BLOCK_LIST.trim().split(","); - } - - return { props: { blockList } }; -} - const Container = styled.div` width: 100vw; height: 100vh; From cc2f59cd02c01bdb9a8d4bf6a25535c5137356de Mon Sep 17 00:00:00 2001 From: Thunnini Date: Mon, 19 Dec 2022 16:11:22 +0900 Subject: [PATCH 2/2] Add environment variable "NEXT_PUBLIC_CHAIN_ALLOWLIST" --- pages/verification/index.tsx | 40 ++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/pages/verification/index.tsx b/pages/verification/index.tsx index b2f6048..8dea20e 100644 --- a/pages/verification/index.tsx +++ b/pages/verification/index.tsx @@ -240,15 +240,33 @@ export default function VerificationPage() { }; 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,7 +276,11 @@ export default function VerificationPage() { }/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 = [];