Skip to content

Feature: New UB Components #7354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Jun 17, 2025
Merged

Feature: New UB Components #7354

merged 50 commits into from
Jun 17, 2025

Conversation

gregfromstl
Copy link
Member

@gregfromstl gregfromstl commented Jun 16, 2025


PR-Codex overview

This PR introduces new components for payment processing and enhances existing functionalities, including the transition from PayEmbed to CheckoutWidget and BuyWidget. It also improves error handling and adds utility functions for token management.

Detailed summary

  • Removed PayEmbed component and replaced it with CheckoutWidget and BuyWidget.
  • Updated payment options in various components to support new widgets.
  • Added TransactionWidget for executing transactions.
  • Enhanced error handling with ErrorBanner and UnsupportedTokenScreen.
  • Introduced utility functions for formatting token amounts and handling fiat conversions.
  • Updated types and interfaces for better type safety and clarity.
  • Improved styling and layout in several UI components.
  • Added placeholder files to maintain directory structures in various directories.

The following files were skipped due to too many changes: packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts, packages/thirdweb/src/react/core/errors/mapBridgeError.test.ts, packages/thirdweb/src/stories/Bridge/UnsupportedTokenScreen.stories.tsx, packages/thirdweb/src/react/web/ui/Bridge/payment-success/SuccessScreen.tsx, packages/thirdweb/src/react/core/hooks/useBridgeRoutes.test.ts, packages/thirdweb/src/stories/Bridge/StepRunner.stories.tsx, packages/thirdweb/src/react/core/hooks/useBridgeError.ts, packages/thirdweb/src/stories/WalletRow.stories.tsx, packages/thirdweb/src/stories/Bridge/ErrorBanner.stories.tsx, packages/thirdweb/src/stories/TokenBalanceRow.stories.tsx, packages/thirdweb/src/react/web/ui/Bridge/payment-selection/WalletFiatSelection.tsx, packages/thirdweb/src/react/web/ui/TransactionButton/ExecutingScreen.tsx, packages/thirdweb/src/react/core/hooks/useBridgePrepare.ts, packages/thirdweb/src/react/web/ui/Bridge/payment-selection/FiatProviderSelection.tsx, packages/thirdweb/src/stories/Bridge/TransactionPayment.stories.tsx, packages/thirdweb/src/stories/Bridge/PaymentSelection.stories.tsx, packages/thirdweb/src/react/web/ui/Bridge/common/TokenAndChain.tsx, packages/thirdweb/src/stories/Bridge/FundWallet.stories.tsx, packages/thirdweb/src/react/web/ui/Bridge/DirectPayment.tsx, packages/thirdweb/src/react/core/hooks/useBridgeError.test.ts, packages/thirdweb/src/stories/Bridge/SuccessScreen.stories.tsx, packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts, packages/thirdweb/src/react/core/hooks/useBridgePrepare.test.ts, packages/thirdweb/src/react/web/ui/Bridge/QuoteLoader.tsx, packages/thirdweb/src/react/core/hooks/usePaymentMethods.ts, packages/thirdweb/src/stories/Bridge/DirectPayment.stories.tsx, apps/playground-web/src/app/connect/pay/embed/RightSection.tsx, pnpm-lock.yaml, packages/thirdweb/src/react/components.md, packages/thirdweb/src/react/core/machines/paymentMachine.ts, packages/thirdweb/src/react/web/ui/Bridge/payment-selection/TokenSelection.tsx, packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentOverview.tsx, packages/thirdweb/src/react/web/ui/Bridge/payment-selection/PaymentSelection.tsx, packages/thirdweb/src/stories/Bridge/BridgeOrchestrator.stories.tsx, apps/playground-web/src/app/connect/pay/components/CodeGen.tsx, packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentDetails.tsx, packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx, packages/thirdweb/src/react/core/hooks/usePaymentMethods.test.ts, packages/thirdweb/src/react/web/ui/Bridge/TransactionPayment.tsx, packages/thirdweb/src/react/web/ui/Bridge/BridgeOrchestrator.tsx, packages/thirdweb/src/react/web/ui/Bridge/payment-success/PaymentReceipt.tsx, packages/thirdweb/src/react/web/ui/Bridge/StepRunner.tsx, apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx, packages/thirdweb/src/stories/Bridge/PaymentDetails.stories.tsx, packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx, packages/thirdweb/src/react/web/ui/Bridge/CheckoutWidget.tsx, packages/thirdweb/src/react/core/hooks/useStepExecutor.ts, packages/thirdweb/src/react/web/ui/Bridge/TransactionWidget.tsx, packages/thirdweb/src/react/core/machines/paymentMachine.test.ts, packages/thirdweb/src/stories/Bridge/fixtures.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Introduced three prebuilt UI widgets: BuyWidget, CheckoutWidget, and TransactionWidget for seamless token purchases, multi-item checkouts, and blockchain transactions.
    • Added a payment orchestration component managing multi-step payment and transaction flows with state machine integration.
    • Launched components for payment method selection, payment details, progress tracking, error handling, and success screens.
    • Enabled fiat onramp provider selection and wallet-based token selection for payments.
    • Added detailed transaction review and receipt components for completed payments.
    • Introduced React hooks for bridge routes, quotes, preparation, payment methods, and error handling.
    • Added utilities for token fetching, conversion, and transaction detail retrieval.
  • Enhancements

    • Improved wallet connection options, theming, localization, and UI styling across payment flows.
    • Refined user experience with enhanced error banners, retry/cancel actions, and animated success indicators.
    • Simplified payment widget APIs with explicit props and better async handling.
    • Improved number formatting and UI responsiveness in wallet and payment components.
  • Documentation

    • Added extensive Storybook stories demonstrating all new components, UI states, themes, and payment scenarios.
    • Published a comprehensive component catalog and developer guides.
  • Bug Fixes / Style

    • Updated UI labels and sidebar links for clarity.
    • Adjusted button hover effects, icon sizes, and text styling for consistency.
    • Removed unused state and deprecated props in payment embed components.
  • Tests

    • Added thorough unit and integration tests for hooks, error mapping, payment flows, adapters, and utilities.
    • Removed flaky auto-connect timeout test to improve test stability.

Copy link
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: 0

🔭 Outside diff range comments (1)
packages/thirdweb/src/react/core/hooks/wallets/useAutoConnectCore.test.tsx (1)

16-18: Avoid shared state between tests by recreating MockStorage and ConnectionManager per test

mockStorage and manager are instantiated once at module scope and then reused across all test cases.
Both of these objects are stateful (e.g. useAutoConnectCore may persist lastConnectedWalletIds in mockStorage).
A mutation in one test can therefore leak into the next test and cause flaky, order-dependent results.

- const mockStorage = new MockStorage();
- const manager = createConnectionManager(mockStorage);
+let mockStorage: MockStorage;
+let manager: ReturnType<typeof createConnectionManager>;
+
+beforeEach(() => {
+  mockStorage = new MockStorage();
+  manager = createConnectionManager(mockStorage);
+});

The wrapper defined below will keep referencing the freshly created manager because it’s closed over a mutable variable.
This small refactor guarantees isolation and makes future additions (or reinstating the timeout test) safer.

🧹 Nitpick comments (1)
packages/thirdweb/src/react/core/hooks/wallets/useAutoConnectCore.test.tsx (1)

94-99: Redundant explicit timeout

waitFor already defaults to a 1000 ms timeout, so passing { timeout: 1000 } is unnecessary noise.
Dropping the option keeps the test concise and avoids the impression that the value is significant.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ad187b and 00c4f27.

📒 Files selected for processing (2)
  • packages/thirdweb/src/react/core/hooks/wallets/useAutoConnectCore.test.tsx (1 hunks)
  • packages/thirdweb/src/wallets/connection/autoConnectCore.test.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/thirdweb/src/wallets/connection/autoConnectCore.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Size
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/thirdweb/src/react/core/hooks/wallets/useAutoConnectCore.test.tsx (1)

1-3: onTimeout behaviour is no longer covered – regression in test scope

The previous commit included a test asserting that useAutoConnectCore calls the onTimeout callback; that entire scenario has been removed.
If the timeout branch is still part of the hook’s contract, please add a replacement test (or confirm that the branch was deleted and can be safely untested).
This keeps critical error-handling logic from silently regressing.

@vercel vercel bot temporarily deployed to Preview – login June 16, 2025 23:42 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground June 16, 2025 23:42 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 June 16, 2025 23:42 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui June 16, 2025 23:42 Inactive
@gregfromstl gregfromstl force-pushed the greg/new-ub-components branch from 1a7e067 to cfc7c79 Compare June 16, 2025 23:48
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground June 16, 2025 23:48 Inactive
@vercel vercel bot temporarily deployed to Preview – login June 16, 2025 23:48 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui June 16, 2025 23:48 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 June 16, 2025 23:48 Inactive
Copy link
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a7e067 and cfc7c79.

📒 Files selected for processing (2)
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/PayModal.tsx (1 hunks)
  • apps/dashboard/src/app/pay/components/client/PayPageEmbed.client.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/PayModal.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Size
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)

@@ -63,7 +63,7 @@ export function PayPageEmbed({
onPurchaseSuccess: (result) => {
if (!redirectUri) return;
const url = new URL(redirectUri);
switch (result.type) {
switch (result?.type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Guard against undefined before the switch to preserve discriminated-union narrowing

Using switch (result?.type) widens the expression to 'crypto' | 'fiat' | 'transaction' | undefined, preventing TypeScript from narrowing result inside each case. This forces result.status / result.transactionHash to be typed as any, defeating the benefit of the discriminated union and risking silent type regressions.

Proposed fix: short-circuit when result is falsy, then switch on the guaranteed, non-optional result.type.

-            switch (result?.type) {
+            if (!result) {
+              return window.open(url.toString());
+            }
+            switch (result.type) {

Optionally add a default branch to future-proof against new result types.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
switch (result?.type) {
if (!result) {
return window.open(url.toString());
}
switch (result.type) {
🤖 Prompt for AI Agents
In apps/dashboard/src/app/pay/components/client/PayPageEmbed.client.tsx at line
66, the switch statement uses optional chaining on result.type, causing
TypeScript to widen the type and lose discriminated union narrowing. To fix
this, add a guard clause before the switch to return early or handle the case
when result is undefined, ensuring that inside the switch statement result is
always defined. Then switch on result.type without optional chaining.
Optionally, add a default case in the switch to handle any future result types
safely.

@gregfromstl gregfromstl force-pushed the greg/new-ub-components branch from 1b600b3 to 74717d7 Compare June 17, 2025 00:07
@vercel vercel bot temporarily deployed to Preview – wallet-ui June 17, 2025 00:07 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 June 17, 2025 00:07 Inactive
@vercel vercel bot temporarily deployed to Preview – login June 17, 2025 00:07 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground June 17, 2025 00:07 Inactive
@gregfromstl gregfromstl merged commit ed81006 into main Jun 17, 2025
16 of 19 checks passed
@gregfromstl gregfromstl deleted the greg/new-ub-components branch June 17, 2025 00:07
@joaquim-verges joaquim-verges mentioned this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dashboard Involves changes to the Dashboard. packages Playground Changes involving the Playground codebase. SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants