Add environment variable "NEXT_PUBLIC_CHAIN_ALLOWLIST"

This commit is contained in:
Thunnini 2022-12-19 16:11:22 +09:00
parent 26c95bfbe5
commit cc2f59cd02

View File

@ -240,15 +240,33 @@ export default function VerificationPage() {
}; };
const fetchChainList = async (wallet: KeplrWallet) => { const fetchChainList = async (wallet: KeplrWallet) => {
const chainIds = (await wallet.getChainInfosWithoutEndpoints()).map( const needAllowList =
(c) => c.chainId, process.env.NEXT_PUBLIC_CHAIN_ALLOWLIST != null &&
); process.env.NEXT_PUBLIC_CHAIN_ALLOWLIST.trim().length !== 0;
const chainKeys = await Promise.allSettled( const chainAllowList = (process.env.NEXT_PUBLIC_CHAIN_ALLOWLIST || "")
chainIds.map((chainId) => wallet.getKey(chainId)), .split(",")
); .map((str) => str.trim())
.filter((str) => str.length > 0)
.map((str) => ChainIdHelper.parse(str).identifier);
const chainInfos = (await wallet.getChainInfosWithoutEndpoints()).map( const chainAllowListMap = new Map<string, true | undefined>();
(chainInfo) => { 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 { return {
chainId: chainInfo.chainId, chainId: chainInfo.chainId,
chainName: chainInfo.chainName, chainName: chainInfo.chainName,
@ -258,7 +276,11 @@ export default function VerificationPage() {
}/chain.png`, }/chain.png`,
isEthermintLike: chainInfo.isEthermintLike, isEthermintLike: chainInfo.isEthermintLike,
}; };
}, });
const chainIds = chainInfos.map((c) => c.chainId);
const chainKeys = await Promise.allSettled(
chainIds.map((chainId) => wallet.getKey(chainId)),
); );
const chainArray = []; const chainArray = [];