diff --git a/src/transaction/hooks/useTransactionType.test.tsx b/src/transaction/hooks/useTransactionType.test.tsx deleted file mode 100644 index 7f179e1ed8..0000000000 --- a/src/transaction/hooks/useTransactionType.test.tsx +++ /dev/null @@ -1,87 +0,0 @@ -import { renderHook } from '@testing-library/react'; -import { describe, expect, it } from 'vitest'; -import { - TRANSACTION_TYPE_CALLS, - TRANSACTION_TYPE_CONTRACTS, -} from '../constants'; -import { useTransactionType } from './useTransactionType'; - -describe('useTransactionType', () => { - it('should return TRANSACTION_TYPE_CALLS when calls are provided', () => { - const { result } = renderHook(() => - useTransactionType({ - calls: [{ to: '0x123', data: '0x456' }], - contracts: undefined, - transactionStatuses: { - [TRANSACTION_TYPE_CALLS]: { batch: 'pending', single: 'pending' }, - [TRANSACTION_TYPE_CONTRACTS]: { batch: 'pending', single: 'pending' }, - }, - walletCapabilities: { hasAtomicBatch: true }, - }), - ); - expect(result.current.transactionType).toBe(TRANSACTION_TYPE_CALLS); - expect(result.current.transactionStatus).toBe('pending'); - }); - - it('should return TRANSACTION_TYPE_CONTRACTS when only contracts are provided', () => { - const { result } = renderHook(() => - useTransactionType({ - calls: undefined, - contracts: [{ to: '0x123', data: '0x456' }], - transactionStatuses: { - [TRANSACTION_TYPE_CALLS]: { batch: 'pending', single: 'pending' }, - [TRANSACTION_TYPE_CONTRACTS]: { batch: 'success', single: 'success' }, - }, - walletCapabilities: { hasAtomicBatch: true }, - }), - ); - expect(result.current.transactionType).toBe(TRANSACTION_TYPE_CONTRACTS); - expect(result.current.transactionStatus).toBe('success'); - }); - - it('should return TRANSACTION_TYPE_CALLS when both calls and contracts are provided', () => { - const { result } = renderHook(() => - useTransactionType({ - calls: [{ to: '0x123', data: '0x456' }], - contracts: [{ to: '0x789', data: '0xabc' }], - transactionStatuses: { - [TRANSACTION_TYPE_CALLS]: { batch: 'error', single: 'error' }, - [TRANSACTION_TYPE_CONTRACTS]: { batch: 'success', single: 'success' }, - }, - walletCapabilities: { hasAtomicBatch: true }, - }), - ); - expect(result.current.transactionType).toBe(TRANSACTION_TYPE_CALLS); - expect(result.current.transactionStatus).toBe('error'); - }); - - it('should return "batch" status when hasAtomicBatch is true', () => { - const { result } = renderHook(() => - useTransactionType({ - calls: [{ to: '0x123', data: '0x456' }], - contracts: undefined, - transactionStatuses: { - [TRANSACTION_TYPE_CALLS]: { batch: 'pending', single: 'success' }, - [TRANSACTION_TYPE_CONTRACTS]: { batch: 'pending', single: 'success' }, - }, - walletCapabilities: { hasAtomicBatch: true }, - }), - ); - expect(result.current.transactionStatus).toBe('pending'); - }); - - it('should return "single" status when hasAtomicBatch is false', () => { - const { result } = renderHook(() => - useTransactionType({ - calls: [{ to: '0x123', data: '0x456' }], - contracts: undefined, - transactionStatuses: { - [TRANSACTION_TYPE_CALLS]: { batch: 'pending', single: 'success' }, - [TRANSACTION_TYPE_CONTRACTS]: { batch: 'pending', single: 'success' }, - }, - walletCapabilities: { hasAtomicBatch: false }, - }), - ); - expect(result.current.transactionStatus).toBe('success'); - }); -}); diff --git a/src/transaction/hooks/useTransactionType.tsx b/src/transaction/hooks/useTransactionType.tsx deleted file mode 100644 index 102583bc55..0000000000 --- a/src/transaction/hooks/useTransactionType.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { useMemo } from 'react'; -import { - TRANSACTION_TYPE_CALLS, - TRANSACTION_TYPE_CONTRACTS, -} from '../constants'; -import type { UseTransactionTypeParams } from '../types'; - -// In the `Transaction` component either `calls` and `contracts` can be passed as props for transactions. -// This hook is used to determine the transaction type based on the props passed. -// It will also return the appropriate transaction status based on the transaction type. -export const useTransactionType = ({ - calls, - contracts, - transactionStatuses, - walletCapabilities, -}: UseTransactionTypeParams) => { - return useMemo(() => { - const transactionType = - calls || !contracts ? TRANSACTION_TYPE_CALLS : TRANSACTION_TYPE_CONTRACTS; - - const singleOrBatched = walletCapabilities.hasAtomicBatch - ? 'batch' - : 'single'; - const transactionStatus = - transactionStatuses[transactionType][singleOrBatched]; - - return { - transactionType, - transactionStatus, - }; - }, [ - calls, - contracts, - transactionStatuses, - walletCapabilities.hasAtomicBatch, - ]); -};