From ba051d0e76ad8f3010b2ea20e9eea72ad59f93d7 Mon Sep 17 00:00:00 2001 From: HeesungB Date: Wed, 21 Dec 2022 01:18:30 +0900 Subject: [PATCH] Add tx hash query retry --- pages/complete/index.tsx | 13 ++++++------- pages/verification/index.tsx | 5 +++++ utils/url.ts | 13 +++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pages/complete/index.tsx b/pages/complete/index.tsx index 33f9c3c..517f282 100644 --- a/pages/complete/index.tsx +++ b/pages/complete/index.tsx @@ -15,7 +15,8 @@ import { TendermintTxTracer } from "@keplr-wallet/cosmos"; import { queryAddressesFromTwitterName } from "../../queries"; import { RegisteredAddresses } from "../../types"; import { SHARE_URL } from "../../constants/twitter"; -import { RPC_URL } from "../../constants/icns"; +import { REST_URL, RPC_URL } from "../../constants/icns"; +import { fetch_retry } from "../../utils/url"; export default function CompletePage() { const router = useRouter(); @@ -35,14 +36,12 @@ export default function CompletePage() { }, [router.query]); const initialize = async (txHash: string, twitterUserName: string) => { - const txTracer = new TendermintTxTracer(RPC_URL, "/websocket"); - try { - const result: { code?: number } = await txTracer.traceTx( - Buffer.from(txHash, "hex"), - ); + const response = await ( + await fetch_retry(`${REST_URL}/cosmos/tx/v1beta1/txs/${txHash}`, 12) + ).json(); - if (!result.code || result.code === 0) { + if (response.code || response.tx_response.code === 0) { amplitude.track("complete registration"); const addresses = await queryAddressesFromTwitterName(twitterUserName); diff --git a/pages/verification/index.tsx b/pages/verification/index.tsx index 0b4d6aa..50c0506 100644 --- a/pages/verification/index.tsx +++ b/pages/verification/index.tsx @@ -370,6 +370,11 @@ export default function VerificationPage() { twitterInfo.accessToken, ); + await verifyTwitterAccount( + walletKey.bech32Address, + twitterInfo.accessToken, + ); + icnsVerificationList.forEach((verification) => { if (verification.status === "fulfilled") { if (verification.value.errors.length > 0) { diff --git a/utils/url.ts b/utils/url.ts index b09e4f1..6ff61e0 100644 --- a/utils/url.ts +++ b/utils/url.ts @@ -21,6 +21,19 @@ export function request( .then((data) => data as TResponse); } +export const fetch_retry = async ( + url: string, + n: number, + options?: RequestInit, +): Promise => { + try { + return await fetch(url, options); + } catch (err) { + if (n === 1) throw err; + return await fetch_retry(url, n - 1, options); + } +}; + export function buildQueryString(query: Record): string { return Object.entries(query) .map(([key, value]) =>