From 950659e2519bdd29983553b4de53132b2ba951b0 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 11 Nov 2024 14:32:32 +0100 Subject: [PATCH] Adds polling for tx proposal --- apps/wallet/src/stores/Safe.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/wallet/src/stores/Safe.ts b/apps/wallet/src/stores/Safe.ts index 33f9cb6a..f26f9394 100644 --- a/apps/wallet/src/stores/Safe.ts +++ b/apps/wallet/src/stores/Safe.ts @@ -17,8 +17,11 @@ export const useSafeStore = defineStore('safe', { return useAuthStore().request(path, options); }, async waitForTransaction(tx: TTransaction) { + const { safeTxHash } = await this.waitForTransactionProposal(tx); + if (!safeTxHash) throw new Error('Could not find transaction hash'); + const { confirmTransaction } = useSafeStore(); - await confirmTransaction(tx.safeTxHash); + await confirmTransaction(safeTxHash); return new Promise((resolve, reject) => { setTimeout(async () => { @@ -31,6 +34,18 @@ export const useSafeStore = defineStore('safe', { }, TX_POLLING_INTERVAL); }); }, + async waitForTransactionProposal(tx: TTransaction) { + return new Promise((resolve, reject) => { + setTimeout(async () => { + const newTx = await this.request(`/transactions/${tx._id}`); + if (!tx.safeTxHash) { + this.waitForTransactionProposal(newTx).then(resolve).catch(reject); + } else { + resolve(newTx); + } + }, TX_POLLING_INTERVAL); + }) as unknown as TTransaction; + }, async confirmTransaction(safeTxHash: string) { const { privateKey, getPrivateKey } = useWeb3AuthStore(); if (!privateKey) await getPrivateKey();