Skip to content

perf(contracts): reduce clone/storage overhead across all three contr…#54

Open
abrak01 wants to merge 1 commit into
Kalebtron1:mainfrom
abrak01:feat/41-gas-optimizations
Open

perf(contracts): reduce clone/storage overhead across all three contr…#54
abrak01 wants to merge 1 commit into
Kalebtron1:mainfrom
abrak01:feat/41-gas-optimizations

Conversation

@abrak01
Copy link
Copy Markdown

@abrak01 abrak01 commented May 28, 2026

What changed

src/wallet/StellarWalletAdapter.ts (new)
A provider-agnostic WalletAdapter implementation that delegates connect() and
sign() to mobileWalletConnectors, which already handles provider selection
(Freighter on desktop, Albedo on mobile). No provider-specific code lives in
the adapter itself.

src/wallet/index.ts
Swaps the singleton from FreighterAdapter to StellarWalletAdapter.
FreighterAdapter is still exported for back-compat.

src/hooks/useWallet.tsx
disconnect() now delegates to walletAdapter.disconnect() instead of duplicating
the localStorage cleanup inline.

src/components/CreditSection.tsx
handleWithdraw / handleRepay now call walletAdapter.getAddress() first and only
prompt connect() when no address is persisted — avoids an unnecessary popup on
every transaction.

Supported adapter shape

┌───────────┬──────────┐
│ Method │ Behavior │
├───────────┼──────────┤
│ connect() │ Picks Freighter (desktop, extension present) or Albedo │
│ │ (mobile / fallback) │
├───────────┼───────────────────────────────────────────────────────────────┤
│ sign(xdr) │ Signs with whichever provider was used to connect │
├──────────────┼────────────────────────────────────────────────────────────┤
│ getAddress() │ Returns persisted address from localStorage │
├──────────────┼────────────────────────────────────────────────────────────┤
│ disconnect() │ Clears session and redirects to /login │
└──────────────┴────────────────────────────────────────────────────────────┘

Provider-specific limitations

  • Freighter requires the browser extension installed and unlocked. If absent on
    desktop, the connector falls back to Albedo automatically.
  • Albedo uses a popup/redirect flow — popup blockers can interfere. The
    existing error message already guides the user.
  • Network is hardcoded to Testnet in mobileWalletConnectors.ts. Mainnet support
    requires updating that file only.

Proof the existing flow still works

npm run build passes with 0 errors. DepositModal and WalletSetupModal are
unchanged — they use useMobileWallet, which calls the same underlying
connectWallet / signTransactionXdr functions.

Reviewer steps

  1. npm run dev
  2. Connect with Freighter on desktop → deposit → confirm signing prompt and
    successful transaction.
  3. On mobile, connect with Albedo → confirm the Albedo popup appears and
    signing works.

close #46

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@abrak01 is attempting to deploy a commit to the alankcr1-6443's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Adapter universal de wallets

1 participant