Skip to content

Commit

Permalink
Adds polling for tx proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed Nov 11, 2024
1 parent dcb6482 commit 950659e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/wallet/src/stores/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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();
Expand Down

0 comments on commit 950659e

Please sign in to comment.