Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jul 8, 2024
1 parent 364d0a0 commit c62d4fc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
5 changes: 2 additions & 3 deletions components/Swap/hooks/useCrossChainFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ 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"

const useCrossChainFee = (
sourceTokenSelected: Token | null,
destinationTokenSelected: Token | null,
sendType: string | null,
fees: any
fees: any,
client: any
) => {
const { client } = useZetaChainClient()
const [crossChainFee, setCrossChainFee] = useState<CrossChainFee | null>(null)
const [loading, setLoading] = useState<boolean>(false)

Expand Down
5 changes: 2 additions & 3 deletions components/Swap/hooks/useDestinationAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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<string>("")
const [destinationAmountIsLoading, setDestinationAmountIsLoading] =
useState<boolean>(false)
Expand Down
6 changes: 2 additions & 4 deletions components/Swap/hooks/useSendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 () => {
Expand Down
11 changes: 8 additions & 3 deletions components/Swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +28,7 @@ interface SwapProps {
}

const Swap: React.FC<SwapProps> = ({ contract }) => {
const signer = useEthersSigner()
const { client } = useZetaChainClient()
const { isLoading, pendingChainId, switchNetwork } = useSwitchNetwork()
const { setInbounds, inbounds } = useCCTXsContext()
Expand Down Expand Up @@ -54,7 +56,8 @@ const Swap: React.FC<SwapProps> = ({ contract }) => {
sourceTokenSelected,
destinationTokenSelected,
sendType,
fees
fees,
client
)

const { isAmountGTFee, isAmountLTBalance } = useAmountValidation(
Expand All @@ -71,7 +74,8 @@ const Swap: React.FC<SwapProps> = ({ contract }) => {
sourceAmount,
crossChainFee,
sendType,
balances
balances,
client
)

const { priorityErrors } = useSwapErrors(
Expand Down Expand Up @@ -105,7 +109,8 @@ const Swap: React.FC<SwapProps> = ({ contract }) => {
inbounds,
setInbounds,
bitcoinAddress,
client
client,
signer
)

const sendDisabled =
Expand Down

0 comments on commit c62d4fc

Please sign in to comment.