@agi-cli/sdk 0.1.146 → 0.1.148
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/package.json
CHANGED
|
@@ -44,7 +44,7 @@ const DEFAULT_MAX_ATTEMPTS = 3;
|
|
|
44
44
|
const DEFAULT_MAX_PAYMENT_ATTEMPTS = 20;
|
|
45
45
|
|
|
46
46
|
export type SetuPaymentCallbacks = {
|
|
47
|
-
onPaymentRequired?: (amountUsd: number) => void;
|
|
47
|
+
onPaymentRequired?: (amountUsd: number, currentBalance?: number) => void;
|
|
48
48
|
onPaymentSigning?: () => void;
|
|
49
49
|
onPaymentComplete?: (data: {
|
|
50
50
|
amountUsd: number;
|
|
@@ -52,6 +52,10 @@ export type SetuPaymentCallbacks = {
|
|
|
52
52
|
transactionId?: string;
|
|
53
53
|
}) => void;
|
|
54
54
|
onPaymentError?: (error: string) => void;
|
|
55
|
+
onPaymentApproval?: (info: {
|
|
56
|
+
amountUsd: number;
|
|
57
|
+
currentBalance: number;
|
|
58
|
+
}) => Promise<'crypto' | 'fiat' | 'cancel'>;
|
|
55
59
|
};
|
|
56
60
|
|
|
57
61
|
export type SetuProviderOptions = {
|
|
@@ -64,6 +68,7 @@ export type SetuProviderOptions = {
|
|
|
64
68
|
providerNpm?: string;
|
|
65
69
|
promptCacheKey?: string;
|
|
66
70
|
promptCacheRetention?: 'in_memory' | '24h';
|
|
71
|
+
topupApprovalMode?: 'auto' | 'approval';
|
|
67
72
|
};
|
|
68
73
|
|
|
69
74
|
export type SetuAuth = {
|
|
@@ -148,6 +153,7 @@ export function createSetuFetch(
|
|
|
148
153
|
const callbacks = options.callbacks ?? {};
|
|
149
154
|
const promptCacheKey = options.promptCacheKey;
|
|
150
155
|
const promptCacheRetention = options.promptCacheRetention;
|
|
156
|
+
const topupApprovalMode = options.topupApprovalMode ?? 'auto';
|
|
151
157
|
|
|
152
158
|
const baseFetch = globalThis.fetch.bind(globalThis);
|
|
153
159
|
|
|
@@ -216,7 +222,26 @@ export function createSetuFetch(
|
|
|
216
222
|
try {
|
|
217
223
|
const amountUsd =
|
|
218
224
|
parseInt(requirement.maxAmountRequired, 10) / 1_000_000;
|
|
219
|
-
|
|
225
|
+
|
|
226
|
+
if (topupApprovalMode === 'approval' && callbacks.onPaymentApproval) {
|
|
227
|
+
const approval = await callbacks.onPaymentApproval({
|
|
228
|
+
amountUsd,
|
|
229
|
+
currentBalance: 0,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (approval === 'cancel') {
|
|
233
|
+
callbacks.onPaymentError?.('Payment cancelled by user');
|
|
234
|
+
throw new Error('Setu: payment cancelled by user');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (approval === 'fiat') {
|
|
238
|
+
const err = new Error('Setu: fiat payment selected');
|
|
239
|
+
(err as Error & { code: string }).code = 'SETU_FIAT_SELECTED';
|
|
240
|
+
throw err;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
callbacks.onPaymentRequired?.(amountUsd, 0);
|
|
220
245
|
|
|
221
246
|
const outcome = await handlePayment({
|
|
222
247
|
requirement,
|