Skip to content

Commit

Permalink
Merge pull request #159 from moonstream-to/sepolia-adoptation
Browse files Browse the repository at this point in the history
wrap getTransaction for delay
  • Loading branch information
Anton-Mushnin authored Mar 5, 2024
2 parents ea4d7b0 + 90ea5ed commit 357c845
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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

0 comments on commit 357c845

Please sign in to comment.