Skip to content

Commit 51b1837

Browse files
committed
refactor: update imports and variable naming in aztecBalanceProvider and aztecWalletStore
1 parent fbb9a5b commit 51b1837

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎apps/app/lib/balances/providers/aztecBalanceProvider.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { BalanceProvider } from "@/Models/BalanceProvider";
22
import { TokenBalance } from "@/Models/Balance";
33
import KnownInternalNames from "@/lib/knownIds";
4-
import { AztecAddress } from "@aztec/aztec.js/addresses";
5-
import { Fr } from "@aztec/aztec.js/fields";
6-
import { createAztecNodeClient } from "@aztec/aztec.js/node";
7-
import { deriveStorageSlotInMap } from "@aztec/stdlib/hash";
84
import { formatUnits } from "viem";
95
import { getNetworkRpcUrl } from "@/lib/rpc/resolveNetworkRpcUrl";
106

117
// Storage slot for public_balances map in the Token contract (slot 9 for standard Aztec token)
12-
const TOKEN_PUBLIC_BALANCES_SLOT = new Fr(9n)
8+
const TOKEN_PUBLIC_BALANCES_SLOT_INDEX = 9n
139

1410
export class AztecBalanceProvider extends BalanceProvider {
1511
supportsNetwork: BalanceProvider['supportsNetwork'] = (network) => {
@@ -22,6 +18,18 @@ export class AztecBalanceProvider extends BalanceProvider {
2218
const nodeUrl = getNetworkRpcUrl(network)
2319
if (!nodeUrl) return []
2420

21+
// Lazy-load Aztec SDK so it never enters the SSR import graph.
22+
// Top-level imports of @aztec/* drag in @aztec/foundation, whose pino logger
23+
// tries to dynamically require pino-pretty at module init and crashes Next's
24+
// serverless bundle (HTTP 500 on every page → social previews break).
25+
const [{ AztecAddress }, { Fr }, { createAztecNodeClient }, { deriveStorageSlotInMap }] = await Promise.all([
26+
import("@aztec/aztec.js/addresses"),
27+
import("@aztec/aztec.js/fields"),
28+
import("@aztec/aztec.js/node"),
29+
import("@aztec/stdlib/hash"),
30+
])
31+
32+
const tokenPublicBalancesSlot = new Fr(TOKEN_PUBLIC_BALANCES_SLOT_INDEX)
2533
const client = createAztecNodeClient(nodeUrl)
2634
const owner = AztecAddress.fromString(address)
2735
const balances: TokenBalance[] = []
@@ -30,7 +38,7 @@ export class AztecBalanceProvider extends BalanceProvider {
3038
try {
3139
const tokenAddr = AztecAddress.fromString(token.contract)
3240
// Type assertions needed: @aztec/aztec.js and @aztec/stdlib resolve to different @aztec/foundation versions
33-
const slot = await deriveStorageSlotInMap(TOKEN_PUBLIC_BALANCES_SLOT as any, owner as any)
41+
const slot = await deriveStorageSlotInMap(tokenPublicBalancesSlot as any, owner as any)
3442
const balanceField = await client.getPublicStorageAt('latest', tokenAddr, slot as any)
3543
const raw = balanceField.toBigInt()
3644
const amount = Number(formatUnits(raw, token.decimals))

‎apps/app/stores/aztecWalletStore.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createWithEqualityFn as create } from 'zustand/traditional'
22
import type { WalletProvider as AztecSDKWalletProvider } from '@aztec/wallet-sdk/manager'
3-
import { Wallet } from '@aztec/aztec.js/wallet'
3+
import type { Wallet } from '@aztec/aztec.js/wallet'
44

55
export type AztecWallet = Wallet
66

0 commit comments

Comments
 (0)