Skip to content

feat(wallet): add ConnectWalletButton and isConnectionRestoring state#7468

Open
kernelwhisperer wants to merge 6 commits into
developfrom
feat/wallet-restoring-spinner
Open

feat(wallet): add ConnectWalletButton and isConnectionRestoring state#7468
kernelwhisperer wants to merge 6 commits into
developfrom
feat/wallet-restoring-spinner

Conversation

@kernelwhisperer
Copy link
Copy Markdown
Contributor

@kernelwhisperer kernelwhisperer commented May 8, 2026

Summary

  • Fixes https://www.notion.so/cownation/Add-a-loader-when-page-is-being-loaded-3028da5f04ca801ba19ccdb9dfa9773c
  • Adds a reusable ConnectWalletButton wrapper and uses it on both affiliate onboarding screens.
  • The button handles wallet restore state from Wagmi/Viem by showing Restoring wallet... and disabling clicks while the connection is reconnecting. This avoids the affiliate pages briefly showing an actionable Connect wallet CTA during wallet restoration.
  • Also exposes ButtonPrimaryProps from @cowprotocol/ui so the wrapper can forward normal ButtonPrimary props directly.

To Test

  1. Test affiliate onboarding pages with a previously connected wallet:
  • Open the affiliate partner onboarding page
  • During wallet restoration, verify the CTA shows Restoring wallet...
  • Verify it does not show Connect wallet during restoration
  • Verify the button is disabled during restoration
  • After restore completes, verify the correct connected/account state is shown
  1. Test trader affiliate onboarding page:
  • Open the trader affiliate onboarding page
  • Verify the same restoring-wallet behavior
  • Verify disconnected users still see Connect wallet
  • Verify connected users see Add code

Background

Before Wagmi/Viem, this was not practical with ethers.js because we did not have a reliable wallet “reconnecting/restoring” state. Wagmi exposes this via useConnection().status === 'reconnecting'.

image

Summary by CodeRabbit

  • New Features
    • Added a translated "Restoring wallet..." UI state that shows a disabled message while the wallet reconnects.
    • Introduced a centralized Connect Wallet button used across the app for a consistent connect experience.
    • Updated onboarding flows and wallet status UI to use the new Connect Wallet button (including a larger CTA where appropriate).

Review Change Stack

@kernelwhisperer kernelwhisperer self-assigned this May 8, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

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

Project Deployment Actions Updated (UTC)
cowfi Ready Ready Preview May 13, 2026 8:40am
explorer-dev Ready Ready Preview May 13, 2026 8:40am
storybook Ready Ready Preview May 13, 2026 8:40am
swap-dev Ready Ready Preview May 13, 2026 8:40am
widget-configurator Ready Ready Preview May 13, 2026 8:40am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored May 13, 2026 8:40am
sdk-tools Ignored Ignored Preview May 13, 2026 8:40am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8998e3a0-9c97-468c-9066-336ef46fec5b

📥 Commits

Reviewing files that changed from the base of the PR and between 8192d2b and 2e2dfb8.

📒 Files selected for processing (1)
  • libs/ui/src/pure/Button/index.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/ui/src/pure/Button/index.tsx

Walkthrough

Adds restoring-connection detection and UI: new useIsRestoringConnection hook/export, WalletInfo flag, ConnectWalletButton component, Web3Status/Web3StatusInner prop and rendering changes, affiliate CTAs updated, and localization for "Restoring wallet...".

Changes

Wallet Restoring State Feature

Layer / File(s) Summary
Wallet State Types
libs/wallet/src/api/types.ts, libs/ui/src/pure/Button/index.tsx
WalletInfo gains optional isConnectionRestoring. ButtonPrimaryProps type added for button props.
Connection Restoring Detection
libs/wallet/src/wagmi/updater.ts
useWalletInfo reads useConnection().status, computes isConnectionRestoring (status === 'reconnecting'), includes it in returned walletInfo, and updates memo deps.
useIsRestoringConnection Hook & Export
libs/wallet/src/wagmi/hooks/useIsRestoringConnection.ts, libs/wallet/src/index.ts
New useIsRestoringConnection() hook implemented and exported from the wallet barrel.
ConnectWalletButton Component
apps/cowswap-frontend/src/modules/wallet/containers/ConnectWalletButton/index.tsx, apps/cowswap-frontend/src/modules/wallet/index.ts
New ConnectWalletButton wraps ButtonPrimary, disables/removes click while restoring and shows "Restoring wallet..."; otherwise opens wallet modal. Barrel export added.
Web3Status Integration
apps/cowswap-frontend/src/modules/wallet/containers/Web3Status/index.tsx, apps/cowswap-frontend/src/modules/wallet/pure/Web3StatusInner/index.tsx
Web3Status reads isConnectionRestoring and passes it to Web3StatusInner. Web3StatusInnerProps gains optional isConnectionRestoring; when true (and no account) it renders a disabled restoring state.
Affiliate Component Usage
apps/cowswap-frontend/src/modules/affiliate/containers/AffiliatePartnerOnboard.tsx, apps/cowswap-frontend/src/modules/affiliate/containers/AffiliateTraderOnboard.tsx
Affiliate onboarding components now import and use ConnectWalletButton instead of inline ButtonPrimary + legacy modal toggler; Trader uses ButtonSize.BIG.
Localization
apps/cowswap-frontend/src/locales/en-US.po
Added msgid "Restoring wallet..." and updated Connect wallet source references to include the new ConnectWalletButton component.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A wallet that pauses, soft and spry,
As networks mend beneath the sky,
A button hushed in patient cheer,
It waits—then hops the path to clear.
Restoring steps, the rabbit smiles near.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding a ConnectWalletButton component and exposing isConnectionRestoring state management.
Description check ✅ Passed The description includes summary, testing steps with checkboxes, and background context. All required template sections are present and adequately filled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/wallet-restoring-spinner

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 8, 2026

Deploying swap-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 00dab29
Status:🚫  Build failed.

View logs

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/cowswap-frontend/src/modules/wallet/containers/ConnectWalletButton/index.tsx (1)

10-10: 💤 Low value

Consider exporting ConnectWalletButtonProps

The type is internal but since ConnectWalletButton is part of the public module API (re-exported from wallet/index.ts), exporting its props type allows consumers to build typed wrappers or pass forwarded props without having to re-derive the intersection type.

♻️ Proposed change
-type ConnectWalletButtonProps = ButtonPrimaryProps & { children?: ReactNode }
+export type ConnectWalletButtonProps = ButtonPrimaryProps & { children?: ReactNode }

And add the re-export to wallet/index.ts:

 export { ConnectWalletButton } from './containers/ConnectWalletButton'
+export type { ConnectWalletButtonProps } from './containers/ConnectWalletButton'

As per coding guidelines, "Public module API must be re-exported via the module index.ts" — the exported component's companion props type is part of that surface.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/cowswap-frontend/src/modules/wallet/containers/ConnectWalletButton/index.tsx`
at line 10, Export the ConnectWalletButtonProps type so consumers can use its
shape: change the declaration of ConnectWalletButtonProps (currently type
ConnectWalletButtonProps = ButtonPrimaryProps & { children?: ReactNode }) to an
exported type and add a corresponding re-export from the wallet module index (so
the public API exposes ConnectWalletButtonProps alongside ConnectWalletButton);
update any imports that should rely on the public re-export instead of internal
paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/cowswap-frontend/src/modules/wallet/containers/ConnectWalletButton/index.tsx`:
- Around line 17-24: The button currently spreads {...rest} before setting
disabled and onClick so caller-supplied disabled/onClick are ignored; fix
ConnectWalletButton by computing a final disabled value (e.g., const
finalDisabled = isConnectionRestoring || !!rest.disabled) and use
disabled={finalDisabled} on ButtonPrimary, then spread {...rest} (or spread
first and explicitly set disabled={finalDisabled} after) so a caller's
disabled=true is respected; keep the onClick override to call toggleWalletModal
when not restoring but add an inline comment above onClick in
ConnectWalletButton explaining the onClick override is intentional to avoid
future confusion.

---

Nitpick comments:
In
`@apps/cowswap-frontend/src/modules/wallet/containers/ConnectWalletButton/index.tsx`:
- Line 10: Export the ConnectWalletButtonProps type so consumers can use its
shape: change the declaration of ConnectWalletButtonProps (currently type
ConnectWalletButtonProps = ButtonPrimaryProps & { children?: ReactNode }) to an
exported type and add a corresponding re-export from the wallet module index (so
the public API exposes ConnectWalletButtonProps alongside ConnectWalletButton);
update any imports that should rely on the public re-export instead of internal
paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7e0896c4-d74f-4898-9c78-1c02c5a2b9a8

📥 Commits

Reviewing files that changed from the base of the PR and between d2d7dab and ef098c3.

📒 Files selected for processing (10)
  • apps/cowswap-frontend/src/locales/en-US.po
  • apps/cowswap-frontend/src/modules/affiliate/containers/AffiliatePartnerOnboard.tsx
  • apps/cowswap-frontend/src/modules/affiliate/containers/AffiliateTraderOnboard.tsx
  • apps/cowswap-frontend/src/modules/wallet/containers/ConnectWalletButton/index.tsx
  • apps/cowswap-frontend/src/modules/wallet/containers/Web3Status/index.tsx
  • apps/cowswap-frontend/src/modules/wallet/index.ts
  • apps/cowswap-frontend/src/modules/wallet/pure/Web3StatusInner/index.tsx
  • libs/ui/src/pure/Button/index.tsx
  • libs/wallet/src/api/types.ts
  • libs/wallet/src/wagmi/updater.ts

Copy link
Copy Markdown
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @kernelwhisperer , the issue is partially fixed, I think.
The original issue is not 100% addressed:

  • open any of affiliate pages
  • connect to a wallet
  • refresh the page --> the page blinks with the 'connect wallet' banner before the cards with stats are loaded.

https://www.loom.com/share/763683430a0c45b793b2e66465742772

@kernelwhisperer
Copy link
Copy Markdown
Contributor Author

@elena-zh try now please 🙏

@elena-zh
Copy link
Copy Markdown
Contributor

elena-zh commented May 8, 2026

Hey @kernelwhisperer , kinda...
Now I started to see 'refecthing' on the card. But sometimes, disconnected state apepars anyways.
image

Might it be possible to show a generic loader on the page until the data is fetched?
image

Copy link
Copy Markdown
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my message above

@kernelwhisperer
Copy link
Copy Markdown
Contributor Author

@elena-zh, there should be only 2 loading states left:

  1. Restoring connection
image
  1. Fetching data
image

Might it be possible to show a generic loader on the page until the data is fetched?

We do this, that's the state number 2

Now I started to see 'refecthing' on the card. But sometimes, disconnected state apepars anyways.

Could you record a video please?

@kernelwhisperer
Copy link
Copy Markdown
Contributor Author

kernelwhisperer commented May 12, 2026

Could you record a video please?

Here it is

I think I found the issue, but I'm not sure. I pushed a new commit: 8192d2b

Copy link
Copy Markdown
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks better now, thank you.

However, I still see 3 different screen states when the page is being loaded https://www.loom.com/share/12868e49884f41dcaef64d1cb4bf24ff

Let's ask @cowprotocol/frontend team for their opinion: if they are Ok with the current implementation, I'll approve the PR.

@kernelwhisperer
Copy link
Copy Markdown
Contributor Author

It looks better now, thank you.

However, I still see 3 different screen states when the page is being loaded https://www.loom.com/share/12868e49884f41dcaef64d1cb4bf24ff

Let's ask @cowprotocol/frontend team for their opinion: if they are Ok with the current implementation, I'll approve the PR.

Those 2 screens, the ones I described above 1.Restoring connection and 2.Fetching data, the reason you might think they are 3 is because the image did not load immediately and caused a layout refresh.

@kernelwhisperer kernelwhisperer requested a review from a team May 13, 2026 07:40
@elena-zh
Copy link
Copy Markdown
Contributor

@kernelwhisperer , i DO understand why they're displayed and appear there. My point is a bit different (and the issue I initially reported): I'm not in favor of showing 2-3 different screens while the page content is being loaded. I'm in favor of showing one generic loader that hides all these states, so there is not visible that the page changes 2-3 states while it is loading.

Copy link
Copy Markdown
Collaborator

@shoom3301 shoom3301 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant!

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.

4 participants