Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Aug 14, 2024
1 parent 57407cf commit de8ee23
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
18 changes: 2 additions & 16 deletions src/components/Transfer/contexts/transferState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = {
Expand All @@ -36,13 +33,6 @@ const defaultTasksData: TransferState = {
/** */
},
filteredRegions: [],
asset: AssetType.TOKEN,
setAsset: () => {
/** */
},
fetchRegions: () => {
/** */
},
};

const TransferStateContext = createContext<TransferState>(defaultTasksData);
Expand All @@ -52,7 +42,7 @@ export const TransferStateProvider = ({
}: {
children: ReactNode;
}) => {
const { regions, fetchRegions } = useRegions();
const { regions } = useRegions();

const [originChain, setOriginChain] = useState<ChainType>(ChainType.RELAY);
const [destinationChain, setDestinationChain] = useState<ChainType>(
Expand All @@ -64,7 +54,6 @@ export const TransferStateProvider = ({
const [filteredRegions, setFilteredRegions] = useState<Array<RegionMetadata>>(
[]
);
const [asset, setAsset] = useState<AssetType>(AssetType.TOKEN);

useEffect(() => {
if (originChain === ChainType.CORETIME) {
Expand All @@ -90,9 +79,6 @@ export const TransferStateProvider = ({
selectedRegion,
setSelectedRegion,
filteredRegions,
asset,
setAsset,
fetchRegions,
}}
>
{children}
Expand Down
9 changes: 5 additions & 4 deletions src/components/Transfer/hooks/useTransferHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Transfer/transferActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down

0 comments on commit de8ee23

Please sign in to comment.