@diviswap/sdk 1.7.11 → 1.7.14
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/cli/index.js +8 -2
- package/dist/cli/templates/nextjs-app/actions.ts.hbs +32 -32
- package/dist/cli/templates/nextjs-app/api-hooks.ts.hbs +10 -10
- package/dist/cli/templates/nextjs-app/api-route.ts.hbs +65 -65
- package/dist/cli/templates/nextjs-app/auth-context.tsx.hbs +1 -1
- package/dist/cli/templates/nextjs-app/client.ts.hbs +5 -5
- package/dist/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +7 -7
- package/dist/cli/templates/nextjs-app/example-page.tsx.hbs +5 -5
- package/dist/cli/templates/nextjs-app/hooks.ts.hbs +7 -7
- package/dist/cli/templates/nextjs-app/kyc-hooks.ts.hbs +3 -3
- package/dist/cli/templates/nextjs-app/kyc-wizard.css.hbs +16 -16
- package/dist/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +24 -24
- package/dist/cli/templates/nextjs-app/layout-wrapper.tsx.hbs +4 -4
- package/dist/cli/templates/nextjs-app/layout.tsx.hbs +4 -4
- package/dist/cli/templates/nextjs-app/middleware.ts.hbs +15 -15
- package/dist/cli/templates/nextjs-app/provider-wrapper.tsx.hbs +4 -4
- package/dist/cli/templates/nextjs-app/provider.tsx.hbs +16 -16
- package/dist/cli/templates/nextjs-app/setup-provider.tsx.hbs +4 -4
- package/dist/cli/templates/react/api-client-wrapper.ts.hbs +13 -13
- package/dist/cli/templates/react/example.tsx.hbs +6 -6
- package/dist/cli/templates/react/tanstack-hooks.ts.hbs +14 -14
- package/dist/cli/templates/webhooks/nextjs.hbs +3 -3
- package/package.json +2 -1
- package/src/cli/templates/index.ts +13 -2
- package/src/cli/templates/nextjs-app/actions.ts.hbs +32 -32
- package/src/cli/templates/nextjs-app/api-hooks.ts.hbs +10 -10
- package/src/cli/templates/nextjs-app/api-route.ts.hbs +65 -65
- package/src/cli/templates/nextjs-app/auth-context.tsx.hbs +1 -1
- package/src/cli/templates/nextjs-app/client.ts.hbs +5 -5
- package/src/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +7 -7
- package/src/cli/templates/nextjs-app/example-page.tsx.hbs +5 -5
- package/src/cli/templates/nextjs-app/hooks.ts.hbs +7 -7
- package/src/cli/templates/nextjs-app/kyc-hooks.ts.hbs +3 -3
- package/src/cli/templates/nextjs-app/kyc-wizard.css.hbs +16 -16
- package/src/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +24 -24
- package/src/cli/templates/nextjs-app/layout-wrapper.tsx.hbs +4 -4
- package/src/cli/templates/nextjs-app/layout.tsx.hbs +4 -4
- package/src/cli/templates/nextjs-app/middleware.ts.hbs +15 -15
- package/src/cli/templates/nextjs-app/provider-wrapper.tsx.hbs +4 -4
- package/src/cli/templates/nextjs-app/provider.tsx.hbs +16 -16
- package/src/cli/templates/nextjs-app/setup-provider.tsx.hbs +4 -4
- package/src/cli/templates/react/api-client-wrapper.ts.hbs +13 -13
- package/src/cli/templates/react/example.tsx.hbs +6 -6
- package/src/cli/templates/react/tanstack-hooks.ts.hbs +14 -14
- package/src/cli/templates/webhooks/nextjs.hbs +3 -3
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { LiberEx } from '@99darwin/liberex-sdk';
|
|
3
3
|
import { cookies } from 'next/headers';
|
|
4
|
-
import type {
|
|
4
|
+
import type { LiberEx as LiberExType } from '@99darwin/liberex-sdk';
|
|
5
5
|
|
|
6
|
-
// Initialize
|
|
7
|
-
function
|
|
6
|
+
// Initialize LiberEx SDK with partner authentication
|
|
7
|
+
function getLiberEx() {
|
|
8
8
|
const config = {
|
|
9
9
|
mode: 'partner' as const,
|
|
10
|
-
keyId: process.env.
|
|
11
|
-
secretKey: process.env.
|
|
10
|
+
keyId: process.env.LIBEREX_PARTNER_KEY_ID!,
|
|
11
|
+
secretKey: process.env.LIBEREX_PARTNER_SECRET_KEY!,
|
|
12
12
|
authMethod: 'hmac' as const,
|
|
13
|
-
environment: (process.env.
|
|
13
|
+
environment: (process.env.NEXT_PUBLIC_LIBEREX_ENV as 'production' | 'sandbox') || 'sandbox'
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
return
|
|
16
|
+
return LiberEx.init(config);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Helper function to handle errors
|
|
20
20
|
function handleError(error: unknown) {
|
|
21
|
-
console.error('
|
|
21
|
+
console.error('LiberEx API error:', error);
|
|
22
22
|
|
|
23
23
|
if (error instanceof Error) {
|
|
24
24
|
return NextResponse.json(
|
|
@@ -35,7 +35,7 @@ function handleError(error: unknown) {
|
|
|
35
35
|
|
|
36
36
|
// Type definitions for handlers
|
|
37
37
|
type HandlerContext = {
|
|
38
|
-
|
|
38
|
+
liberex: LiberExType;
|
|
39
39
|
cookieStore: Awaited<ReturnType<typeof cookies>>;
|
|
40
40
|
};
|
|
41
41
|
|
|
@@ -43,7 +43,7 @@ type ActionHandler = (params: any, context: HandlerContext) => Promise<NextRespo
|
|
|
43
43
|
type ResourceHandler = (searchParams: URLSearchParams, context: HandlerContext) => Promise<NextResponse>;
|
|
44
44
|
|
|
45
45
|
// Helper function to set customer context from request
|
|
46
|
-
function setCustomerContext(
|
|
46
|
+
function setCustomerContext(liberex: LiberExType, params: any) {
|
|
47
47
|
// In partner authentication, you need to identify your user from your session/auth
|
|
48
48
|
// For this example, we'll expect customerId and customerEmail in the request
|
|
49
49
|
// In production, you'd get this from your own authentication system
|
|
@@ -51,14 +51,14 @@ function setCustomerContext(diviswap: DiviswapType, params: any) {
|
|
|
51
51
|
const customerId = params.customerId || 'demo-customer-123';
|
|
52
52
|
const customerEmail = params.customerEmail || 'demo@yourapp.com';
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
liberex.setCustomer(customerId, customerEmail);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// POST action handlers
|
|
58
58
|
const postHandlers: Record<string, ActionHandler> = {
|
|
59
|
-
setCustomer: async (params, {
|
|
59
|
+
setCustomer: async (params, { liberex }) => {
|
|
60
60
|
try {
|
|
61
|
-
|
|
61
|
+
liberex.setCustomer(params.customerId, params.customerEmail);
|
|
62
62
|
return NextResponse.json({
|
|
63
63
|
success: true,
|
|
64
64
|
customerId: params.customerId,
|
|
@@ -70,9 +70,9 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
|
|
73
|
-
clearCustomer: async (_, {
|
|
73
|
+
clearCustomer: async (_, { liberex }) => {
|
|
74
74
|
try {
|
|
75
|
-
|
|
75
|
+
liberex.clearCustomer();
|
|
76
76
|
return NextResponse.json({ success: true });
|
|
77
77
|
} catch (error: any) {
|
|
78
78
|
console.error('Clear customer error:', error);
|
|
@@ -80,9 +80,9 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
|
|
83
|
-
createTransaction: async (params, {
|
|
83
|
+
createTransaction: async (params, { liberex }) => {
|
|
84
84
|
// Set customer context before API calls
|
|
85
|
-
setCustomerContext(
|
|
85
|
+
setCustomerContext(liberex, params);
|
|
86
86
|
|
|
87
87
|
// Use the appropriate method based on transaction type
|
|
88
88
|
let transaction;
|
|
@@ -121,17 +121,17 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
121
121
|
// Use environment-appropriate method
|
|
122
122
|
// Production: uses regular offramp (creates completed transaction)
|
|
123
123
|
// Sandbox/Development: uses offrampTest (creates pending transaction)
|
|
124
|
-
const isProduction = process.env.
|
|
124
|
+
const isProduction = process.env.NEXT_PUBLIC_LIBEREX_ENV === 'production';
|
|
125
125
|
transaction = isProduction
|
|
126
|
-
? await
|
|
127
|
-
: await
|
|
126
|
+
? await liberex.transactions.offramp(sdkParams)
|
|
127
|
+
: await liberex.transactions.offrampTest(sdkParams);
|
|
128
128
|
}
|
|
129
129
|
return NextResponse.json(transaction);
|
|
130
130
|
},
|
|
131
131
|
|
|
132
|
-
createPayee: async (params, {
|
|
132
|
+
createPayee: async (params, { liberex }) => {
|
|
133
133
|
// Set customer context before API calls
|
|
134
|
-
setCustomerContext(
|
|
134
|
+
setCustomerContext(liberex, params);
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
// Check if the SDK is sending structured debit card data
|
|
@@ -144,7 +144,7 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
144
144
|
setAsDefault: params.setAsDefault || false
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
const payee = await
|
|
147
|
+
const payee = await liberex.payees.create(debitCardPayload);
|
|
148
148
|
return NextResponse.json(payee);
|
|
149
149
|
}
|
|
150
150
|
// Handle legacy flat structure for debit cards
|
|
@@ -172,11 +172,11 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
172
172
|
setAsDefault: params.setAsDefault || false
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
-
const payee = await
|
|
175
|
+
const payee = await liberex.payees.create(debitCardPayload);
|
|
176
176
|
return NextResponse.json(payee);
|
|
177
177
|
} else {
|
|
178
178
|
// Bank account structure
|
|
179
|
-
const payee = await
|
|
179
|
+
const payee = await liberex.payees.create({
|
|
180
180
|
nickname: params.nickname,
|
|
181
181
|
accountNumber: params.accountNumber,
|
|
182
182
|
routingNumber: params.routingNumber,
|
|
@@ -188,23 +188,23 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
188
188
|
},
|
|
189
189
|
|
|
190
190
|
{{#if (includes features "fees")}}
|
|
191
|
-
calculateFees: async (params, {
|
|
192
|
-
const fees = await
|
|
191
|
+
calculateFees: async (params, { liberex }) => {
|
|
192
|
+
const fees = await liberex.fees.calculateFees({
|
|
193
193
|
amount: params.amount,
|
|
194
194
|
userId: undefined
|
|
195
195
|
});
|
|
196
196
|
return NextResponse.json(fees);
|
|
197
197
|
},
|
|
198
198
|
|
|
199
|
-
getIntegratorFees: async (_, {
|
|
200
|
-
const fees = await
|
|
199
|
+
getIntegratorFees: async (_, { liberex }) => {
|
|
200
|
+
const fees = await liberex.fees.getFees();
|
|
201
201
|
return NextResponse.json(fees);
|
|
202
202
|
},
|
|
203
203
|
{{/if}}
|
|
204
204
|
|
|
205
|
-
submitKYC: async (params, {
|
|
205
|
+
submitKYC: async (params, { liberex }) => {
|
|
206
206
|
// Set customer context before KYC submission
|
|
207
|
-
setCustomerContext(
|
|
207
|
+
setCustomerContext(liberex, params);
|
|
208
208
|
|
|
209
209
|
try {
|
|
210
210
|
|
|
@@ -248,7 +248,7 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
|
|
251
|
-
const result = await
|
|
251
|
+
const result = await liberex.kyc.submitPersonalInfo(kycPayload);
|
|
252
252
|
|
|
253
253
|
return NextResponse.json(result);
|
|
254
254
|
} catch (error: any) {
|
|
@@ -260,12 +260,12 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
260
260
|
}
|
|
261
261
|
},
|
|
262
262
|
|
|
263
|
-
createAddress: async (params, {
|
|
263
|
+
createAddress: async (params, { liberex }) => {
|
|
264
264
|
// Set customer context before API call
|
|
265
|
-
setCustomerContext(
|
|
265
|
+
setCustomerContext(liberex, params);
|
|
266
266
|
|
|
267
267
|
try {
|
|
268
|
-
const address = await
|
|
268
|
+
const address = await liberex.addresses.create({
|
|
269
269
|
chain_id: params.chain_id,
|
|
270
270
|
address: params.address,
|
|
271
271
|
is_default: params.is_default
|
|
@@ -278,12 +278,12 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
278
278
|
}
|
|
279
279
|
},
|
|
280
280
|
|
|
281
|
-
setDefaultAddress: async (params, {
|
|
281
|
+
setDefaultAddress: async (params, { liberex }) => {
|
|
282
282
|
// Set customer context before API call
|
|
283
|
-
setCustomerContext(
|
|
283
|
+
setCustomerContext(liberex, params);
|
|
284
284
|
|
|
285
285
|
try {
|
|
286
|
-
await
|
|
286
|
+
await liberex.addresses.setDefault({
|
|
287
287
|
chain_id: params.chain_id,
|
|
288
288
|
address: params.address
|
|
289
289
|
});
|
|
@@ -295,12 +295,12 @@ const postHandlers: Record<string, ActionHandler> = {
|
|
|
295
295
|
}
|
|
296
296
|
},
|
|
297
297
|
|
|
298
|
-
deleteAddress: async (params, {
|
|
298
|
+
deleteAddress: async (params, { liberex }) => {
|
|
299
299
|
// Set customer context before API call
|
|
300
|
-
setCustomerContext(
|
|
300
|
+
setCustomerContext(liberex, params);
|
|
301
301
|
|
|
302
302
|
try {
|
|
303
|
-
await
|
|
303
|
+
await liberex.addresses.delete({
|
|
304
304
|
chain_id: params.chain_id,
|
|
305
305
|
address: params.address
|
|
306
306
|
});
|
|
@@ -330,8 +330,8 @@ export async function POST(request: NextRequest) {
|
|
|
330
330
|
);
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
const
|
|
334
|
-
return await handler(params, {
|
|
333
|
+
const liberex = getLiberEx();
|
|
334
|
+
return await handler(params, { liberex, cookieStore });
|
|
335
335
|
} catch (error) {
|
|
336
336
|
return handleError(error);
|
|
337
337
|
}
|
|
@@ -339,12 +339,12 @@ export async function POST(request: NextRequest) {
|
|
|
339
339
|
|
|
340
340
|
// GET resource handlers
|
|
341
341
|
const getHandlers: Record<string, ResourceHandler> = {
|
|
342
|
-
customerStatus: async (searchParams, {
|
|
342
|
+
customerStatus: async (searchParams, { liberex }) => {
|
|
343
343
|
const customerId = searchParams.get('customerId') || 'demo-customer-123';
|
|
344
344
|
const customerEmail = searchParams.get('customerEmail') || 'demo@yourapp.com';
|
|
345
345
|
|
|
346
346
|
// Set customer context
|
|
347
|
-
|
|
347
|
+
liberex.setCustomer(customerId, customerEmail);
|
|
348
348
|
|
|
349
349
|
return NextResponse.json({
|
|
350
350
|
customerId,
|
|
@@ -354,30 +354,30 @@ const getHandlers: Record<string, ResourceHandler> = {
|
|
|
354
354
|
});
|
|
355
355
|
},
|
|
356
356
|
|
|
357
|
-
payees: async (searchParams, {
|
|
357
|
+
payees: async (searchParams, { liberex }) => {
|
|
358
358
|
const customerId = searchParams.get('customerId') || 'demo-customer-123';
|
|
359
359
|
const customerEmail = searchParams.get('customerEmail') || 'demo@yourapp.com';
|
|
360
360
|
|
|
361
361
|
// Set customer context before API call
|
|
362
|
-
|
|
362
|
+
liberex.setCustomer(customerId, customerEmail);
|
|
363
363
|
|
|
364
|
-
const payees = await
|
|
364
|
+
const payees = await liberex.payees.list();
|
|
365
365
|
return NextResponse.json(payees);
|
|
366
366
|
},
|
|
367
367
|
|
|
368
|
-
transactions: async (searchParams, {
|
|
368
|
+
transactions: async (searchParams, { liberex }) => {
|
|
369
369
|
const customerId = searchParams.get('customerId') || 'demo-customer-123';
|
|
370
370
|
const customerEmail = searchParams.get('customerEmail') || 'demo@yourapp.com';
|
|
371
371
|
|
|
372
372
|
// Set customer context before API call
|
|
373
|
-
|
|
373
|
+
liberex.setCustomer(customerId, customerEmail);
|
|
374
374
|
|
|
375
375
|
const limit = searchParams.get('limit');
|
|
376
376
|
const offset = searchParams.get('offset');
|
|
377
377
|
const status = searchParams.get('status');
|
|
378
378
|
const type = searchParams.get('type');
|
|
379
379
|
|
|
380
|
-
const transactions = await
|
|
380
|
+
const transactions = await liberex.transactions.list({
|
|
381
381
|
limit: limit ? Number(limit) : 10,
|
|
382
382
|
offset: offset ? Number(offset) : 0,
|
|
383
383
|
status: status as 'pending' | 'processing' | 'completed' | 'failed' | undefined,
|
|
@@ -387,16 +387,16 @@ const getHandlers: Record<string, ResourceHandler> = {
|
|
|
387
387
|
return NextResponse.json(transactions);
|
|
388
388
|
},
|
|
389
389
|
|
|
390
|
-
kycStatus: async (searchParams, {
|
|
390
|
+
kycStatus: async (searchParams, { liberex }) => {
|
|
391
391
|
const customerId = searchParams.get('customerId') || 'demo-customer-123';
|
|
392
392
|
const customerEmail = searchParams.get('customerEmail') || 'demo@yourapp.com';
|
|
393
393
|
|
|
394
394
|
// Set customer context before API call
|
|
395
|
-
|
|
395
|
+
liberex.setCustomer(customerId, customerEmail);
|
|
396
396
|
|
|
397
397
|
try {
|
|
398
398
|
|
|
399
|
-
const status = await
|
|
399
|
+
const status = await liberex.kyc.getComplianceStatus();
|
|
400
400
|
return NextResponse.json(status);
|
|
401
401
|
} catch (error: any) {
|
|
402
402
|
console.error('Failed to get KYC status:', error);
|
|
@@ -412,17 +412,17 @@ const getHandlers: Record<string, ResourceHandler> = {
|
|
|
412
412
|
}
|
|
413
413
|
},
|
|
414
414
|
|
|
415
|
-
addresses: async (searchParams, {
|
|
415
|
+
addresses: async (searchParams, { liberex }) => {
|
|
416
416
|
const customerId = searchParams.get('customerId') || 'demo-customer-123';
|
|
417
417
|
const customerEmail = searchParams.get('customerEmail') || 'demo@yourapp.com';
|
|
418
418
|
|
|
419
419
|
// Set customer context before API call
|
|
420
|
-
|
|
420
|
+
liberex.setCustomer(customerId, customerEmail);
|
|
421
421
|
|
|
422
422
|
const chain_id = searchParams.get('chain_id');
|
|
423
423
|
const is_default = searchParams.get('is_default');
|
|
424
424
|
|
|
425
|
-
const addresses = await
|
|
425
|
+
const addresses = await liberex.addresses.list({
|
|
426
426
|
...(chain_id && { chain_id: Number(chain_id) }),
|
|
427
427
|
...(is_default !== null && { is_default: is_default === 'true' })
|
|
428
428
|
});
|
|
@@ -447,8 +447,8 @@ export async function GET(request: NextRequest) {
|
|
|
447
447
|
);
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
const
|
|
451
|
-
return await handler(searchParams, {
|
|
450
|
+
const liberex = getLiberEx();
|
|
451
|
+
return await handler(searchParams, { liberex, cookieStore });
|
|
452
452
|
} catch (error) {
|
|
453
453
|
return handleError(error);
|
|
454
454
|
}
|
|
@@ -457,7 +457,7 @@ export async function GET(request: NextRequest) {
|
|
|
457
457
|
{{#if (includes features "webhooks")}}
|
|
458
458
|
// DELETE resource handlers
|
|
459
459
|
const deleteHandlers: Record<string, ResourceHandler> = {
|
|
460
|
-
payee: async (searchParams, {
|
|
460
|
+
payee: async (searchParams, { liberex }) => {
|
|
461
461
|
const customerId = searchParams.get('customerId') || 'demo-customer-123';
|
|
462
462
|
const customerEmail = searchParams.get('customerEmail') || 'demo@yourapp.com';
|
|
463
463
|
const id = searchParams.get('id');
|
|
@@ -470,9 +470,9 @@ const deleteHandlers: Record<string, ResourceHandler> = {
|
|
|
470
470
|
}
|
|
471
471
|
|
|
472
472
|
// Set customer context before API call
|
|
473
|
-
|
|
473
|
+
liberex.setCustomer(customerId, customerEmail);
|
|
474
474
|
|
|
475
|
-
await
|
|
475
|
+
await liberex.payees.delete(id);
|
|
476
476
|
return NextResponse.json({ success: true });
|
|
477
477
|
},
|
|
478
478
|
};
|
|
@@ -493,8 +493,8 @@ export async function DELETE(request: NextRequest) {
|
|
|
493
493
|
);
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
const
|
|
497
|
-
return await handler(searchParams, {
|
|
496
|
+
const liberex = getLiberEx();
|
|
497
|
+
return await handler(searchParams, { liberex, cookieStore });
|
|
498
498
|
} catch (error) {
|
|
499
499
|
return handleError(error);
|
|
500
500
|
}
|
|
@@ -26,7 +26,7 @@ interface {{prefix}}AuthProviderProps {
|
|
|
26
26
|
clearCustomer: () => Promise<void>;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
// This provider receives props instead of using
|
|
29
|
+
// This provider receives props instead of using useLiberEx directly
|
|
30
30
|
// to avoid circular dependencies
|
|
31
31
|
export function {{prefix}}AuthProvider({
|
|
32
32
|
children,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// This file is auto-generated by
|
|
2
|
-
// It provides a client for communicating with the
|
|
1
|
+
// This file is auto-generated by LiberEx SDK CLI
|
|
2
|
+
// It provides a client for communicating with the LiberEx API routes
|
|
3
3
|
|
|
4
|
-
export class
|
|
5
|
-
constructor(private baseUrl: string = '/api/
|
|
4
|
+
export class LiberExClient {
|
|
5
|
+
constructor(private baseUrl: string = '/api/liberex') {}
|
|
6
6
|
|
|
7
7
|
private async request<T = any>(
|
|
8
8
|
endpoint: string,
|
|
9
9
|
options: RequestInit = {}
|
|
10
10
|
): Promise<T> {
|
|
11
|
-
const response = await fetch(
|
|
11
|
+
const response = await fetch(this.baseUrl + endpoint, {
|
|
12
12
|
...options,
|
|
13
13
|
headers: {
|
|
14
14
|
'Content-Type': 'application/json',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
|
-
import { use{{prefix}}Auth } from '~/context/
|
|
4
|
+
import { use{{prefix}}Auth } from '~/context/liberex-auth-context';
|
|
5
5
|
|
|
6
6
|
export function use{{prefix}}Dashboard() {
|
|
7
7
|
const { customerId, customerEmail, isAuthenticated } = use{{prefix}}Auth();
|
|
@@ -15,14 +15,14 @@ export function use{{prefix}}Dashboard() {
|
|
|
15
15
|
customerEmail,
|
|
16
16
|
...params
|
|
17
17
|
});
|
|
18
|
-
const response = await fetch(`/api/
|
|
18
|
+
const response = await fetch(`/api/liberex?${queryParams}`);
|
|
19
19
|
if (!response.ok) throw new Error('Failed to fetch transactions');
|
|
20
20
|
return response.json();
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const getPayees = async () => {
|
|
24
24
|
if (!isAuthenticated || !customerId) return [];
|
|
25
|
-
const response = await fetch(`/api/
|
|
25
|
+
const response = await fetch(`/api/liberex?resource=payees&customerId=${customerId}&customerEmail=${customerEmail}`);
|
|
26
26
|
if (!response.ok) throw new Error('Failed to fetch payees');
|
|
27
27
|
return response.json();
|
|
28
28
|
};
|
|
@@ -36,14 +36,14 @@ export function use{{prefix}}Dashboard() {
|
|
|
36
36
|
...(params?.chain_id && { chain_id: params.chain_id.toString() }),
|
|
37
37
|
...(params?.is_default !== undefined && { is_default: params.is_default.toString() })
|
|
38
38
|
});
|
|
39
|
-
const response = await fetch(`/api/
|
|
39
|
+
const response = await fetch(`/api/liberex?${queryParams}`);
|
|
40
40
|
if (!response.ok) throw new Error('Failed to fetch addresses');
|
|
41
41
|
return response.json();
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const createAddress = async (data: { chain_id: number; address: string; is_default?: boolean }) => {
|
|
45
45
|
if (!isAuthenticated || !customerId) throw new Error('Not authenticated');
|
|
46
|
-
const response = await fetch('/api/
|
|
46
|
+
const response = await fetch('/api/liberex', {
|
|
47
47
|
method: 'POST',
|
|
48
48
|
headers: { 'Content-Type': 'application/json' },
|
|
49
49
|
body: JSON.stringify({
|
|
@@ -59,7 +59,7 @@ export function use{{prefix}}Dashboard() {
|
|
|
59
59
|
|
|
60
60
|
const setDefaultAddress = async (data: { chain_id: number; address: string }) => {
|
|
61
61
|
if (!isAuthenticated || !customerId) throw new Error('Not authenticated');
|
|
62
|
-
const response = await fetch('/api/
|
|
62
|
+
const response = await fetch('/api/liberex', {
|
|
63
63
|
method: 'POST',
|
|
64
64
|
headers: { 'Content-Type': 'application/json' },
|
|
65
65
|
body: JSON.stringify({
|
|
@@ -75,7 +75,7 @@ export function use{{prefix}}Dashboard() {
|
|
|
75
75
|
|
|
76
76
|
const deleteAddress = async (data: { chain_id: number; address: string }) => {
|
|
77
77
|
if (!isAuthenticated || !customerId) throw new Error('Not authenticated');
|
|
78
|
-
const response = await fetch('/api/
|
|
78
|
+
const response = await fetch('/api/liberex', {
|
|
79
79
|
method: 'POST',
|
|
80
80
|
headers: { 'Content-Type': 'application/json' },
|
|
81
81
|
body: JSON.stringify({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import { LiberexKYC, LiberexKYCModal } from '@/components/
|
|
5
|
-
import '@/components/
|
|
4
|
+
import { LiberexKYC, LiberexKYCModal } from '@/components/liberex-kyc-wizard';
|
|
5
|
+
import '@/components/liberex-kyc-wizard.css';
|
|
6
6
|
|
|
7
|
-
export default function
|
|
7
|
+
export default function LiberExDemo() {
|
|
8
8
|
// Demo state
|
|
9
9
|
const [currentDemo, setCurrentDemo] = useState<'kyc-inline' | 'kyc-modal' | 'features'>('kyc-inline');
|
|
10
10
|
const [showKYCModal, setShowKYCModal] = useState(false);
|
|
@@ -29,7 +29,7 @@ export default function DiviswapDemo() {
|
|
|
29
29
|
<div className="bg-white shadow">
|
|
30
30
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
31
31
|
<div className="flex justify-between items-center py-6">
|
|
32
|
-
<h1 className="text-2xl font-bold text-gray-900">
|
|
32
|
+
<h1 className="text-2xl font-bold text-gray-900">LiberEx KYC Wizard Demo</h1>
|
|
33
33
|
<div className="text-sm text-gray-600">
|
|
34
34
|
Ready-to-use KYC component
|
|
35
35
|
</div>
|
|
@@ -132,7 +132,7 @@ export default function DiviswapDemo() {
|
|
|
132
132
|
<h3 className="text-lg font-medium text-gray-900 mb-4">Integration Code</h3>
|
|
133
133
|
<div className="bg-gray-50 rounded-md p-4 text-left">
|
|
134
134
|
<pre className="text-sm text-gray-800 overflow-x-auto">
|
|
135
|
-
{`import { LiberexKYCModal } from '@/components/
|
|
135
|
+
{`import { LiberexKYCModal } from '@/components/liberex-kyc-wizard';
|
|
136
136
|
|
|
137
137
|
function MyComponent() {
|
|
138
138
|
const [showKYC, setShowKYC] = useState(false);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useLiberEx } from '{{providerImportPath}}';
|
|
3
3
|
import type { Transaction, Payee, TransactionStatus } from '{{typesImportPath}}';
|
|
4
4
|
|
|
5
5
|
// IMPORTANT: These hooks use direct SDK calls which may not work properly
|
|
@@ -7,11 +7,11 @@ import type { Transaction, Payee, TransactionStatus } from '{{typesImportPath}}'
|
|
|
7
7
|
// pattern demonstrated in api-hooks.ts instead.
|
|
8
8
|
|
|
9
9
|
// Re-export the main hook
|
|
10
|
-
export {
|
|
10
|
+
export { useLiberEx };
|
|
11
11
|
|
|
12
12
|
// Convenience hook for authentication
|
|
13
13
|
export function useAuth() {
|
|
14
|
-
const { user, login, logout, register, loading, error } =
|
|
14
|
+
const { user, login, logout, register, loading, error } = useLiberEx();
|
|
15
15
|
|
|
16
16
|
return {
|
|
17
17
|
user,
|
|
@@ -27,7 +27,7 @@ export function useAuth() {
|
|
|
27
27
|
|
|
28
28
|
// Hook for managing transactions
|
|
29
29
|
export function useTransactions() {
|
|
30
|
-
const { createTransaction, getTransactions, error } =
|
|
30
|
+
const { createTransaction, getTransactions, error } = useLiberEx();
|
|
31
31
|
const [transactions, setTransactions] = useState<Transaction[]>([]);
|
|
32
32
|
const [loading, setLoading] = useState(false);
|
|
33
33
|
|
|
@@ -76,7 +76,7 @@ export function useTransactions() {
|
|
|
76
76
|
|
|
77
77
|
// Hook for managing payees
|
|
78
78
|
export function usePayees() {
|
|
79
|
-
const { getPayees, createPayee, deletePayee, error } =
|
|
79
|
+
const { getPayees, createPayee, deletePayee, error } = useLiberEx();
|
|
80
80
|
const [payees, setPayees] = useState<Payee[]>([]);
|
|
81
81
|
const [loading, setLoading] = useState(false);
|
|
82
82
|
|
|
@@ -141,7 +141,7 @@ export function usePayees() {
|
|
|
141
141
|
{{#if (includes features "fees")}}
|
|
142
142
|
// Hook for fee calculations
|
|
143
143
|
export function useFeeCalculator() {
|
|
144
|
-
const { calculateFees } =
|
|
144
|
+
const { calculateFees } = useLiberEx();
|
|
145
145
|
const [fees, setFees] = useState<any>(null);
|
|
146
146
|
const [loading, setLoading] = useState(false);
|
|
147
147
|
const [error, setError] = useState<Error | null>(null);
|
|
@@ -184,7 +184,7 @@ export function useFeeCalculator() {
|
|
|
184
184
|
{{#if (includes features "realtime")}}
|
|
185
185
|
// Hook for real-time transaction updates
|
|
186
186
|
export function useTransactionUpdates(transactionId?: string) {
|
|
187
|
-
const { socket, subscribeToTransaction, unsubscribeFromTransaction } =
|
|
187
|
+
const { socket, subscribeToTransaction, unsubscribeFromTransaction } = useLiberEx();
|
|
188
188
|
const [updates, setUpdates] = useState<any[]>([]);
|
|
189
189
|
const [latestStatus, setLatestStatus] = useState<TransactionStatus | null>(null);
|
|
190
190
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import { use{{prefix}}Auth } from '~/context/
|
|
4
|
+
import { use{{prefix}}Auth } from '~/context/liberex-auth-context';
|
|
5
5
|
|
|
6
6
|
interface KYCFormData {
|
|
7
7
|
firstName: string;
|
|
@@ -29,7 +29,7 @@ export function use{{prefix}}KYC() {
|
|
|
29
29
|
|
|
30
30
|
try {
|
|
31
31
|
// Format date of birth
|
|
32
|
-
const dateOfBirth =
|
|
32
|
+
const dateOfBirth = formData.dobYear + '-' + formData.dobMonth.padStart(2, '0') + '-' + formData.dobDay.padStart(2, '0');
|
|
33
33
|
|
|
34
34
|
// Prepare KYC data
|
|
35
35
|
const kycData = {
|
|
@@ -53,7 +53,7 @@ export function use{{prefix}}KYC() {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
// Call API to submit KYC
|
|
56
|
-
const response = await fetch('/api/
|
|
56
|
+
const response = await fetch('/api/liberex', {
|
|
57
57
|
method: 'POST',
|
|
58
58
|
headers: { 'Content-Type': 'application/json' },
|
|
59
59
|
body: JSON.stringify({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
.
|
|
1
|
+
/* LiberEx KYC Wizard Styles */
|
|
2
|
+
.liberex-kyc-container {
|
|
3
3
|
max-width: 600px;
|
|
4
4
|
margin: 0 auto;
|
|
5
5
|
padding: 2rem;
|
|
@@ -288,7 +288,7 @@
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
/* Modal */
|
|
291
|
-
.
|
|
291
|
+
.liberex-kyc-modal-overlay {
|
|
292
292
|
position: fixed;
|
|
293
293
|
top: 0;
|
|
294
294
|
left: 0;
|
|
@@ -302,7 +302,7 @@
|
|
|
302
302
|
padding: 1rem;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
.
|
|
305
|
+
.liberex-kyc-modal {
|
|
306
306
|
background-color: white;
|
|
307
307
|
border-radius: 12px;
|
|
308
308
|
max-width: 600px;
|
|
@@ -311,54 +311,54 @@
|
|
|
311
311
|
overflow-y: auto;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
.
|
|
314
|
+
.liberex-kyc-modal .liberex-kyc-container {
|
|
315
315
|
border: none;
|
|
316
316
|
box-shadow: none;
|
|
317
317
|
margin: 0;
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
/* Dark Theme */
|
|
321
|
-
.
|
|
321
|
+
.liberex-kyc-container[data-theme="dark"] {
|
|
322
322
|
background-color: #1f2937;
|
|
323
323
|
color: #f9fafb;
|
|
324
324
|
border-color: #374151;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
.
|
|
328
|
-
.
|
|
327
|
+
.liberex-kyc-container[data-theme="dark"] .form-field input,
|
|
328
|
+
.liberex-kyc-container[data-theme="dark"] .form-field select {
|
|
329
329
|
background-color: #374151;
|
|
330
330
|
border-color: #4b5563;
|
|
331
331
|
color: #f9fafb;
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
.
|
|
335
|
-
.
|
|
334
|
+
.liberex-kyc-container[data-theme="dark"] .form-field input:focus,
|
|
335
|
+
.liberex-kyc-container[data-theme="dark"] .form-field select:focus {
|
|
336
336
|
border-color: #6366f1;
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
.
|
|
339
|
+
.liberex-kyc-container[data-theme="dark"] .review-section {
|
|
340
340
|
background-color: #374151;
|
|
341
341
|
border-color: #4b5563;
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
-
.
|
|
344
|
+
.liberex-kyc-container[data-theme="dark"] .btn-secondary {
|
|
345
345
|
border-color: #4b5563;
|
|
346
346
|
color: #d1d5db;
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
.
|
|
349
|
+
.liberex-kyc-container[data-theme="dark"] .btn-secondary:hover {
|
|
350
350
|
background-color: #374151;
|
|
351
351
|
border-color: #6b7280;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
.
|
|
354
|
+
.liberex-kyc-container[data-theme="dark"] .info-box {
|
|
355
355
|
background-color: #064e3b;
|
|
356
356
|
border-color: #047857;
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
/* Responsive Design */
|
|
360
360
|
@media (max-width: 640px) {
|
|
361
|
-
.
|
|
361
|
+
.liberex-kyc-container {
|
|
362
362
|
padding: 1rem;
|
|
363
363
|
margin: 1rem;
|
|
364
364
|
}
|
|
@@ -417,7 +417,7 @@
|
|
|
417
417
|
|
|
418
418
|
/* High Contrast Mode */
|
|
419
419
|
@media (prefers-contrast: high) {
|
|
420
|
-
.
|
|
420
|
+
.liberex-kyc-container {
|
|
421
421
|
border-width: 2px;
|
|
422
422
|
}
|
|
423
423
|
|