From 346fb298083e9f7c449311c257b54714d31df577 Mon Sep 17 00:00:00 2001 From: Usame Algan Date: Fri, 31 May 2024 15:50:36 +0200 Subject: [PATCH] chore: Remove usePendingSafe hook --- .../__tests__/usePendingSafe.test.ts | 71 ------------------- .../create/steps/StatusStep/usePendingSafe.ts | 29 -------- 2 files changed, 100 deletions(-) delete mode 100644 src/components/new-safe/create/steps/StatusStep/__tests__/usePendingSafe.test.ts delete mode 100644 src/components/new-safe/create/steps/StatusStep/usePendingSafe.ts diff --git a/src/components/new-safe/create/steps/StatusStep/__tests__/usePendingSafe.test.ts b/src/components/new-safe/create/steps/StatusStep/__tests__/usePendingSafe.test.ts deleted file mode 100644 index 03cad0f74c..0000000000 --- a/src/components/new-safe/create/steps/StatusStep/__tests__/usePendingSafe.test.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { renderHook } from '@/tests/test-utils' -import { usePendingSafe } from '../usePendingSafe' - -import { toBeHex } from 'ethers' -import { useCurrentChain } from '@/hooks/useChains' - -// mock useCurrentChain -jest.mock('@/hooks/useChains', () => ({ - useCurrentChain: jest.fn(() => ({ - shortName: 'gor', - chainId: '5', - chainName: 'Goerli', - features: [], - })), -})) - -describe('usePendingSafe()', () => { - const mockPendingSafe1 = { - name: 'joyful-rinkeby-safe', - threshold: 1, - owners: [], - saltNonce: 123, - address: toBeHex('0x10', 20), - } - const mockPendingSafe2 = { - name: 'joyful-rinkeby-safe', - threshold: 1, - owners: [], - saltNonce: 123, - address: toBeHex('0x10', 20), - } - - beforeEach(() => { - window.localStorage.clear() - }) - it('Should initially be undefined', () => { - const { result } = renderHook(() => usePendingSafe()) - expect(result.current[0]).toBeUndefined() - }) - - it('Should set the pendingSafe per ChainId', async () => { - const { result, rerender } = renderHook(() => usePendingSafe()) - - result.current[1](mockPendingSafe1) - - rerender() - - expect(result.current[0]).toEqual(mockPendingSafe1) - ;(useCurrentChain as jest.Mock).mockImplementation(() => ({ - shortName: 'eth', - chainId: '1', - chainName: 'Ethereum', - features: [], - })) - - rerender() - expect(result.current[0]).toEqual(undefined) - - result.current[1](mockPendingSafe2) - rerender() - expect(result.current[0]).toEqual(mockPendingSafe2) - ;(useCurrentChain as jest.Mock).mockImplementation(() => ({ - shortName: 'gor', - chainId: '5', - chainName: 'Goerli', - features: [], - })) - rerender() - expect(result.current[0]).toEqual(mockPendingSafe1) - }) -}) diff --git a/src/components/new-safe/create/steps/StatusStep/usePendingSafe.ts b/src/components/new-safe/create/steps/StatusStep/usePendingSafe.ts deleted file mode 100644 index 08c3ac543e..0000000000 --- a/src/components/new-safe/create/steps/StatusStep/usePendingSafe.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useCurrentChain } from '@/hooks/useChains' -import useLocalStorage from '@/services/local-storage/useLocalStorage' -import { useCallback } from 'react' -import type { PendingSafeByChain, PendingSafeData } from '../../types' - -const SAFE_PENDING_CREATION_STORAGE_KEY = 'pendingSafe_v2' - -export const usePendingSafe = (): [PendingSafeData | undefined, (safe: PendingSafeData | undefined) => void] => { - const [pendingSafes, setPendingSafes] = useLocalStorage(SAFE_PENDING_CREATION_STORAGE_KEY) - - const chainInfo = useCurrentChain() - - const pendingSafe = chainInfo && pendingSafes?.[chainInfo.chainId] - const setPendingSafe = useCallback( - (safe: PendingSafeData | undefined) => { - if (!chainInfo?.chainId) { - return - } - - // Always copy the object because useLocalStorage does not check for deep equality when writing back to ls - const newPendingSafes = pendingSafes ? { ...pendingSafes } : {} - newPendingSafes[chainInfo.chainId] = safe - setPendingSafes(newPendingSafes) - }, - [chainInfo?.chainId, pendingSafes, setPendingSafes], - ) - - return [pendingSafe, setPendingSafe] -}