@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.
- package/dist/{chunk-YIXMIOVW.js → chunk-QNDSSO77.js} +1 -1
- package/dist/{chunk-5ABKU4SW.js → chunk-V7CAVLPS.js} +2571 -731
- package/dist/chunk-V7CAVLPS.js.map +1 -0
- package/dist/element.cjs +2535 -740
- package/dist/element.cjs.map +1 -1
- package/dist/element.js +1 -1
- package/dist/index.cjs +2554 -739
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -4
- package/dist/index.d.ts +42 -4
- package/dist/index.js +22 -2
- package/dist/mocked/index.cjs +2606 -808
- package/dist/mocked/index.cjs.map +1 -1
- package/dist/mocked/index.d.cts +5 -2
- package/dist/mocked/index.d.ts +5 -2
- package/dist/mocked/index.js +7 -4
- package/dist/mocked/index.js.map +1 -1
- package/dist/register.cjs +2597 -760
- package/dist/register.cjs.map +1 -1
- package/dist/{widgetRuntimeContract-BPILUGC4.d.cts → widgetRuntimeContract-DyvLXMBy.d.cts} +59 -2
- package/dist/{widgetRuntimeContract-BPILUGC4.d.ts → widgetRuntimeContract-DyvLXMBy.d.ts} +59 -2
- package/package.json +6 -1
- package/dist/chunk-5ABKU4SW.js.map +0 -1
- /package/dist/{chunk-YIXMIOVW.js.map → chunk-QNDSSO77.js.map} +0 -0
package/dist/mocked/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { g as AiCreditsWidgetProps, c as AiCreditsBackendClient, s as DiscountConfig, z as AccountCreditResponse, F as CreditHistoryQuery, H as CreditHistoryResponse, T as TransactionsResponse, e as AccountRef, I as CeloEventsRecordResponse, S as SettlementResult, J as ChannelOperationResponse, W as WithdrawPrincipalRequest, K as WithdrawPrincipalResponse, O as OperatorConsentResponse, d as AiCreditsChainClient, j as AiCreditsQuote, B as BuyerOperatorStatus, L as OperatorConsentPayloadResponse } from '../widgetRuntimeContract-
|
|
2
|
+
import { g as AiCreditsWidgetProps, c as AiCreditsBackendClient, s as DiscountConfig, z as AccountCreditResponse, F as CreditHistoryQuery, H as CreditHistoryResponse, T as TransactionsResponse, e as AccountRef, I as CeloEventsRecordResponse, S as SettlementResult, J as ChannelOperationResponse, W as WithdrawPrincipalRequest, K as WithdrawPrincipalResponse, O as OperatorConsentResponse, d as AiCreditsChainClient, j as AiCreditsQuote, B as BuyerOperatorStatus, L as OperatorConsentPayloadResponse } from '../widgetRuntimeContract-DyvLXMBy.cjs';
|
|
3
3
|
import 'viem';
|
|
4
4
|
import '@goodwidget/ui';
|
|
5
5
|
|
|
@@ -28,7 +28,10 @@ declare class MockAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
|
28
28
|
waitForSettlement(ref: AccountRef): Promise<SettlementResult>;
|
|
29
29
|
closeChannel(channelId: string): Promise<ChannelOperationResponse>;
|
|
30
30
|
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
31
|
-
submitOperatorConsent(buyer: string
|
|
31
|
+
submitOperatorConsent(buyer: string, {}: {
|
|
32
|
+
nonce: string;
|
|
33
|
+
signature: string;
|
|
34
|
+
}): Promise<OperatorConsentResponse>;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
declare class MockAiCreditsChainClient implements AiCreditsChainClient {
|
package/dist/mocked/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { g as AiCreditsWidgetProps, c as AiCreditsBackendClient, s as DiscountConfig, z as AccountCreditResponse, F as CreditHistoryQuery, H as CreditHistoryResponse, T as TransactionsResponse, e as AccountRef, I as CeloEventsRecordResponse, S as SettlementResult, J as ChannelOperationResponse, W as WithdrawPrincipalRequest, K as WithdrawPrincipalResponse, O as OperatorConsentResponse, d as AiCreditsChainClient, j as AiCreditsQuote, B as BuyerOperatorStatus, L as OperatorConsentPayloadResponse } from '../widgetRuntimeContract-
|
|
2
|
+
import { g as AiCreditsWidgetProps, c as AiCreditsBackendClient, s as DiscountConfig, z as AccountCreditResponse, F as CreditHistoryQuery, H as CreditHistoryResponse, T as TransactionsResponse, e as AccountRef, I as CeloEventsRecordResponse, S as SettlementResult, J as ChannelOperationResponse, W as WithdrawPrincipalRequest, K as WithdrawPrincipalResponse, O as OperatorConsentResponse, d as AiCreditsChainClient, j as AiCreditsQuote, B as BuyerOperatorStatus, L as OperatorConsentPayloadResponse } from '../widgetRuntimeContract-DyvLXMBy.js';
|
|
3
3
|
import 'viem';
|
|
4
4
|
import '@goodwidget/ui';
|
|
5
5
|
|
|
@@ -28,7 +28,10 @@ declare class MockAiCreditsBackendClient implements AiCreditsBackendClient {
|
|
|
28
28
|
waitForSettlement(ref: AccountRef): Promise<SettlementResult>;
|
|
29
29
|
closeChannel(channelId: string): Promise<ChannelOperationResponse>;
|
|
30
30
|
withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse>;
|
|
31
|
-
submitOperatorConsent(buyer: string
|
|
31
|
+
submitOperatorConsent(buyer: string, {}: {
|
|
32
|
+
nonce: string;
|
|
33
|
+
signature: string;
|
|
34
|
+
}): Promise<OperatorConsentResponse>;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
declare class MockAiCreditsChainClient implements AiCreditsChainClient {
|
package/dist/mocked/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-QNDSSO77.js";
|
|
2
2
|
import {
|
|
3
3
|
ANTSEED_DEPOSITS_BASE_ADDRESS,
|
|
4
4
|
AiCreditsWidget,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
buildQuoteAmounts,
|
|
8
8
|
buildSetOperatorPayload,
|
|
9
9
|
totalCreditUsdFromProfile
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-V7CAVLPS.js";
|
|
11
11
|
|
|
12
12
|
// src/mocked/AiCreditsMockWidget.tsx
|
|
13
13
|
import { useMemo } from "react";
|
|
@@ -295,11 +295,14 @@ var MockAiCreditsBackendClient = class {
|
|
|
295
295
|
await sleep(MOCK_DELAY_MS);
|
|
296
296
|
return { account: buyer, amountUsd: body.amount, bridge: { enabled: true, txHash: "0xmock" } };
|
|
297
297
|
}
|
|
298
|
-
async submitOperatorConsent(buyer) {
|
|
298
|
+
async submitOperatorConsent(buyer, {}) {
|
|
299
299
|
await sleep(MOCK_DELAY_MS);
|
|
300
300
|
const normalizedBuyer = normalizeAddress2(buyer);
|
|
301
301
|
markMockOperatorConsent(normalizedBuyer);
|
|
302
|
-
return {
|
|
302
|
+
return {
|
|
303
|
+
buyer: normalizedBuyer,
|
|
304
|
+
bridge: { enabled: true, txHash: "0xmock" }
|
|
305
|
+
};
|
|
303
306
|
}
|
|
304
307
|
};
|
|
305
308
|
|
package/dist/mocked/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mocked/AiCreditsMockWidget.tsx","../../src/mocked/chainClient.ts","../../src/mocked/backendClient.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { AiCreditsWidget, type AiCreditsWidgetProps } from '..'\nimport { MockAiCreditsBackendClient } from './backendClient'\nimport { MockAiCreditsChainClient } from './chainClient'\n\nexport function MockAiCreditsWidget(props: Omit<AiCreditsWidgetProps, 'adapterOptions' | 'environment'>) {\n const backendClient = useMemo(() => new MockAiCreditsBackendClient(), [])\n const chainClient = useMemo(() => new MockAiCreditsChainClient(), [])\n\n return (\n <AiCreditsWidget\n {...props}\n environment=\"development\"\n adapterOptions={{\n backendClient,\n chainClient,\n skipVaultPaymentValidation: true,\n prepareSettlement: (ref, creditUsd) => backendClient.prepareSettlement(ref, creditUsd),\n }}\n />\n )\n}\n","import type { AccountRef } from '../backendTypes'\nimport { BASE_CHAIN_ID, type AiCreditsChainClient } from '../chainClient'\nimport { ANTSEED_DEPOSITS_BASE_ADDRESS, buildSetOperatorPayload } from '../operatorConsent'\nimport { buildQuoteAmounts } from '../quoteMath'\nimport type { BuyerOperatorStatus, OperatorConsentPayloadResponse } from '../operatorConsent'\nimport type { AiCreditsQuote } from '../widgetRuntimeContract'\n\nconst mockOperatorAcceptedBuyers = new Set<string>()\n\nfunction normalizeAddress(address: string): string {\n return address.toLowerCase()\n}\n\nexport function markMockOperatorConsent(buyer: string): void {\n mockOperatorAcceptedBuyers.add(normalizeAddress(buyer))\n}\n\nexport class MockAiCreditsChainClient implements AiCreditsChainClient {\n private operatorAccepted: boolean\n private readonly gdUsdPerToken: number\n private readonly goodIdVerified: boolean\n\n constructor(\n options: { operatorAccepted?: boolean; gdUsdPerToken?: number; goodIdVerified?: boolean } = {},\n ) {\n this.operatorAccepted = options.operatorAccepted ?? false\n this.gdUsdPerToken = options.gdUsdPerToken ?? 0.0015\n this.goodIdVerified = options.goodIdVerified ?? false\n }\n\n async isGoodIdVerified(): Promise<boolean> {\n return this.goodIdVerified\n }\n\n async fetchGdUsdPerToken(): Promise<number> {\n return this.gdUsdPerToken\n }\n\n async buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote> {\n return buildQuoteAmounts(depositG, streamG)\n }\n\n async getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus> {\n const payer = normalizeAddress(ref.payer)\n const buyer = normalizeAddress(ref.buyer)\n const operatorAddress = '0x0000000000000000000000000000000000000004'\n const operatorAccepted = this.operatorAccepted || mockOperatorAcceptedBuyers.has(buyer)\n return {\n enabled: true,\n account: payer,\n buyerAddress: buyer,\n operatorAddress,\n currentOperator: operatorAccepted ? operatorAddress : '0x0000000000000000000000000000000000000000',\n operatorAccepted,\n consentNonce: '0',\n }\n }\n\n async buildOperatorConsentPayload(\n ref: AccountRef,\n operatorStatus?: BuyerOperatorStatus,\n ): Promise<OperatorConsentPayloadResponse> {\n const status = operatorStatus ?? (await this.getBuyerOperatorStatus(ref))\n if (!status.enabled || !status.operatorAddress) {\n return {\n enabled: false,\n account: normalizeAddress(ref.payer),\n buyerAddress: normalizeAddress(ref.buyer),\n }\n }\n return {\n enabled: true,\n account: normalizeAddress(ref.payer),\n buyerAddress: normalizeAddress(ref.buyer),\n typedData: buildSetOperatorPayload(\n BASE_CHAIN_ID,\n ANTSEED_DEPOSITS_BASE_ADDRESS,\n status.operatorAddress,\n BigInt(status.consentNonce),\n { name: 'AntseedDeposits', version: '1' },\n ),\n }\n }\n\n async getWithdrawableUsd(): Promise<string> {\n return '0'\n }\n}\n","import type {\n AccountCreditResponse,\n AccountRef,\n CeloEventsRecordResponse,\n ChannelOperationResponse,\n CreditHistoryQuery,\n CreditHistoryResponse,\n DiscountConfig,\n GdCreditEntry,\n OperatorConsentResponse,\n SettlementResult,\n TransactionsResponse,\n UserCreditProfile,\n WithdrawPrincipalRequest,\n WithdrawPrincipalResponse,\n} from '../backendClient'\nimport { DEFAULT_DISCOUNT_CONFIG, totalCreditUsdFromProfile } from '../backendClient'\nimport type { AiCreditsBackendClient } from '../backendClient'\nimport { markMockOperatorConsent } from './chainClient'\n\nconst MOCK_DELAY_MS = 600\nconst DEFAULT_HISTORY_LIMIT = 20\nconst MAX_HISTORY_LIMIT = 100\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nfunction normalizeAddress(address: string): string {\n return address.toLowerCase()\n}\n\nfunction paginateGdCredits(\n entries: GdCreditEntry[],\n options: CreditHistoryQuery = {},\n): CreditHistoryResponse {\n let result = [...entries].sort((a, b) => {\n const byCreated = b.createdAt.localeCompare(a.createdAt)\n return byCreated !== 0 ? byCreated : b.id.localeCompare(a.id)\n })\n if (options.source) result = result.filter((entry) => entry.source === options.source)\n if (options.fundingStatus) result = result.filter((entry) => entry.fundingStatus === options.fundingStatus)\n if (options.from) {\n const fromMs = Date.parse(options.from)\n result = result.filter((entry) => Date.parse(entry.createdAt) >= fromMs)\n }\n if (options.to) {\n const toMs = Date.parse(options.to)\n result = result.filter((entry) => Date.parse(entry.createdAt) <= toMs)\n }\n const limit = options.limit === undefined\n ? DEFAULT_HISTORY_LIMIT\n : Math.min(Math.max(1, Math.floor(options.limit)), MAX_HISTORY_LIMIT)\n const offset = Math.max(0, Math.floor(options.offset ?? 0))\n return {\n account: '',\n items: result.slice(offset, offset + limit),\n total: result.length,\n limit,\n offset,\n hasMore: offset + limit < result.length,\n }\n}\n\nfunction createDemoHistory(account: string): GdCreditEntry[] {\n const normalized = normalizeAddress(account)\n return [\n {\n id: 'demo-deposit-1', account: normalized, rootAccount: normalized, source: 'deposit',\n gdAmountWei: '440000000000000000000', totalCreditUsd: '6600', principalUsd: '6000',\n bonusUsd: '600', fundingStatus: 'funded', txHash: '0xdemo01', logIndex: 0,\n createdAt: '2026-06-25T14:30:00.000Z', streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n {\n id: 'demo-stream-update-1', account: normalized, rootAccount: normalized, source: 'streamUpdate',\n gdAmountWei: '10000000000000000000', totalCreditUsd: '0', principalUsd: '0',\n bonusUsd: '0', fundingStatus: 'funded', txHash: '0xdemo02', logIndex: 0,\n createdAt: '2026-06-24T12:00:00.000Z', streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n {\n id: 'demo-stream-request-1', account: normalized, rootAccount: normalized, source: 'streamRequest',\n gdAmountWei: '8000000000000000000', totalCreditUsd: '1200', principalUsd: '1000',\n bonusUsd: '200', fundingStatus: 'pending', txHash: '0xdemo03', logIndex: 0,\n createdAt: '2026-06-23T09:15:00.000Z', streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n {\n id: 'demo-stream-cron-1', account: normalized, rootAccount: normalized, source: 'streamCron',\n gdAmountWei: '5000000000000000000', totalCreditUsd: '900', principalUsd: '750',\n bonusUsd: '150', fundingStatus: 'funded', createdAt: '2026-06-22T08:00:00.000Z',\n streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n ]\n}\n\nexport class MockAiCreditsBackendClient implements AiCreditsBackendClient {\n private activeRef: AccountRef | null = null\n private lastCreditUsd = 0n\n private readonly accountStates = new Map<string, {\n principalUsd: bigint\n bonusUsd: bigint\n transactions: GdCreditEntry[]\n rootAccount: string\n }>()\n\n private getState(payer: string) {\n const key = normalizeAddress(payer)\n if (!this.accountStates.has(key)) {\n this.accountStates.set(key, {\n principalUsd: 0n, bonusUsd: 0n, transactions: createDemoHistory(key), rootAccount: key,\n })\n }\n return this.accountStates.get(key)!\n }\n\n async getDiscountConfig(): Promise<DiscountConfig> {\n await sleep(MOCK_DELAY_MS)\n return { ...DEFAULT_DISCOUNT_CONFIG }\n }\n\n private buildProfile(payer: string): UserCreditProfile {\n const state = this.getState(payer)\n const now = new Date().toISOString()\n const outstanding = state.transactions\n .filter((entry) => entry.fundingStatus === 'pending' || entry.fundingStatus === 'failed')\n .reduce((sum, entry) => sum + BigInt(entry.totalCreditUsd), 0n)\n return {\n account: normalizeAddress(payer), rootAccount: state.rootAccount, createdAt: now, updatedAt: now,\n totalGdDepositedWei: '0', totalPrincipalUsd: state.principalUsd.toString(),\n totalBonusUsd: state.bonusUsd.toString(), totalGDStreamedWei: '0',\n totalOutstandingFundingUsd: outstanding.toString(), streamFlowRateWeiPerSecond: '0',\n }\n }\n\n async getAccountCredit(payer: string): Promise<AccountCreditResponse> {\n await sleep(MOCK_DELAY_MS)\n const profile = this.buildProfile(payer)\n return { account: profile.account, profile }\n }\n\n async getCreditHistory(payer: string, options: CreditHistoryQuery = {}): Promise<CreditHistoryResponse> {\n await sleep(MOCK_DELAY_MS)\n return { ...paginateGdCredits(this.getState(payer).transactions, options), account: normalizeAddress(payer) }\n }\n\n async getOutstanding(payer: string): Promise<{ outstandingFundingUsd: string; count: number }> {\n await sleep(MOCK_DELAY_MS)\n const pending = this.getState(payer).transactions.filter(\n (entry) => entry.fundingStatus === 'pending' || entry.fundingStatus === 'failed',\n )\n return {\n outstandingFundingUsd: pending.reduce((sum, entry) => sum + BigInt(entry.totalCreditUsd || '0'), 0n).toString(),\n count: pending.length,\n }\n }\n\n async getTransactions(payer: string, options: { status?: 'pending' | 'funded' | 'failed'; limit?: number; cursor?: string } = {}): Promise<TransactionsResponse> {\n const history = await this.getCreditHistory(payer, {\n fundingStatus: options.status, limit: options.limit, offset: options.cursor ? Number(options.cursor) || 0 : 0,\n })\n return { account: history.account, transactions: history.items }\n }\n\n prepareSettlement(ref: AccountRef, creditUsd: bigint): void {\n this.activeRef = { payer: normalizeAddress(ref.payer), buyer: normalizeAddress(ref.buyer) }\n this.lastCreditUsd = creditUsd\n }\n\n async notifyPayment(txHash: string): Promise<CeloEventsRecordResponse> {\n await sleep(MOCK_DELAY_MS)\n const ref = this.activeRef\n if (!ref) return { txHash, events: [] }\n const now = new Date().toISOString()\n const entry: GdCreditEntry = {\n id: `${txHash}:0`, account: ref.payer, rootAccount: ref.payer, source: 'deposit',\n gdAmountWei: '0', totalCreditUsd: this.lastCreditUsd.toString(), principalUsd: this.lastCreditUsd.toString(),\n bonusUsd: '0', fundingStatus: 'pending', txHash, logIndex: 0, createdAt: now,\n streamUpdateMonth: now.slice(0, 7), buyerAddress: ref.buyer,\n }\n const state = this.getState(ref.payer)\n if (!state.transactions.find((item) => item.id === entry.id)) state.transactions.unshift(entry)\n return { txHash, events: [entry] }\n }\n\n async waitForSettlement(ref: AccountRef): Promise<SettlementResult> {\n await sleep(MOCK_DELAY_MS)\n const state = this.getState(ref.payer)\n for (const entry of state.transactions) {\n if (entry.fundingStatus !== 'pending') continue\n entry.fundingStatus = 'funded'\n state.principalUsd += BigInt(entry.principalUsd)\n state.bonusUsd += BigInt(entry.bonusUsd)\n }\n return { totalCreditUsd: totalCreditUsdFromProfile(this.buildProfile(ref.payer)) }\n }\n\n async closeChannel(channelId: string): Promise<ChannelOperationResponse> {\n await sleep(MOCK_DELAY_MS)\n return { channelId, action: 'close', bridge: { enabled: true, txHash: '0xmock' } }\n }\n\n async withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse> {\n await sleep(MOCK_DELAY_MS)\n return { account: buyer, amountUsd: body.amount, bridge: { enabled: true, txHash: '0xmock' } }\n }\n\n async submitOperatorConsent(buyer: string): Promise<OperatorConsentResponse> {\n await sleep(MOCK_DELAY_MS)\n const normalizedBuyer = normalizeAddress(buyer)\n markMockOperatorConsent(normalizedBuyer)\n return { buyer: normalizedBuyer, bridge: { enabled: true, txHash: '0xmock' } }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,eAAe;;;ACOxB,IAAM,6BAA6B,oBAAI,IAAY;AAEnD,SAAS,iBAAiB,SAAyB;AACjD,SAAO,QAAQ,YAAY;AAC7B;AAEO,SAAS,wBAAwB,OAAqB;AAC3D,6BAA2B,IAAI,iBAAiB,KAAK,CAAC;AACxD;AAEO,IAAM,2BAAN,MAA+D;AAAA,EAC5D;AAAA,EACS;AAAA,EACA;AAAA,EAEjB,YACE,UAA4F,CAAC,GAC7F;AACA,SAAK,mBAAmB,QAAQ,oBAAoB;AACpD,SAAK,gBAAgB,QAAQ,iBAAiB;AAC9C,SAAK,iBAAiB,QAAQ,kBAAkB;AAAA,EAClD;AAAA,EAEA,MAAM,mBAAqC;AACzC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,qBAAsC;AAC1C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,WAAW,UAAkB,SAA0C;AAC3E,WAAO,kBAAkB,UAAU,OAAO;AAAA,EAC5C;AAAA,EAEA,MAAM,uBAAuB,KAA+C;AAC1E,UAAM,QAAQ,iBAAiB,IAAI,KAAK;AACxC,UAAM,QAAQ,iBAAiB,IAAI,KAAK;AACxC,UAAM,kBAAkB;AACxB,UAAM,mBAAmB,KAAK,oBAAoB,2BAA2B,IAAI,KAAK;AACtF,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS;AAAA,MACT,cAAc;AAAA,MACd;AAAA,MACA,iBAAiB,mBAAmB,kBAAkB;AAAA,M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J;","names":["normalizeAddress"]}
|
|
1
|
+
{"version":3,"sources":["../../src/mocked/AiCreditsMockWidget.tsx","../../src/mocked/chainClient.ts","../../src/mocked/backendClient.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { AiCreditsWidget, type AiCreditsWidgetProps } from '..'\nimport { MockAiCreditsBackendClient } from './backendClient'\nimport { MockAiCreditsChainClient } from './chainClient'\n\nexport function MockAiCreditsWidget(props: Omit<AiCreditsWidgetProps, 'adapterOptions' | 'environment'>) {\n const backendClient = useMemo(() => new MockAiCreditsBackendClient(), [])\n const chainClient = useMemo(() => new MockAiCreditsChainClient(), [])\n\n return (\n <AiCreditsWidget\n {...props}\n environment=\"development\"\n adapterOptions={{\n backendClient,\n chainClient,\n skipVaultPaymentValidation: true,\n prepareSettlement: (ref, creditUsd) => backendClient.prepareSettlement(ref, creditUsd),\n }}\n />\n )\n}\n","import type { AccountRef } from '../backendTypes'\nimport { BASE_CHAIN_ID, type AiCreditsChainClient } from '../chainClient'\nimport { ANTSEED_DEPOSITS_BASE_ADDRESS, buildSetOperatorPayload } from '../operatorConsent'\nimport { buildQuoteAmounts } from '../quoteMath'\nimport type { BuyerOperatorStatus, OperatorConsentPayloadResponse } from '../operatorConsent'\nimport type { AiCreditsQuote } from '../widgetRuntimeContract'\n\nconst mockOperatorAcceptedBuyers = new Set<string>()\n\nfunction normalizeAddress(address: string): string {\n return address.toLowerCase()\n}\n\nexport function markMockOperatorConsent(buyer: string): void {\n mockOperatorAcceptedBuyers.add(normalizeAddress(buyer))\n}\n\nexport class MockAiCreditsChainClient implements AiCreditsChainClient {\n private operatorAccepted: boolean\n private readonly gdUsdPerToken: number\n private readonly goodIdVerified: boolean\n\n constructor(\n options: { operatorAccepted?: boolean; gdUsdPerToken?: number; goodIdVerified?: boolean } = {},\n ) {\n this.operatorAccepted = options.operatorAccepted ?? false\n this.gdUsdPerToken = options.gdUsdPerToken ?? 0.0015\n this.goodIdVerified = options.goodIdVerified ?? false\n }\n\n async isGoodIdVerified(): Promise<boolean> {\n return this.goodIdVerified\n }\n\n async fetchGdUsdPerToken(): Promise<number> {\n return this.gdUsdPerToken\n }\n\n async buildQuote(depositG: string, streamG: string): Promise<AiCreditsQuote> {\n return buildQuoteAmounts(depositG, streamG)\n }\n\n async getBuyerOperatorStatus(ref: AccountRef): Promise<BuyerOperatorStatus> {\n const payer = normalizeAddress(ref.payer)\n const buyer = normalizeAddress(ref.buyer)\n const operatorAddress = '0x0000000000000000000000000000000000000004'\n const operatorAccepted = this.operatorAccepted || mockOperatorAcceptedBuyers.has(buyer)\n return {\n enabled: true,\n account: payer,\n buyerAddress: buyer,\n operatorAddress,\n currentOperator: operatorAccepted ? operatorAddress : '0x0000000000000000000000000000000000000000',\n operatorAccepted,\n consentNonce: '0',\n }\n }\n\n async buildOperatorConsentPayload(\n ref: AccountRef,\n operatorStatus?: BuyerOperatorStatus,\n ): Promise<OperatorConsentPayloadResponse> {\n const status = operatorStatus ?? (await this.getBuyerOperatorStatus(ref))\n if (!status.enabled || !status.operatorAddress) {\n return {\n enabled: false,\n account: normalizeAddress(ref.payer),\n buyerAddress: normalizeAddress(ref.buyer),\n }\n }\n return {\n enabled: true,\n account: normalizeAddress(ref.payer),\n buyerAddress: normalizeAddress(ref.buyer),\n typedData: buildSetOperatorPayload(\n BASE_CHAIN_ID,\n ANTSEED_DEPOSITS_BASE_ADDRESS,\n status.operatorAddress,\n BigInt(status.consentNonce),\n { name: 'AntseedDeposits', version: '1' },\n ),\n }\n }\n\n async getWithdrawableUsd(): Promise<string> {\n return '0'\n }\n}\n","import type {\n AccountCreditResponse,\n AccountRef,\n CeloEventsRecordResponse,\n ChannelOperationResponse,\n CreditHistoryQuery,\n CreditHistoryResponse,\n DiscountConfig,\n GdCreditEntry,\n OperatorConsentResponse,\n SettlementResult,\n TransactionsResponse,\n UserCreditProfile,\n WithdrawPrincipalRequest,\n WithdrawPrincipalResponse,\n} from '../backendClient'\nimport { DEFAULT_DISCOUNT_CONFIG, totalCreditUsdFromProfile } from '../backendClient'\nimport type { AiCreditsBackendClient } from '../backendClient'\nimport { markMockOperatorConsent } from './chainClient'\n\nconst MOCK_DELAY_MS = 600\nconst DEFAULT_HISTORY_LIMIT = 20\nconst MAX_HISTORY_LIMIT = 100\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nfunction normalizeAddress(address: string): string {\n return address.toLowerCase()\n}\n\nfunction paginateGdCredits(\n entries: GdCreditEntry[],\n options: CreditHistoryQuery = {},\n): CreditHistoryResponse {\n let result = [...entries].sort((a, b) => {\n const byCreated = b.createdAt.localeCompare(a.createdAt)\n return byCreated !== 0 ? byCreated : b.id.localeCompare(a.id)\n })\n if (options.source) result = result.filter((entry) => entry.source === options.source)\n if (options.fundingStatus) result = result.filter((entry) => entry.fundingStatus === options.fundingStatus)\n if (options.from) {\n const fromMs = Date.parse(options.from)\n result = result.filter((entry) => Date.parse(entry.createdAt) >= fromMs)\n }\n if (options.to) {\n const toMs = Date.parse(options.to)\n result = result.filter((entry) => Date.parse(entry.createdAt) <= toMs)\n }\n const limit = options.limit === undefined\n ? DEFAULT_HISTORY_LIMIT\n : Math.min(Math.max(1, Math.floor(options.limit)), MAX_HISTORY_LIMIT)\n const offset = Math.max(0, Math.floor(options.offset ?? 0))\n return {\n account: '',\n items: result.slice(offset, offset + limit),\n total: result.length,\n limit,\n offset,\n hasMore: offset + limit < result.length,\n }\n}\n\nfunction createDemoHistory(account: string): GdCreditEntry[] {\n const normalized = normalizeAddress(account)\n return [\n {\n id: 'demo-deposit-1', account: normalized, rootAccount: normalized, source: 'deposit',\n gdAmountWei: '440000000000000000000', totalCreditUsd: '6600', principalUsd: '6000',\n bonusUsd: '600', fundingStatus: 'funded', txHash: '0xdemo01', logIndex: 0,\n createdAt: '2026-06-25T14:30:00.000Z', streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n {\n id: 'demo-stream-update-1', account: normalized, rootAccount: normalized, source: 'streamUpdate',\n gdAmountWei: '10000000000000000000', totalCreditUsd: '0', principalUsd: '0',\n bonusUsd: '0', fundingStatus: 'funded', txHash: '0xdemo02', logIndex: 0,\n createdAt: '2026-06-24T12:00:00.000Z', streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n {\n id: 'demo-stream-request-1', account: normalized, rootAccount: normalized, source: 'streamRequest',\n gdAmountWei: '8000000000000000000', totalCreditUsd: '1200', principalUsd: '1000',\n bonusUsd: '200', fundingStatus: 'pending', txHash: '0xdemo03', logIndex: 0,\n createdAt: '2026-06-23T09:15:00.000Z', streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n {\n id: 'demo-stream-cron-1', account: normalized, rootAccount: normalized, source: 'streamCron',\n gdAmountWei: '5000000000000000000', totalCreditUsd: '900', principalUsd: '750',\n bonusUsd: '150', fundingStatus: 'funded', createdAt: '2026-06-22T08:00:00.000Z',\n streamUpdateMonth: '2026-06', buyerAddress: normalized,\n },\n ]\n}\n\nexport class MockAiCreditsBackendClient implements AiCreditsBackendClient {\n private activeRef: AccountRef | null = null\n private lastCreditUsd = 0n\n private readonly accountStates = new Map<string, {\n principalUsd: bigint\n bonusUsd: bigint\n transactions: GdCreditEntry[]\n rootAccount: string\n }>()\n\n private getState(payer: string) {\n const key = normalizeAddress(payer)\n if (!this.accountStates.has(key)) {\n this.accountStates.set(key, {\n principalUsd: 0n,\n bonusUsd: 0n,\n transactions: createDemoHistory(key),\n rootAccount: key,\n })\n }\n return this.accountStates.get(key)!\n }\n\n async getDiscountConfig(): Promise<DiscountConfig> {\n await sleep(MOCK_DELAY_MS)\n return { ...DEFAULT_DISCOUNT_CONFIG }\n }\n\n private buildProfile(payer: string): UserCreditProfile {\n const state = this.getState(payer)\n const now = new Date().toISOString()\n const outstanding = state.transactions\n .filter((entry) => entry.fundingStatus === 'pending' || entry.fundingStatus === 'failed')\n .reduce((sum, entry) => sum + BigInt(entry.totalCreditUsd), 0n)\n return {\n account: normalizeAddress(payer),\n rootAccount: state.rootAccount,\n createdAt: now,\n updatedAt: now,\n totalGdDepositedWei: '0',\n totalPrincipalUsd: state.principalUsd.toString(),\n totalBonusUsd: state.bonusUsd.toString(),\n totalGDStreamedWei: '0',\n totalOutstandingFundingUsd: outstanding.toString(),\n streamFlowRateWeiPerSecond: '0',\n }\n }\n\n async getAccountCredit(payer: string): Promise<AccountCreditResponse> {\n await sleep(MOCK_DELAY_MS)\n const profile = this.buildProfile(payer)\n return { account: profile.account, profile }\n }\n\n async getCreditHistory(payer: string, options: CreditHistoryQuery = {}): Promise<CreditHistoryResponse> {\n await sleep(MOCK_DELAY_MS)\n return { ...paginateGdCredits(this.getState(payer).transactions, options), account: normalizeAddress(payer) }\n }\n\n async getOutstanding(payer: string): Promise<{ outstandingFundingUsd: string; count: number }> {\n await sleep(MOCK_DELAY_MS)\n const pending = this.getState(payer).transactions.filter(\n (entry) => entry.fundingStatus === 'pending' || entry.fundingStatus === 'failed',\n )\n return {\n outstandingFundingUsd: pending.reduce((sum, entry) => sum + BigInt(entry.totalCreditUsd || '0'), 0n).toString(),\n count: pending.length,\n }\n }\n\n async getTransactions(payer: string, options: { status?: 'pending' | 'funded' | 'failed'; limit?: number; cursor?: string } = {}): Promise<TransactionsResponse> {\n const history = await this.getCreditHistory(payer, {\n fundingStatus: options.status, limit: options.limit, offset: options.cursor ? Number(options.cursor) || 0 : 0,\n })\n return { account: history.account, transactions: history.items }\n }\n\n prepareSettlement(ref: AccountRef, creditUsd: bigint): void {\n this.activeRef = { payer: normalizeAddress(ref.payer), buyer: normalizeAddress(ref.buyer) }\n this.lastCreditUsd = creditUsd\n }\n\n async notifyPayment(txHash: string): Promise<CeloEventsRecordResponse> {\n await sleep(MOCK_DELAY_MS)\n const ref = this.activeRef\n if (!ref) return { txHash, events: [] }\n const now = new Date().toISOString()\n const entry: GdCreditEntry = {\n id: `${txHash}:0`, account: ref.payer, rootAccount: ref.payer, source: 'deposit',\n gdAmountWei: '0', totalCreditUsd: this.lastCreditUsd.toString(), principalUsd: this.lastCreditUsd.toString(),\n bonusUsd: '0', fundingStatus: 'pending', txHash, logIndex: 0, createdAt: now,\n streamUpdateMonth: now.slice(0, 7), buyerAddress: ref.buyer,\n }\n const state = this.getState(ref.payer)\n if (!state.transactions.find((item) => item.id === entry.id)) state.transactions.unshift(entry)\n return { txHash, events: [entry] }\n }\n\n async waitForSettlement(ref: AccountRef): Promise<SettlementResult> {\n await sleep(MOCK_DELAY_MS)\n const state = this.getState(ref.payer)\n for (const entry of state.transactions) {\n if (entry.fundingStatus !== 'pending') continue\n entry.fundingStatus = 'funded'\n state.principalUsd += BigInt(entry.principalUsd)\n state.bonusUsd += BigInt(entry.bonusUsd)\n }\n return { totalCreditUsd: totalCreditUsdFromProfile(this.buildProfile(ref.payer)) }\n }\n\n async closeChannel(channelId: string): Promise<ChannelOperationResponse> {\n await sleep(MOCK_DELAY_MS)\n return { channelId, action: 'close', bridge: { enabled: true, txHash: '0xmock' } }\n }\n\n async withdrawCredits(buyer: string, body: WithdrawPrincipalRequest): Promise<WithdrawPrincipalResponse> {\n await sleep(MOCK_DELAY_MS)\n return { account: buyer, amountUsd: body.amount, bridge: { enabled: true, txHash: '0xmock' } }\n }\n\n async submitOperatorConsent(\n buyer: string,\n {}: { nonce: string; signature: string },\n ): Promise<OperatorConsentResponse> {\n await sleep(MOCK_DELAY_MS)\n const normalizedBuyer = normalizeAddress(buyer)\n markMockOperatorConsent(normalizedBuyer)\n return {\n buyer: normalizedBuyer,\n bridge: { enabled: true, txHash: '0xmock' },\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,eAAe;;;ACOxB,IAAM,6BAA6B,oBAAI,IAAY;AAEnD,SAAS,iBAAiB,SAAyB;AACjD,SAAO,QAAQ,YAAY;AAC7B;AAEO,SAAS,wBAAwB,OAAqB;AAC3D,6BAA2B,IAAI,iBAAiB,KAAK,CAAC;AACxD;AAEO,IAAM,2BAAN,MAA+D;AAAA,EAC5D;AAAA,EACS;AAAA,EACA;AAAA,EAEj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