From de8ee23ed4088f8248dd66116c3fd2e98df758d2 Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 14 Aug 2024 18:57:40 +0200 Subject: [PATCH] more cleanup --- .../Transfer/contexts/transferState.tsx | 18 ++---------------- .../Transfer/hooks/useTransferHandlers.ts | 9 +++++---- src/components/Transfer/transferActions.tsx | 2 +- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/components/Transfer/contexts/transferState.tsx b/src/components/Transfer/contexts/transferState.tsx index 4a9789b4..fe7224df 100644 --- a/src/components/Transfer/contexts/transferState.tsx +++ b/src/components/Transfer/contexts/transferState.tsx @@ -7,7 +7,7 @@ import { } from 'react'; import { useRegions } from '@/contexts/regions'; -import { AssetType, ChainType, RegionLocation, RegionMetadata } from '@/models'; +import { ChainType, RegionLocation, RegionMetadata } from '@/models'; interface TransferState { originChain: ChainType; @@ -17,9 +17,6 @@ interface TransferState { selectedRegion: RegionMetadata | null; setSelectedRegion: (_region: RegionMetadata | null) => void; filteredRegions: RegionMetadata[]; - asset: AssetType; - setAsset: (_asset: AssetType) => void; - fetchRegions: () => void; } const defaultTasksData: TransferState = { @@ -36,13 +33,6 @@ const defaultTasksData: TransferState = { /** */ }, filteredRegions: [], - asset: AssetType.TOKEN, - setAsset: () => { - /** */ - }, - fetchRegions: () => { - /** */ - }, }; const TransferStateContext = createContext(defaultTasksData); @@ -52,7 +42,7 @@ export const TransferStateProvider = ({ }: { children: ReactNode; }) => { - const { regions, fetchRegions } = useRegions(); + const { regions } = useRegions(); const [originChain, setOriginChain] = useState(ChainType.RELAY); const [destinationChain, setDestinationChain] = useState( @@ -64,7 +54,6 @@ export const TransferStateProvider = ({ const [filteredRegions, setFilteredRegions] = useState>( [] ); - const [asset, setAsset] = useState(AssetType.TOKEN); useEffect(() => { if (originChain === ChainType.CORETIME) { @@ -90,9 +79,6 @@ export const TransferStateProvider = ({ selectedRegion, setSelectedRegion, filteredRegions, - asset, - setAsset, - fetchRegions, }} > {children} diff --git a/src/components/Transfer/hooks/useTransferHandlers.ts b/src/components/Transfer/hooks/useTransferHandlers.ts index 1b358341..848d27b3 100644 --- a/src/components/Transfer/hooks/useTransferHandlers.ts +++ b/src/components/Transfer/hooks/useTransferHandlers.ts @@ -15,16 +15,17 @@ import { } from '@/utils/transfers/native'; import { useAccounts } from '@/contexts/account'; +import { useCoretimeApi, useRegionXApi, useRelayApi } from '@/contexts/apis'; import { ApiState } from '@/contexts/apis/types'; import { useToast } from '@/contexts/toast'; import { AssetType, ChainType } from '@/models'; +import { assetType } from '../common'; import { useTransferState } from '../contexts/transferState'; -import { useCoretimeApi, useRegionXApi, useRelayApi } from '@/contexts/apis'; export const useTransferHandlers = () => { const { toastError, toastInfo, toastWarning, toastSuccess } = useToast(); - const { originChain, destinationChain, selectedRegion, asset } = + const { originChain, destinationChain, selectedRegion } = useTransferState(); const { @@ -73,9 +74,9 @@ export const useTransferHandlers = () => { } setWorking(true); - if (asset === AssetType.REGION) { + if (assetType(originChain, destinationChain) === AssetType.REGION) { await handleRegionTransfer(); - } else if (asset === AssetType.TOKEN) { + } else if (assetType(originChain, destinationChain) === AssetType.TOKEN) { await handleTokenTransfer(); } }; diff --git a/src/components/Transfer/transferActions.tsx b/src/components/Transfer/transferActions.tsx index 63a1f7d6..effcd487 100644 --- a/src/components/Transfer/transferActions.tsx +++ b/src/components/Transfer/transferActions.tsx @@ -8,6 +8,7 @@ import { ProgressButton } from '@/components/Elements/Buttons/ProgressButton'; import { AddressInput } from '@/components/Elements/Inputs/AddressInput'; import { AmountInput } from '@/components/Elements/Inputs/AmountInput'; +import { useRelayApi } from '@/contexts/apis'; import { useBalances } from '@/contexts/balance'; import { useNetwork } from '@/contexts/network'; import { useToast } from '@/contexts/toast'; @@ -16,7 +17,6 @@ import { AssetType, ChainType } from '@/models'; import { assetType } from './common'; import { useTransferState } from './contexts/transferState'; import { useTransferHandlers } from './hooks/useTransferHandlers'; -import { useRelayApi } from '@/contexts/apis'; const TransferActions = () => { const {