From acd5a83a71cf0193aeca85e5b699964296ed3d79 Mon Sep 17 00:00:00 2001 From: iamacook Date: Wed, 8 Nov 2023 11:49:20 +0100 Subject: [PATCH] fix: add `timestamp` and validity to state --- src/hooks/loadables/useLoadRecovery.ts | 28 ++++++++++++++++++++++++-- src/store/recoverySlice.ts | 9 ++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/hooks/loadables/useLoadRecovery.ts b/src/hooks/loadables/useLoadRecovery.ts index 17ebfd953d..f42bbc6e3c 100644 --- a/src/hooks/loadables/useLoadRecovery.ts +++ b/src/hooks/loadables/useLoadRecovery.ts @@ -1,4 +1,5 @@ import { SENTINEL_ADDRESS } from '@safe-global/safe-core-sdk/dist/src/utils/constants' +import { BigNumber } from 'ethers' import type { Delay } from '@gnosis.pm/zodiac' import { getDelayModifiers } from '@/services/recovery/delay-modifier' @@ -16,21 +17,44 @@ const REFRESH_DELAY = 5 * 60 * 1_000 // 5 minutes const getRecoveryState = async (delayModifier: Delay): Promise => { const transactionAddedFilter = delayModifier.filters.TransactionAdded() - const [[modules], txCooldown, txNonce, queueNonce, transactionsAdded] = await Promise.all([ + const [[modules], txExpiration, txCooldown, txNonce, queueNonce, transactionsAdded] = await Promise.all([ delayModifier.getModulesPaginated(SENTINEL_ADDRESS, MAX_PAGE_SIZE), + delayModifier.txExpiration(), delayModifier.txCooldown(), delayModifier.txNonce(), delayModifier.queueNonce(), delayModifier.queryFilter(transactionAddedFilter), ]) + const queue = await Promise.all( + transactionsAdded + // Only queued transactions with queueNonce >= current txNonce + .filter(({ args }) => args.queueNonce.gte(txNonce)) + .map(async (event) => { + const txBlock = await event.getBlock() + + const validFrom = BigNumber.from(txBlock.timestamp).add(txCooldown) + const expiresAt = txExpiration.isZero() + ? null // Never expires + : validFrom.add(txExpiration).toString() + + return { + ...event, + timestamp: txBlock.timestamp, + validFrom: validFrom.toString(), + expiresAt, + } + }), + ) + return { address: delayModifier.address, modules, + txExpiration: txExpiration.toString(), txCooldown: txCooldown.toString(), txNonce: txNonce.toString(), queueNonce: queueNonce.toString(), - transactionsAdded: transactionsAdded.filter(({ args }) => args.queueNonce.gte(txNonce)), + queue, } } diff --git a/src/store/recoverySlice.ts b/src/store/recoverySlice.ts index 839b216497..7b317ed0e1 100644 --- a/src/store/recoverySlice.ts +++ b/src/store/recoverySlice.ts @@ -3,13 +3,20 @@ import type { TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Del import { makeLoadableSlice } from './common' +type QueuedTransactionAdded = TransactionAddedEvent & { + timestamp: number + validFrom: string + expiresAt: string | null +} + export type RecoveryState = Array<{ address: string modules: Array + txExpiration: string txCooldown: string txNonce: string queueNonce: string - transactionsAdded: Array + queue: Array }> const initialState: RecoveryState = []