Merge branch 'Thunnini/chain-whitelist'

# Conflicts:
#	pages/verification/index.tsx
This commit is contained in:
Thunnini 2022-12-20 14:49:01 +09:00
commit 81fa455857

View File

@ -59,9 +59,8 @@ import Axios from "axios";
import { BackButton } from "../../components/back-button"; import { BackButton } from "../../components/back-button";
import { FinalCheckModal } from "../../components/final-check-modal"; import { FinalCheckModal } from "../../components/final-check-modal";
import { ErrorModal } from "../../components/error-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 router = useRouter();
const [twitterAuthInfo, setTwitterAuthInfo] = useState<TwitterProfileType>(); const [twitterAuthInfo, setTwitterAuthInfo] = useState<TwitterProfileType>();
@ -240,15 +239,33 @@ export default function VerificationPage(props: { blockList: string[] }) {
}; };
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,15 +275,15 @@ export default function VerificationPage(props: { blockList: string[] }) {
}/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 = [];
for (let i = 0; i < chainKeys.length; i++) { for (let i = 0; i < chainKeys.length; i++) {
if (props.blockList.includes(chainInfos[i].prefix)) {
continue;
}
const chainKey = chainKeys[i]; const chainKey = chainKeys[i];
if (chainKey.status !== "fulfilled") { if (chainKey.status !== "fulfilled") {
console.log("Failed to get key from wallet", chainKey); 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` const Container = styled.div`
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;