Skip to content

Prepare AI Credits Widget for GoodWallet integration - #134

Open
L03TJ3 with Copilot wants to merge 5 commits into
mainfrom
copilot/prep-ai-credits-widget-goodwallet-integration
Open

Prepare AI Credits Widget for GoodWallet integration#134
L03TJ3 with Copilot wants to merge 5 commits into
mainfrom
copilot/prep-ai-credits-widget-goodwallet-integration

Conversation

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

AI Credits now accepts GoodWallet’s injected EIP-1193 provider and theme overrides consistently in React and Custom Element hosts. Production configuration fails closed rather than silently activating mock clients.

  • Host integration

    • Forward Custom Element provider, config, theme overrides, and default theme to AiCreditsWidget.
    • Preserve existing payment success/error events.
  • Production safety

    • Add an unavailable backend client for missing production/staging backend configuration.
    • Restrict mock backend and chain clients to development.
    • Retain widget-owned Celo/Base RPC and contract defaults.
  • SSR and packaging

    • Make @goodwidget/ai-credits-widget/register defer browser-only element imports until registration.
    • Make Custom Element class evaluation safe without DOM globals.
    • Package typed ESM/CJS entries for React, element, and register consumers.
  • Consumer documentation

    • Document React and Custom Element integration.
    • Document required EIP-1193 methods:
      eth_accounts, eth_chainId, eth_requestAccounts,
      wallet_switchEthereumChain, personal_sign, and eth_sendTransaction.
import { AiCreditsWidget } from '@goodwidget/ai-credits-widget'

<AiCreditsWidget provider={provider} backendUrl={backendUrl} themeOverrides={themeOverrides} />

Copilot AI requested review from Copilot and removed request for Copilot July 29, 2026 13:14
Copilot AI linked an issue Jul 29, 2026 that may be closed by this pull request
15 tasks
Co-authored-by: L03TJ3 <6606028+L03TJ3@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 29, 2026 13:23
Copilot AI changed the title [WIP] Prepare AI Credits Widget for GoodWallet integration Prepare AI Credits Widget for GoodWallet integration Jul 29, 2026
Copilot AI requested a review from L03TJ3 July 29, 2026 13:26
…widget structure

- Simplified payment status checks in the adapter by removing redundant conditions for 'backend_unavailable'.
- Updated the logic for setting derived statuses to improve clarity and maintainability.
- Enhanced the AiCreditsWidgetElement structure by creating a base class for better property management.
- Introduced bridged property handling in createMiniAppElement to improve component integration and state management.
Copilot AI review requested due to automatic review settings July 29, 2026 18:54

Copilot AI 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.

Pull request overview

Prepares the AI Credits widget package for GoodWallet integration by aligning provider/theming handoff across React and Custom Element hosts, tightening production safety around backend/chain client selection, and making register SSR-friendly.

Changes:

  • Forward Custom Element runtime inputs (provider/config/theme overrides/default theme + bridged properties like backendUrl) into AiCreditsWidget.
  • Fail closed when production/staging backend configuration is missing; restrict mock backend/chain clients to development.
  • Make @goodwidget/ai-credits-widget/register SSR-safe via guarded, deferred element import; add consumer-facing docs and package export/sideEffects metadata.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/embed/src/createMiniAppElement.tsx Adds SSR-safe HTMLElement base and improved property bridging into React + provider/theming propagation.
packages/ai-credits-widget/src/register.ts Defers element import until runtime and guards customElements for SSR/Next.js safety.
packages/ai-credits-widget/src/index.ts Exposes UnavailableAiCreditsBackendClient from the package root.
packages/ai-credits-widget/src/element.ts Bridges backendUrl as a property and exports a typed element class.
packages/ai-credits-widget/src/chainClient.ts Updates mock behavior gating by widget environment and adjusts mock method signatures.
packages/ai-credits-widget/src/backendClient.ts Introduces an unavailable backend client and environment-aware backend client factory.
packages/ai-credits-widget/src/AiCreditsWidget.tsx Removes an unused import (no behavioral change).
packages/ai-credits-widget/src/adapter.ts Threads environment into backend/chain client creation and adds a backend-unavailable state on missing prod config.
packages/ai-credits-widget/README.md Documents React + Custom Element usage and required EIP-1193 capabilities.
packages/ai-credits-widget/package.json Ensures typed ESM/CJS exports for ., ./element, ./register, with correct publish files + sideEffects.

Comment thread packages/embed/src/createMiniAppElement.tsx
Comment thread packages/ai-credits-widget/src/chainClient.ts
Comment thread packages/ai-credits-widget/src/backendClient.ts
Comment thread packages/ai-credits-widget/src/register.ts Outdated
…niAppElement return type

- Introduced new MiniAppElement and MiniAppElementConstructor interfaces to enhance type safety and clarity in the embed package.
- Changed the return type of createMiniAppElement to MiniAppElementConstructor for better integration and usage consistency.
- Updated index export to include the new types for improved accessibility in other modules.
@blueogin

Copy link
Copy Markdown
Contributor

@copilot
review this pr

…ibility

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

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
review this pr

Reviewed and addressed the outstanding PR feedback in commit 6d44cbd.

Changes included:

  • fixed custom-element pre-upgrade hydration for provider/themeOverrides/config
  • restored backward-compatible createChainClient call patterns
  • threaded environment into history backend-client creation
  • guarded register auto-call against unhandled import rejection

Validation run:

  • pnpm --filter @goodwidget/embed lint
  • pnpm --filter @goodwidget/ai-credits-widget lint
  • pnpm --filter @goodwidget/embed build
  • pnpm --filter @goodwidget/ai-credits-widget build
  • parallel validation (CodeQL clean)

Copilot AI requested a review from blueogin July 29, 2026 21:01
@blueogin
blueogin marked this pull request as ready for review July 29, 2026 21:10
@blueogin
blueogin requested a review from a team July 29, 2026 21:10

@sirpy sirpy 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.

@blueogin there are many open issues, resolve and reply.

_options: { txHashes?: string[]; previousBalance?: string } = {},
): Promise<SettlementResult> {
async waitForSettlement(ref: AccountRef): Promise<SettlementResult> {
await sleep(MOCK_DELAY_MS)

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.

is it really waiting for settlement? what is the mock delay for

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 mock-only behavior. It waits for the shared 600ms mock delay to exercise the pending/loading UI, then marks pending mock transactions as funded. It does not poll real settlement; the production client handles actual settlement polling.


async getWithdrawableUsd(_buyer: string): Promise<string> {
async getWithdrawableUsd(): Promise<string> {
return '0'

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.

what are these mock values?

@blueogin blueogin Jul 30, 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.

The mock intentionally returns "0" because it does not model FundingVault principal balances

@blueogin
blueogin requested a review from sirpy July 30, 2026 12:46
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] Prepare AI Credits Widget for GoodWallet integration

5 participants