@goodwidget/ai-credits-widget 0.1.6 → 0.1.8
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.
- package/README.md +1 -1
- package/dist/{chunk-V7CAVLPS.js → chunk-635NKGPL.js} +2287 -1830
- package/dist/chunk-635NKGPL.js.map +1 -0
- package/dist/element.cjs +2291 -1867
- package/dist/element.cjs.map +1 -1
- package/dist/element.js +1 -1
- package/dist/index.cjs +2292 -1868
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +3 -3
- package/dist/mocked/index.cjs +2334 -1891
- package/dist/mocked/index.cjs.map +1 -1
- package/dist/mocked/index.d.cts +10 -5
- package/dist/mocked/index.d.ts +10 -5
- package/dist/mocked/index.js +42 -23
- package/dist/mocked/index.js.map +1 -1
- package/dist/register.cjs +2352 -1924
- package/dist/register.cjs.map +1 -1
- package/dist/{widgetRuntimeContract-DyvLXMBy.d.cts → widgetRuntimeContract-Bcb5Ej6O.d.cts} +103 -47
- package/dist/{widgetRuntimeContract-DyvLXMBy.d.ts → widgetRuntimeContract-Bcb5Ej6O.d.ts} +103 -47
- package/package.json +4 -4
- package/dist/chunk-V7CAVLPS.js.map +0 -1
|
@@ -15,10 +15,10 @@ type Eip712SigningPayload = {
|
|
|
15
15
|
}>>;
|
|
16
16
|
message: Record<string, string | number>;
|
|
17
17
|
};
|
|
18
|
-
type
|
|
18
|
+
type SignerOperatorStatus = {
|
|
19
19
|
enabled: boolean;
|
|
20
20
|
account: string;
|
|
21
|
-
|
|
21
|
+
signerAddress: string;
|
|
22
22
|
operatorAddress?: string;
|
|
23
23
|
currentOperator: string;
|
|
24
24
|
operatorAccepted: boolean;
|
|
@@ -27,13 +27,13 @@ type BuyerOperatorStatus = {
|
|
|
27
27
|
type OperatorConsentPayloadResponse = {
|
|
28
28
|
enabled: boolean;
|
|
29
29
|
account: string;
|
|
30
|
-
|
|
30
|
+
signerAddress: string;
|
|
31
31
|
typedData?: Eip712SigningPayload;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
type AccountRef = {
|
|
35
35
|
payer: string;
|
|
36
|
-
|
|
36
|
+
signer: string;
|
|
37
37
|
};
|
|
38
38
|
type UserCreditProfile = {
|
|
39
39
|
account: string;
|
|
@@ -64,7 +64,13 @@ type GdCreditEntry = {
|
|
|
64
64
|
logIndex?: number;
|
|
65
65
|
createdAt: string;
|
|
66
66
|
streamUpdateMonth: string;
|
|
67
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Renamed from the wire's `buyerAddress` in `getCreditHistory`. Keep the
|
|
69
|
+
* mapping there: reading the wire name directly leaves this undefined, and an
|
|
70
|
+
* entry with no signer address matches no signer filter — it only ever shows
|
|
71
|
+
* under "All signers".
|
|
72
|
+
*/
|
|
73
|
+
signerAddress?: string;
|
|
68
74
|
};
|
|
69
75
|
type AccountCreditResponse = {
|
|
70
76
|
account: string;
|
|
@@ -88,10 +94,16 @@ type CreditHistoryQuery = {
|
|
|
88
94
|
};
|
|
89
95
|
type AccountView = {
|
|
90
96
|
account: string;
|
|
91
|
-
|
|
97
|
+
signer: string | null;
|
|
92
98
|
profile: UserCreditProfile;
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Null when the operator read did not answer. Distinct from a read that came
|
|
101
|
+
* back saying "no operator": callers must not present an unread status as
|
|
102
|
+
* "not authorized", or an already-authorized account looks unconfigured.
|
|
103
|
+
*/
|
|
104
|
+
operator: SignerOperatorStatus | null;
|
|
105
|
+
/** Null when the withdrawable read did not answer. */
|
|
106
|
+
withdrawableUsd: string | null;
|
|
95
107
|
outstandingFundingUsd: string;
|
|
96
108
|
outstandingFundingCount: number;
|
|
97
109
|
};
|
|
@@ -115,7 +127,7 @@ type DiscountConfig = {
|
|
|
115
127
|
streamBonusPercent: number;
|
|
116
128
|
};
|
|
117
129
|
|
|
118
|
-
declare const DEFAULT_BASE_RPC_URL = "https://
|
|
130
|
+
declare const DEFAULT_BASE_RPC_URL = "https://base.drpc.org";
|
|
119
131
|
declare const CELO_GOODID_ADDRESS: "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
|
|
120
132
|
declare const DEFAULT_CELO_RPC_URL = "https://forno.celo.org";
|
|
121
133
|
type AiCreditsChainClientOptions = {
|
|
@@ -128,22 +140,24 @@ type AiCreditsChainClientOptions = {
|
|
|
128
140
|
};
|
|
129
141
|
interface AiCreditsChainClient {
|
|
130
142
|
fetchGdUsdPerToken(): Promise<number>;
|
|
143
|
+
/** Resolves the GoodID whitelist state, or rejects when the read fails. */
|
|
131
144
|
isGoodIdVerified(account: string): Promise<boolean>;
|
|
132
145
|
buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
|
|
133
|
-
|
|
134
|
-
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?:
|
|
135
|
-
getWithdrawableUsd(
|
|
146
|
+
getSignerOperatorStatus(ref: AccountRef): Promise<SignerOperatorStatus>;
|
|
147
|
+
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: SignerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
|
|
148
|
+
getWithdrawableUsd(signer: string): Promise<string>;
|
|
149
|
+
getSignerAuthNonce(signer: string): Promise<bigint>;
|
|
136
150
|
}
|
|
137
151
|
declare function createChainClient(options?: AiCreditsChainClientOptions): AiCreditsChainClient;
|
|
138
152
|
|
|
139
153
|
type WithdrawPrincipalRequest = {
|
|
140
154
|
amount: string;
|
|
141
155
|
recipient: string;
|
|
142
|
-
|
|
156
|
+
nonce: string;
|
|
143
157
|
signature: string;
|
|
144
158
|
};
|
|
145
159
|
type ChannelOperationRequest = {
|
|
146
|
-
|
|
160
|
+
nonce?: string;
|
|
147
161
|
signature?: string;
|
|
148
162
|
};
|
|
149
163
|
type BridgeResponse = {
|
|
@@ -165,23 +179,34 @@ type OperatorConsentRequest = {
|
|
|
165
179
|
signature: string;
|
|
166
180
|
};
|
|
167
181
|
type OperatorConsentResponse = {
|
|
168
|
-
|
|
182
|
+
signer: string;
|
|
169
183
|
bridge: BridgeResponse;
|
|
170
184
|
};
|
|
185
|
+
type OperatorRevokeRequest = {
|
|
186
|
+
nonce: string;
|
|
187
|
+
signature: string;
|
|
188
|
+
};
|
|
189
|
+
type OperatorRevokeResponse = OperatorConsentResponse;
|
|
171
190
|
declare function totalCreditUsdFromProfile(profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>): string;
|
|
172
191
|
declare function totalCreditUsdFromStatus(status: {
|
|
173
192
|
profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>;
|
|
174
193
|
}): string;
|
|
175
194
|
type AccountEnrichment = {
|
|
176
195
|
totalCreditUsd: string;
|
|
177
|
-
goodIdVerified: boolean;
|
|
178
196
|
totalGdDepositedG: string;
|
|
179
197
|
monthlyStreamG: string;
|
|
180
198
|
};
|
|
181
199
|
type BuildAccountViewOptions = {
|
|
182
|
-
|
|
200
|
+
signerAddress?: string | null;
|
|
183
201
|
};
|
|
184
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Derives the display fields that need no further network access.
|
|
204
|
+
*
|
|
205
|
+
* GoodID verification is deliberately not read here. Chaining it to the backend
|
|
206
|
+
* credit fetch meant any backend error also cleared the verified flag, and it
|
|
207
|
+
* re-ran on every refresh; the adapter resolves it once per account instead.
|
|
208
|
+
*/
|
|
209
|
+
declare function enrichAccountView(view: AccountView): AccountEnrichment;
|
|
185
210
|
interface AiCreditsBackendClient {
|
|
186
211
|
getDiscountConfig(): Promise<DiscountConfig>;
|
|
187
212
|
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
@@ -201,8 +226,9 @@ interface AiCreditsBackendClient {
|
|
|
201
226
|
previousBalance?: string;
|
|
202
227
|
}): Promise<SettlementResult>;
|
|
203
228
|
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
204
|
-
withdrawCredits(
|
|
205
|
-
submitOperatorConsent(
|
|
229
|
+
withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
230
|
+
submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
231
|
+
revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
|
|
206
232
|
}
|
|
207
233
|
declare const DEFAULT_DISCOUNT_CONFIG: DiscountConfig;
|
|
208
234
|
declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
@@ -228,8 +254,9 @@ declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient
|
|
|
228
254
|
previousBalance?: string;
|
|
229
255
|
}): Promise<SettlementResult>;
|
|
230
256
|
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
231
|
-
withdrawCredits(
|
|
232
|
-
submitOperatorConsent(
|
|
257
|
+
withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
258
|
+
submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
259
|
+
revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
|
|
233
260
|
}
|
|
234
261
|
declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
235
262
|
private unavailable;
|
|
@@ -243,6 +270,7 @@ declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClien
|
|
|
243
270
|
closeChannel(): Promise<never>;
|
|
244
271
|
withdrawCredits(): Promise<never>;
|
|
245
272
|
submitOperatorConsent(): Promise<never>;
|
|
273
|
+
revokeOperatorConsent(): Promise<never>;
|
|
246
274
|
}
|
|
247
275
|
declare function createBackendClient(backendUrl: string | undefined): AiCreditsBackendClient;
|
|
248
276
|
declare function buildAccountView(payer: string, backend: AiCreditsBackendClient, chain: AiCreditsChainClient, options?: BuildAccountViewOptions): Promise<AccountView>;
|
|
@@ -263,11 +291,11 @@ interface AiCreditsWidgetAdapterState {
|
|
|
263
291
|
gdUsdPerToken: number | null;
|
|
264
292
|
totalCreditUsd: string | null;
|
|
265
293
|
isGoodIdVerified: boolean;
|
|
266
|
-
/** Active
|
|
267
|
-
|
|
268
|
-
/** Active
|
|
269
|
-
|
|
270
|
-
/** Active
|
|
294
|
+
/** Active signer public address. */
|
|
295
|
+
signerPubKey: string | null;
|
|
296
|
+
/** Active signer private key from the local per-payer key map. */
|
|
297
|
+
signerPrvKey: string | null;
|
|
298
|
+
/** Active signer deep-link operator signature, if present. */
|
|
271
299
|
operatorSignature: string | null;
|
|
272
300
|
operatorConsented: boolean;
|
|
273
301
|
/** True while submitting / waiting for on-chain operator consent. */
|
|
@@ -277,6 +305,8 @@ interface AiCreditsWidgetAdapterState {
|
|
|
277
305
|
currentOperator: string | null;
|
|
278
306
|
minDepositUsd: string | null;
|
|
279
307
|
minStreamUsd: string | null;
|
|
308
|
+
/** Bonus credit earned so far, in micro-USD. Folded into `totalCreditUsd`. */
|
|
309
|
+
totalBonusUsd: string | null;
|
|
280
310
|
totalGdDepositedG: string | null;
|
|
281
311
|
monthlyStreamG: string | null;
|
|
282
312
|
withdrawableUsd: string | null;
|
|
@@ -284,39 +314,40 @@ interface AiCreditsWidgetAdapterState {
|
|
|
284
314
|
streamBonusPercent: number;
|
|
285
315
|
error: string | null;
|
|
286
316
|
activeTab: AiCreditsWidgetTab;
|
|
287
|
-
|
|
288
|
-
/** Deterministic
|
|
289
|
-
|
|
317
|
+
signers: string[];
|
|
318
|
+
/** Deterministic signer derived from the payer wallet Sign & Generate path. */
|
|
319
|
+
derivedSignerAddress: string | null;
|
|
290
320
|
}
|
|
291
321
|
interface AiCreditsWidgetAdapterActions {
|
|
292
322
|
connect: () => Promise<void>;
|
|
293
323
|
switchChain: () => Promise<void>;
|
|
294
324
|
/**
|
|
295
|
-
* Creates or restores the single deterministic
|
|
296
|
-
* If a derived key already exists locally, selects that
|
|
325
|
+
* Creates or restores the single deterministic signer for this payer wallet.
|
|
326
|
+
* If a derived key already exists locally, selects that signer without re-signing.
|
|
297
327
|
*/
|
|
298
|
-
|
|
328
|
+
generateSignerKey: () => Promise<void>;
|
|
299
329
|
/**
|
|
300
|
-
* Switches the active
|
|
301
|
-
* Address should be in `state.
|
|
330
|
+
* Switches the active signer and reloads that signer's account view.
|
|
331
|
+
* Address should be in `state.signers`.
|
|
302
332
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
333
|
+
selectSigner: (address: string) => Promise<void>;
|
|
334
|
+
discoverSigners: (addresses: string[]) => void;
|
|
305
335
|
/**
|
|
306
|
-
* Imports a signer key, stores it and selects it as the active
|
|
307
|
-
* Resolves with the imported
|
|
336
|
+
* Imports a signer key, stores it and selects it as the active signer.
|
|
337
|
+
* Resolves with the imported Signer Address, or `null` when the key could
|
|
308
338
|
* not be imported — callers use that to report the outcome of *this* import
|
|
309
|
-
* rather than the state of whichever
|
|
339
|
+
* rather than the state of whichever signer happened to be active.
|
|
310
340
|
*/
|
|
311
|
-
|
|
341
|
+
importSignerFromPrivateKey: (privateKey: string) => Promise<string | null>;
|
|
312
342
|
/**
|
|
313
|
-
* Applies an NCDI deep-link
|
|
314
|
-
* (`
|
|
343
|
+
* Applies an NCDI deep-link signer assignment from URL GET parameters
|
|
344
|
+
* (`signerAddress` + `operatorSignature`). Selects the signer immediately,
|
|
315
345
|
* submits the pre-signed operator approval token, and starts the buy flow.
|
|
316
|
-
* Never accepts a
|
|
346
|
+
* Never accepts a signer private key.
|
|
317
347
|
*/
|
|
318
|
-
|
|
348
|
+
applyDeepLinkSigner: (address: string, operatorSignature: string) => Promise<void>;
|
|
319
349
|
signOperatorConsent: () => Promise<void>;
|
|
350
|
+
revokeOperatorConsent: () => Promise<void>;
|
|
320
351
|
syncOperatorConsentFromChain: () => Promise<void>;
|
|
321
352
|
buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
|
|
322
353
|
pay: (quote: AiCreditsQuote) => Promise<void>;
|
|
@@ -347,7 +378,7 @@ interface AiCreditsPaySuccessDetail {
|
|
|
347
378
|
address: string;
|
|
348
379
|
chainId: number;
|
|
349
380
|
transactionHash: string;
|
|
350
|
-
|
|
381
|
+
signerPubKey: string;
|
|
351
382
|
creditUsdMicro: string;
|
|
352
383
|
}
|
|
353
384
|
interface AiCreditsPayErrorDetail {
|
|
@@ -379,6 +410,31 @@ interface AiCreditsWidgetProps {
|
|
|
379
410
|
disconnectLabel?: string;
|
|
380
411
|
/** Icon for the chip's menu action, mirroring `disconnectLabel`. */
|
|
381
412
|
disconnectIcon?: IconName;
|
|
413
|
+
/**
|
|
414
|
+
* Integrator-owned live address (e.g. from a wallet-connection SDK's own
|
|
415
|
+
* reactive account hook). See `GoodWidgetProviderProps.addressOverride`.
|
|
416
|
+
*/
|
|
417
|
+
addressOverride?: string | null;
|
|
418
|
+
/**
|
|
419
|
+
* Integrator-owned live chain id, mirroring `addressOverride`. See
|
|
420
|
+
* `GoodWidgetProviderProps.chainIdOverride`. Worth supplying for connectors
|
|
421
|
+
* that do not reliably emit `chainChanged` — a WalletConnect session bridged
|
|
422
|
+
* through AppKit, for one — otherwise the widget can keep reporting the wrong
|
|
423
|
+
* network after the user has already switched.
|
|
424
|
+
*/
|
|
425
|
+
chainIdOverride?: number | null;
|
|
426
|
+
/**
|
|
427
|
+
* Integrator-owned chain-switch fallback, used when the wallet rejects or
|
|
428
|
+
* ignores `wallet_switchEthereumChain`. See
|
|
429
|
+
* `GoodWidgetProviderProps.switchChainOverride`. Without it, wallets that
|
|
430
|
+
* cannot be switched from a page leave the user stuck on the wrong network.
|
|
431
|
+
*/
|
|
432
|
+
switchChainOverride?: (chainId: number) => Promise<void>;
|
|
433
|
+
/**
|
|
434
|
+
* Chain ids the passed-down provider can currently execute on. See
|
|
435
|
+
* `GoodWidgetProviderProps.availableChainIdsOverride`.
|
|
436
|
+
*/
|
|
437
|
+
availableChainIdsOverride?: number[] | null;
|
|
382
438
|
environment?: AiCreditsWidgetEnvironment;
|
|
383
439
|
backendUrl?: string;
|
|
384
440
|
baseRpcUrl?: string;
|
|
@@ -396,4 +452,4 @@ interface AiCreditsWidgetProps {
|
|
|
396
452
|
testId?: string;
|
|
397
453
|
}
|
|
398
454
|
|
|
399
|
-
export { type AiCreditsWidgetEnvironment as A, type
|
|
455
|
+
export { type AiCreditsWidgetEnvironment as A, type CreditHistoryQuery as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryResponse as F, type GdCreditEntry as G, type CeloEventsRecordResponse as H, type SettlementResult as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorRevokeResponse as L, type OperatorConsentPayloadResponse as M, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SignerOperatorStatus as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
|
|
@@ -15,10 +15,10 @@ type Eip712SigningPayload = {
|
|
|
15
15
|
}>>;
|
|
16
16
|
message: Record<string, string | number>;
|
|
17
17
|
};
|
|
18
|
-
type
|
|
18
|
+
type SignerOperatorStatus = {
|
|
19
19
|
enabled: boolean;
|
|
20
20
|
account: string;
|
|
21
|
-
|
|
21
|
+
signerAddress: string;
|
|
22
22
|
operatorAddress?: string;
|
|
23
23
|
currentOperator: string;
|
|
24
24
|
operatorAccepted: boolean;
|
|
@@ -27,13 +27,13 @@ type BuyerOperatorStatus = {
|
|
|
27
27
|
type OperatorConsentPayloadResponse = {
|
|
28
28
|
enabled: boolean;
|
|
29
29
|
account: string;
|
|
30
|
-
|
|
30
|
+
signerAddress: string;
|
|
31
31
|
typedData?: Eip712SigningPayload;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
type AccountRef = {
|
|
35
35
|
payer: string;
|
|
36
|
-
|
|
36
|
+
signer: string;
|
|
37
37
|
};
|
|
38
38
|
type UserCreditProfile = {
|
|
39
39
|
account: string;
|
|
@@ -64,7 +64,13 @@ type GdCreditEntry = {
|
|
|
64
64
|
logIndex?: number;
|
|
65
65
|
createdAt: string;
|
|
66
66
|
streamUpdateMonth: string;
|
|
67
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Renamed from the wire's `buyerAddress` in `getCreditHistory`. Keep the
|
|
69
|
+
* mapping there: reading the wire name directly leaves this undefined, and an
|
|
70
|
+
* entry with no signer address matches no signer filter — it only ever shows
|
|
71
|
+
* under "All signers".
|
|
72
|
+
*/
|
|
73
|
+
signerAddress?: string;
|
|
68
74
|
};
|
|
69
75
|
type AccountCreditResponse = {
|
|
70
76
|
account: string;
|
|
@@ -88,10 +94,16 @@ type CreditHistoryQuery = {
|
|
|
88
94
|
};
|
|
89
95
|
type AccountView = {
|
|
90
96
|
account: string;
|
|
91
|
-
|
|
97
|
+
signer: string | null;
|
|
92
98
|
profile: UserCreditProfile;
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Null when the operator read did not answer. Distinct from a read that came
|
|
101
|
+
* back saying "no operator": callers must not present an unread status as
|
|
102
|
+
* "not authorized", or an already-authorized account looks unconfigured.
|
|
103
|
+
*/
|
|
104
|
+
operator: SignerOperatorStatus | null;
|
|
105
|
+
/** Null when the withdrawable read did not answer. */
|
|
106
|
+
withdrawableUsd: string | null;
|
|
95
107
|
outstandingFundingUsd: string;
|
|
96
108
|
outstandingFundingCount: number;
|
|
97
109
|
};
|
|
@@ -115,7 +127,7 @@ type DiscountConfig = {
|
|
|
115
127
|
streamBonusPercent: number;
|
|
116
128
|
};
|
|
117
129
|
|
|
118
|
-
declare const DEFAULT_BASE_RPC_URL = "https://
|
|
130
|
+
declare const DEFAULT_BASE_RPC_URL = "https://base.drpc.org";
|
|
119
131
|
declare const CELO_GOODID_ADDRESS: "0xC361A6E67822a0EDc17D899227dd9FC50BD62F42";
|
|
120
132
|
declare const DEFAULT_CELO_RPC_URL = "https://forno.celo.org";
|
|
121
133
|
type AiCreditsChainClientOptions = {
|
|
@@ -128,22 +140,24 @@ type AiCreditsChainClientOptions = {
|
|
|
128
140
|
};
|
|
129
141
|
interface AiCreditsChainClient {
|
|
130
142
|
fetchGdUsdPerToken(): Promise<number>;
|
|
143
|
+
/** Resolves the GoodID whitelist state, or rejects when the read fails. */
|
|
131
144
|
isGoodIdVerified(account: string): Promise<boolean>;
|
|
132
145
|
buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote>;
|
|
133
|
-
|
|
134
|
-
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?:
|
|
135
|
-
getWithdrawableUsd(
|
|
146
|
+
getSignerOperatorStatus(ref: AccountRef): Promise<SignerOperatorStatus>;
|
|
147
|
+
buildOperatorConsentPayload(ref: AccountRef, operatorStatus?: SignerOperatorStatus): Promise<OperatorConsentPayloadResponse>;
|
|
148
|
+
getWithdrawableUsd(signer: string): Promise<string>;
|
|
149
|
+
getSignerAuthNonce(signer: string): Promise<bigint>;
|
|
136
150
|
}
|
|
137
151
|
declare function createChainClient(options?: AiCreditsChainClientOptions): AiCreditsChainClient;
|
|
138
152
|
|
|
139
153
|
type WithdrawPrincipalRequest = {
|
|
140
154
|
amount: string;
|
|
141
155
|
recipient: string;
|
|
142
|
-
|
|
156
|
+
nonce: string;
|
|
143
157
|
signature: string;
|
|
144
158
|
};
|
|
145
159
|
type ChannelOperationRequest = {
|
|
146
|
-
|
|
160
|
+
nonce?: string;
|
|
147
161
|
signature?: string;
|
|
148
162
|
};
|
|
149
163
|
type BridgeResponse = {
|
|
@@ -165,23 +179,34 @@ type OperatorConsentRequest = {
|
|
|
165
179
|
signature: string;
|
|
166
180
|
};
|
|
167
181
|
type OperatorConsentResponse = {
|
|
168
|
-
|
|
182
|
+
signer: string;
|
|
169
183
|
bridge: BridgeResponse;
|
|
170
184
|
};
|
|
185
|
+
type OperatorRevokeRequest = {
|
|
186
|
+
nonce: string;
|
|
187
|
+
signature: string;
|
|
188
|
+
};
|
|
189
|
+
type OperatorRevokeResponse = OperatorConsentResponse;
|
|
171
190
|
declare function totalCreditUsdFromProfile(profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>): string;
|
|
172
191
|
declare function totalCreditUsdFromStatus(status: {
|
|
173
192
|
profile: Pick<UserCreditProfile, 'totalPrincipalUsd' | 'totalBonusUsd'>;
|
|
174
193
|
}): string;
|
|
175
194
|
type AccountEnrichment = {
|
|
176
195
|
totalCreditUsd: string;
|
|
177
|
-
goodIdVerified: boolean;
|
|
178
196
|
totalGdDepositedG: string;
|
|
179
197
|
monthlyStreamG: string;
|
|
180
198
|
};
|
|
181
199
|
type BuildAccountViewOptions = {
|
|
182
|
-
|
|
200
|
+
signerAddress?: string | null;
|
|
183
201
|
};
|
|
184
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Derives the display fields that need no further network access.
|
|
204
|
+
*
|
|
205
|
+
* GoodID verification is deliberately not read here. Chaining it to the backend
|
|
206
|
+
* credit fetch meant any backend error also cleared the verified flag, and it
|
|
207
|
+
* re-ran on every refresh; the adapter resolves it once per account instead.
|
|
208
|
+
*/
|
|
209
|
+
declare function enrichAccountView(view: AccountView): AccountEnrichment;
|
|
185
210
|
interface AiCreditsBackendClient {
|
|
186
211
|
getDiscountConfig(): Promise<DiscountConfig>;
|
|
187
212
|
getAccountCredit(payer: string): Promise<AccountCreditResponse>;
|
|
@@ -201,8 +226,9 @@ interface AiCreditsBackendClient {
|
|
|
201
226
|
previousBalance?: string;
|
|
202
227
|
}): Promise<SettlementResult>;
|
|
203
228
|
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
204
|
-
withdrawCredits(
|
|
205
|
-
submitOperatorConsent(
|
|
229
|
+
withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
230
|
+
submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
231
|
+
revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
|
|
206
232
|
}
|
|
207
233
|
declare const DEFAULT_DISCOUNT_CONFIG: DiscountConfig;
|
|
208
234
|
declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
@@ -228,8 +254,9 @@ declare class ProductionAiCreditsBackendClient implements AiCreditsBackendClient
|
|
|
228
254
|
previousBalance?: string;
|
|
229
255
|
}): Promise<SettlementResult>;
|
|
230
256
|
closeChannel(channelId: string, body?: ChannelOperationRequest): Promise<ChannelOperationResponse>;
|
|
231
|
-
withdrawCredits(
|
|
232
|
-
submitOperatorConsent(
|
|
257
|
+
withdrawCredits(signer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
258
|
+
submitOperatorConsent(signer: string, body: OperatorConsentRequest): Promise<OperatorConsentResponse>;
|
|
259
|
+
revokeOperatorConsent(signer: string, body: OperatorRevokeRequest): Promise<OperatorRevokeResponse>;
|
|
233
260
|
}
|
|
234
261
|
declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
235
262
|
private unavailable;
|
|
@@ -243,6 +270,7 @@ declare class UnavailableAiCreditsBackendClient implements AiCreditsBackendClien
|
|
|
243
270
|
closeChannel(): Promise<never>;
|
|
244
271
|
withdrawCredits(): Promise<never>;
|
|
245
272
|
submitOperatorConsent(): Promise<never>;
|
|
273
|
+
revokeOperatorConsent(): Promise<never>;
|
|
246
274
|
}
|
|
247
275
|
declare function createBackendClient(backendUrl: string | undefined): AiCreditsBackendClient;
|
|
248
276
|
declare function buildAccountView(payer: string, backend: AiCreditsBackendClient, chain: AiCreditsChainClient, options?: BuildAccountViewOptions): Promise<AccountView>;
|
|
@@ -263,11 +291,11 @@ interface AiCreditsWidgetAdapterState {
|
|
|
263
291
|
gdUsdPerToken: number | null;
|
|
264
292
|
totalCreditUsd: string | null;
|
|
265
293
|
isGoodIdVerified: boolean;
|
|
266
|
-
/** Active
|
|
267
|
-
|
|
268
|
-
/** Active
|
|
269
|
-
|
|
270
|
-
/** Active
|
|
294
|
+
/** Active signer public address. */
|
|
295
|
+
signerPubKey: string | null;
|
|
296
|
+
/** Active signer private key from the local per-payer key map. */
|
|
297
|
+
signerPrvKey: string | null;
|
|
298
|
+
/** Active signer deep-link operator signature, if present. */
|
|
271
299
|
operatorSignature: string | null;
|
|
272
300
|
operatorConsented: boolean;
|
|
273
301
|
/** True while submitting / waiting for on-chain operator consent. */
|
|
@@ -277,6 +305,8 @@ interface AiCreditsWidgetAdapterState {
|
|
|
277
305
|
currentOperator: string | null;
|
|
278
306
|
minDepositUsd: string | null;
|
|
279
307
|
minStreamUsd: string | null;
|
|
308
|
+
/** Bonus credit earned so far, in micro-USD. Folded into `totalCreditUsd`. */
|
|
309
|
+
totalBonusUsd: string | null;
|
|
280
310
|
totalGdDepositedG: string | null;
|
|
281
311
|
monthlyStreamG: string | null;
|
|
282
312
|
withdrawableUsd: string | null;
|
|
@@ -284,39 +314,40 @@ interface AiCreditsWidgetAdapterState {
|
|
|
284
314
|
streamBonusPercent: number;
|
|
285
315
|
error: string | null;
|
|
286
316
|
activeTab: AiCreditsWidgetTab;
|
|
287
|
-
|
|
288
|
-
/** Deterministic
|
|
289
|
-
|
|
317
|
+
signers: string[];
|
|
318
|
+
/** Deterministic signer derived from the payer wallet Sign & Generate path. */
|
|
319
|
+
derivedSignerAddress: string | null;
|
|
290
320
|
}
|
|
291
321
|
interface AiCreditsWidgetAdapterActions {
|
|
292
322
|
connect: () => Promise<void>;
|
|
293
323
|
switchChain: () => Promise<void>;
|
|
294
324
|
/**
|
|
295
|
-
* Creates or restores the single deterministic
|
|
296
|
-
* If a derived key already exists locally, selects that
|
|
325
|
+
* Creates or restores the single deterministic signer for this payer wallet.
|
|
326
|
+
* If a derived key already exists locally, selects that signer without re-signing.
|
|
297
327
|
*/
|
|
298
|
-
|
|
328
|
+
generateSignerKey: () => Promise<void>;
|
|
299
329
|
/**
|
|
300
|
-
* Switches the active
|
|
301
|
-
* Address should be in `state.
|
|
330
|
+
* Switches the active signer and reloads that signer's account view.
|
|
331
|
+
* Address should be in `state.signers`.
|
|
302
332
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
333
|
+
selectSigner: (address: string) => Promise<void>;
|
|
334
|
+
discoverSigners: (addresses: string[]) => void;
|
|
305
335
|
/**
|
|
306
|
-
* Imports a signer key, stores it and selects it as the active
|
|
307
|
-
* Resolves with the imported
|
|
336
|
+
* Imports a signer key, stores it and selects it as the active signer.
|
|
337
|
+
* Resolves with the imported Signer Address, or `null` when the key could
|
|
308
338
|
* not be imported — callers use that to report the outcome of *this* import
|
|
309
|
-
* rather than the state of whichever
|
|
339
|
+
* rather than the state of whichever signer happened to be active.
|
|
310
340
|
*/
|
|
311
|
-
|
|
341
|
+
importSignerFromPrivateKey: (privateKey: string) => Promise<string | null>;
|
|
312
342
|
/**
|
|
313
|
-
* Applies an NCDI deep-link
|
|
314
|
-
* (`
|
|
343
|
+
* Applies an NCDI deep-link signer assignment from URL GET parameters
|
|
344
|
+
* (`signerAddress` + `operatorSignature`). Selects the signer immediately,
|
|
315
345
|
* submits the pre-signed operator approval token, and starts the buy flow.
|
|
316
|
-
* Never accepts a
|
|
346
|
+
* Never accepts a signer private key.
|
|
317
347
|
*/
|
|
318
|
-
|
|
348
|
+
applyDeepLinkSigner: (address: string, operatorSignature: string) => Promise<void>;
|
|
319
349
|
signOperatorConsent: () => Promise<void>;
|
|
350
|
+
revokeOperatorConsent: () => Promise<void>;
|
|
320
351
|
syncOperatorConsentFromChain: () => Promise<void>;
|
|
321
352
|
buildQuote: (depositG: string, streamG: string) => Promise<AiCreditsQuote>;
|
|
322
353
|
pay: (quote: AiCreditsQuote) => Promise<void>;
|
|
@@ -347,7 +378,7 @@ interface AiCreditsPaySuccessDetail {
|
|
|
347
378
|
address: string;
|
|
348
379
|
chainId: number;
|
|
349
380
|
transactionHash: string;
|
|
350
|
-
|
|
381
|
+
signerPubKey: string;
|
|
351
382
|
creditUsdMicro: string;
|
|
352
383
|
}
|
|
353
384
|
interface AiCreditsPayErrorDetail {
|
|
@@ -379,6 +410,31 @@ interface AiCreditsWidgetProps {
|
|
|
379
410
|
disconnectLabel?: string;
|
|
380
411
|
/** Icon for the chip's menu action, mirroring `disconnectLabel`. */
|
|
381
412
|
disconnectIcon?: IconName;
|
|
413
|
+
/**
|
|
414
|
+
* Integrator-owned live address (e.g. from a wallet-connection SDK's own
|
|
415
|
+
* reactive account hook). See `GoodWidgetProviderProps.addressOverride`.
|
|
416
|
+
*/
|
|
417
|
+
addressOverride?: string | null;
|
|
418
|
+
/**
|
|
419
|
+
* Integrator-owned live chain id, mirroring `addressOverride`. See
|
|
420
|
+
* `GoodWidgetProviderProps.chainIdOverride`. Worth supplying for connectors
|
|
421
|
+
* that do not reliably emit `chainChanged` — a WalletConnect session bridged
|
|
422
|
+
* through AppKit, for one — otherwise the widget can keep reporting the wrong
|
|
423
|
+
* network after the user has already switched.
|
|
424
|
+
*/
|
|
425
|
+
chainIdOverride?: number | null;
|
|
426
|
+
/**
|
|
427
|
+
* Integrator-owned chain-switch fallback, used when the wallet rejects or
|
|
428
|
+
* ignores `wallet_switchEthereumChain`. See
|
|
429
|
+
* `GoodWidgetProviderProps.switchChainOverride`. Without it, wallets that
|
|
430
|
+
* cannot be switched from a page leave the user stuck on the wrong network.
|
|
431
|
+
*/
|
|
432
|
+
switchChainOverride?: (chainId: number) => Promise<void>;
|
|
433
|
+
/**
|
|
434
|
+
* Chain ids the passed-down provider can currently execute on. See
|
|
435
|
+
* `GoodWidgetProviderProps.availableChainIdsOverride`.
|
|
436
|
+
*/
|
|
437
|
+
availableChainIdsOverride?: number[] | null;
|
|
382
438
|
environment?: AiCreditsWidgetEnvironment;
|
|
383
439
|
backendUrl?: string;
|
|
384
440
|
baseRpcUrl?: string;
|
|
@@ -396,4 +452,4 @@ interface AiCreditsWidgetProps {
|
|
|
396
452
|
testId?: string;
|
|
397
453
|
}
|
|
398
454
|
|
|
399
|
-
export { type AiCreditsWidgetEnvironment as A, type
|
|
455
|
+
export { type AiCreditsWidgetEnvironment as A, type CreditHistoryQuery as B, CELO_GOODID_ADDRESS as C, DEFAULT_BASE_RPC_URL as D, type Eip712SigningPayload as E, type CreditHistoryResponse as F, type GdCreditEntry as G, type CeloEventsRecordResponse as H, type SettlementResult as I, type ChannelOperationResponse as J, type WithdrawPrincipalResponse as K, type OperatorRevokeResponse as L, type OperatorConsentPayloadResponse as M, type OperatorConsentResponse as O, ProductionAiCreditsBackendClient as P, type SignerOperatorStatus as S, type TransactionsResponse as T, UnavailableAiCreditsBackendClient as U, type WithdrawPrincipalRequest as W, type AiCreditsPaySuccessDetail as a, type AiCreditsPayErrorDetail as b, type AiCreditsBackendClient as c, type AiCreditsChainClient as d, type AccountRef as e, type AiCreditsWidgetAdapterResult as f, type AiCreditsWidgetProps as g, type AccountEnrichment as h, type AccountView as i, type AiCreditsQuote as j, type AiCreditsWidgetAdapterActions as k, type AiCreditsWidgetAdapterFactory as l, type AiCreditsWidgetAdapterFactoryInput as m, type AiCreditsWidgetAdapterState as n, type AiCreditsWidgetStatus as o, type AiCreditsWidgetTab as p, DEFAULT_CELO_RPC_URL as q, DEFAULT_DISCOUNT_CONFIG as r, type DiscountConfig as s, buildAccountView as t, createBackendClient as u, createChainClient as v, enrichAccountView as w, totalCreditUsdFromProfile as x, totalCreditUsdFromStatus as y, type AccountCreditResponse as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodwidget/ai-credits-widget",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "GoodWidget for buying AI coding credits with G$ on Celo",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@goodsdks/citizen-sdk": "1.2.7",
|
|
50
50
|
"viem": "^2.0.0",
|
|
51
|
-
"@goodwidget/core": "0.1.
|
|
52
|
-
"@goodwidget/
|
|
53
|
-
"@goodwidget/
|
|
51
|
+
"@goodwidget/core": "0.1.5",
|
|
52
|
+
"@goodwidget/embed": "0.1.4",
|
|
53
|
+
"@goodwidget/ui": "0.1.5"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/react": "^18.3.0",
|