Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap getTransaction for delay #159

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions web/src/tokenInterfaces/FullcountPlayerAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,22 @@ export async function startSessionFullcountPlayer({
return { sessionID: data.session_id, sign: "0x" + data.signature };
}

const delay = (delayInms: number) => {
return new Promise((resolve) => setTimeout(resolve, delayInms));
};

const getTransaction = async (transactionHash: string) => {
for (let attempt = 1; attempt <= 10; attempt++) {
const web3 = new Web3(RPC);
const transaction = await web3.eth.getTransaction(transactionHash);
if (transaction) return transaction;
await delay(2 * 1000);
}
throw new Error(`Failed to receive transaction from getTransaction("${transactionHash}")`);
};

export const checkTransaction = async (transactionHash: string) => {
const web3 = new Web3(RPC);
const receipt = await web3.eth.getTransactionReceipt(transactionHash);
return receipt && receipt.status;
return await getTransaction(transactionHash);
};

export function joinSessionFullcountPlayer({
Expand Down
4 changes: 3 additions & 1 deletion web/src/utils/getWeb3Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CHAIN_ID,
GAME_CONTRACT,
MULTICALL2_CONTRACT_ADDRESSES,
RPC,
TOKEN_CONTRACT,
} from "../constants";

Expand All @@ -12,6 +13,7 @@ import FullcountABIImported from "../web3/abi/FullcountABI.json";
import TokenABIImported from "../web3/abi/BLBABI.json";
import MulticallABIImported from "../web3/abi/Multicall2.json";
import { MoonstreamWeb3ProviderInterface } from "../types/Moonstream";
import Web3 from "web3";
const FullcountABI = FullcountABIImported as unknown as AbiItem[];
const TokenABI = TokenABIImported as unknown as AbiItem[];
const MulticallABI = MulticallABIImported as unknown as AbiItem[];
Expand All @@ -33,7 +35,7 @@ export const getContracts = (web3ctx: MoonstreamWeb3ProviderInterface) => {
};

export const getMulticallContract = (web3ctx: MoonstreamWeb3ProviderInterface) => {
const { web3 } = web3ctx;
const web3 = new Web3(RPC);
const MULTICALL2_CONTRACT_ADDRESS =
MULTICALL2_CONTRACT_ADDRESSES[String(CHAIN_ID) as keyof typeof MULTICALL2_CONTRACT_ADDRESSES];
const multicallContract = new web3.eth.Contract(
Expand Down
Loading