Convert buy G$ to a GoodWidget
Parent issue: #94
Overview
This plan covers converting the "Buy G$" feature into a GoodWidget. The widget enables users to buy G$ using fiat via the Onramper widget, which buys a stable token on Celo into a user-owned smart contract. The smart contract then converts it to G$ and sends it back to the user's wallet.
Reference Files
GoodWidget (target repo)
- Existing widget components and structure to be used as the foundation for the new Buy G$ widget.
GoodProtocolUI (UI reference)
src/pages/gd/BuyGD/index.tsx — GoodProtocolUI BuyGD
- Provides the basic layout and UI structure for the Buy G$ page.
good-design (widget reference)
packages/good-design/src/apps/onramp/ — GoodWeb3-Mono onramp app
- The existing Onramper widget implementation. Components, state management, and UI patterns should be referenced.
web3-sdkv2 (Buy G$ SDK)
packages/sdk-v2/src/sdk/buygd/react.tsx — BuyGD React SDK
- Provides React hooks and utilities for the Buy G$ flow. This SDK should be imported as
@gooddollar/web3-sdkv2.
Required States, Flows, and Behaviors
States
- Idle / Initial — Widget is displayed with the Onramper integration ready. User sees fiat input options and supported currencies.
- Loading / Connecting — While connecting wallet or initializing the Onramper widget.
- Onramper Flow — User is interacting with the Onramper widget (selecting fiat currency, amount, payment method).
- Transaction Pending — Stable token purchased on Celo; smart contract conversion to G$ in progress.
- Success — G$ tokens received in user's wallet. Show confirmation with transaction details.
- Error — Any failure in the flow (Onramper error, conversion failure, network error). Show actionable error message with retry option.
- No Wallet — User doesn't have a connected wallet. Prompt wallet connection.
Flows
- Buy G$ flow:
- User connects wallet (if not connected)
- User selects fiat currency and amount in Onramper widget
- Onramper buys stable token (e.g., USDC/cUSD) on Celo into the user-owned smart contract
- Smart contract converts stable token → G$
- G$ is sent to user's wallet
- Success confirmation displayed
Behaviors
- Wallet connection state should persist across widget re-renders
- Onramper widget should be embedded within the GoodWidget layout
- Transaction status should be polled/monitored and UI updated accordingly
- Errors should be user-friendly with retry options
- Responsive design for mobile and desktop
Execution Plan
Phase 1: Analysis & Setup
- Map existing GoodWidget component architecture and patterns.
- Review the referenced files from GoodProtocolUI, good-design, and web3-sdkv2.
- Ensure
@gooddollar/web3-sdkv2 is available as a dependency in GoodWidget.
Phase 2: Core Widget Implementation
- Create the Buy G$ widget component structure:
BuyGDWidget — main widget container
- Sub-components for each state (idle, loading, onramper, pending, success, error)
- Integrate
@gooddollar/web3-sdkv2 buy GD hooks (useBuyGD or equivalent from buygd/react.tsx).
- Embed the Onramper widget within the GoodWidget layout, referencing the good-design onramp implementation.
- Implement wallet connection handling within the widget.
Phase 3: UI Implementation
- Implement the UI using GoodWidget reusable components, referencing GoodProtocolUI's
BuyGD/index.tsx for layout and design patterns.
- Create or adapt components as needed:
- New in widget package:
BuyGDWidget, state-specific sub-components, Onramper wrapper
- Reusable (packages/ui): Any generic UI elements (e.g., transaction status banners, amount selectors) that could be useful across widgets should be added to the shared UI package
- Ensure responsive and accessible design.
Phase 4: Transaction Flow
- Implement transaction monitoring for the stable token purchase and G$ conversion.
- Handle all states (pending, success, error) with appropriate UI feedback.
- Implement retry logic for failed transactions.
Phase 5: Testing & Polish
- Test all user flows and states.
- Verify wallet connection scenarios (connected, not connected, wrong network).
- Test error scenarios and edge cases.
Acceptance Criteria
Human-Reviewer Checklist
Convert buy G$ to a GoodWidget
Parent issue: #94
Overview
This plan covers converting the "Buy G$" feature into a GoodWidget. The widget enables users to buy G$ using fiat via the Onramper widget, which buys a stable token on Celo into a user-owned smart contract. The smart contract then converts it to G$ and sends it back to the user's wallet.
Reference Files
GoodWidget (target repo)
GoodProtocolUI (UI reference)
src/pages/gd/BuyGD/index.tsx— GoodProtocolUI BuyGDgood-design (widget reference)
packages/good-design/src/apps/onramp/— GoodWeb3-Mono onramp appweb3-sdkv2 (Buy G$ SDK)
packages/sdk-v2/src/sdk/buygd/react.tsx— BuyGD React SDK@gooddollar/web3-sdkv2.Required States, Flows, and Behaviors
States
Flows
Behaviors
Execution Plan
Phase 1: Analysis & Setup
@gooddollar/web3-sdkv2is available as a dependency in GoodWidget.Phase 2: Core Widget Implementation
BuyGDWidget— main widget container@gooddollar/web3-sdkv2buy GD hooks (useBuyGDor equivalent frombuygd/react.tsx).Phase 3: UI Implementation
BuyGD/index.tsxfor layout and design patterns.BuyGDWidget, state-specific sub-components, Onramper wrapperPhase 4: Transaction Flow
Phase 5: Testing & Polish
Acceptance Criteria
@gooddollar/web3-sdkv2for the Buy G$ SDK functionalityHuman-Reviewer Checklist
@gooddollar/web3-sdkv2buy GD hooks are used correctly (not reimplemented)