forked from LaconicNetwork/icns-frontend
Pooling tx response by interval
This commit is contained in:
parent
fd20eb3c9e
commit
d69cedd105
@ -11,11 +11,10 @@ import AlertCircleOutlineIcon from "../../public/images/svg/alert-circle-outline
|
|||||||
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { TendermintTxTracer } from "@keplr-wallet/cosmos";
|
|
||||||
import { queryAddressesFromTwitterName } from "../../queries";
|
import { queryAddressesFromTwitterName } from "../../queries";
|
||||||
import { RegisteredAddresses } from "../../types";
|
import { RegisteredAddresses } from "../../types";
|
||||||
import { SHARE_URL } from "../../constants/twitter";
|
import { SHARE_URL } from "../../constants/twitter";
|
||||||
import { RPC_URL } from "../../constants/icns";
|
import { REST_URL, RPC_URL } from "../../constants/icns";
|
||||||
|
|
||||||
export default function CompletePage() {
|
export default function CompletePage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -35,19 +34,33 @@ export default function CompletePage() {
|
|||||||
}, [router.query]);
|
}, [router.query]);
|
||||||
|
|
||||||
const initialize = async (txHash: string, twitterUserName: string) => {
|
const initialize = async (txHash: string, twitterUserName: string) => {
|
||||||
const txTracer = new TendermintTxTracer(RPC_URL, "/websocket");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result: { code?: number } = await txTracer.traceTx(
|
for (let i = 0; i < 20; i++) {
|
||||||
Buffer.from(txHash, "hex"),
|
// Try to fetch tx response per 3sec, 20times.
|
||||||
);
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||||
|
|
||||||
if (!result.code || result.code === 0) {
|
const res = await fetch(`${REST_URL}/cosmos/tx/v1beta1/txs/${txHash}`);
|
||||||
amplitude.track("complete registration");
|
|
||||||
|
|
||||||
const addresses = await queryAddressesFromTwitterName(twitterUserName);
|
if (res.ok && res.status === 200) {
|
||||||
setRegisteredAddressed(addresses.data.addresses);
|
const txRes = await res.json();
|
||||||
setIsSuccess(true);
|
|
||||||
|
if (txRes && txRes.tx_response) {
|
||||||
|
if (
|
||||||
|
txRes.tx_response.code == null ||
|
||||||
|
txRes.tx_response.code === 0
|
||||||
|
) {
|
||||||
|
amplitude.track("complete registration");
|
||||||
|
|
||||||
|
const addresses = await queryAddressesFromTwitterName(
|
||||||
|
twitterUserName,
|
||||||
|
);
|
||||||
|
setRegisteredAddressed(addresses.data.addresses);
|
||||||
|
setIsSuccess(true);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("error", e);
|
console.log("error", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user