diff --git a/src/components/dashboard/PendingTxs/PendingRecoveryListItem.tsx b/src/components/dashboard/PendingTxs/PendingRecoveryListItem.tsx index 54732e42c2..a133870e26 100644 --- a/src/components/dashboard/PendingTxs/PendingRecoveryListItem.tsx +++ b/src/components/dashboard/PendingTxs/PendingRecoveryListItem.tsx @@ -9,7 +9,7 @@ import { RecoveryInfo } from '@/components/recovery/RecoveryInfo' import { RecoveryStatus } from '@/components/recovery/RecoveryStatus' import { RecoveryType } from '@/components/recovery/RecoveryType' import { AppRoutes } from '@/config/routes' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' import css from './styles.module.css' diff --git a/src/components/dashboard/PendingTxs/PendingTxList.test.ts b/src/components/dashboard/PendingTxs/PendingTxList.test.ts index 012c0d4fdc..14f6cca3b9 100644 --- a/src/components/dashboard/PendingTxs/PendingTxList.test.ts +++ b/src/components/dashboard/PendingTxs/PendingTxList.test.ts @@ -5,7 +5,7 @@ import type { MultisigExecutionInfo, Transaction } from '@safe-global/safe-gatew import { safeInfoBuilder } from '@/tests/builders/safe' import { _getTransactionsToDisplay } from './PendingTxsList' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' describe('_getTransactionsToDisplay', () => { it('should return the recovery queue if it has more than or equal to MAX_TXS items', () => { diff --git a/src/components/dashboard/PendingTxs/PendingTxsList.tsx b/src/components/dashboard/PendingTxs/PendingTxsList.tsx index 459c304223..07130bd344 100644 --- a/src/components/dashboard/PendingTxs/PendingTxsList.tsx +++ b/src/components/dashboard/PendingTxs/PendingTxsList.tsx @@ -15,7 +15,7 @@ import useSafeInfo from '@/hooks/useSafeInfo' import { useRecoveryQueue } from '@/hooks/useRecoveryQueue' import { PendingRecoveryListItem } from './PendingRecoveryListItem' import type { SafeInfo, Transaction } from '@safe-global/safe-gateway-typescript-sdk' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' const MAX_TXS = 4 diff --git a/src/components/dashboard/RecoveryHeader/index.test.tsx b/src/components/dashboard/RecoveryHeader/index.test.tsx index 7ea4106633..c1dc830935 100644 --- a/src/components/dashboard/RecoveryHeader/index.test.tsx +++ b/src/components/dashboard/RecoveryHeader/index.test.tsx @@ -2,7 +2,7 @@ import { BigNumber } from 'ethers' import { _RecoveryHeader } from '.' import { render } from '@/tests/test-utils' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' describe('RecoveryHeader', () => { it('should not render a widget if the chain does not support recovery', () => { diff --git a/src/components/dashboard/RecoveryHeader/index.tsx b/src/components/dashboard/RecoveryHeader/index.tsx index 6320797ccc..a474f194e1 100644 --- a/src/components/dashboard/RecoveryHeader/index.tsx +++ b/src/components/dashboard/RecoveryHeader/index.tsx @@ -10,7 +10,7 @@ import { RecoveryProposalCard } from '@/components/recovery/RecoveryCards/Recove import { RecoveryInProgressCard } from '@/components/recovery/RecoveryCards/RecoveryInProgressCard' import { WidgetContainer, WidgetBody } from '../styled' import useIsSafeOwner from '@/hooks/useIsSafeOwner' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function _RecoveryHeader({ isGuardian, diff --git a/src/components/recovery/CancelRecoveryButton/index.tsx b/src/components/recovery/CancelRecoveryButton/index.tsx index 70b928e28c..218d586d64 100644 --- a/src/components/recovery/CancelRecoveryButton/index.tsx +++ b/src/components/recovery/CancelRecoveryButton/index.tsx @@ -7,7 +7,7 @@ import IconButton from '@mui/material/IconButton' import CheckWallet from '@/components/common/CheckWallet' import { TxModalContext } from '@/components/tx-flow' import { CancelRecoveryFlow } from '@/components/tx-flow/flows/CancelRecovery' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function CancelRecoveryButton({ recovery, diff --git a/src/components/recovery/ExecuteRecoveryButton/index.tsx b/src/components/recovery/ExecuteRecoveryButton/index.tsx index e86a55be87..5e7f13ed18 100644 --- a/src/components/recovery/ExecuteRecoveryButton/index.tsx +++ b/src/components/recovery/ExecuteRecoveryButton/index.tsx @@ -10,8 +10,8 @@ import useOnboard from '@/hooks/wallets/useOnboard' import useSafeInfo from '@/hooks/useSafeInfo' import { useRecoveryTxState } from '@/hooks/useRecoveryTxState' import { Errors, logError } from '@/services/exceptions' -import { RecoveryLoaderContext } from '../RecoveryLoaderContext' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import { RecoveryContext } from '../RecoveryContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function ExecuteRecoveryButton({ recovery, @@ -23,7 +23,7 @@ export function ExecuteRecoveryButton({ const { isExecutable } = useRecoveryTxState(recovery) const onboard = useOnboard() const { safe } = useSafeInfo() - const { refetch } = useContext(RecoveryLoaderContext) + const { refetch } = useContext(RecoveryContext) const onClick = async (e: SyntheticEvent) => { e.stopPropagation() diff --git a/src/components/recovery/RecoveryCards/RecoveryInProgressCard.tsx b/src/components/recovery/RecoveryCards/RecoveryInProgressCard.tsx index 29cb1f9090..579860fd6f 100644 --- a/src/components/recovery/RecoveryCards/RecoveryInProgressCard.tsx +++ b/src/components/recovery/RecoveryCards/RecoveryInProgressCard.tsx @@ -7,7 +7,7 @@ import { Countdown } from '@/components/common/Countdown' import RecoveryPending from '@/public/images/common/recovery-pending.svg' import ExternalLink from '@/components/common/ExternalLink' import { AppRoutes } from '@/config/routes' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' import css from './styles.module.css' diff --git a/src/components/recovery/RecoveryCards/__tests__/RecoveryInProgressCard.test.tsx b/src/components/recovery/RecoveryCards/__tests__/RecoveryInProgressCard.test.tsx index a80a85dad9..6f7a59d1e1 100644 --- a/src/components/recovery/RecoveryCards/__tests__/RecoveryInProgressCard.test.tsx +++ b/src/components/recovery/RecoveryCards/__tests__/RecoveryInProgressCard.test.tsx @@ -4,7 +4,7 @@ import { fireEvent, waitFor } from '@testing-library/react' import { render } from '@/tests/test-utils' import { RecoveryInProgressCard } from '../RecoveryInProgressCard' import { useRecoveryTxState } from '@/hooks/useRecoveryTxState' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' jest.mock('@/hooks/useRecoveryTxState') diff --git a/src/components/recovery/RecoveryLoaderContext/__tests__/index.test.tsx b/src/components/recovery/RecoveryContext/__tests__/index.test.tsx similarity index 93% rename from src/components/recovery/RecoveryLoaderContext/__tests__/index.test.tsx rename to src/components/recovery/RecoveryContext/__tests__/index.test.tsx index 35dc8c2b99..9565e9650f 100644 --- a/src/components/recovery/RecoveryLoaderContext/__tests__/index.test.tsx +++ b/src/components/recovery/RecoveryContext/__tests__/index.test.tsx @@ -10,7 +10,7 @@ import { txDispatch, TxEvent } from '@/services/tx/txEvents' import { chainBuilder } from '@/tests/builders/chains' import { addressExBuilder, safeInfoBuilder } from '@/tests/builders/safe' import { act, fireEvent, render, waitFor } from '@/tests/test-utils' -import { RecoveryLoaderContext, RecoveryLoaderProvider } from '..' +import { RecoveryContext, RecoveryProvider } from '..' import { getTxDetails } from '@/services/tx/txDetails' jest.mock('@/services/recovery/delay-modifier') @@ -30,7 +30,7 @@ const mockUseCurrentChain = useCurrentChain as jest.MockedFunction const mockGetTxDetails = getTxDetails as jest.MockedFunction -describe('RecoveryLoaderContext', () => { +describe('RecoveryContext', () => { beforeEach(() => { jest.clearAllMocks() @@ -54,15 +54,15 @@ describe('RecoveryLoaderContext', () => { mockGetDelayModifiers.mockResolvedValue(delayModifiers as any) function Test() { - const { refetch } = useContext(RecoveryLoaderContext) + const { refetch } = useContext(RecoveryContext) return } const { queryByText } = render( - + - , + , ) await waitFor(() => { @@ -98,9 +98,9 @@ describe('RecoveryLoaderContext', () => { mockGetTxDetails.mockResolvedValue({ txData: { to: { value: delayModifierAddress } } } as any) render( - + <> - , + , ) await waitFor(() => { diff --git a/src/components/recovery/RecoveryLoaderContext/__tests__/useDelayModifier.test.ts b/src/components/recovery/RecoveryContext/__tests__/useDelayModifier.test.ts similarity index 100% rename from src/components/recovery/RecoveryLoaderContext/__tests__/useDelayModifier.test.ts rename to src/components/recovery/RecoveryContext/__tests__/useDelayModifier.test.ts diff --git a/src/components/recovery/RecoveryLoaderContext/__tests__/useRecoveryState.test.ts b/src/components/recovery/RecoveryContext/__tests__/useRecoveryState.test.ts similarity index 100% rename from src/components/recovery/RecoveryLoaderContext/__tests__/useRecoveryState.test.ts rename to src/components/recovery/RecoveryContext/__tests__/useRecoveryState.test.ts diff --git a/src/components/recovery/RecoveryLoaderContext/index.tsx b/src/components/recovery/RecoveryContext/index.tsx similarity index 84% rename from src/components/recovery/RecoveryLoaderContext/index.tsx rename to src/components/recovery/RecoveryContext/index.tsx index 821def4732..99e3382838 100644 --- a/src/components/recovery/RecoveryLoaderContext/index.tsx +++ b/src/components/recovery/RecoveryContext/index.tsx @@ -1,7 +1,8 @@ -import { createContext, useEffect } from 'react' +import { createContext, useContext, useEffect } from 'react' import type { ReactElement, ReactNode } from 'react' import type { TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Delay' import type { BigNumber } from 'ethers' + import { TxEvent, txSubscribe } from '@/services/tx/txEvents' import { sameAddress } from '@/utils/addresses' import { getTxDetails } from '@/services/tx/txDetails' @@ -31,7 +32,7 @@ export type RecoveryStateItem = { export type RecoveryState = Array // State of current Safe, populated on load -export const RecoveryLoaderContext = createContext<{ +export const RecoveryContext = createContext<{ state: AsyncResult refetch: () => void }>({ @@ -39,7 +40,7 @@ export const RecoveryLoaderContext = createContext<{ refetch: () => {}, }) -export function RecoveryLoaderProvider({ children }: { children: ReactNode }): ReactElement { +export function RecoveryProvider({ children }: { children: ReactNode }): ReactElement { const { safe } = useSafeInfo() const [delayModifiers, delayModifiersError, delayModifiersLoading] = useDelayModifiers() @@ -80,8 +81,10 @@ export function RecoveryLoaderProvider({ children }: { children: ReactNode }): R const loading = delayModifiersLoading || recoveryStateLoading return ( - - {children} - + {children} ) } + +export function useRecovery(): AsyncResult { + return useContext(RecoveryContext).state +} diff --git a/src/components/recovery/RecoveryLoaderContext/useDelayModifiers.ts b/src/components/recovery/RecoveryContext/useDelayModifiers.ts similarity index 100% rename from src/components/recovery/RecoveryLoaderContext/useDelayModifiers.ts rename to src/components/recovery/RecoveryContext/useDelayModifiers.ts diff --git a/src/components/recovery/RecoveryLoaderContext/useRecoveryState.ts b/src/components/recovery/RecoveryContext/useRecoveryState.ts similarity index 100% rename from src/components/recovery/RecoveryLoaderContext/useRecoveryState.ts rename to src/components/recovery/RecoveryContext/useRecoveryState.ts diff --git a/src/components/recovery/RecoveryDetails/index.tsx b/src/components/recovery/RecoveryDetails/index.tsx index b95fccbc0a..fc0193b10a 100644 --- a/src/components/recovery/RecoveryDetails/index.tsx +++ b/src/components/recovery/RecoveryDetails/index.tsx @@ -12,7 +12,7 @@ import useSafeInfo from '@/hooks/useSafeInfo' import ErrorMessage from '@/components/tx/ErrorMessage' import { RecoverySigners } from '../RecoverySigners' import { Errors, logError } from '@/services/exceptions' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' import txDetailsCss from '@/components/transactions/TxDetails/styles.module.css' import summaryCss from '@/components/transactions/TxDetails/Summary/styles.module.css' diff --git a/src/components/recovery/RecoveryListItem/index.tsx b/src/components/recovery/RecoveryListItem/index.tsx index 7f56492d70..8905d392a8 100644 --- a/src/components/recovery/RecoveryListItem/index.tsx +++ b/src/components/recovery/RecoveryListItem/index.tsx @@ -5,7 +5,7 @@ import type { ReactElement } from 'react' import txListItemCss from '@/components/transactions/TxListItem/styles.module.css' import { RecoverySummary } from '../RecoverySummary' import { RecoveryDetails } from '../RecoveryDetails' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function RecoveryListItem({ item }: { item: RecoveryQueueItem }): ReactElement { return ( diff --git a/src/components/recovery/RecoveryModal/index.test.tsx b/src/components/recovery/RecoveryModal/index.test.tsx index 6ffaf6987f..c17a10f27d 100644 --- a/src/components/recovery/RecoveryModal/index.test.tsx +++ b/src/components/recovery/RecoveryModal/index.test.tsx @@ -8,7 +8,7 @@ import { safeInfoBuilder } from '@/tests/builders/safe' import { connectedWalletBuilder } from '@/tests/builders/wallet' import * as safeInfo from '@/hooks/useSafeInfo' import { _useDidDismissProposal } from './index' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' describe('RecoveryModal', () => { describe('component', () => { diff --git a/src/components/recovery/RecoveryModal/index.tsx b/src/components/recovery/RecoveryModal/index.tsx index 4e36630687..13d0c396b7 100644 --- a/src/components/recovery/RecoveryModal/index.tsx +++ b/src/components/recovery/RecoveryModal/index.tsx @@ -13,7 +13,7 @@ import useLocalStorage from '@/services/local-storage/useLocalStorage' import useWallet from '@/hooks/wallets/useWallet' import useSafeInfo from '@/hooks/useSafeInfo' import { sameAddress } from '@/utils/addresses' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function _RecoveryModal({ children, diff --git a/src/components/recovery/RecoverySigners/index.tsx b/src/components/recovery/RecoverySigners/index.tsx index 25a32490ee..38e31fc129 100644 --- a/src/components/recovery/RecoverySigners/index.tsx +++ b/src/components/recovery/RecoverySigners/index.tsx @@ -8,7 +8,7 @@ import { Countdown } from '@/components/common/Countdown' import { ExecuteRecoveryButton } from '../ExecuteRecoveryButton' import { CancelRecoveryButton } from '../CancelRecoveryButton' import { useRecoveryTxState } from '@/hooks/useRecoveryTxState' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' import txSignersCss from '@/components/transactions/TxSigners/styles.module.css' import { formatDate } from '@/utils/date' diff --git a/src/components/recovery/RecoveryStatus/index.tsx b/src/components/recovery/RecoveryStatus/index.tsx index a4008ecee6..03db49acf7 100644 --- a/src/components/recovery/RecoveryStatus/index.tsx +++ b/src/components/recovery/RecoveryStatus/index.tsx @@ -3,7 +3,7 @@ import type { ReactElement } from 'react' import ClockIcon from '@/public/images/common/clock.svg' import { useRecoveryTxState } from '@/hooks/useRecoveryTxState' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export const RecoveryStatus = ({ recovery }: { recovery: RecoveryQueueItem }): ReactElement => { const { isExecutable, isExpired } = useRecoveryTxState(recovery) diff --git a/src/components/recovery/RecoverySummary/index.tsx b/src/components/recovery/RecoverySummary/index.tsx index 0f58cb93ec..a017611ade 100644 --- a/src/components/recovery/RecoverySummary/index.tsx +++ b/src/components/recovery/RecoverySummary/index.tsx @@ -8,7 +8,7 @@ import { RecoveryStatus } from '../RecoveryStatus' import { ExecuteRecoveryButton } from '../ExecuteRecoveryButton' import { CancelRecoveryButton } from '../CancelRecoveryButton' import useWallet from '@/hooks/wallets/useWallet' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' import txSummaryCss from '@/components/transactions/TxSummary/styles.module.css' diff --git a/src/components/settings/Recovery/ConfirmRemoveRecoveryModal.tsx b/src/components/settings/Recovery/ConfirmRemoveRecoveryModal.tsx index 0881d7abb5..da16bb6867 100644 --- a/src/components/settings/Recovery/ConfirmRemoveRecoveryModal.tsx +++ b/src/components/settings/Recovery/ConfirmRemoveRecoveryModal.tsx @@ -15,7 +15,7 @@ import type { ReactElement } from 'react' import AlertIcon from '@/public/images/notifications/alert.svg' import { TxModalContext } from '@/components/tx-flow' import { RemoveRecoveryFlow } from '@/components/tx-flow/flows/RemoveRecovery' -import type { RecoveryStateItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryStateItem } from '@/components/recovery/RecoveryContext' export function ConfirmRemoveRecoveryModal({ open, diff --git a/src/components/settings/Recovery/DelayModifierRow.tsx b/src/components/settings/Recovery/DelayModifierRow.tsx index 3bab0bc6d5..44a7c205ed 100644 --- a/src/components/settings/Recovery/DelayModifierRow.tsx +++ b/src/components/settings/Recovery/DelayModifierRow.tsx @@ -8,7 +8,7 @@ import DeleteIcon from '@/public/images/common/delete.svg' import EditIcon from '@/public/images/common/edit.svg' import CheckWallet from '@/components/common/CheckWallet' import { ConfirmRemoveRecoveryModal } from './ConfirmRemoveRecoveryModal' -import type { RecoveryStateItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryStateItem } from '@/components/recovery/RecoveryContext' export function DelayModifierRow({ delayModifier }: { delayModifier: RecoveryStateItem }): ReactElement | null { const { setTxFlow } = useContext(TxModalContext) diff --git a/src/components/settings/Recovery/index.tsx b/src/components/settings/Recovery/index.tsx index 4b259e915b..76811a9fc5 100644 --- a/src/components/settings/Recovery/index.tsx +++ b/src/components/settings/Recovery/index.tsx @@ -7,8 +7,7 @@ import { TxModalContext } from '@/components/tx-flow' import { Chip } from '@/components/common/Chip' import ExternalLink from '@/components/common/ExternalLink' import { DelayModifierRow } from './DelayModifierRow' -import useIsSafeOwner from '@/hooks/useIsSafeOwner' -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' +import { useRecovery } from '@/components/recovery/RecoveryContext' import EthHashInfo from '@/components/common/EthHashInfo' import EnhancedTable from '@/components/common/EnhancedTable' import InfoIcon from '@/public/images/notifications/info.svg' @@ -68,8 +67,7 @@ const headCells = [ export function Recovery(): ReactElement { const { setTxFlow } = useContext(TxModalContext) - const [recovery] = useContext(RecoveryLoaderContext).state - const isOwner = useIsSafeOwner() + const [recovery] = useRecovery() const rows = useMemo(() => { return recovery?.flatMap((delayModifier) => { diff --git a/src/components/settings/SafeModules/index.tsx b/src/components/settings/SafeModules/index.tsx index b71f1d6d71..77e6ff8d1d 100644 --- a/src/components/settings/SafeModules/index.tsx +++ b/src/components/settings/SafeModules/index.tsx @@ -8,7 +8,7 @@ import DeleteIcon from '@/public/images/common/delete.svg' import CheckWallet from '@/components/common/CheckWallet' import { useContext, useState } from 'react' import { TxModalContext } from '@/components/tx-flow' -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' +import { useRecovery } from '@/components/recovery/RecoveryContext' import { selectDelayModifierByAddress } from '@/services/recovery/selectors' import { ConfirmRemoveRecoveryModal } from '../Recovery/ConfirmRemoveRecoveryModal' @@ -25,8 +25,8 @@ const NoModules = () => { const ModuleDisplay = ({ moduleAddress, chainId, name }: { moduleAddress: string; chainId: string; name?: string }) => { const { setTxFlow } = useContext(TxModalContext) const [confirmRemoveRecovery, setConfirmRemoveRecovery] = useState(false) - const [data] = useContext(RecoveryLoaderContext).state - const delayModifier = data && selectDelayModifierByAddress(data, moduleAddress) + const [recovery] = useRecovery() + const delayModifier = recovery && selectDelayModifierByAddress(recovery, moduleAddress) const onRemove = () => { if (delayModifier) { diff --git a/src/components/tx-flow/flows/CancelRecovery/CancelRecoveryFlowReview.tsx b/src/components/tx-flow/flows/CancelRecovery/CancelRecoveryFlowReview.tsx index a138e3afa5..87809bd9c1 100644 --- a/src/components/tx-flow/flows/CancelRecovery/CancelRecoveryFlowReview.tsx +++ b/src/components/tx-flow/flows/CancelRecovery/CancelRecoveryFlowReview.tsx @@ -8,7 +8,7 @@ import { useWeb3ReadOnly } from '@/hooks/wallets/web3' import { getRecoverySkipTransaction } from '@/services/recovery/transaction' import { createTx } from '@/services/tx/tx-sender' import ErrorMessage from '@/components/tx/ErrorMessage' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function CancelRecoveryFlowReview({ recovery }: { recovery: RecoveryQueueItem }): ReactElement { const web3ReadOnly = useWeb3ReadOnly() diff --git a/src/components/tx-flow/flows/CancelRecovery/index.tsx b/src/components/tx-flow/flows/CancelRecovery/index.tsx index 2794f82c66..87274909bf 100644 --- a/src/components/tx-flow/flows/CancelRecovery/index.tsx +++ b/src/components/tx-flow/flows/CancelRecovery/index.tsx @@ -4,7 +4,7 @@ import TxLayout from '../../common/TxLayout' import { CancelRecoveryFlowReview } from './CancelRecoveryFlowReview' import { CancelRecoveryOverview } from './CancelRecoveryOverview' import useTxStepper from '../../useTxStepper' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function CancelRecoveryFlow({ recovery }: { recovery: RecoveryQueueItem }): ReactElement { const { step, nextStep, prevStep } = useTxStepper(undefined) diff --git a/src/components/tx-flow/flows/RecoverAccount/RecoverAccountFlowReview.tsx b/src/components/tx-flow/flows/RecoverAccount/RecoverAccountFlowReview.tsx index 7ced4ac21c..63245f06e3 100644 --- a/src/components/tx-flow/flows/RecoverAccount/RecoverAccountFlowReview.tsx +++ b/src/components/tx-flow/flows/RecoverAccount/RecoverAccountFlowReview.tsx @@ -24,7 +24,7 @@ import { TxModalContext } from '../..' import { asError } from '@/services/exceptions/utils' import { trackError, Errors } from '@/services/exceptions' import { getCountdown } from '@/utils/date' -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' +import { RecoveryContext } from '@/components/recovery/RecoveryContext' import type { RecoverAccountFlowProps } from '.' import commonCss from '@/components/tx-flow/common/styles.module.css' @@ -41,9 +41,11 @@ export function RecoverAccountFlowReview({ params }: { params: RecoverAccountFlo const { safe } = useSafeInfo() const wallet = useWallet() const onboard = useOnboard() - const [data] = useContext(RecoveryLoaderContext).state + const { + refetch, + state: [data], + } = useContext(RecoveryContext) const recovery = data && selectDelayModifierByGuardian(data, wallet?.address ?? '') - const { refetch } = useContext(RecoveryLoaderContext) // Proposal const txCooldown = recovery?.txCooldown?.toNumber() diff --git a/src/components/tx-flow/flows/RemoveRecovery/index.tsx b/src/components/tx-flow/flows/RemoveRecovery/index.tsx index c9868cb919..cfcc056d8c 100644 --- a/src/components/tx-flow/flows/RemoveRecovery/index.tsx +++ b/src/components/tx-flow/flows/RemoveRecovery/index.tsx @@ -5,7 +5,7 @@ import RecoveryPlus from '@/public/images/common/recovery-plus.svg' import useTxStepper from '../../useTxStepper' import { RemoveRecoveryFlowOverview } from './RemoveRecoveryFlowOverview' import { RemoveRecoveryFlowReview } from './RemoveRecoveryFlowReview' -import type { RecoveryStateItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryStateItem } from '@/components/recovery/RecoveryContext' export type RecoveryFlowProps = { delayModifier: RecoveryStateItem diff --git a/src/hooks/__tests__/useRecoveryTxState.test.tsx b/src/hooks/__tests__/useRecoveryTxState.test.tsx index a5fe06e8bf..3ee6a0ec47 100644 --- a/src/hooks/__tests__/useRecoveryTxState.test.tsx +++ b/src/hooks/__tests__/useRecoveryTxState.test.tsx @@ -3,7 +3,7 @@ import { faker } from '@faker-js/faker' import { useRecoveryTxState } from '../useRecoveryTxState' import { renderHook } from '@/tests/test-utils' -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' +import { RecoveryContext } from '@/components/recovery/RecoveryContext' describe('useRecoveryTxState', () => { beforeEach(() => { @@ -46,7 +46,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[1].queue[0] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) @@ -83,7 +83,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[0].queue[0] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) @@ -120,7 +120,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[0].queue[0] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) @@ -157,7 +157,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[0].queue[0] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) @@ -221,7 +221,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[1].queue[1] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) @@ -264,7 +264,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[0].queue[1] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) @@ -307,7 +307,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[0].queue[1] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) @@ -350,7 +350,7 @@ describe('useRecoveryTxState', () => { const { result } = renderHook(() => useRecoveryTxState(data[0].queue[1] as any), { wrapper: ({ children }) => ( - {children} + {children} ), }) diff --git a/src/hooks/useIsGuardian.ts b/src/hooks/useIsGuardian.ts index 16b987a3a7..8ba0ee89e1 100644 --- a/src/hooks/useIsGuardian.ts +++ b/src/hooks/useIsGuardian.ts @@ -1,11 +1,9 @@ -import { useContext } from 'react' - import { selectDelayModifierByGuardian } from '@/services/recovery/selectors' import useWallet from './wallets/useWallet' -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' +import { useRecovery } from '@/components/recovery/RecoveryContext' export function useIsGuardian() { - const [data] = useContext(RecoveryLoaderContext).state + const [recovery] = useRecovery() const wallet = useWallet() - return !wallet?.address || !data || !selectDelayModifierByGuardian(data, wallet.address) + return !wallet?.address || !recovery || !selectDelayModifierByGuardian(recovery, wallet.address) } diff --git a/src/hooks/useIsRecoveryEnabled.ts b/src/hooks/useIsRecoveryEnabled.ts index f6b67320ad..90862befa6 100644 --- a/src/hooks/useIsRecoveryEnabled.ts +++ b/src/hooks/useIsRecoveryEnabled.ts @@ -1,8 +1,6 @@ -import { useContext } from 'react' - -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' +import { useRecovery } from '@/components/recovery/RecoveryContext' export function useIsRecoveryEnabled(): boolean { - const [data] = useContext(RecoveryLoaderContext).state - return !!data && data.length > 0 + const [recovery] = useRecovery() + return !!recovery && recovery.length > 0 } diff --git a/src/hooks/useRecoveryQueue.ts b/src/hooks/useRecoveryQueue.ts index 33574a782b..f81b4486ae 100644 --- a/src/hooks/useRecoveryQueue.ts +++ b/src/hooks/useRecoveryQueue.ts @@ -1,13 +1,11 @@ -import { useContext } from 'react' - import { selectRecoveryQueues } from '@/services/recovery/selectors' import { useClock } from './useClock' -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import { useRecovery } from '@/components/recovery/RecoveryContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function useRecoveryQueue(): Array { - const [data] = useContext(RecoveryLoaderContext).state - const queue = data && selectRecoveryQueues(data) + const [recovery] = useRecovery() + const queue = recovery && selectRecoveryQueues(recovery) const clock = useClock() if (!queue) { diff --git a/src/hooks/useRecoveryTxState.ts b/src/hooks/useRecoveryTxState.ts index e5e3813fdf..d34f6b7da9 100644 --- a/src/hooks/useRecoveryTxState.ts +++ b/src/hooks/useRecoveryTxState.ts @@ -1,10 +1,8 @@ -import { useContext } from 'react' - import { useClock } from './useClock' import { selectDelayModifierByTxHash } from '@/services/recovery/selectors' -import { RecoveryLoaderContext } from '@/components/recovery/RecoveryLoaderContext' +import { useRecovery } from '@/components/recovery/RecoveryContext' import { sameAddress } from '@/utils/addresses' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' export function useRecoveryTxState({ validFrom, expiresAt, transactionHash, args, address }: RecoveryQueueItem): { isNext: boolean @@ -12,8 +10,8 @@ export function useRecoveryTxState({ validFrom, expiresAt, transactionHash, args isExpired: boolean remainingSeconds: number } { - const [data] = useContext(RecoveryLoaderContext).state - const recovery = data && selectDelayModifierByTxHash(data, transactionHash) + const [recovery] = useRecovery() + const delayModifier = recovery && selectDelayModifierByTxHash(recovery, transactionHash) // We don't display seconds in the interface, so we can use a 60s interval const timestamp = useClock(60_000) @@ -23,7 +21,8 @@ export function useRecoveryTxState({ validFrom, expiresAt, transactionHash, args const isExpired = expiresAt ? expiresAt.toNumber() <= Date.now() : false // Check module address in case multiple Delay Modifiers enabled - const isNext = recovery ? sameAddress(recovery.address, address) && args.queueNonce.eq(recovery.txNonce) : false + const isNext = + !delayModifier || (sameAddress(delayModifier.address, address) && args.queueNonce.eq(delayModifier.txNonce)) const isExecutable = isNext && isValid && !isExpired const remainingSeconds = isValid ? 0 : Math.ceil(remainingMs.div(1_000).toNumber()) diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index c2fb947cef..a849581113 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -44,7 +44,7 @@ import useABTesting from '@/services/tracking/useAbTesting' import { AbTest } from '@/services/tracking/abTesting' import { useNotificationTracking } from '@/components/settings/PushNotifications/hooks/useNotificationTracking' import MobilePairingModal from '@/services/pairing/QRModal' -import { RecoveryLoaderProvider } from '@/components/recovery/RecoveryLoaderContext' +import { RecoveryProvider } from '@/components/recovery/RecoveryContext' const GATEWAY_URL = IS_PRODUCTION || cgwDebugStorage.get() ? GATEWAY_URL_PRODUCTION : GATEWAY_URL_STAGING @@ -84,11 +84,11 @@ export const AppProviders = ({ children }: { children: ReactNode | ReactNode[] } {(safeTheme: Theme) => ( - + {children} - + )} diff --git a/src/services/recovery/__tests__/selectors.test.ts b/src/services/recovery/__tests__/selectors.test.ts index df24bce6ed..65967c6efd 100644 --- a/src/services/recovery/__tests__/selectors.test.ts +++ b/src/services/recovery/__tests__/selectors.test.ts @@ -7,7 +7,7 @@ import { selectDelayModifierByTxHash, selectDelayModifierByAddress, } from '../selectors' -import type { RecoveryStateItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryStateItem } from '@/components/recovery/RecoveryContext' describe('selectors', () => { describe('selectDelayModifierByGuardian', () => { diff --git a/src/services/recovery/recovery-state.ts b/src/services/recovery/recovery-state.ts index 8ab265ca56..919c60fcc3 100644 --- a/src/services/recovery/recovery-state.ts +++ b/src/services/recovery/recovery-state.ts @@ -13,7 +13,7 @@ import { trimTrailingSlash } from '@/utils/url' import { sameAddress } from '@/utils/addresses' import { isMultiSendCalldata } from '@/utils/transaction-calldata' import { decodeMultiSendTxs } from '@/utils/transactions' -import type { RecoveryQueueItem, RecoveryState, RecoveryStateItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem, RecoveryState, RecoveryStateItem } from '@/components/recovery/RecoveryContext' const MAX_PAGE_SIZE = 100 diff --git a/src/services/recovery/selectors.ts b/src/services/recovery/selectors.ts index e4f3af6122..ebeabaa962 100644 --- a/src/services/recovery/selectors.ts +++ b/src/services/recovery/selectors.ts @@ -1,6 +1,6 @@ import { createSelector } from '@reduxjs/toolkit' -import type { RecoveryState } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryState } from '@/components/recovery/RecoveryContext' import { sameAddress } from '@/utils/addresses' // Identity function to help with type inference diff --git a/src/services/recovery/transaction.ts b/src/services/recovery/transaction.ts index b3ecc063fb..de94c7d8bd 100644 --- a/src/services/recovery/transaction.ts +++ b/src/services/recovery/transaction.ts @@ -7,7 +7,7 @@ import { sameAddress } from '@/utils/addresses' import { getModuleInstance, KnownContracts } from '@gnosis.pm/zodiac' import type { MetaTransactionData } from '@safe-global/safe-core-sdk-types' import type { AddressEx, SafeInfo } from '@safe-global/safe-gateway-typescript-sdk' -import type { RecoveryQueueItem } from '@/components/recovery/RecoveryLoaderContext' +import type { RecoveryQueueItem } from '@/components/recovery/RecoveryContext' import type { JsonRpcProvider } from '@ethersproject/providers' export function getRecoveryProposalTransactions({