feat: AI Credits Widget — buy AI coding credits with G$ on Celo#63
Conversation
- widgetRuntimeContract.ts: 13 states, all action types, adapter factory pattern - mockBackendClient.ts: interface + mock + production client, createBackendClient factory - adapter.ts: useAiCreditsAdapter hook with full state machine (EIP-712 consent, buyer key gen, Celo payment) - aiCreditsComponents.tsx: all widget-specific components (AiCreditsHero, BuyerKeyPanel, OperatorConsentStep, AmountPicker, CreditsBalance, SetupSnippet, UsageLog, AiCreditsFlowStepper) - AiCreditsWidget.tsx: main widget with GoodWidgetProvider wrapper and state-driven render - integration.ts: manifest with Celo+Base chain IDs and all 13 states - element.ts + register.ts: <ai-credits-widget> web component bridge - index.ts: public exports - Storybook stories: QA + Showcase stories for all 13 states - aiCreditsWidgetStories.tsx: mock state factory and story helpers - Playwright smoke tests: states.spec.ts covering all states - pnpm build passes, pnpm lint passes (0 errors)
|
@copilot can you run the tests and commit the outputted screenshots of the widget? |
Done — all 13 tests now pass and screenshots are committed to Two bugs were fixed along the way:
Screenshots: |
blueogin
left a comment
There was a problem hiding this comment.
Buyer key
now Random bytes truncated to a pseudo-address; private key discarded (adapter.ts ~373–381)
Real generatePrivateKey + privateKeyToAccount; user keeps private key for AntSeed
Operator consent
now Payer walletClient.signTypedData (~405–426)
Calls backend to get signature(eip712 style)
Consent submission
now Signature only updates local state
calls backend with signature
(We can combine Operator Consent and Consent Submission into 1 and also can use 1 backend api endpoint)
Celo payment
now G$.transfer to stub 0x00…01 (~556–565)
approve + CeloGdAntSeedVault.deposit(amount, data) (data ABI-encoded AntSeed buyer address: abi.encode(buyerAddress). Required.)
GoodID
isGoodIdVerified always false in live adapter; never read on-chain
Vault isGoodIDVerified → hero badge + 20% stream bonus in quotes
the backend repository: https://github.com/GoodDollar/antseed-integration
…t, vault deposit, on-chain GoodID
All 5 corrections are in (commit 1. Buyer key — switched from random-bytes pseudo-address to 2 & 3. Operator consent + submission (combined into 1 handler) — removed 4. Celo payment — replaced 5. GoodID — Backend client updated to match the actual Worker API ( |
|
@copilot For buttons, “Generate new key” and “Paste existing key” are the same size and color, giving them equal visual weight. The primary action (generate) should be emphasized.
|
… startPurchase action and UI updates for credit addition
…s-widget and ui package, utilizing @react-native-clipboard/clipboard for native support
|
@copilot |
Co-authored-by: blueogin <43612769+blueogin@users.noreply.github.com>
Done — all 13 tests pass and screenshots are refreshed in |
…hance widget states, including renaming and restructuring for clarity
…ed components for improved clarity and functionality in ai-credits-widget
…nal widget states, and known limitations section for better user guidance
…ios and removal of outdated files
…-widget for improved user guidance and interaction
… state updates in ai-credits-widget and enhance InfoTooltip component for better user interaction
…th new minimum deposit and stream values for improved user experience
…ing validation and user feedback for deposit and stream amounts
…hannel operations, and tooltip guidance for better user experience
…rer user guidance on buyer key generation and operations
…ios and ensure accuracy in visual testing
…its-widget for enhanced user feedback on payment conditions
…backend API usage details and enhance funding history calculations for improved clarity and user experience
…ove backend integration and add polling for consent confirmation
…perator consent details, improve funding history messaging, and refactor bridge response handling for better clarity and integration

Full implementation of the AI Credits Widget, enabling users to buy AI coding credits with G$ on Celo.
Buyer Key (
packages/ai-credits-widget)generatePrivateKey()+privateKeyToAccount()via viem/accounts; user retains private key for AntSeed authenticationflex: 1keeps copy icon always visible; compact icon buttons with copied-state feedbackOperator consent
POST /v1/auth/nonce→ payer wallet signs plain message →POST /v1/auth/api-keys→ stores returnedgd_live_…API keyCelo payment — single wallet confirmation via Multicall3
All Celo on-chain calls are batched into one
Multicall3.aggregate3transaction (one wallet popup, one tx):streamAmountG > 0(stream before deposit in aggregate3):G$.increaseAllowance(CFA, MAX_UINT256 - existing)— skipped if existing CFA allowance ≥ monthly stream budgethost.callAgreement(CFA, createFlow/updateFlow calldata, userData=abi.encode(buyerKey))— CFA resolved live from Superfluid host; usesupdateFlowif a flow already existsdepositAmountG > 0:3.
G$.transferAndCall(vault, depositWei, abi.encode(buyerKey))— single sub-call, no separate approvevaultAddressoption added toUseAiCreditsAdapterOptions(from env/backend config; falls back to placeholder until vault is deployed).Addresses (Celo mainnet, chainId 42220):
0xcA11bde05977b3631167028862bE2a173976CA110xA4Ff07cF81C02CFD356184879D953970cA9575850x62B8B11039FcfE5aB0C56E502b1C372A3d2a9c7AGoodID
vault.isGoodIDVerified(address)read on-chain; drives the hero badge and 20% stream bonus in quotesStepper hierarchy (
packages/ui)$colorSofttext, font weight600400Tests
All 13 widget state Playwright tests pass with committed screenshots (
tests/widgets/ai-credits-widget/test-results/).