diff --git a/hooks/swap/types.ts b/hooks/swap/types.ts index 8f8fb71..7c339f1 100644 --- a/hooks/swap/types.ts +++ b/hooks/swap/types.ts @@ -34,3 +34,12 @@ export interface Inbound { inboundHash: string desc: string } + +export interface Token { + symbol: string + chain_name: string + coin_type: string + ticker: string + zrc20?: string + contract?: string +} diff --git a/hooks/swap/useSendType.ts b/hooks/swap/useSendType.ts index 9a12728..06fb0de 100644 --- a/hooks/swap/useSendType.ts +++ b/hooks/swap/useSendType.ts @@ -1,5 +1,7 @@ import { useEffect, useState } from "react" +import type { Token } from "./types" + export const sendTypeDetails = { crossChainZeta: { title: "Transfer" }, wrapZeta: { title: "Wrap" }, @@ -19,18 +21,21 @@ export const sendTypeDetails = { fromZetaChainSwapAndWithdraw: { title: "Swap and Withdraw" }, } -export const computeSendType = (s: any, d: any) => { +export const computeSendType = ( + s: Token | null, + d: Token | null +): string | null => { if (!s || !d) return null - const fromZETA = /\bzeta\b/i.test(s?.symbol) - const fromZETAorWZETA = /\bw?zeta\b/i.test(s?.symbol) + const fromZETA = /\bzeta\b/i.test(s.symbol) + const fromZETAorWZETA = /\bw?zeta\b/i.test(s.symbol) const fromZetaChain = s.chain_name === "zeta_testnet" const fromBTC = s.symbol === "tBTC" const fromBitcoin = s.chain_name === "btc_testnet" const fromWZETA = s.symbol === "WZETA" const fromGas = s.coin_type === "Gas" const fromERC20 = s.coin_type === "ERC20" - const toZETAorWZETA = /\bw?zeta\b/i.test(d?.symbol) + const toZETAorWZETA = /\bw?zeta\b/i.test(d.symbol) const toWZETA = d.symbol === "WZETA" const toZETA = d.symbol === "ZETA" const toZetaChain = d.chain_name === "zeta_testnet" @@ -90,10 +95,10 @@ export const computeSendType = (s: any, d: any) => { } const useSendType = ( - sourceTokenSelected: any, - destinationTokenSelected: any + sourceTokenSelected: Token | null, + destinationTokenSelected: Token | null ) => { - const [sendType, setSendType] = useState(null) + const [sendType, setSendType] = useState(null) useEffect(() => { setSendType(computeSendType(sourceTokenSelected, destinationTokenSelected))