-
Notifications
You must be signed in to change notification settings - Fork 14
Prepare AI Credits Widget for GoodWallet integration #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/prep-ai-credits-widget-goodwallet-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d7905c4
Initial plan
Copilot 8c9cb2a
fix: prepare AI Credits widget host integration
Copilot 48516c4
refactor(ai-credits): streamline payment status handling and enhance …
blueogin a48f982
refactor(embed): update MiniAppElement interfaces and adjust createMi…
blueogin 6d44cbd
fix ai-credits review feedback for element upgrades and client compat…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # AI Credits Widget | ||
|
|
||
| ```tsx | ||
| import { AiCreditsWidget } from '@goodwidget/ai-credits-widget' | ||
|
|
||
| <AiCreditsWidget provider={provider} backendUrl="https://your-ai-credits-backend.example" /> | ||
| ``` | ||
|
|
||
| For a Custom Element, import `@goodwidget/ai-credits-widget/register`. This import is safe during | ||
| Node.js and Next.js server evaluation; it registers `<ai-credits-widget>` only in a browser. Set | ||
| the injected EIP-1193 provider and optional `themeOverrides` as element properties. | ||
|
|
||
| Production requires `backendUrl`. The widget keeps its Celo and Base RPC and contract defaults | ||
| internally and fails closed with a backend-unavailable state when the production backend is absent. | ||
| Only the `development` environment may use the built-in mock backend and chain clients. | ||
|
|
||
| ## EIP-1193 capabilities | ||
|
|
||
| Grant only these EIP-1193 methods to the injected provider: | ||
|
|
||
| - `eth_accounts` and `eth_chainId` to read the connected wallet. | ||
| - `eth_requestAccounts` when the user selects **Connect Wallet**. | ||
| - `wallet_switchEthereumChain` when the user selects the Celo network switch action. | ||
| - `personal_sign` when the user generates the buyer key. | ||
| - `eth_sendTransaction` when the user confirms a Celo payment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import { | |
| type Chain, | ||
| type PublicClient, | ||
| } from 'viem' | ||
| import type { AiCreditsQuote } from './widgetRuntimeContract' | ||
| import type { AiCreditsQuote, AiCreditsWidgetEnvironment } from './widgetRuntimeContract' | ||
| import type { BuyerOperatorStatus, OperatorConsentPayloadResponse } from './operatorConsent' | ||
| import { ANTSEED_DEPOSITS_BASE_ADDRESS, buildSetOperatorPayload } from './operatorConsent' | ||
| import type { AccountRef } from './backendTypes' | ||
|
|
@@ -254,7 +254,7 @@ export class MockAiCreditsChainClient implements AiCreditsChainClient { | |
| this.goodIdVerified = options.goodIdVerified ?? false | ||
| } | ||
|
|
||
| async isGoodIdVerified(_account: string): Promise<boolean> { | ||
| async isGoodIdVerified(): Promise<boolean> { | ||
| return this.goodIdVerified | ||
| } | ||
|
|
||
|
|
@@ -308,16 +308,40 @@ export class MockAiCreditsChainClient implements AiCreditsChainClient { | |
| } | ||
| } | ||
|
|
||
| async getWithdrawableUsd(_buyer: string): Promise<string> { | ||
| async getWithdrawableUsd(): Promise<string> { | ||
| return '0' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are these mock values?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| } | ||
|
|
||
| export function createChainClient( | ||
| backendUrl: string | undefined, | ||
| options: AiCreditsChainClientOptions = {}, | ||
| options?: AiCreditsChainClientOptions, | ||
| environment?: AiCreditsWidgetEnvironment, | ||
| ): AiCreditsChainClient | ||
| export function createChainClient( | ||
| options?: AiCreditsChainClientOptions, | ||
| environment?: AiCreditsWidgetEnvironment, | ||
| ): AiCreditsChainClient | ||
| export function createChainClient( | ||
| backendUrlOrOptions: string | undefined | AiCreditsChainClientOptions = {}, | ||
| optionsOrEnvironment: AiCreditsChainClientOptions | AiCreditsWidgetEnvironment = {}, | ||
| maybeEnvironment?: AiCreditsWidgetEnvironment, | ||
| ): AiCreditsChainClient { | ||
| if (!backendUrl) { | ||
| const usingLegacySignature = | ||
| typeof backendUrlOrOptions === 'string' || | ||
| (backendUrlOrOptions === undefined && | ||
| (typeof optionsOrEnvironment === 'object' || typeof optionsOrEnvironment === 'undefined')) | ||
| const backendUrl = usingLegacySignature ? backendUrlOrOptions : undefined | ||
| const options = (usingLegacySignature | ||
| ? typeof optionsOrEnvironment === 'object' | ||
| ? optionsOrEnvironment | ||
| : {} | ||
| : backendUrlOrOptions) as AiCreditsChainClientOptions | ||
| const environment: AiCreditsWidgetEnvironment = usingLegacySignature | ||
| ? (maybeEnvironment ?? (backendUrl ? 'production' : 'development')) | ||
| : (typeof optionsOrEnvironment === 'string' ? optionsOrEnvironment : 'production') | ||
|
|
||
| if (environment === 'development') { | ||
|
blueogin marked this conversation as resolved.
|
||
| return new MockAiCreditsChainClient() | ||
| } | ||
| return new ProductionAiCreditsChainClient({ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.