Prepare AI Credits Widget for GoodWallet integration#134
Conversation
Co-authored-by: L03TJ3 <6606028+L03TJ3@users.noreply.github.com>
…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.
There was a problem hiding this comment.
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) intoAiCreditsWidget. - Fail closed when production/staging backend configuration is missing; restrict mock backend/chain clients to
development. - Make
@goodwidget/ai-credits-widget/registerSSR-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. |
…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.
|
@copilot |
…ibility Co-authored-by: blueogin <43612769+blueogin@users.noreply.github.com>
Reviewed and addressed the outstanding PR feedback in commit Changes included:
Validation run:
|
| _options: { txHashes?: string[]; previousBalance?: string } = {}, | ||
| ): Promise<SettlementResult> { | ||
| async waitForSettlement(ref: AccountRef): Promise<SettlementResult> { | ||
| await sleep(MOCK_DELAY_MS) |
There was a problem hiding this comment.
is it really waiting for settlement? what is the mock delay for
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
The mock intentionally returns "0" because it does not model FundingVault principal balances
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
AiCreditsWidget.Production safety
development.SSR and packaging
@goodwidget/ai-credits-widget/registerdefer browser-only element imports until registration.Consumer documentation
eth_accounts,eth_chainId,eth_requestAccounts,wallet_switchEthereumChain,personal_sign, andeth_sendTransaction.