Skip to content

feat: AI Credits Widget — buy AI coding credits with G$ on Celo#63

Open
Copilot wants to merge 30 commits into
mainfrom
copilot/buy-ai-coding-credits
Open

feat: AI Credits Widget — buy AI coding credits with G$ on Celo#63
Copilot wants to merge 30 commits into
mainfrom
copilot/buy-ai-coding-credits

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Full implementation of the AI Credits Widget, enabling users to buy AI coding credits with G$ on Celo.

Buyer Key (packages/ai-credits-widget)

  • Real generatePrivateKey() + privateKeyToAccount() via viem/accounts; user retains private key for AntSeed authentication
  • Private key hidden by default with explicit Reveal / Hide toggle and save-before-continue warning
  • Action row: primary Generate New Key (full-width, blue) + smaller outline Paste Existing Key side-by-side
  • Key rows: single-line truncation + flex: 1 keeps copy icon always visible; compact icon buttons with copied-state feedback
  • Intro text at full body contrast (no secondary/faint styling)

Operator consent

  • Combined into one flow: POST /v1/auth/nonce → payer wallet signs plain message → POST /v1/auth/api-keys → stores returned gd_live_… API key

Celo payment — single wallet confirmation via Multicall3

All Celo on-chain calls are batched into one Multicall3.aggregate3 transaction (one wallet popup, one tx):

  • If streamAmountG > 0 (stream before deposit in aggregate3):
    1. G$.increaseAllowance(CFA, MAX_UINT256 - existing) — skipped if existing CFA allowance ≥ monthly stream budget
    2. host.callAgreement(CFA, createFlow/updateFlow calldata, userData=abi.encode(buyerKey)) — CFA resolved live from Superfluid host; uses updateFlow if a flow already exists
  • If depositAmountG > 0:
    3. G$.transferAndCall(vault, depositWei, abi.encode(buyerKey)) — single sub-call, no separate approve

vaultAddress option added to UseAiCreditsAdapterOptions (from env/backend config; falls back to placeholder until vault is deployed).

Addresses (Celo mainnet, chainId 42220):

  • Multicall3: 0xcA11bde05977b3631167028862bE2a173976CA11
  • Superfluid host: 0xA4Ff07cF81C02CFD356184879D953970cA957585
  • G$ SuperToken: 0x62B8B11039FcfE5aB0C56E502b1C372A3d2a9c7A

GoodID

  • vault.isGoodIDVerified(address) read on-chain; drives the hero badge and 20% stream bonus in quotes

Stepper hierarchy (packages/ui)

  • Active step: 3px left accent bar in the primary color
  • Completed steps: $colorSoft text, font weight 600
  • Pending steps: font weight 400

Tests

All 13 widget state Playwright tests pass with committed screenshots (tests/widgets/ai-credits-widget/test-results/).

- 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 AI changed the title [WIP] Add AI credits widget to buy AI coding credits with G$ feat: AI Credits Widget — buy AI coding credits with G$ on Celo Jun 23, 2026
Copilot AI requested a review from blueogin June 23, 2026 13:08
@sirpy sirpy linked an issue Jun 24, 2026 that may be closed by this pull request
20 tasks
@L03TJ3

L03TJ3 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@copilot can you run the tests and commit the outputted screenshots of the widget?

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@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 tests/widgets/ai-credits-widget/test-results/.

Two bugs were fixed along the way:

  • Icon color tokens in aiCreditsComponents.tsx had a $ prefix ("$primary", "$success") which is not part of the IconColor type — this crashed 5 stories at render time. Fixed to "primary" / "success".
  • Strict-mode violations in 3 test assertions (getByText('+20%'), getByText('Transaction submitted'), getByText('Transaction reverted')) each matched multiple elements. Fixed with exact/full text strings.

Screenshots: acw-01-disconnected.pngacw-13-unsupported-chain.png (commit fix: icon color tokens + test selectors; add Playwright screenshots for all 13 states).

Copilot AI requested a review from L03TJ3 June 24, 2026 11:37

@blueogin blueogin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot

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

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Buyer key...

All 5 corrections are in (commit fix: correct adapter per review — real buyer key, backend auth consent, vault deposit, on-chain GoodID):

1. Buyer key — switched from random-bytes pseudo-address to generatePrivateKey() + privateKeyToAccount() (viem/accounts). The private key is now shown once in BuyerKeyPanel with a save-warning; the derived address is ABI-encoded into the vault deposit data.

2 & 3. Operator consent + submission (combined into 1 handler) — removed walletClient.signTypedData against the stub operator address. New handleSignOperatorConsent calls POST /v1/auth/nonce → payer wallet signs the plain message → POST /v1/auth/api-keys → stores the returned gd_live_... API key in state as apiKey.

4. Celo payment — replaced G$.transfer(stub) with G$.approve(CELO_GD_ANTSEED_VAULT, amount) + CeloGdAntSeedVault.deposit(amount, abi.encode(buyerKeyAddress)). The vault address is a placeholder pending deployment; marked with a TODO comment.

5. GoodIDloadBalance now reads vault.isGoodIDVerified(address) on-chain alongside the G$ balance in the same Promise.all. The result feeds the hero badge and the 20% stream bonus calculation in bonusPercent.

Backend client updated to match the actual Worker API (/v1/auth/nonce, /v1/auth/api-keys, /v1/celo/events/record, /v1/accounts/{account}/credit). All 13 Playwright state tests pass with fresh screenshots.

Copilot AI requested a review from blueogin June 24, 2026 12:22
@blueogin

Copy link
Copy Markdown
Contributor

@copilot
As you can see in the screenshot, the Private key and Public Key is overflowed, it misses copy icon

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.
The private key is shown in plain text by default. There is no masking (dots) or a controlled “reveal” toggle with a warning about exposing the secret.
Buttons use black as the primary color, while the wallet UI uses the green accent. This breaks brand consistency.

image

Copilot AI changed the title feat: AI Credits Widget — buy AI coding credits with G$ on Celo Improve Buyer Key panel safety, hierarchy, and key-field usability Jun 24, 2026
Co-authored-by: blueogin <43612769+blueogin@users.noreply.github.com>

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
can you run the tests and commit the generated screenshots of the widget?

Done — all 13 tests pass and the screenshots have been refreshed in tests/widgets/ai-credits-widget/test-results/ (commit test: refresh ai-credits-widget Playwright screenshots (13/13 pass)).

@blueogin

Copy link
Copy Markdown
Contributor

@copilot
run tests and commit generated screenshots

…ots (13/13 pass)

Co-authored-by: blueogin <43612769+blueogin@users.noreply.github.com>

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
run tests and commit generated screenshots

Done. Fixed a stale 'AI Credits (Base)' assertion in the has_credits test (the component renders 'AI Credits'), then ran all 13 tests — all pass. Screenshots refreshed in tests/widgets/ai-credits-widget/test-results/ (commit fix: correct has_credits test assertion + refresh Playwright screenshots (13/13 pass)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

try and use the blue-glow. not everywhere, but I think on something like this. gives it a bit more depth (also on the actual credit-balance, similar to wallet-v2 balance card)

@blueogin blueogin Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this state is removed as we have "connect wallet" stepper

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some black cards you have used a lighter-black color.
i think this is the better pattern, and should be applied (black on black cards just looks flat)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is different from actual screen - not sure why it's happening
I attached actual screen
image

whiteSpace: 'nowrap',
} as React.CSSProperties

async function handleCopyAddress() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please verify this behavior. navigator.clipboard will not work in react-native

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here you see how we handled for wallet-v1 native vs web:
https://github.com/GoodDollar/GoodDAPP/tree/master/src/components/permissions/api

might be outdated so should be verified against latest native versions and permissions flow

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's resolved

blueogin added 5 commits June 26, 2026 13:25
… startPurchase action and UI updates for credit addition
…s-widget and ui package, utilizing @react-native-clipboard/clipboard for native support
@blueogin

Copy link
Copy Markdown
Contributor

@copilot
run tests and commit generated screenshots

@blueogin blueogin marked this pull request as ready for review June 26, 2026 18:10
@blueogin blueogin requested a review from a team June 26, 2026 18:10
Co-authored-by: blueogin <43612769+blueogin@users.noreply.github.com>

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
run tests and commit generated screenshots

Done — all 13 tests pass and screenshots are refreshed in tests/widgets/ai-credits-widget/test-results/ (commit test: refresh Playwright screenshots + update lockfile (13/13 pass)). The lockfile was also updated to include the new @react-native-clipboard/clipboard peer dependency added to packages/ui.

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.

[PLAN] AI Credits Widget: Buy AI coding credits with G$

3 participants