@diviswap/sdk 1.7.16 → 1.7.17
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 +1 -1
- package/dist/cli/templates/nextjs-app/actions.ts.hbs +45 -38
- 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 +4 -4
- package/dist/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +7 -7
- package/dist/cli/templates/nextjs-app/example-page.tsx.hbs +9 -9
- package/dist/cli/templates/nextjs-app/hooks.ts.hbs +7 -7
- package/dist/cli/templates/nextjs-app/kyc-hooks.ts.hbs +2 -2
- package/dist/cli/templates/nextjs-app/kyc-wizard.css.hbs +16 -16
- package/dist/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +71 -38
- 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 +15 -15
- package/dist/cli/templates/nextjs-app/setup-provider.tsx.hbs +4 -4
- package/dist/cli/templates/react/api-client-wrapper.ts.hbs +11 -11
- 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 +1 -1
- package/src/cli/templates/nextjs-app/actions.ts.hbs +45 -38
- 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 +4 -4
- package/src/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +7 -7
- package/src/cli/templates/nextjs-app/example-page.tsx.hbs +9 -9
- package/src/cli/templates/nextjs-app/hooks.ts.hbs +7 -7
- package/src/cli/templates/nextjs-app/kyc-hooks.ts.hbs +2 -2
- package/src/cli/templates/nextjs-app/kyc-wizard.css.hbs +16 -16
- package/src/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +71 -38
- 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 +15 -15
- package/src/cli/templates/nextjs-app/setup-provider.tsx.hbs +4 -4
- package/src/cli/templates/react/api-client-wrapper.ts.hbs +11 -11
- 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,22 +1,22 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
|
-
// This middleware adds
|
|
3
|
+
// This middleware adds Diviswap session information to requests
|
|
4
4
|
// Note: In middleware, we use request.cookies (not the async cookies() from next/headers)
|
|
5
|
-
export function
|
|
6
|
-
// Check for
|
|
7
|
-
const
|
|
5
|
+
export function diviswapMiddleware(request: NextRequest) {
|
|
6
|
+
// Check for Diviswap session cookie
|
|
7
|
+
const diviswapSession = request.cookies.get('diviswap_session');
|
|
8
8
|
|
|
9
|
-
if (!
|
|
9
|
+
if (!diviswapSession) {
|
|
10
10
|
// No session, proceed without authentication
|
|
11
11
|
return NextResponse.next();
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
// Add session to headers for API routes
|
|
15
15
|
const requestHeaders = new Headers(request.headers);
|
|
16
|
-
requestHeaders.set('x-
|
|
16
|
+
requestHeaders.set('x-diviswap-session', diviswapSession.value);
|
|
17
17
|
|
|
18
18
|
// You can also add other headers or perform additional checks here
|
|
19
|
-
requestHeaders.set('x-
|
|
19
|
+
requestHeaders.set('x-diviswap-client-version', '1.0.0');
|
|
20
20
|
|
|
21
21
|
return NextResponse.next({
|
|
22
22
|
request: {
|
|
@@ -26,24 +26,24 @@ export function liberexMiddleware(request: NextRequest) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// Optional: Add route protection
|
|
29
|
-
export function
|
|
30
|
-
const
|
|
29
|
+
export function protectDiviswapRoutes(request: NextRequest) {
|
|
30
|
+
const diviswapSession = request.cookies.get('diviswap_session');
|
|
31
31
|
|
|
32
32
|
// List of protected routes
|
|
33
33
|
const protectedRoutes = [
|
|
34
|
-
'/
|
|
35
|
-
'/
|
|
36
|
-
'/
|
|
34
|
+
'/diviswap/dashboard',
|
|
35
|
+
'/diviswap/transactions',
|
|
36
|
+
'/diviswap/settings'
|
|
37
37
|
];
|
|
38
38
|
|
|
39
39
|
const isProtectedRoute = protectedRoutes.some(route =>
|
|
40
40
|
request.nextUrl.pathname.startsWith(route)
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
if (isProtectedRoute && !
|
|
43
|
+
if (isProtectedRoute && !diviswapSession) {
|
|
44
44
|
// Redirect to login page
|
|
45
|
-
return NextResponse.redirect(new URL('/
|
|
45
|
+
return NextResponse.redirect(new URL('/diviswap', request.url));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
return
|
|
48
|
+
return diviswapMiddleware(request);
|
|
49
49
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { DiviswapProvider } from '@diviswap/sdk/react';
|
|
4
4
|
|
|
5
|
-
// Wrapper to ensure client-side rendering for
|
|
6
|
-
export function
|
|
7
|
-
return <
|
|
5
|
+
// Wrapper to ensure client-side rendering for Diviswap components
|
|
6
|
+
export function DiviswapClientProvider({ children }: { children: React.ReactNode }) {
|
|
7
|
+
return <DiviswapProvider>{children}</DiviswapProvider>;
|
|
8
8
|
}
|
|
@@ -6,7 +6,7 @@ import type { User, Transaction, Payee, TransactionStatus } from './lbx-types';
|
|
|
6
6
|
import io, { Socket } from 'socket.io-client';
|
|
7
7
|
{{/if}}
|
|
8
8
|
|
|
9
|
-
interface
|
|
9
|
+
interface DiviswapContextValue {
|
|
10
10
|
// Customer state (for partner authentication)
|
|
11
11
|
customerId: string | null;
|
|
12
12
|
customerEmail: string | null;
|
|
@@ -63,11 +63,11 @@ interface LiberExContextValue {
|
|
|
63
63
|
{{/if}}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const
|
|
66
|
+
const DiviswapContext = createContext<DiviswapContextValue | null>(null);
|
|
67
67
|
|
|
68
68
|
// API client class
|
|
69
|
-
class
|
|
70
|
-
constructor(private baseUrl: string = '/api/
|
|
69
|
+
class DiviswapClient {
|
|
70
|
+
constructor(private baseUrl: string = '/api/diviswap') {}
|
|
71
71
|
|
|
72
72
|
private async request<T = any>(
|
|
73
73
|
endpoint: string,
|
|
@@ -168,7 +168,7 @@ class LiberExClient {
|
|
|
168
168
|
{{/if}}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
export function
|
|
171
|
+
export function DiviswapProvider({ children }: { children: React.ReactNode }) {
|
|
172
172
|
const [customerId, setCustomerId] = useState<string | null>(null);
|
|
173
173
|
const [customerEmail, setCustomerEmail] = useState<string | null>(null);
|
|
174
174
|
const [loading, setLoading] = useState(false);
|
|
@@ -177,7 +177,7 @@ export function LiberExProvider({ children }: { children: React.ReactNode }) {
|
|
|
177
177
|
const [socket, setSocket] = useState<Socket | null>(null);
|
|
178
178
|
{{/if}}
|
|
179
179
|
|
|
180
|
-
const client = new
|
|
180
|
+
const client = new DiviswapClient('/api/diviswap');
|
|
181
181
|
|
|
182
182
|
// Initialize with demo customer for development
|
|
183
183
|
useEffect(() => {
|
|
@@ -192,7 +192,7 @@ export function LiberExProvider({ children }: { children: React.ReactNode }) {
|
|
|
192
192
|
useEffect(() => {
|
|
193
193
|
if (customerId && customerEmail) {
|
|
194
194
|
const socketInstance = io(
|
|
195
|
-
process.env.
|
|
195
|
+
process.env.NEXT_PUBLIC_DIVISWAP_WS_URL || 'wss://ws.diviswap.io',
|
|
196
196
|
{
|
|
197
197
|
auth: {
|
|
198
198
|
customerId,
|
|
@@ -205,11 +205,11 @@ export function LiberExProvider({ children }: { children: React.ReactNode }) {
|
|
|
205
205
|
);
|
|
206
206
|
|
|
207
207
|
socketInstance.on('connect', () => {
|
|
208
|
-
console.log('Connected to
|
|
208
|
+
console.log('Connected to Diviswap WebSocket');
|
|
209
209
|
});
|
|
210
210
|
|
|
211
211
|
socketInstance.on('disconnect', () => {
|
|
212
|
-
console.log('Disconnected from
|
|
212
|
+
console.log('Disconnected from Diviswap WebSocket');
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
socketInstance.on('transaction:update', (data) => {
|
|
@@ -368,7 +368,7 @@ export function LiberExProvider({ children }: { children: React.ReactNode }) {
|
|
|
368
368
|
}, [socket]);
|
|
369
369
|
{{/if}}
|
|
370
370
|
|
|
371
|
-
const value:
|
|
371
|
+
const value: DiviswapContextValue = {
|
|
372
372
|
customerId,
|
|
373
373
|
customerEmail,
|
|
374
374
|
loading,
|
|
@@ -393,16 +393,16 @@ export function LiberExProvider({ children }: { children: React.ReactNode }) {
|
|
|
393
393
|
};
|
|
394
394
|
|
|
395
395
|
return (
|
|
396
|
-
<
|
|
396
|
+
<DiviswapContext.Provider value={value}>
|
|
397
397
|
{children}
|
|
398
|
-
</
|
|
398
|
+
</DiviswapContext.Provider>
|
|
399
399
|
);
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
export function
|
|
403
|
-
const context = useContext(
|
|
402
|
+
export function useDiviswap() {
|
|
403
|
+
const context = useContext(DiviswapContext);
|
|
404
404
|
if (!context) {
|
|
405
|
-
throw new Error('
|
|
405
|
+
throw new Error('useDiviswap must be used within a DiviswapProvider');
|
|
406
406
|
}
|
|
407
407
|
return context;
|
|
408
408
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Add this to your root layout.tsx to enable
|
|
2
|
+
* Add this to your root layout.tsx to enable Diviswap functionality
|
|
3
3
|
*
|
|
4
4
|
* Example:
|
|
5
5
|
*
|
|
6
|
-
* import {
|
|
6
|
+
* import { DiviswapProvider } from '@diviswap/sdk/react';
|
|
7
7
|
*
|
|
8
8
|
* export default function RootLayout({
|
|
9
9
|
* children,
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* return (
|
|
14
14
|
* <html lang="en">
|
|
15
15
|
* <body>
|
|
16
|
-
* <
|
|
16
|
+
* <DiviswapProvider>
|
|
17
17
|
* {children}
|
|
18
|
-
* </
|
|
18
|
+
* </DiviswapProvider>
|
|
19
19
|
* </body>
|
|
20
20
|
* </html>
|
|
21
21
|
* );
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* API client wrapper for custom backend integration
|
|
3
|
-
* This allows you to proxy
|
|
3
|
+
* This allows you to proxy Diviswap API calls through your own backend
|
|
4
4
|
* for additional security and custom logic
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -40,46 +40,46 @@ class ApiClient {
|
|
|
40
40
|
return response.json();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
//
|
|
44
|
-
|
|
43
|
+
// Diviswap-specific endpoints
|
|
44
|
+
diviswap = {
|
|
45
45
|
// Authentication
|
|
46
46
|
login: (email: string, password: string) =>
|
|
47
|
-
this.request('/
|
|
47
|
+
this.request('/diviswap', {
|
|
48
48
|
method: 'POST',
|
|
49
49
|
body: JSON.stringify({ action: 'login', email, password }),
|
|
50
50
|
}),
|
|
51
51
|
|
|
52
52
|
logout: () =>
|
|
53
|
-
this.request('/
|
|
53
|
+
this.request('/diviswap', {
|
|
54
54
|
method: 'POST',
|
|
55
55
|
body: JSON.stringify({ action: 'logout' }),
|
|
56
56
|
}),
|
|
57
57
|
|
|
58
58
|
getSession: () =>
|
|
59
|
-
this.request('/
|
|
59
|
+
this.request('/diviswap', { params: { resource: 'session' } }),
|
|
60
60
|
|
|
61
61
|
// Transactions
|
|
62
62
|
createTransaction: (data: any) =>
|
|
63
|
-
this.request('/
|
|
63
|
+
this.request('/diviswap', {
|
|
64
64
|
method: 'POST',
|
|
65
65
|
body: JSON.stringify({ action: 'createTransaction', ...data }),
|
|
66
66
|
}),
|
|
67
67
|
|
|
68
68
|
getTransactions: (filters?: any) =>
|
|
69
|
-
this.request('/
|
|
69
|
+
this.request('/diviswap', { params: { resource: 'transactions', ...filters } }),
|
|
70
70
|
|
|
71
71
|
// Payees
|
|
72
72
|
createPayee: (data: any) =>
|
|
73
|
-
this.request('/
|
|
73
|
+
this.request('/diviswap', {
|
|
74
74
|
method: 'POST',
|
|
75
75
|
body: JSON.stringify({ action: 'createPayee', ...data }),
|
|
76
76
|
}),
|
|
77
77
|
|
|
78
78
|
getPayees: () =>
|
|
79
|
-
this.request('/
|
|
79
|
+
this.request('/diviswap', { params: { resource: 'payees' } }),
|
|
80
80
|
|
|
81
81
|
deletePayee: (id: string) =>
|
|
82
|
-
this.request('/
|
|
82
|
+
this.request('/diviswap', {
|
|
83
83
|
method: 'DELETE',
|
|
84
84
|
params: { resource: 'payee', id },
|
|
85
85
|
}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { DiviswapProvider, useDiviswap } from '@diviswap/sdk/react';
|
|
3
3
|
import { apiClient } from './api-client';
|
|
4
4
|
|
|
5
5
|
function TransactionDemo() {
|
|
@@ -11,7 +11,7 @@ function TransactionDemo() {
|
|
|
11
11
|
logout,
|
|
12
12
|
createTransaction,
|
|
13
13
|
getTransactions
|
|
14
|
-
} =
|
|
14
|
+
} = useDiviswap();
|
|
15
15
|
|
|
16
16
|
const handleLogin = async () => {
|
|
17
17
|
try {
|
|
@@ -44,8 +44,8 @@ function TransactionDemo() {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return (
|
|
47
|
-
<div className="
|
|
48
|
-
<h1>
|
|
47
|
+
<div className="diviswap-demo">
|
|
48
|
+
<h1>Diviswap Demo</h1>
|
|
49
49
|
|
|
50
50
|
{!user ? (
|
|
51
51
|
<button onClick={handleLogin}>Login</button>
|
|
@@ -62,8 +62,8 @@ function TransactionDemo() {
|
|
|
62
62
|
|
|
63
63
|
export default function App() {
|
|
64
64
|
return (
|
|
65
|
-
<
|
|
65
|
+
<DiviswapProvider>
|
|
66
66
|
<TransactionDemo />
|
|
67
|
-
</
|
|
67
|
+
</DiviswapProvider>
|
|
68
68
|
);
|
|
69
69
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Example of using TanStack Query with
|
|
2
|
+
* Example of using TanStack Query with Diviswap API routes
|
|
3
3
|
* This provides automatic caching, background refetching, and optimistic updates
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -8,17 +8,17 @@ import { apiClient } from './api-client';
|
|
|
8
8
|
|
|
9
9
|
// Query keys for cache invalidation
|
|
10
10
|
const queryKeys = {
|
|
11
|
-
user: ['
|
|
12
|
-
transactions: (filters?: any) => ['
|
|
13
|
-
payees: ['
|
|
14
|
-
fees: (amount: number) => ['
|
|
11
|
+
user: ['diviswap', 'user'],
|
|
12
|
+
transactions: (filters?: any) => ['diviswap', 'transactions', filters],
|
|
13
|
+
payees: ['diviswap', 'payees'],
|
|
14
|
+
fees: (amount: number) => ['diviswap', 'fees', amount],
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// User hooks
|
|
18
18
|
export function useUser() {
|
|
19
19
|
return useQuery({
|
|
20
20
|
queryKey: queryKeys.user,
|
|
21
|
-
queryFn: () => apiClient.
|
|
21
|
+
queryFn: () => apiClient.diviswap.getSession(),
|
|
22
22
|
retry: false,
|
|
23
23
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
24
24
|
});
|
|
@@ -29,7 +29,7 @@ export function useLogin() {
|
|
|
29
29
|
|
|
30
30
|
return useMutation({
|
|
31
31
|
mutationFn: ({ email, password }: { email: string; password: string }) =>
|
|
32
|
-
apiClient.
|
|
32
|
+
apiClient.diviswap.login(email, password),
|
|
33
33
|
onSuccess: (data) => {
|
|
34
34
|
queryClient.setQueryData(queryKeys.user, data.user);
|
|
35
35
|
queryClient.invalidateQueries({ queryKey: queryKeys.transactions() });
|
|
@@ -42,7 +42,7 @@ export function useLogout() {
|
|
|
42
42
|
const queryClient = useQueryClient();
|
|
43
43
|
|
|
44
44
|
return useMutation({
|
|
45
|
-
mutationFn: () => apiClient.
|
|
45
|
+
mutationFn: () => apiClient.diviswap.logout(),
|
|
46
46
|
onSuccess: () => {
|
|
47
47
|
queryClient.clear(); // Clear all cached data
|
|
48
48
|
},
|
|
@@ -55,7 +55,7 @@ export function useTransactions(filters?: any) {
|
|
|
55
55
|
|
|
56
56
|
return useQuery({
|
|
57
57
|
queryKey: queryKeys.transactions(filters),
|
|
58
|
-
queryFn: () => apiClient.
|
|
58
|
+
queryFn: () => apiClient.diviswap.getTransactions(filters),
|
|
59
59
|
enabled: !!user, // Only fetch if user is authenticated
|
|
60
60
|
staleTime: 30 * 1000, // 30 seconds
|
|
61
61
|
});
|
|
@@ -65,7 +65,7 @@ export function useCreateTransaction() {
|
|
|
65
65
|
const queryClient = useQueryClient();
|
|
66
66
|
|
|
67
67
|
return useMutation({
|
|
68
|
-
mutationFn: (data: any) => apiClient.
|
|
68
|
+
mutationFn: (data: any) => apiClient.diviswap.createTransaction(data),
|
|
69
69
|
onSuccess: () => {
|
|
70
70
|
// Invalidate and refetch transactions
|
|
71
71
|
queryClient.invalidateQueries({ queryKey: queryKeys.transactions() });
|
|
@@ -82,7 +82,7 @@ export function usePayees() {
|
|
|
82
82
|
|
|
83
83
|
return useQuery({
|
|
84
84
|
queryKey: queryKeys.payees,
|
|
85
|
-
queryFn: () => apiClient.
|
|
85
|
+
queryFn: () => apiClient.diviswap.getPayees(),
|
|
86
86
|
enabled: !!user,
|
|
87
87
|
staleTime: 60 * 1000, // 1 minute
|
|
88
88
|
});
|
|
@@ -92,7 +92,7 @@ export function useCreatePayee() {
|
|
|
92
92
|
const queryClient = useQueryClient();
|
|
93
93
|
|
|
94
94
|
return useMutation({
|
|
95
|
-
mutationFn: (data: any) => apiClient.
|
|
95
|
+
mutationFn: (data: any) => apiClient.diviswap.createPayee(data),
|
|
96
96
|
onSuccess: (newPayee) => {
|
|
97
97
|
// Optimistically add the new payee to the cache
|
|
98
98
|
queryClient.setQueryData(queryKeys.payees, (old: any[] = []) => {
|
|
@@ -106,7 +106,7 @@ export function useDeletePayee() {
|
|
|
106
106
|
const queryClient = useQueryClient();
|
|
107
107
|
|
|
108
108
|
return useMutation({
|
|
109
|
-
mutationFn: (id: string) => apiClient.
|
|
109
|
+
mutationFn: (id: string) => apiClient.diviswap.deletePayee(id),
|
|
110
110
|
onMutate: async (deletedId) => {
|
|
111
111
|
// Cancel in-flight queries
|
|
112
112
|
await queryClient.cancelQueries({ queryKey: queryKeys.payees });
|
|
@@ -139,7 +139,7 @@ export function useDeletePayee() {
|
|
|
139
139
|
export function useFeeCalculation(amount: number, enabled = true) {
|
|
140
140
|
return useQuery({
|
|
141
141
|
queryKey: queryKeys.fees(amount),
|
|
142
|
-
queryFn: () => apiClient.
|
|
142
|
+
queryFn: () => apiClient.diviswap.calculateFees(amount),
|
|
143
143
|
enabled: enabled && amount > 0,
|
|
144
144
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
145
145
|
gcTime: 10 * 60 * 1000, // 10 minutes (formerly cacheTime)
|
|
@@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
|
|
|
24
24
|
const rawBody = await request.text();
|
|
25
25
|
|
|
26
26
|
// Get signature from headers
|
|
27
|
-
const signature = request.headers.get('x-
|
|
27
|
+
const signature = request.headers.get('x-diviswap-signature');
|
|
28
28
|
|
|
29
29
|
if (!signature) {
|
|
30
30
|
return NextResponse.json(
|
|
@@ -34,9 +34,9 @@ export async function POST(request: NextRequest) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// Verify signature
|
|
37
|
-
const webhookSecret = process.env.
|
|
37
|
+
const webhookSecret = process.env.DIVISWAP_WEBHOOK_SECRET;
|
|
38
38
|
if (!webhookSecret) {
|
|
39
|
-
console.error('
|
|
39
|
+
console.error('DIVISWAP_WEBHOOK_SECRET not configured');
|
|
40
40
|
return NextResponse.json(
|
|
41
41
|
{ error: 'Webhook secret not configured' },
|
|
42
42
|
{ status: 500 }
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Diviswap } from '@diviswap/sdk';
|
|
4
4
|
import type { Transaction, Payee } from '@diviswap/sdk';
|
|
5
5
|
import { revalidatePath } from 'next/cache';
|
|
6
6
|
import { cookies } from 'next/headers';
|
|
7
7
|
|
|
8
|
-
// Initialize
|
|
9
|
-
function
|
|
10
|
-
return
|
|
11
|
-
apiKey: process.env.
|
|
12
|
-
clientId: process.env.
|
|
13
|
-
environment: (process.env.
|
|
8
|
+
// Initialize Diviswap SDK
|
|
9
|
+
function getDiviswap() {
|
|
10
|
+
return Diviswap.init({
|
|
11
|
+
apiKey: process.env.DIVISWAP_API_KEY!,
|
|
12
|
+
clientId: process.env.DIVISWAP_CLIENT_ID!,
|
|
13
|
+
environment: (process.env.NEXT_PUBLIC_DIVISWAP_ENV as 'production' | 'sandbox') || 'production',
|
|
14
14
|
debug: true // Enable debug logging
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -18,7 +18,7 @@ function getLiberEx() {
|
|
|
18
18
|
// Helper to get session token from cookies
|
|
19
19
|
async function getSessionToken() {
|
|
20
20
|
const cookieStore = await cookies();
|
|
21
|
-
const session = cookieStore.get('
|
|
21
|
+
const session = cookieStore.get('diviswap_session');
|
|
22
22
|
return session?.value;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -32,6 +32,7 @@ export async function createTransactionAction(data: {
|
|
|
32
32
|
// Required for offramp
|
|
33
33
|
fromAddress?: string;
|
|
34
34
|
chain?: string;
|
|
35
|
+
txHash?: string; // Required for offramp - transaction hash from blockchain
|
|
35
36
|
}) {
|
|
36
37
|
try {
|
|
37
38
|
const sessionToken = await getSessionToken();
|
|
@@ -39,29 +40,35 @@ export async function createTransactionAction(data: {
|
|
|
39
40
|
return { success: false, error: 'Not authenticated' };
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
const
|
|
43
|
-
|
|
43
|
+
const diviswap = getDiviswap();
|
|
44
|
+
|
|
44
45
|
// Use the appropriate method based on transaction type
|
|
45
46
|
let transaction;
|
|
46
47
|
if (data.type === 'onramp') {
|
|
47
48
|
// Note: Onramp is not yet available in v1 API
|
|
48
49
|
return { success: false, error: 'Onramp transactions are not yet available' };
|
|
49
50
|
} else {
|
|
50
|
-
|
|
51
|
+
// Offramp requires txHash - must send crypto transaction first
|
|
52
|
+
if (!data.txHash) {
|
|
53
|
+
return { success: false, error: 'txHash is required for offramp transactions. Send the crypto transaction first.' };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
transaction = await diviswap.transactions.offramp({
|
|
51
57
|
amount: data.amount,
|
|
52
58
|
currency: data.currency || 'USD',
|
|
53
59
|
payeeId: data.payeeId!,
|
|
54
|
-
fromAddress: data.fromAddress!,
|
|
55
|
-
chain: data.chain || 'ethereum'
|
|
60
|
+
fromAddress: data.fromAddress!,
|
|
61
|
+
chain: data.chain || 'ethereum',
|
|
62
|
+
txHash: data.txHash
|
|
56
63
|
});
|
|
57
64
|
}
|
|
58
|
-
|
|
59
|
-
revalidatePath('/
|
|
65
|
+
|
|
66
|
+
revalidatePath('/diviswap');
|
|
60
67
|
return { success: true, transaction };
|
|
61
68
|
} catch (error) {
|
|
62
|
-
return {
|
|
63
|
-
success: false,
|
|
64
|
-
error: error instanceof Error ? error.message : 'Transaction creation failed'
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
error: error instanceof Error ? error.message : 'Transaction creation failed'
|
|
65
72
|
};
|
|
66
73
|
}
|
|
67
74
|
}
|
|
@@ -78,8 +85,8 @@ export async function getTransactionsAction(filters?: {
|
|
|
78
85
|
return { success: false, error: 'Not authenticated' };
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
const
|
|
82
|
-
const transactions = await
|
|
88
|
+
const diviswap = getDiviswap();
|
|
89
|
+
const transactions = await diviswap.transactions.list(filters);
|
|
83
90
|
|
|
84
91
|
return { success: true, transactions };
|
|
85
92
|
} catch (error) {
|
|
@@ -98,8 +105,8 @@ export async function getPayeesAction() {
|
|
|
98
105
|
return { success: false, error: 'Not authenticated' };
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
const
|
|
102
|
-
const payees = await
|
|
108
|
+
const diviswap = getDiviswap();
|
|
109
|
+
const payees = await diviswap.payees.list();
|
|
103
110
|
|
|
104
111
|
return { success: true, payees };
|
|
105
112
|
} catch (error) {
|
|
@@ -122,8 +129,8 @@ export async function createPayeeAction(data: {
|
|
|
122
129
|
return { success: false, error: 'Not authenticated' };
|
|
123
130
|
}
|
|
124
131
|
|
|
125
|
-
const
|
|
126
|
-
const payee = await
|
|
132
|
+
const diviswap = getDiviswap();
|
|
133
|
+
const payee = await diviswap.payees.create({
|
|
127
134
|
nickname: data.nickname,
|
|
128
135
|
accountNumber: data.accountNumber,
|
|
129
136
|
routingNumber: data.routingNumber,
|
|
@@ -131,7 +138,7 @@ export async function createPayeeAction(data: {
|
|
|
131
138
|
setAsDefault: false
|
|
132
139
|
});
|
|
133
140
|
|
|
134
|
-
revalidatePath('/
|
|
141
|
+
revalidatePath('/diviswap');
|
|
135
142
|
return { success: true, payee };
|
|
136
143
|
} catch (error) {
|
|
137
144
|
return {
|
|
@@ -148,10 +155,10 @@ export async function deletePayeeAction(payeeId: string) {
|
|
|
148
155
|
return { success: false, error: 'Not authenticated' };
|
|
149
156
|
}
|
|
150
157
|
|
|
151
|
-
const
|
|
152
|
-
await
|
|
158
|
+
const diviswap = getDiviswap();
|
|
159
|
+
await diviswap.payees.delete(payeeId);
|
|
153
160
|
|
|
154
|
-
revalidatePath('/
|
|
161
|
+
revalidatePath('/diviswap');
|
|
155
162
|
return { success: true };
|
|
156
163
|
} catch (error) {
|
|
157
164
|
return {
|
|
@@ -169,8 +176,8 @@ export async function calculateFeesAction(data: {
|
|
|
169
176
|
currency?: string;
|
|
170
177
|
}) {
|
|
171
178
|
try {
|
|
172
|
-
const
|
|
173
|
-
const fees = await
|
|
179
|
+
const diviswap = getDiviswap();
|
|
180
|
+
const fees = await diviswap.fees.calculateFees({
|
|
174
181
|
amount: data.amount,
|
|
175
182
|
userId: undefined // Optional: for per-user fees
|
|
176
183
|
});
|
|
@@ -191,8 +198,8 @@ export async function getIntegratorFeesAction() {
|
|
|
191
198
|
return { success: false, error: 'Not authenticated' };
|
|
192
199
|
}
|
|
193
200
|
|
|
194
|
-
const
|
|
195
|
-
const fees = await
|
|
201
|
+
const diviswap = getDiviswap();
|
|
202
|
+
const fees = await diviswap.fees.getFees();
|
|
196
203
|
|
|
197
204
|
return { success: true, fees };
|
|
198
205
|
} catch (error) {
|
|
@@ -213,10 +220,10 @@ export async function updateIntegratorFeeAction(data: {
|
|
|
213
220
|
return { success: false, error: 'Not authenticated' };
|
|
214
221
|
}
|
|
215
222
|
|
|
216
|
-
const
|
|
217
|
-
const fee = await
|
|
223
|
+
const diviswap = getDiviswap();
|
|
224
|
+
const fee = await diviswap.fees.setFee(data);
|
|
218
225
|
|
|
219
|
-
revalidatePath('/
|
|
226
|
+
revalidatePath('/diviswap');
|
|
220
227
|
return { success: true, fee };
|
|
221
228
|
} catch (error) {
|
|
222
229
|
return {
|
|
@@ -235,8 +242,8 @@ export async function getCurrentUserAction() {
|
|
|
235
242
|
return { success: false, user: null };
|
|
236
243
|
}
|
|
237
244
|
|
|
238
|
-
const
|
|
239
|
-
const user = await
|
|
245
|
+
const diviswap = getDiviswap();
|
|
246
|
+
const user = await diviswap.auth.getProfile();
|
|
240
247
|
|
|
241
248
|
return { success: true, user };
|
|
242
249
|
} catch (error) {
|
|
@@ -247,7 +254,7 @@ export async function getCurrentUserAction() {
|
|
|
247
254
|
// Utility action for checking API status
|
|
248
255
|
export async function checkApiStatusAction() {
|
|
249
256
|
try {
|
|
250
|
-
const
|
|
257
|
+
const diviswap = getDiviswap();
|
|
251
258
|
// Note: Health check endpoint not available in SDK
|
|
252
259
|
return { success: true, status: 'OK' };
|
|
253
260
|
} catch (error) {
|