@goodwidget/ai-credits-widget 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Address } from 'viem';
2
- import { GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
2
+ import { IconName, GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
3
3
 
4
4
  type Eip712SigningPayload = {
5
5
  primaryType: string;
@@ -249,11 +249,12 @@ declare function buildAccountView(payer: string, backend: AiCreditsBackendClient
249
249
 
250
250
  type AiCreditsWidgetEnvironment = 'production' | 'staging' | 'development';
251
251
  type AiCreditsWidgetStatus = 'disconnected' | 'connecting' | 'purchase_setup' | 'quote_ready' | 'payment_pending' | 'payment_confirmed' | 'insufficient_g_balance' | 'payment_failed' | 'backend_unavailable' | 'unsupported_chain';
252
- type AiCreditsWidgetTab = 'buy' | 'manage' | 'history';
252
+ type AiCreditsWidgetTab = 'buy' | 'setup' | 'manage' | 'history';
253
253
  interface AiCreditsQuote {
254
254
  depositAmountG: string;
255
255
  streamAmountG: string;
256
256
  }
257
+
257
258
  interface AiCreditsWidgetAdapterState {
258
259
  status: AiCreditsWidgetStatus;
259
260
  address: string | null;
@@ -262,10 +263,18 @@ interface AiCreditsWidgetAdapterState {
262
263
  gdUsdPerToken: number | null;
263
264
  totalCreditUsd: string | null;
264
265
  isGoodIdVerified: boolean;
266
+ /** Active buyer public address. */
265
267
  buyerPubKey: string | null;
268
+ /** Active buyer private key from the local per-payer key map. */
266
269
  buyerPrvKey: string | null;
270
+ /** Active buyer deep-link operator signature, if present. */
271
+ operatorSignature: string | null;
267
272
  operatorConsented: boolean;
273
+ /** True while submitting / waiting for on-chain operator consent. */
274
+ operatorConsentPending: boolean;
268
275
  operatorAddress: string | null;
276
+ /** Operator currently configured for the active signer, if any. */
277
+ currentOperator: string | null;
269
278
  minDepositUsd: string | null;
270
279
  minStreamUsd: string | null;
271
280
  totalGdDepositedG: string | null;
@@ -275,11 +284,38 @@ interface AiCreditsWidgetAdapterState {
275
284
  streamBonusPercent: number;
276
285
  error: string | null;
277
286
  activeTab: AiCreditsWidgetTab;
287
+ buyers: string[];
288
+ /** Deterministic buyer derived from the payer wallet Sign & Generate path. */
289
+ derivedBuyerAddress: string | null;
278
290
  }
279
291
  interface AiCreditsWidgetAdapterActions {
280
292
  connect: () => Promise<void>;
281
293
  switchChain: () => Promise<void>;
294
+ /**
295
+ * Creates or restores the single deterministic buyer for this payer wallet.
296
+ * If a derived key already exists locally, selects that buyer without re-signing.
297
+ */
282
298
  generateBuyerKey: () => Promise<void>;
299
+ /**
300
+ * Switches the active buyer and reloads that buyer's account view.
301
+ * Address should be in `state.buyers`.
302
+ */
303
+ selectBuyer: (address: string) => Promise<void>;
304
+ discoverBuyers: (addresses: string[]) => void;
305
+ /**
306
+ * Imports a signer key, stores it and selects it as the active buyer.
307
+ * Resolves with the imported buyer address, or `null` when the key could
308
+ * not be imported — callers use that to report the outcome of *this* import
309
+ * rather than the state of whichever buyer happened to be active.
310
+ */
311
+ importBuyerFromPrivateKey: (privateKey: string) => Promise<string | null>;
312
+ /**
313
+ * Applies an NCDI deep-link buyer assignment from URL GET parameters
314
+ * (`buyerAddress` + `operatorSignature`). Selects the buyer immediately,
315
+ * submits the pre-signed operator approval token, and starts the buy flow.
316
+ * Never accepts a buyer private key.
317
+ */
318
+ applyDeepLinkBuyer: (address: string, operatorSignature: string) => Promise<void>;
283
319
  signOperatorConsent: () => Promise<void>;
284
320
  syncOperatorConsentFromChain: () => Promise<void>;
285
321
  buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
@@ -322,6 +358,27 @@ interface AiCreditsPayErrorDetail {
322
358
  interface AiCreditsWidgetProps {
323
359
  provider?: unknown;
324
360
  connectOverride?: () => Promise<void>;
361
+ /**
362
+ * Shows the connected-wallet chip (address, and disconnect when the host supplies
363
+ * `disconnectOverride`) in the widget header.
364
+ *
365
+ * Off by default: wallet hosts own the connection and must not offer a second,
366
+ * widget-local way to end it. Standalone deployments and Storybook opt in.
367
+ */
368
+ showWalletControls?: boolean;
369
+ /**
370
+ * Integrator-owned wallet disconnect flow. Without it the chip renders the address
371
+ * only, and its menu explains that the session belongs to the host.
372
+ */
373
+ disconnectOverride?: () => Promise<void>;
374
+ /**
375
+ * Label for the chip's menu action. Defaults to "Disconnect", which only fits when
376
+ * `disconnectOverride` really ends the session — integrators who instead open an
377
+ * account modal should relabel it.
378
+ */
379
+ disconnectLabel?: string;
380
+ /** Icon for the chip's menu action, mirroring `disconnectLabel`. */
381
+ disconnectIcon?: IconName;
325
382
  environment?: AiCreditsWidgetEnvironment;
326
383
  backendUrl?: string;
327
384
  baseRpcUrl?: string;
@@ -1,5 +1,5 @@
1
1
  import { Address } from 'viem';
2
- import { GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
2
+ import { IconName, GoodWidgetThemeOverrides, GoodWidgetConfig } from '@goodwidget/ui';
3
3
 
4
4
  type Eip712SigningPayload = {
5
5
  primaryType: string;
@@ -249,11 +249,12 @@ declare function buildAccountView(payer: string, backend: AiCreditsBackendClient
249
249
 
250
250
  type AiCreditsWidgetEnvironment = 'production' | 'staging' | 'development';
251
251
  type AiCreditsWidgetStatus = 'disconnected' | 'connecting' | 'purchase_setup' | 'quote_ready' | 'payment_pending' | 'payment_confirmed' | 'insufficient_g_balance' | 'payment_failed' | 'backend_unavailable' | 'unsupported_chain';
252
- type AiCreditsWidgetTab = 'buy' | 'manage' | 'history';
252
+ type AiCreditsWidgetTab = 'buy' | 'setup' | 'manage' | 'history';
253
253
  interface AiCreditsQuote {
254
254
  depositAmountG: string;
255
255
  streamAmountG: string;
256
256
  }
257
+
257
258
  interface AiCreditsWidgetAdapterState {
258
259
  status: AiCreditsWidgetStatus;
259
260
  address: string | null;
@@ -262,10 +263,18 @@ interface AiCreditsWidgetAdapterState {
262
263
  gdUsdPerToken: number | null;
263
264
  totalCreditUsd: string | null;
264
265
  isGoodIdVerified: boolean;
266
+ /** Active buyer public address. */
265
267
  buyerPubKey: string | null;
268
+ /** Active buyer private key from the local per-payer key map. */
266
269
  buyerPrvKey: string | null;
270
+ /** Active buyer deep-link operator signature, if present. */
271
+ operatorSignature: string | null;
267
272
  operatorConsented: boolean;
273
+ /** True while submitting / waiting for on-chain operator consent. */
274
+ operatorConsentPending: boolean;
268
275
  operatorAddress: string | null;
276
+ /** Operator currently configured for the active signer, if any. */
277
+ currentOperator: string | null;
269
278
  minDepositUsd: string | null;
270
279
  minStreamUsd: string | null;
271
280
  totalGdDepositedG: string | null;
@@ -275,11 +284,38 @@ interface AiCreditsWidgetAdapterState {
275
284
  streamBonusPercent: number;
276
285
  error: string | null;
277
286
  activeTab: AiCreditsWidgetTab;
287
+ buyers: string[];
288
+ /** Deterministic buyer derived from the payer wallet Sign & Generate path. */
289
+ derivedBuyerAddress: string | null;
278
290
  }
279
291
  interface AiCreditsWidgetAdapterActions {
280
292
  connect: () => Promise<void>;
281
293
  switchChain: () => Promise<void>;
294
+ /**
295
+ * Creates or restores the single deterministic buyer for this payer wallet.
296
+ * If a derived key already exists locally, selects that buyer without re-signing.
297
+ */
282
298
  generateBuyerKey: () => Promise<void>;
299
+ /**
300
+ * Switches the active buyer and reloads that buyer's account view.
301
+ * Address should be in `state.buyers`.
302
+ */
303
+ selectBuyer: (address: string) => Promise<void>;
304
+ discoverBuyers: (addresses: string[]) => void;
305
+ /**
306
+ * Imports a signer key, stores it and selects it as the active buyer.
307
+ * Resolves with the imported buyer address, or `null` when the key could
308
+ * not be imported — callers use that to report the outcome of *this* import
309
+ * rather than the state of whichever buyer happened to be active.
310
+ */
311
+ importBuyerFromPrivateKey: (privateKey: string) => Promise<string | null>;
312
+ /**
313
+ * Applies an NCDI deep-link buyer assignment from URL GET parameters
314
+ * (`buyerAddress` + `operatorSignature`). Selects the buyer immediately,
315
+ * submits the pre-signed operator approval token, and starts the buy flow.
316
+ * Never accepts a buyer private key.
317
+ */
318
+ applyDeepLinkBuyer: (address: string, operatorSignature: string) => Promise<void>;
283
319
  signOperatorConsent: () => Promise<void>;
284
320
  syncOperatorConsentFromChain: () => Promise<void>;
285
321
  buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
@@ -322,6 +358,27 @@ interface AiCreditsPayErrorDetail {
322
358
  interface AiCreditsWidgetProps {
323
359
  provider?: unknown;
324
360
  connectOverride?: () => Promise<void>;
361
+ /**
362
+ * Shows the connected-wallet chip (address, and disconnect when the host supplies
363
+ * `disconnectOverride`) in the widget header.
364
+ *
365
+ * Off by default: wallet hosts own the connection and must not offer a second,
366
+ * widget-local way to end it. Standalone deployments and Storybook opt in.
367
+ */
368
+ showWalletControls?: boolean;
369
+ /**
370
+ * Integrator-owned wallet disconnect flow. Without it the chip renders the address
371
+ * only, and its menu explains that the session belongs to the host.
372
+ */
373
+ disconnectOverride?: () => Promise<void>;
374
+ /**
375
+ * Label for the chip's menu action. Defaults to "Disconnect", which only fits when
376
+ * `disconnectOverride` really ends the session — integrators who instead open an
377
+ * account modal should relabel it.
378
+ */
379
+ disconnectLabel?: string;
380
+ /** Icon for the chip's menu action, mirroring `disconnectLabel`. */
381
+ disconnectIcon?: IconName;
325
382
  environment?: AiCreditsWidgetEnvironment;
326
383
  backendUrl?: string;
327
384
  baseRpcUrl?: string;
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@goodwidget/ai-credits-widget",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "GoodWidget for buying AI coding credits with G$ on Celo",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/GoodDollar/GoodWidget.git",
8
+ "directory": "packages/ai-credits-widget"
9
+ },
5
10
  "files": [
6
11
  "dist",
7
12
  "README.md"