From c62d4fcc1773ffbce7316a4e4caf2185c9b88410 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Mon, 8 Jul 2024 18:17:12 +0300 Subject: [PATCH] refactor --- components/Swap/hooks/useCrossChainFee.ts | 5 ++--- components/Swap/hooks/useDestinationAmount.ts | 5 ++--- components/Swap/hooks/useSendTransaction.ts | 6 ++---- components/Swap/index.tsx | 11 ++++++++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/components/Swap/hooks/useCrossChainFee.ts b/components/Swap/hooks/useCrossChainFee.ts index babc1aa..02700c7 100644 --- a/components/Swap/hooks/useCrossChainFee.ts +++ b/components/Swap/hooks/useCrossChainFee.ts @@ -2,7 +2,6 @@ import { useEffect, useState } from "react" import { utils } from "ethers" import { roundNumber } from "@/lib/utils" -import { useZetaChainClient } from "@/hooks/useZetaChainClient" import type { CrossChainFee, Token } from "./types" @@ -10,9 +9,9 @@ const useCrossChainFee = ( sourceTokenSelected: Token | null, destinationTokenSelected: Token | null, sendType: string | null, - fees: any + fees: any, + client: any ) => { - const { client } = useZetaChainClient() const [crossChainFee, setCrossChainFee] = useState(null) const [loading, setLoading] = useState(false) diff --git a/components/Swap/hooks/useDestinationAmount.ts b/components/Swap/hooks/useDestinationAmount.ts index 409b494..a4583a3 100644 --- a/components/Swap/hooks/useDestinationAmount.ts +++ b/components/Swap/hooks/useDestinationAmount.ts @@ -3,7 +3,6 @@ import { utils } from "ethers" import debounce from "lodash/debounce" import { roundNumber } from "@/lib/utils" -import { useZetaChainClient } from "@/hooks/useZetaChainClient" import type { Balance, CrossChainFee, Token } from "./types" @@ -13,9 +12,9 @@ const useDestinationAmount = ( sourceAmount: string, crossChainFee: CrossChainFee | null, sendType: string | null, - balances: any + balances: any, + client: any ) => { - const { client } = useZetaChainClient() const [destinationAmount, setDestinationAmount] = useState("") const [destinationAmountIsLoading, setDestinationAmountIsLoading] = useState(false) diff --git a/components/Swap/hooks/useSendTransaction.ts b/components/Swap/hooks/useSendTransaction.ts index 9480dda..ab64ca1 100644 --- a/components/Swap/hooks/useSendTransaction.ts +++ b/components/Swap/hooks/useSendTransaction.ts @@ -8,8 +8,6 @@ import { ethers } from "ethers" import { parseEther, parseUnits } from "viem" import { useAccount } from "wagmi" -import { useEthersSigner } from "@/hooks/useEthersSigner" - import SwapToAnyToken from "./SwapToAnyToken.json" import type { Inbound, Token } from "./types" @@ -24,10 +22,10 @@ const useSendTransaction = ( inbounds: Inbound[], setInbounds: (inbounds: Inbound[]) => void, bitcoinAddress: string, - client: any + client: any, + signer: any ) => { const { address } = useAccount() - const signer = useEthersSigner() const [isSending, setIsSending] = useState(false) const handleSend = async () => { diff --git a/components/Swap/index.tsx b/components/Swap/index.tsx index 60b37f5..4833c04 100644 --- a/components/Swap/index.tsx +++ b/components/Swap/index.tsx @@ -7,6 +7,7 @@ import { useFeesContext } from "@/context/FeesContext" import { useAccount, useNetwork, useSwitchNetwork } from "wagmi" import { formatAddress } from "@/lib/utils" +import { useEthersSigner } from "@/hooks/useEthersSigner" import { useZetaChainClient } from "@/hooks/useZetaChainClient" import useSendType, { computeSendType, @@ -27,6 +28,7 @@ interface SwapProps { } const Swap: React.FC = ({ contract }) => { + const signer = useEthersSigner() const { client } = useZetaChainClient() const { isLoading, pendingChainId, switchNetwork } = useSwitchNetwork() const { setInbounds, inbounds } = useCCTXsContext() @@ -54,7 +56,8 @@ const Swap: React.FC = ({ contract }) => { sourceTokenSelected, destinationTokenSelected, sendType, - fees + fees, + client ) const { isAmountGTFee, isAmountLTBalance } = useAmountValidation( @@ -71,7 +74,8 @@ const Swap: React.FC = ({ contract }) => { sourceAmount, crossChainFee, sendType, - balances + balances, + client ) const { priorityErrors } = useSwapErrors( @@ -105,7 +109,8 @@ const Swap: React.FC = ({ contract }) => { inbounds, setInbounds, bitcoinAddress, - client + client, + signer ) const sendDisabled =