Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transfer dialog: enable wbtc bridge #231

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/dialogs/transfer/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const QUOTE_STALE_TIME = 1000 * 60 * 1 // 1 minute
4 changes: 2 additions & 2 deletions components/dialogs/transfer/hooks/use-bridge-confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export function useBridgeConfirmation(
lifiExplorerLink: hasLifiExplorerLink(data)
? data.bridgeExplorerLink
: "",
receivedAmount: hasReceiving(data) ? data.receiving.amount ?? "0" : "0",
receiveHash: hasReceiving(data) ? data.receiving.txHash ?? "" : "",
receivedAmount: hasReceiving(data) ? (data.receiving.amount ?? "0") : "0",
receiveHash: hasReceiving(data) ? (data.receiving.txHash ?? "") : "",
}
}, [data])

Expand Down
11 changes: 11 additions & 0 deletions components/dialogs/transfer/transfer-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { WETHForm } from "@/components/dialogs/transfer/weth-form"

import { isTestnet } from "@/lib/viem"

import { WBTCForm } from "./wbtc-form"

export function TransferForm({
className,
direction,
Expand Down Expand Up @@ -67,6 +69,15 @@ export function TransferForm({
onSuccess={onSuccess}
/>
)
} else if (form.watch("mint") === Token.findByTicker("WBTC").address) {
return (
<WBTCForm
className={className}
form={form}
header={header}
onSuccess={onSuccess}
/>
)
}
}
return (
Expand Down
10 changes: 2 additions & 8 deletions components/dialogs/transfer/usdc-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AlertCircle, Check, Loader2 } from "lucide-react"
import { UseFormReturn, useWatch } from "react-hook-form"
import { toast } from "sonner"
import { useDebounceValue } from "usehooks-ts"
import { formatUnits, isAddress, parseUnits } from "viem"
import { formatUnits, isAddress } from "viem"
import { mainnet } from "viem/chains"
import { useAccount, useSendTransaction, useSwitchChain } from "wagmi"
import { z } from "zod"
Expand Down Expand Up @@ -84,15 +84,14 @@ import { chain, getFormattedChainName, solana } from "@/lib/viem"
import { useServerStore } from "@/providers/state-provider/server-store-provider"
import { mainnetConfig } from "@/providers/wagmi-provider/config"

import { QUOTE_STALE_TIME } from "./constants"
import { EVMStep, STEP_CONFIGS, SVMStep, TransferStep } from "./types"

const USDC_L1_TOKEN = ETHEREUM_TOKENS["USDC"]
const USDC_L2_TOKEN = Token.findByTicker("USDC")
const USDCE_L2_TOKEN = ADDITIONAL_TOKENS["USDC.e"]
const USDC_SOLANA_TOKEN = SOLANA_TOKENS["USDC"]

const QUOTE_STALE_TIME = 1000 * 60 * 1 // 1 minute

export function USDCForm({
className,
form,
Expand Down Expand Up @@ -200,11 +199,6 @@ export function USDCForm({
return network === chain.id && snapshot.swapRequired
}, [network, snapshot.swapRequired])

const remainingUsdceBalance =
parseUnits(amount, USDC_L2_TOKEN.decimals) > (usdcL2Balance ?? BigInt(0))
? combinedBalance - parseUnits(amount, USDC_L2_TOKEN.decimals)
: usdceL2Balance ?? BigInt(0)

const switchChainAndInvoke = async (chainId: number, fn: () => void) =>
switchChainAsync({ chainId })
.then(fn)
Expand Down
Loading
Loading