Skip to content

Commit

Permalink
assets page: fetch native eth balance on l2
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Oct 18, 2024
1 parent 88be534 commit 56c8988
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/api/tokens/get-combined-balances/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ export async function GET(req: Request) {
)

// Add native ETH balance to WETH
const ethBalance = await readEthBalance(process.env.RPC_URL_MAINNET!, address)
const ethBalanceL1 = await readEthBalance(
process.env.RPC_URL_MAINNET!,
address,
)
const ethBalanceL2 = await readEthBalance(process.env.RPC_URL!, address)
const currentWethBalance = combinedBalances.get("WETH") || BigInt(0)
combinedBalances.set("WETH", currentWethBalance + ethBalance)
combinedBalances.set("WETH", currentWethBalance + ethBalanceL1 + ethBalanceL2)

// Add USDC.e balance to USDC
const usdceBalance = await readErc20BalanceOf(
Expand Down
5 changes: 4 additions & 1 deletion hooks/use-combined-balances.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Token } from "@renegade-fi/react"
import { useQuery } from "@tanstack/react-query"

async function fetchCombinedBalances(address: string) {
async function fetchCombinedBalances(address: `0x${string}`) {
const response = await fetch(
`/api/tokens/get-combined-balances?address=${address}`,
{
cache: "no-store",
},
)
if (!response.ok) {
throw new Error("Failed to fetch combined balances")
Expand Down

0 comments on commit 56c8988

Please sign in to comment.