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

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jul 5, 2024
1 parent 484263f commit f5aca0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
9 changes: 9 additions & 0 deletions hooks/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 12 additions & 7 deletions hooks/swap/useSendType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useEffect, useState } from "react"

import type { Token } from "./types"

export const sendTypeDetails = {
crossChainZeta: { title: "Transfer" },
wrapZeta: { title: "Wrap" },
Expand All @@ -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"
Expand Down Expand Up @@ -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<any>(null)
const [sendType, setSendType] = useState<string | null>(null)

useEffect(() => {
setSendType(computeSendType(sourceTokenSelected, destinationTokenSelected))
Expand Down

0 comments on commit f5aca0c

Please sign in to comment.