@@ -6,6 +6,7 @@ import { CallData, RpcProvider } from 'starknet';
66import { VRF_PROVIDER_ADDRESS } from "../helpers/constants" ;
77import { translateEvent } from "../helpers/events" ;
88import { useDynamicConnector } from "./starknet" ;
9+ import { delay } from "../helpers/utilities" ;
910
1011export const DojoContext = createContext ( )
1112
@@ -43,7 +44,6 @@ export const DojoProvider = ({ children }) => {
4344
4445 if ( includeVRF ) {
4546 let contractAddress = txs [ txs . length - 1 ] . contractAddress
46-
4747 txs . unshift ( {
4848 contractAddress : VRF_PROVIDER_ADDRESS ,
4949 entrypoint : 'request_random' ,
@@ -56,8 +56,8 @@ export const DojoProvider = ({ children }) => {
5656
5757 try {
5858 const tx = await account . execute ( txs ) ;
59- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
60- const receipt = await account . waitForTransaction ( tx . transaction_hash , { retryInterval : 500 } )
59+ await delay ( 1000 ) ;
60+ const receipt = await waitForTransaction ( tx . transaction_hash , 0 )
6161
6262 if ( receipt . execution_status === "REVERTED" ) {
6363 console . log ( 'contract error' , receipt )
@@ -78,6 +78,25 @@ export const DojoProvider = ({ children }) => {
7878 }
7979 }
8080
81+ const waitForTransaction = async ( txHash , retries ) => {
82+ if ( retries > 9 ) {
83+ throw new Error ( "Transaction failed" ) ;
84+ }
85+
86+ try {
87+ const receipt = await account . waitForTransaction (
88+ txHash ,
89+ { retryInterval : 500 }
90+ ) ;
91+
92+ return receipt ;
93+ } catch ( error ) {
94+ console . error ( "Error waiting for transaction :" , error ) ;
95+ await delay ( 500 ) ;
96+ return waitForTransaction ( txHash , retries + 1 ) ;
97+ }
98+ }
99+
81100 return (
82101 < DojoContext . Provider
83102 value = { {
0 commit comments