-
Notifications
You must be signed in to change notification settings - Fork 14
AI Credits widget: explicit operator consent, updated consent copy, antseed-only view #153
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| const deepLinkQuery = | ||
| '&buyerAddress=0x1111111111111111111111111111111111111111' + | ||
| `&operatorSignature=0x${'ab'.repeat(64)}` | ||
|
|
||
| test('source=antseed renders only the purchase widget, without landing-page sections', async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto('/?source=antseed') | ||
|
|
||
| await expect(page.getByTestId('ai-credits-purchase-only')).toBeVisible() | ||
| await expect(page.getByTestId('purchase-frame')).toBeVisible() | ||
| await expect(page.getByTestId('ai-credits-landing-page')).toHaveCount(0) | ||
| await expect(page.getByTestId('benefits-strip')).toHaveCount(0) | ||
| await expect(page.getByTestId('agent-skills')).toHaveCount(0) | ||
| }) | ||
|
|
||
| test('omitting source keeps the full landing page unchanged', async ({ page }) => { | ||
| await page.goto('/') | ||
|
|
||
| await expect(page.getByTestId('ai-credits-landing-page')).toBeVisible() | ||
| await expect(page.getByTestId('ai-credits-purchase-only')).toHaveCount(0) | ||
| }) | ||
|
|
||
| test('source=antseed composes with buyerAddress and operatorSignature deep-link params', async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(`/?source=antseed${deepLinkQuery}`) | ||
|
|
||
| await expect(page.getByTestId('ai-credits-purchase-only')).toBeVisible() | ||
| await expect(page.getByTestId('purchase-frame')).toBeVisible() | ||
| await expect(page.getByTestId('ai-credits-landing-page')).toHaveCount(0) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -916,6 +916,10 @@ export function useAiCreditsAdapter({ | |
| return | ||
| } | ||
|
|
||
| // Pre-fill the buyer identity and the pending signature only. Consent must never be | ||
| // submitted here — it is only ever submitted from handleSignOperatorConsent, in | ||
| // response to an explicit user click on OperatorConsentStep. A deep-link-supplied | ||
| // signature is not itself user approval; it just saves the user from re-signing. | ||
| storeDeepLinkParams({ | ||
| buyerAddress: trimmedAddress, | ||
| operatorSignature: trimmedSignature, | ||
|
|
@@ -939,85 +943,12 @@ export function useAiCreditsAdapter({ | |
| totalGdDepositedG: null, | ||
| monthlyStreamG: null, | ||
| activeTab: 'buy', | ||
| operatorConsentPending: true, | ||
| operatorConsentPending: false, | ||
| error: null, | ||
| }), | ||
| ) | ||
|
|
||
| const ref: AccountRef = { payer: address, buyer: trimmedAddress } | ||
|
|
||
| try { | ||
| const operatorStatus = await chainClient.getBuyerOperatorStatus(ref) | ||
|
|
||
| if (!operatorStatus.enabled) { | ||
| throw new Error('Operator consent is not available for this deep-link buyer') | ||
| } | ||
|
|
||
| if (!operatorStatus.operatorAccepted) { | ||
| await backendClient.submitOperatorConsent(ref.buyer, { | ||
| nonce: operatorStatus.consentNonce, | ||
| signature: trimmedSignature, | ||
| }) | ||
| await waitForOperatorConsent(chainClient, ref) | ||
| } | ||
|
|
||
| setBuyerOperatorConsented(address, trimmedAddress, true) | ||
| const buyerList = resolveBuyerList(address, trimmedAddress) | ||
| let accountPatch: Partial<AiCreditsWidgetAdapterState> = {} | ||
| try { | ||
| const view = await buildAccountView(address, backendClient, chainClient, { | ||
| buyerAddress: trimmedAddress, | ||
| }) | ||
| const enriched = await enrichAccountView(view, chainClient) | ||
| accountPatch = viewToStatePatch(view, enriched, INITIAL_STATE, { | ||
| balanceMode: 'always', | ||
| }) | ||
| if (accountPatch.operatorConsented !== undefined) { | ||
| setBuyerOperatorConsented(address, trimmedAddress, accountPatch.operatorConsented) | ||
| } | ||
| } catch { | ||
| accountPatch = {} | ||
| } | ||
| const nextBuyerFields = buildBuyerStateFields( | ||
| address, | ||
| buyerList.buyers, | ||
| buyerList.selected, | ||
| ) | ||
| setState((prev) => | ||
| withDerivedStatus( | ||
| prev, | ||
| { | ||
| ...accountPatch, | ||
| ...nextBuyerFields, | ||
| operatorConsented: true, | ||
| operatorConsentPending: false, | ||
| activeTab: 'buy', | ||
| error: null, | ||
| }, | ||
| true, | ||
| ), | ||
| ) | ||
| clearDeepLinkArtifacts() | ||
| } catch (err: unknown) { | ||
| setState((prev) => | ||
| withDerivedStatus( | ||
| prev, | ||
| { | ||
| error: deepLinkManualFallbackMessage( | ||
| err instanceof Error | ||
| ? err.message | ||
| : 'Could not apply deep-link operator approval.', | ||
| ), | ||
| activeTab: 'buy', | ||
| status: 'purchase_setup', | ||
| operatorConsentPending: false, | ||
| }, | ||
| true, | ||
| ), | ||
| ) | ||
| } | ||
| }, | ||
| [address, backendClient, chainClient, resolveBuyerList], | ||
| [address], | ||
| ) | ||
|
Comment on lines
950
to
952
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. All values referenced inside
The |
||
|
|
||
| const handleSignOperatorConsent = useCallback(async () => { | ||
|
|
@@ -1083,6 +1014,7 @@ export function useAiCreditsAdapter({ | |
| ...(!onNonBuyTab ? { status: 'purchase_setup' } : {}), | ||
| }), | ||
| ) | ||
| clearDeepLinkArtifacts() | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -1126,6 +1058,7 @@ export function useAiCreditsAdapter({ | |
| ...(!onNonBuyTab ? { status: 'purchase_setup' } : {}), | ||
| }), | ||
| ) | ||
| clearDeepLinkArtifacts() | ||
| } catch (err: unknown) { | ||
| setState((prev) => ({ | ||
| ...prev, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.