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: wrap eth #134

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
23bb1fb
transfer dialog: wrap eth
sehyunc Sep 27, 2024
6f6069d
transfer dialog: add USDC form
sehyunc Oct 3, 2024
5a9296d
status display works well
sehyunc Oct 5, 2024
dc24688
prevent deposit failure by estimating amt correctly (indirect)
sehyunc Oct 5, 2024
ef1a1f7
exact received amount in deposit
sehyunc Oct 5, 2024
4d06f67
animate loading panel
sehyunc Oct 6, 2024
fb1da12
works well with frozen values
sehyunc Oct 6, 2024
31ba5f5
standardize swap state
sehyunc Oct 7, 2024
62b0e40
standardize allowance required
sehyunc Oct 7, 2024
e643a7e
reset statuses onsubmit or amount change
sehyunc Oct 7, 2024
afa2a0a
fix button and button disabled states
sehyunc Oct 7, 2024
97252c2
weth form works
sehyunc Oct 7, 2024
1e2dab2
default form works
sehyunc Oct 7, 2024
2f3a764
s
sehyunc Oct 7, 2024
2baa5d4
fix default form
sehyunc Oct 7, 2024
e4f2dd2
fix weth form
sehyunc Oct 7, 2024
185c551
fix wait fortask
sehyunc Oct 7, 2024
b60d511
fix usdc swap error
sehyunc Oct 7, 2024
9528771
fix swap
sehyunc Oct 8, 2024
175c04a
reset deposit task in all forms
sehyunc Oct 8, 2024
0508394
check amount < MIN_TRANSFER_AMT before swapping
sehyunc Oct 8, 2024
bc0159c
use toAmountMin of estimate
sehyunc Oct 8, 2024
647d9a2
add second page for status display
sehyunc Oct 8, 2024
e3f98eb
lowercase wallet
sehyunc Oct 8, 2024
7e166c1
s
sehyunc Oct 8, 2024
6643d06
token balances stale time 0
sehyunc Oct 8, 2024
3c686ad
s
sehyunc Oct 8, 2024
5157f6c
dont show wrap warning if amount greater than combined bal
sehyunc Oct 8, 2024
e4b1202
allowance required default form
sehyunc Oct 8, 2024
1bb6967
show all task steps
sehyunc Oct 8, 2024
35b59ba
use weth form for withdraw
sehyunc Oct 9, 2024
4b812c2
add unwrap eth switch
sehyunc Oct 9, 2024
dae2fec
s
sehyunc Oct 9, 2024
d074714
s
sehyunc Oct 9, 2024
7191ed8
cleanup
sehyunc Oct 9, 2024
5794904
more specific error in weth form
sehyunc Oct 9, 2024
34fd3e7
move tooltips to the right
sehyunc Oct 9, 2024
1f0c47d
fix max weth form
sehyunc Oct 9, 2024
caa24cf
show confirm
sehyunc Oct 9, 2024
75a2cea
unwrap eth -> unwrap weth
sehyunc Oct 9, 2024
c7cc15e
responsive status page
sehyunc Oct 9, 2024
a54e1e0
disable refresh on block
sehyunc Oct 9, 2024
16989b5
transition colors
sehyunc Oct 9, 2024
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
2 changes: 1 addition & 1 deletion app/components/animated-ellipsis.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function AnimatedEllipsis() {
return (
<span className="inline-flex">
<span className="">
<span className="animate-ellipsis">.</span>
<span
className="animate-ellipsis"
Expand Down
14 changes: 0 additions & 14 deletions app/components/task-toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ function processTask(incomingTask: Task) {
description: state,
icon: <Loader2 className="h-4 w-4 animate-spin text-black" />,
})
} else if (
incomingTask.state === "Updating Validity Proofs" &&
isDepositTask(incomingTask)
) {
const message = generateCompletionToastMessage(incomingTask)
toast.success(message, { id, description: "Completed", icon: undefined })
} else {
const message = generateStartToastMessage(incomingTask)
toast.success(message, {
Expand All @@ -94,14 +88,6 @@ function processWithdrawTask(incomingTask: Task) {
} else if (incomingTask.state === "Failed") {
const message = generateFailedToastMessage(incomingTask)
toast.error(message, { id, icon: undefined, duration: 10000 })
} else if (incomingTask.state === "Updating Validity Proofs") {
const message = generateCompletionToastMessage(incomingTask)
toast.success(message, {
id,
description: "Completed",
icon: undefined,
duration: 10000,
})
} else if (incomingTask.state === "Proving") {
const message = generateStartToastMessage(incomingTask)
toast.success(message, {
Expand Down
39 changes: 32 additions & 7 deletions components/dialogs/token-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as React from "react"
import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons"
import { Token, useBackOfQueueWallet } from "@renegade-fi/react"
import { erc20Abi, isAddress } from "viem"
import { useAccount, useReadContracts } from "wagmi"
import { useAccount, useBalance, useReadContracts } from "wagmi"

import { ExternalTransferDirection } from "@/components/dialogs/transfer/transfer-dialog"
import { ExternalTransferDirection } from "@/components/dialogs/transfer/helpers"
import { Button } from "@/components/ui/button"
import {
Command,
Expand All @@ -24,7 +24,8 @@ import {
import { useMediaQuery } from "@/hooks/use-media-query"
import { useRefreshOnBlock } from "@/hooks/use-refresh-on-block"
import { formatNumber } from "@/lib/format"
import { DISPLAY_TOKENS } from "@/lib/token"
import { useReadErc20BalanceOf } from "@/lib/generated"
import { ADDITIONAL_TOKENS, DISPLAY_TOKENS } from "@/lib/token"
import { cn } from "@/lib/utils"

const tokens = DISPLAY_TOKENS().map((token) => ({
Expand All @@ -43,6 +44,7 @@ export function TokenSelect({
}) {
const [open, setOpen] = React.useState(false)
const { address } = useAccount()

const { data: l2Balances, queryKey } = useReadContracts({
contracts: DISPLAY_TOKENS().map((token) => ({
address: token.address,
Expand All @@ -60,6 +62,7 @@ export function TokenSelect({
balance.status === "success" ? BigInt(balance.result) : BigInt(0),
]),
),
staleTime: 0,
},
})

Expand All @@ -73,10 +76,32 @@ export function TokenSelect({
},
})

const displayBalances =
direction === ExternalTransferDirection.Deposit
? l2Balances
: renegadeBalances
// Alternative balances (e.g. ETH, USDC.e)
const { data: ethBalance } = useBalance({ address })
const { data: usdceBalance } = useReadErc20BalanceOf({
address: ADDITIONAL_TOKENS["USDC.e"].address,
args: [address ?? "0x"],
query: {
enabled: !!address,
staleTime: 0,
},
})

// TODO: Sometimes old balances are added
const displayBalances = React.useMemo(() => {
if (direction !== ExternalTransferDirection.Deposit) return renegadeBalances
if (!l2Balances) return undefined
const weth = Token.findByTicker("WETH")
const usdc = Token.findByTicker("USDC")
const combinedEthBalance =
(l2Balances?.get(weth.address) ?? BigInt(0)) +
(ethBalance?.value ?? BigInt(0))
const combinedUsdcBalance =
(l2Balances?.get(usdc.address) ?? BigInt(0)) + (usdceBalance ?? BigInt(0))
return new Map(l2Balances)
.set(weth.address, combinedEthBalance)
.set(usdc.address, combinedUsdcBalance)
}, [direction, ethBalance?.value, l2Balances, renegadeBalances, usdceBalance])

const isDesktop = useMediaQuery("(min-width: 1024px)")

Expand Down
Loading
Loading