Compare commits

...

2 Commits

Author SHA1 Message Date
HeesungB
679a4cc506 Remove test logic 2022-12-21 01:19:19 +09:00
HeesungB
ba051d0e76 Add tx hash query retry 2022-12-21 01:18:30 +09:00
2 changed files with 19 additions and 7 deletions

View File

@ -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);

View File

@ -21,6 +21,19 @@ export function request<TResponse>(
.then((data) => data as TResponse);
}
export const fetch_retry = async (
url: string,
n: number,
options?: RequestInit,
): Promise<Response> => {
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, any>): string {
return Object.entries(query)
.map(([key, value]) =>