Skip to content

feat: extract use-auth and use-wallet-accounts hooks across JS SDK examples#59

Open
avneesh0612 wants to merge 8 commits into
mainfrom
feat/extract-auth-hooks
Open

feat: extract use-auth and use-wallet-accounts hooks across JS SDK examples#59
avneesh0612 wants to merge 8 commits into
mainfrom
feat/extract-auth-hooks

Conversation

@avneesh0612
Copy link
Copy Markdown
Contributor

Summary

  • Extracts use-auth and use-wallet-accounts hooks from inline provider/component logic into dedicated hook files across all Next.js examples using the Dynamic JS SDK
  • Removes duplicated auth state management code from providers.tsx and components
  • All examples now follow a consistent pattern for checking auth state and accessing wallet accounts

Examples Updated

Example Files Added Files Modified
nextjs-bridge-mayan hooks/use-auth.ts, hooks/use-wallet-accounts.ts lib/providers.tsx
nextjs-defi-lending-morpho hooks/use-auth.ts, hooks/use-wallet-accounts.ts lib/providers.tsx
nextjs-moneygram-ramp hooks/use-auth.ts, hooks/use-wallet-accounts.ts components/header.tsx, components/ramp-app.tsx
nextjs-stablecoin-yield-aave hooks/use-auth.ts, hooks/use-wallet-accounts.ts lib/providers.tsx
nextjs-stablecoin-yield-kamino hooks/use-auth.ts, hooks/use-wallet-accounts.ts lib/providers.tsx
nextjs-stablecoin-yield-pods hooks/use-auth.ts, hooks/use-wallet-accounts.ts lib/providers.tsx

Hook Pattern

Both hooks use useSyncExternalStore over Dynamic client events for reactive, subscription-based state:

// use-auth.ts — returns true when user is signed in
export function useAuth(): boolean

// use-wallet-accounts.ts — returns array of connected wallet accounts
export function useWalletAccounts(): WalletAccount[]

Test plan

  • Run pnpm dev in each updated example and verify auth state reflects correctly on sign-in / sign-out
  • Confirm wallet addresses display correctly after connecting
  • No regression in existing functionality

🤖 Generated with Claude Code

…amples

Add reusable `use-auth` and `use-wallet-accounts` hooks to all Next.js
examples that use the Dynamic JS SDK, removing duplicated inline logic
from providers and components. Affected examples:
- nextjs-bridge-mayan
- nextjs-defi-lending-morpho
- nextjs-moneygram-ramp
- nextjs-stablecoin-yield-aave
- nextjs-stablecoin-yield-kamino
- nextjs-stablecoin-yield-pods

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kamino Error Error May 22, 2026 10:54pm
nextjs-iron-ramp Ready Ready Preview, Comment May 22, 2026 10:54pm
predictions-market-demo Ready Ready Preview, Comment May 22, 2026 10:54pm

Request Review

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

Deployment failed with the following error:

There is no GitHub account connected to this Vercel account.

Replace custom useSyncExternalStore-based hooks with the official
@dynamic-labs-sdk/react-hooks package across all JS SDK examples.

- useAuth: delegate to useUser() from react-hooks (null = signed out)
- useEvmWalletAccount / useSolanaWalletAccount / useWalletAccounts:
  delegate to useWalletAccounts() from react-hooks with chain filters
- Providers: wrap with DynamicProvider from react-hooks
- Remove manual onEvent subscriptions and getWalletAccounts polling

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Replace @dynamic-labs-sdk/* with the current @dynamic-labs/* packages
across all JS SDK examples. Key changes:
- createDynamicClient → createClient + .extend() pattern
- useUser/useWalletAccounts → useReactiveClient(dynamicClient)
- DynamicProvider removed (not needed in new API)
- State accessed via client.auth.authenticatedUser and client.wallets.userWallets
- Wallet chain filtering via w.chain === "EVM" | "SOL"

Packages updated:
- @dynamic-labs/client@4.83.1
- @dynamic-labs/react-hooks@4.83.1
- @dynamic-labs/waas-evm@4.83.1 (EVM examples)
- @dynamic-labs/waas-svm@4.83.1 (Solana examples)
- @dynamic-labs/viem-extension@4.83.1 (morpho, aave)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Delete hooks/use-auth.ts and hooks/use-wallet-accounts.ts from all
JS SDK examples — the indirection is unnecessary. All callers now use
useReactiveClient(dynamicClient) directly from @dynamic-labs/react-hooks
and access state via client.auth.authenticatedUser and
client.wallets.userWallets.

Also completes the @dynamic-labs-sdk → @dynamic-labs migration:
- All old SDK imports removed from providers, components, and hooks
- Wallet filtering: w.chain === "EVM" | "SOL" (no type guards)
- Wallet creation: dynamicClient.wallets.embedded.createWallet()
- Auth: dynamicClient.auth.logout(), dynamicClient.ui.auth.show()

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
avneesh0612 and others added 2 commits May 23, 2026 04:13
* feat(iron-ramp): add Solana wallet support

Adds end-to-end Solana support to the nextjs-iron-ramp example alongside
the existing EVM flow. Every place that previously assumed a single EVM
wallet now handles both ecosystems.

## What changed

**Wallet connectors**
- Add `@dynamic-labs/solana@4.52.2` and register `SolanaWalletConnectors`
  alongside `EthereumWalletConnectors` in the provider.

**Constants & chain selector**
- Add `Solana` to the `CHAINS` list.
- In the Quick Ramp chain dropdown, show all EVM chains when any EVM
  wallet is registered; show Solana only when a Solana wallet is
  registered (falls back to all chains if nothing is registered yet).

**Address handling**
- Solana addresses (base58, no `0x` prefix) are never lowercased; all
  comparisons use exact-match. EVM addresses keep case-insensitive
  comparison everywhere.
- Blockchain is detected from the address itself rather than chain IDs,
  so it works for both ecosystems without extra config.

**Wallet registration — onboarding step**
- The "Register Wallet" card is replaced with a multi-wallet card:
  fetches already-linked wallets from Iron Finance on mount and marks
  them as "Linked ✓".
- Renders every wallet from `useUserWallets()` with a SOL / EVM badge,
  network label, and per-wallet Link button.
- Calls `useSwitchWallet` to make the target wallet the Dynamic primary
  before requesting a signature, so the signing prompt appears on the
  correct wallet.
- The Continue button appears once ≥1 wallet is linked and advances to
  the bank step separately.

**Wallet registration — status card (main page)**
- Onboarding Status card now lists all registered wallets (SOL / EVM
  badges + copy buttons) instead of just the first one.
- "+ Link another wallet" button appears for any connected but
  unregistered wallet; clicking it runs the same sign + register flow
  inline without leaving the page.

**Wallet selection — Quick Ramp**
- When the user picks a registered wallet from the dropdown, calls
  `useSwitchWallet` so the Dynamic primary wallet stays in sync.

**Iron Finance API — `recipient_account_id`**
- For GET `/api/autoramps/quote` (onramp and offramp), passes
  `recipient_account_id` (registered UUID) instead of the raw
  address/IBAN when available — required by Iron Finance for some
  destination currencies (e.g. USDC on Solana).
- POST `/api/autoramps` (create) continues to use the `recipient_account`
  object, which is what that endpoint accepts.

**Resilience fixes**
- `handleAddBankAccount`: on 409 "already exists", looks up the
  registered bank by IBAN and advances to complete instead of getting
  stuck on the bank step.
- `syncToDynamic` in `useKYCMetadata`: retries up to 3 times with
  increasing delays; logs at `warn` instead of `error` to avoid the
  Next.js dev error overlay on transient network failures.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* chore(iron-ramp): remove unused @dynamic-labs/ethereum-aa dependency

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* chore: update packages

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…examples

- kamino: fix deposit minimum pre-flight (minDepositAmount is in raw token
  units; divide by 10^decimals for human-readable comparison)
- pods: add "use client" + ssr:false to header to fix DynamicButton hydration
- pods: add mounted guard for auth-gated Positions section
- pods: fix position balance parsing — balance lives in
  spotPosition.currentPosition.humanized, not p.balance; update
  RawWalletPosition types to match actual API shape
- pods: set filterSpamTokens:true on getBalances call
- iron-ramp: mark resolved pnpm-lock.yaml conflict

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace local use-auth.ts and use-wallet-accounts.ts wrapper files across
the 6 examples with direct imports from @dynamic-labs-sdk/react-hooks.

Each providers.tsx now uses useUser() and useWalletAccounts() directly;
moneygram components (header, ramp-app) import useUser/useWalletAccounts
from the package instead of local wrappers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Only the 6 target examples should be modified on this branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread examples/vite-stablecoin-payment-links/package-lock.json Outdated
Comment thread examples/vite-stablecoin-payment-links/package-lock.json Outdated
Comment thread examples/vite-stablecoin-payment-links/package-lock.json Outdated
Comment thread examples/react-native-expo-demo/package-lock.json Outdated
Comment thread examples/react-native-expo-demo/package-lock.json Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant