@gatewayfm/ups-react 0.1.14 → 0.1.16
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/index.d.mts +56 -2
- package/dist/index.d.ts +56 -2
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { UPSConfig, UPSClient, WalletState, AuthState, Account, EIP1193Provider, ConnectedWallet, CreateAccountParams, CreateAccountResponse,
|
|
3
|
+
import { UPSConfig, UPSClient, WalletState, AuthState, Account, EIP1193Provider, ConnectedWallet, CreateAccountParams, CreateAccountResponse, Invoice, SettleResponse, PaymentRequirements, SignedAuthorization, VerifyResponse, Escrow, EscrowActionResponse, InvoiceResponse, CreateInvoiceRequest, InvoiceListResponse } from '@gatewayfm/ups-sdk';
|
|
4
4
|
export { Account, PaymentRequirements, SettleResponse as PaymentResult, UPSConfig } from '@gatewayfm/ups-sdk';
|
|
5
5
|
import * as zustand from 'zustand';
|
|
6
6
|
import { UseMutationResult, UseQueryResult } from '@tanstack/react-query';
|
|
@@ -104,5 +104,59 @@ interface UsePaymentSettleReturn {
|
|
|
104
104
|
error: Error | null;
|
|
105
105
|
}
|
|
106
106
|
declare function usePaymentSettle(): UsePaymentSettleReturn;
|
|
107
|
+
interface UsePayInvoiceParams {
|
|
108
|
+
invoice: Invoice;
|
|
109
|
+
paymentParams: {
|
|
110
|
+
amount: string;
|
|
111
|
+
asset: string;
|
|
112
|
+
network: string;
|
|
113
|
+
payTo?: string;
|
|
114
|
+
from?: string;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
interface UsePayInvoiceReturn {
|
|
118
|
+
payInvoice: (params: UsePayInvoiceParams) => Promise<SettleResponse>;
|
|
119
|
+
isPending: boolean;
|
|
120
|
+
error: Error | null;
|
|
121
|
+
data: SettleResponse | undefined;
|
|
122
|
+
}
|
|
123
|
+
declare function usePayInvoice(): UsePayInvoiceReturn;
|
|
124
|
+
|
|
125
|
+
declare function useEscrow(id: string): UseQueryResult<Escrow, Error>;
|
|
126
|
+
interface UseReleaseEscrowReturn {
|
|
127
|
+
release: (id: string) => Promise<EscrowActionResponse>;
|
|
128
|
+
isPending: boolean;
|
|
129
|
+
error: Error | null;
|
|
130
|
+
}
|
|
131
|
+
declare function useReleaseEscrow(): UseReleaseEscrowReturn;
|
|
132
|
+
interface UseRefundEscrowReturn {
|
|
133
|
+
refund: (id: string) => Promise<EscrowActionResponse>;
|
|
134
|
+
isPending: boolean;
|
|
135
|
+
error: Error | null;
|
|
136
|
+
}
|
|
137
|
+
declare function useRefundEscrow(): UseRefundEscrowReturn;
|
|
138
|
+
|
|
139
|
+
declare function useInvoice(id: string): UseQueryResult<Invoice, Error>;
|
|
140
|
+
interface UseInvoicesParams {
|
|
141
|
+
merchant?: string;
|
|
142
|
+
payer?: string;
|
|
143
|
+
page_size?: number;
|
|
144
|
+
page_token?: string;
|
|
145
|
+
}
|
|
146
|
+
declare function useInvoices(params?: UseInvoicesParams): UseQueryResult<InvoiceListResponse, Error>;
|
|
147
|
+
interface UseCreateInvoiceReturn {
|
|
148
|
+
createInvoice: (request: CreateInvoiceRequest) => Promise<InvoiceResponse>;
|
|
149
|
+
isPending: boolean;
|
|
150
|
+
error: Error | null;
|
|
151
|
+
data: InvoiceResponse | undefined;
|
|
152
|
+
reset: () => void;
|
|
153
|
+
}
|
|
154
|
+
declare function useCreateInvoice(): UseCreateInvoiceReturn;
|
|
155
|
+
interface UseCancelInvoiceReturn {
|
|
156
|
+
cancelInvoice: (id: string) => Promise<InvoiceResponse>;
|
|
157
|
+
isPending: boolean;
|
|
158
|
+
error: Error | null;
|
|
159
|
+
}
|
|
160
|
+
declare function useCancelInvoice(): UseCancelInvoiceReturn;
|
|
107
161
|
|
|
108
|
-
export { UPSProvider, generateSalt, useAccount, useAccountByWallet, useAccounts, useAuth, useConnect, useCreateAccount, useCurrentAccount, useDisconnect, usePayment, usePaymentSettle, usePaymentVerify, usePredictAddress, useUPSClient, useUPSContext, useUPSStore, useWallet };
|
|
162
|
+
export { UPSProvider, generateSalt, useAccount, useAccountByWallet, useAccounts, useAuth, useCancelInvoice, useConnect, useCreateAccount, useCreateInvoice, useCurrentAccount, useDisconnect, useEscrow, useInvoice, useInvoices, usePayInvoice, usePayment, usePaymentSettle, usePaymentVerify, usePredictAddress, useRefundEscrow, useReleaseEscrow, useUPSClient, useUPSContext, useUPSStore, useWallet };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { UPSConfig, UPSClient, WalletState, AuthState, Account, EIP1193Provider, ConnectedWallet, CreateAccountParams, CreateAccountResponse,
|
|
3
|
+
import { UPSConfig, UPSClient, WalletState, AuthState, Account, EIP1193Provider, ConnectedWallet, CreateAccountParams, CreateAccountResponse, Invoice, SettleResponse, PaymentRequirements, SignedAuthorization, VerifyResponse, Escrow, EscrowActionResponse, InvoiceResponse, CreateInvoiceRequest, InvoiceListResponse } from '@gatewayfm/ups-sdk';
|
|
4
4
|
export { Account, PaymentRequirements, SettleResponse as PaymentResult, UPSConfig } from '@gatewayfm/ups-sdk';
|
|
5
5
|
import * as zustand from 'zustand';
|
|
6
6
|
import { UseMutationResult, UseQueryResult } from '@tanstack/react-query';
|
|
@@ -104,5 +104,59 @@ interface UsePaymentSettleReturn {
|
|
|
104
104
|
error: Error | null;
|
|
105
105
|
}
|
|
106
106
|
declare function usePaymentSettle(): UsePaymentSettleReturn;
|
|
107
|
+
interface UsePayInvoiceParams {
|
|
108
|
+
invoice: Invoice;
|
|
109
|
+
paymentParams: {
|
|
110
|
+
amount: string;
|
|
111
|
+
asset: string;
|
|
112
|
+
network: string;
|
|
113
|
+
payTo?: string;
|
|
114
|
+
from?: string;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
interface UsePayInvoiceReturn {
|
|
118
|
+
payInvoice: (params: UsePayInvoiceParams) => Promise<SettleResponse>;
|
|
119
|
+
isPending: boolean;
|
|
120
|
+
error: Error | null;
|
|
121
|
+
data: SettleResponse | undefined;
|
|
122
|
+
}
|
|
123
|
+
declare function usePayInvoice(): UsePayInvoiceReturn;
|
|
124
|
+
|
|
125
|
+
declare function useEscrow(id: string): UseQueryResult<Escrow, Error>;
|
|
126
|
+
interface UseReleaseEscrowReturn {
|
|
127
|
+
release: (id: string) => Promise<EscrowActionResponse>;
|
|
128
|
+
isPending: boolean;
|
|
129
|
+
error: Error | null;
|
|
130
|
+
}
|
|
131
|
+
declare function useReleaseEscrow(): UseReleaseEscrowReturn;
|
|
132
|
+
interface UseRefundEscrowReturn {
|
|
133
|
+
refund: (id: string) => Promise<EscrowActionResponse>;
|
|
134
|
+
isPending: boolean;
|
|
135
|
+
error: Error | null;
|
|
136
|
+
}
|
|
137
|
+
declare function useRefundEscrow(): UseRefundEscrowReturn;
|
|
138
|
+
|
|
139
|
+
declare function useInvoice(id: string): UseQueryResult<Invoice, Error>;
|
|
140
|
+
interface UseInvoicesParams {
|
|
141
|
+
merchant?: string;
|
|
142
|
+
payer?: string;
|
|
143
|
+
page_size?: number;
|
|
144
|
+
page_token?: string;
|
|
145
|
+
}
|
|
146
|
+
declare function useInvoices(params?: UseInvoicesParams): UseQueryResult<InvoiceListResponse, Error>;
|
|
147
|
+
interface UseCreateInvoiceReturn {
|
|
148
|
+
createInvoice: (request: CreateInvoiceRequest) => Promise<InvoiceResponse>;
|
|
149
|
+
isPending: boolean;
|
|
150
|
+
error: Error | null;
|
|
151
|
+
data: InvoiceResponse | undefined;
|
|
152
|
+
reset: () => void;
|
|
153
|
+
}
|
|
154
|
+
declare function useCreateInvoice(): UseCreateInvoiceReturn;
|
|
155
|
+
interface UseCancelInvoiceReturn {
|
|
156
|
+
cancelInvoice: (id: string) => Promise<InvoiceResponse>;
|
|
157
|
+
isPending: boolean;
|
|
158
|
+
error: Error | null;
|
|
159
|
+
}
|
|
160
|
+
declare function useCancelInvoice(): UseCancelInvoiceReturn;
|
|
107
161
|
|
|
108
|
-
export { UPSProvider, generateSalt, useAccount, useAccountByWallet, useAccounts, useAuth, useConnect, useCreateAccount, useCurrentAccount, useDisconnect, usePayment, usePaymentSettle, usePaymentVerify, usePredictAddress, useUPSClient, useUPSContext, useUPSStore, useWallet };
|
|
162
|
+
export { UPSProvider, generateSalt, useAccount, useAccountByWallet, useAccounts, useAuth, useCancelInvoice, useConnect, useCreateAccount, useCreateInvoice, useCurrentAccount, useDisconnect, useEscrow, useInvoice, useInvoices, usePayInvoice, usePayment, usePaymentSettle, usePaymentVerify, usePredictAddress, useRefundEscrow, useReleaseEscrow, useUPSClient, useUPSContext, useUPSStore, useWallet };
|
package/dist/index.js
CHANGED
|
@@ -251,6 +251,123 @@ function usePaymentSettle() {
|
|
|
251
251
|
error: mutation.error
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
|
+
function usePayInvoice() {
|
|
255
|
+
const client = useUPSClient();
|
|
256
|
+
const mutation = reactQuery.useMutation({
|
|
257
|
+
mutationFn: (params) => client.payment.payInvoice(
|
|
258
|
+
params.invoice,
|
|
259
|
+
params.paymentParams
|
|
260
|
+
)
|
|
261
|
+
});
|
|
262
|
+
return {
|
|
263
|
+
payInvoice: mutation.mutateAsync,
|
|
264
|
+
isPending: mutation.isPending,
|
|
265
|
+
error: mutation.error,
|
|
266
|
+
data: mutation.data
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
var escrowKeys = {
|
|
270
|
+
all: ["escrows"],
|
|
271
|
+
detail: (id) => [...escrowKeys.all, "detail", id]
|
|
272
|
+
};
|
|
273
|
+
function useEscrow(id) {
|
|
274
|
+
const client = useUPSClient();
|
|
275
|
+
const isAuthenticated = useUPSStore((state) => state.authState.isAuthenticated);
|
|
276
|
+
return reactQuery.useQuery({
|
|
277
|
+
queryKey: escrowKeys.detail(id),
|
|
278
|
+
queryFn: () => client.escrow.get(id),
|
|
279
|
+
enabled: isAuthenticated && !!id
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function useReleaseEscrow() {
|
|
283
|
+
const client = useUPSClient();
|
|
284
|
+
const queryClient = reactQuery.useQueryClient();
|
|
285
|
+
const mutation = reactQuery.useMutation({
|
|
286
|
+
mutationFn: (id) => client.escrow.release(id, client.config.network),
|
|
287
|
+
onSuccess: (data, variables) => {
|
|
288
|
+
queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
release: mutation.mutateAsync,
|
|
293
|
+
isPending: mutation.isPending,
|
|
294
|
+
error: mutation.error
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function useRefundEscrow() {
|
|
298
|
+
const client = useUPSClient();
|
|
299
|
+
const queryClient = reactQuery.useQueryClient();
|
|
300
|
+
const mutation = reactQuery.useMutation({
|
|
301
|
+
mutationFn: (id) => client.escrow.refund(id, client.config.network),
|
|
302
|
+
onSuccess: (data, variables) => {
|
|
303
|
+
queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
return {
|
|
307
|
+
refund: mutation.mutateAsync,
|
|
308
|
+
isPending: mutation.isPending,
|
|
309
|
+
error: mutation.error
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
var invoiceKeys = {
|
|
313
|
+
all: ["invoices"],
|
|
314
|
+
list: (params) => [...invoiceKeys.all, "list", params],
|
|
315
|
+
detail: (id) => [...invoiceKeys.all, "detail", id]
|
|
316
|
+
};
|
|
317
|
+
function useInvoice(id) {
|
|
318
|
+
const client = useUPSClient();
|
|
319
|
+
const isAuthenticated = useUPSStore((state) => state.authState.isAuthenticated);
|
|
320
|
+
return reactQuery.useQuery({
|
|
321
|
+
queryKey: invoiceKeys.detail(id),
|
|
322
|
+
queryFn: async () => {
|
|
323
|
+
const response = await client.invoice.get(id);
|
|
324
|
+
return response.invoice;
|
|
325
|
+
},
|
|
326
|
+
enabled: isAuthenticated && !!id
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function useInvoices(params = {}) {
|
|
330
|
+
const client = useUPSClient();
|
|
331
|
+
const isAuthenticated = useUPSStore((state) => state.authState.isAuthenticated);
|
|
332
|
+
return reactQuery.useQuery({
|
|
333
|
+
queryKey: invoiceKeys.list(params),
|
|
334
|
+
queryFn: () => client.invoice.list(params),
|
|
335
|
+
enabled: isAuthenticated
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
function useCreateInvoice() {
|
|
339
|
+
const client = useUPSClient();
|
|
340
|
+
const queryClient = reactQuery.useQueryClient();
|
|
341
|
+
const mutation = reactQuery.useMutation({
|
|
342
|
+
mutationFn: (request) => client.invoice.create(request),
|
|
343
|
+
onSuccess: () => {
|
|
344
|
+
queryClient.invalidateQueries({ queryKey: invoiceKeys.all });
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
return {
|
|
348
|
+
createInvoice: mutation.mutateAsync,
|
|
349
|
+
isPending: mutation.isPending,
|
|
350
|
+
error: mutation.error,
|
|
351
|
+
data: mutation.data,
|
|
352
|
+
reset: mutation.reset
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function useCancelInvoice() {
|
|
356
|
+
const client = useUPSClient();
|
|
357
|
+
const queryClient = reactQuery.useQueryClient();
|
|
358
|
+
const mutation = reactQuery.useMutation({
|
|
359
|
+
mutationFn: (id) => client.invoice.cancel(id),
|
|
360
|
+
onSuccess: (data) => {
|
|
361
|
+
queryClient.invalidateQueries({ queryKey: invoiceKeys.detail(data.invoice.invoice_id) });
|
|
362
|
+
queryClient.invalidateQueries({ queryKey: invoiceKeys.list() });
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
cancelInvoice: mutation.mutateAsync,
|
|
367
|
+
isPending: mutation.isPending,
|
|
368
|
+
error: mutation.error
|
|
369
|
+
};
|
|
370
|
+
}
|
|
254
371
|
|
|
255
372
|
exports.UPSProvider = UPSProvider;
|
|
256
373
|
exports.generateSalt = generateSalt;
|
|
@@ -258,14 +375,22 @@ exports.useAccount = useAccount;
|
|
|
258
375
|
exports.useAccountByWallet = useAccountByWallet;
|
|
259
376
|
exports.useAccounts = useAccounts;
|
|
260
377
|
exports.useAuth = useAuth;
|
|
378
|
+
exports.useCancelInvoice = useCancelInvoice;
|
|
261
379
|
exports.useConnect = useConnect;
|
|
262
380
|
exports.useCreateAccount = useCreateAccount;
|
|
381
|
+
exports.useCreateInvoice = useCreateInvoice;
|
|
263
382
|
exports.useCurrentAccount = useCurrentAccount;
|
|
264
383
|
exports.useDisconnect = useDisconnect;
|
|
384
|
+
exports.useEscrow = useEscrow;
|
|
385
|
+
exports.useInvoice = useInvoice;
|
|
386
|
+
exports.useInvoices = useInvoices;
|
|
387
|
+
exports.usePayInvoice = usePayInvoice;
|
|
265
388
|
exports.usePayment = usePayment;
|
|
266
389
|
exports.usePaymentSettle = usePaymentSettle;
|
|
267
390
|
exports.usePaymentVerify = usePaymentVerify;
|
|
268
391
|
exports.usePredictAddress = usePredictAddress;
|
|
392
|
+
exports.useRefundEscrow = useRefundEscrow;
|
|
393
|
+
exports.useReleaseEscrow = useReleaseEscrow;
|
|
269
394
|
exports.useUPSClient = useUPSClient;
|
|
270
395
|
exports.useUPSContext = useUPSContext;
|
|
271
396
|
exports.useUPSStore = useUPSStore;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store.ts","../src/provider.tsx","../src/hooks/use-wallet.ts","../src/hooks/use-auth.ts","../src/hooks/use-account.ts","../src/hooks/use-payment.ts"],"names":["create","createContext","useState","useMemo","UPSClient","useEffect","jsx","useContext","useMutation","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;AAQO,SAAS,gBAAA,GAA2C;AACvD,EAAA,MAAM,SAAS,YAAA,EAAa;AAE5B,EAAA,MAAM,WAAWA,sBAAAA,CAAY;AAAA,IACzB,UAAA,EAAY,CAAC,MAAA,KACT,MAAA,CAAO,QAAQ,MAAA,CAAO,MAAA,CAAO,MAAA,EAAQ,MAAA,CAAO,YAAY;AAAA,GAC/D,CAAA;AAED,EAAA,OAAO;AAAA,IACH,MAAA,EAAQ,CAAC,MAAA,EAAQ,YAAA,KAAiB,SAAS,WAAA,CAAY,EAAE,MAAA,EAAQ,YAAA,EAAc,CAAA;AAAA,IAC/E,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GACpB;AACJ;AAQO,SAAS,gBAAA,GAA2C;AACvD,EAAA,MAAM,SAAS,YAAA,EAAa;AAE5B,EAAA,MAAM,WAAWA,sBAAAA,CAAY;AAAA,IACzB,UAAA,EAAY,CAAC,MAAA,KACT,MAAA,CAAO,QAAQ,MAAA,CAAO,MAAA,CAAO,MAAA,EAAQ,MAAA,CAAO,YAAY;AAAA,GAC/D,CAAA;AAED,EAAA,OAAO;AAAA,IACH,MAAA,EAAQ,CAAC,MAAA,EAAQ,YAAA,KAAiB,SAAS,WAAA,CAAY,EAAE,MAAA,EAAQ,YAAA,EAAc,CAAA;AAAA,IAC/E,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GACpB;AACJ","file":"index.js","sourcesContent":["import { create } from 'zustand';\nimport type { UPSClient, WalletState, AuthState, Account } from '@gatewayfm/ups-sdk';\n\nexport interface UPSStore {\n // Client instance\n client: UPSClient | null;\n setClient: (client: UPSClient | null) => void;\n\n // Wallet state (synced from SDK)\n walletState: WalletState;\n setWalletState: (state: WalletState) => void;\n\n // Auth state (synced from SDK)\n authState: AuthState;\n setAuthState: (state: AuthState) => void;\n\n // Current user's account (after creation)\n currentAccount: Account | null;\n setCurrentAccount: (account: Account | null) => void;\n}\n\nexport const useUPSStore = create<UPSStore>((set) => ({\n client: null,\n setClient: (client) => set({ client }),\n\n walletState: {\n address: null,\n chainId: null,\n isConnected: false,\n provider: null,\n },\n setWalletState: (walletState) => set({ walletState }),\n\n authState: {\n isAuthenticated: false,\n token: null,\n expiresAt: null,\n address: null,\n },\n setAuthState: (authState) => set({ authState }),\n\n currentAccount: null,\n setCurrentAccount: (currentAccount) => set({ currentAccount }),\n}));\n","import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';\nimport { UPSClient, type UPSConfig } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from './store';\n\ninterface UPSContextValue {\n client: UPSClient | null;\n isInitialized: boolean;\n}\n\nconst UPSContext = createContext<UPSContextValue>({\n client: null,\n isInitialized: false,\n});\n\nexport interface UPSProviderProps {\n config: UPSConfig;\n children: React.ReactNode;\n}\n\nexport const UPSProvider = ({ config, children }: UPSProviderProps) => {\n const setClient = useUPSStore((state) => state.setClient);\n const setWalletState = useUPSStore((state) => state.setWalletState);\n const setAuthState = useUPSStore((state) => state.setAuthState);\n const [isInitialized, setIsInitialized] = useState(false);\n\n // Initialize client only once (or when config deep changes, but strictly speaking config shouldn't change often)\n // We use useMemo to hold the instance.\n const client = useMemo(() => {\n return new UPSClient(config);\n }, [JSON.stringify(config)]);\n\n useEffect(() => {\n setClient(client);\n\n // Subscribe to state changes\n const unsubWallet = client.wallet.onStateChange((state) => {\n setWalletState(state);\n });\n\n const unsubAuth = client.auth.onStateChange((state) => {\n setAuthState(state);\n });\n\n // Initial sync\n setWalletState(client.wallet.state);\n setAuthState(client.auth.state);\n\n setIsInitialized(true);\n\n return () => {\n unsubWallet();\n unsubAuth();\n client.destroy();\n setClient(null);\n };\n }, [client, setClient, setWalletState, setAuthState]);\n\n const value = useMemo(() => ({\n client,\n isInitialized\n }), [client, isInitialized]);\n\n return <UPSContext.Provider value={value}>{children}</UPSContext.Provider>;\n};\n\nexport const useUPSContext = () => useContext(UPSContext);\n\nexport const useUPSClient = () => {\n const { client } = useUPSContext();\n if (!client) {\n throw new Error('useUPSClient must be used within a UPSProvider');\n }\n return client;\n};\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type EIP1193Provider, type ConnectedWallet, type WalletState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseWalletReturn {\n // State\n state: WalletState;\n address: string | null;\n chainId: number | null;\n isConnected: boolean;\n\n // Actions (TanStack Query mutations)\n connect: UseMutationResult<ConnectedWallet, Error, EIP1193Provider>;\n disconnect: UseMutationResult<void, Error, void>;\n\n // Direct methods\n signMessage: (message: string) => Promise<string>;\n switchChain: (chainId: number) => Promise<void>;\n}\n\nexport function useWallet(): UseWalletReturn {\n const client = useUPSClient();\n const walletState = useUPSStore((state) => state.walletState);\n\n const connectMutation = useMutation({\n mutationFn: async (provider: EIP1193Provider) => {\n return await client.connect(provider);\n },\n });\n\n const disconnectMutation = useMutation({\n mutationFn: async () => {\n await client.disconnect();\n },\n });\n\n return {\n state: walletState,\n address: walletState.address,\n chainId: walletState.chainId,\n isConnected: walletState.isConnected,\n connect: connectMutation,\n disconnect: disconnectMutation,\n signMessage: (message: string) => client.wallet.signMessage(message),\n switchChain: (chainId: number) => client.wallet.switchChain(chainId),\n };\n}\n\nexport interface UseConnectReturn {\n connect: (provider?: EIP1193Provider) => Promise<ConnectedWallet>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useConnect(): UseConnectReturn {\n const { connect } = useWallet();\n\n const connectFn = async (provider?: EIP1193Provider) => {\n if (provider) {\n return connect.mutateAsync(provider);\n }\n\n // Default to window.ethereum\n if (typeof window !== 'undefined' && (window as unknown as { ethereum: EIP1193Provider }).ethereum) {\n return connect.mutateAsync((window as unknown as { ethereum: EIP1193Provider }).ethereum);\n }\n\n throw new Error('No EIP-1193 provider found (window.ethereum is undefined)');\n };\n\n return {\n connect: connectFn,\n isPending: connect.isPending,\n error: connect.error,\n };\n}\n\nexport interface UseDisconnectReturn {\n disconnect: () => Promise<void>;\n isPending: boolean;\n}\n\nexport function useDisconnect(): UseDisconnectReturn {\n const { disconnect } = useWallet();\n\n return {\n disconnect: async () => {\n await disconnect.mutateAsync();\n },\n isPending: disconnect.isPending,\n };\n}\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type AuthState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseAuthReturn {\n // State\n state: AuthState;\n isAuthenticated: boolean;\n\n // Actions\n authenticate: UseMutationResult<void, Error, void>;\n logout: () => void;\n}\n\nexport function useAuth(): UseAuthReturn {\n const client = useUPSClient();\n const authState = useUPSStore((state) => state.authState);\n\n const authenticateMutation = useMutation({\n mutationFn: async () => {\n await client.authenticate();\n },\n });\n\n return {\n state: authState,\n isAuthenticated: authState.isAuthenticated,\n authenticate: authenticateMutation,\n logout: () => client.auth.logout(),\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport { type Account, type CreateAccountParams, type CreateAccountResponse } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nconst accountKeys = {\n all: ['accounts'] as const,\n list: () => [...accountKeys.all, 'list'] as const,\n detail: (id: string) => [...accountKeys.all, 'detail', id] as const,\n byWallet: (address: string) => [...accountKeys.all, 'wallet', address] as const,\n};\n\nexport function useAccounts(): UseQueryResult<Account[], Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.list(),\n queryFn: () => client.account.list(),\n enabled: isAuthenticated,\n });\n}\n\nexport function useAccount(id: string): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.detail(id),\n queryFn: () => client.account.get(id),\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport function useAccountByWallet(address: string | null): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.byWallet(address || ''),\n queryFn: () => client.account.getByWallet(address!),\n enabled: isAuthenticated && !!address,\n });\n}\n\nexport interface UsePredictAddressReturn {\n predictAddress: (owner: string, salt: string) => Promise<string>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePredictAddress(): UsePredictAddressReturn {\n const client = useUPSClient();\n const mutation = useMutation({\n mutationFn: (params: { owner: string, salt: string }) =>\n client.account.predictAddress({ ownerAddress: params.owner, salt: params.salt }),\n });\n\n return {\n predictAddress: (owner, salt) => mutation.mutateAsync({ owner, salt }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UseCreateAccountReturn {\n createAccount: (params: CreateAccountParams) => Promise<CreateAccountResponse>;\n isPending: boolean;\n error: Error | null;\n data: CreateAccountResponse | undefined;\n reset: () => void;\n}\n\nexport function useCreateAccount(): UseCreateAccountReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n const setCurrentAccount = useUPSStore(state => state.setCurrentAccount);\n\n const mutation = useMutation({\n mutationFn: (params: CreateAccountParams) => client.account.create(params),\n onSuccess: (data) => {\n setCurrentAccount(data.account);\n queryClient.invalidateQueries({ queryKey: accountKeys.list() });\n },\n });\n\n return {\n createAccount: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport function useCurrentAccount(): Account | null {\n return useUPSStore(state => state.currentAccount);\n}\n\nexport function generateSalt(): string {\n const array = new Uint8Array(32);\n if (typeof window !== 'undefined' && window.crypto) {\n window.crypto.getRandomValues(array);\n } else {\n // Fallback for non-browser environments if needed (e.g. during build/test)\n for (let i = 0; i < 32; i++) {\n array[i] = Math.floor(Math.random() * 256);\n }\n }\n return '0x' + Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');\n}\n","import { useMutation } from '@tanstack/react-query';\nimport {\n type PaymentRequirements,\n type SignedAuthorization,\n type VerifyResponse,\n type SettleResponse\n} from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\n\nexport interface UsePaymentParams {\n requirements: PaymentRequirements;\n from: string; // Payer SmartAccount address\n}\n\n// PaymentResult is SettleResponse from SDK type\nexport interface UsePaymentReturn {\n pay: (params: UsePaymentParams) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n data: SettleResponse | undefined;\n reset: () => void;\n}\n\nexport function usePayment(): UsePaymentReturn {\n const client = useUPSClient();\n\n // client.payment.pay takes { requirements, from }\n const mutation = useMutation({\n mutationFn: (params: UsePaymentParams) => client.payment.pay({\n requirements: params.requirements,\n from: params.from\n }),\n });\n\n return {\n pay: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport interface UsePaymentVerifyReturn {\n verify: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<VerifyResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentVerify(): UsePaymentVerifyReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.verify(params.signed, params.requirements),\n });\n\n return {\n verify: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UsePaymentSettleReturn {\n settle: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentSettle(): UsePaymentSettleReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.settle(params.signed, params.requirements),\n });\n\n return {\n settle: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/store.ts","../src/provider.tsx","../src/hooks/use-wallet.ts","../src/hooks/use-auth.ts","../src/hooks/use-account.ts","../src/hooks/use-payment.ts","../src/hooks/use-escrow.ts","../src/hooks/use-invoice.ts"],"names":["create","createContext","useState","useMemo","UPSClient","useEffect","jsx","useContext","useMutation","useQuery","useQueryClient"],"mappings":";;;;;;;;;AAqBO,IAAM,WAAA,GAAcA,cAAA,CAAiB,CAAC,GAAA,MAAS;AAAA,EAClD,MAAA,EAAQ,IAAA;AAAA,EACR,WAAW,CAAC,MAAA,KAAW,GAAA,CAAI,EAAE,QAAQ,CAAA;AAAA,EAErC,WAAA,EAAa;AAAA,IACT,OAAA,EAAS,IAAA;AAAA,IACT,OAAA,EAAS,IAAA;AAAA,IACT,WAAA,EAAa,KAAA;AAAA,IACb,QAAA,EAAU;AAAA,GACd;AAAA,EACA,gBAAgB,CAAC,WAAA,KAAgB,GAAA,CAAI,EAAE,aAAa,CAAA;AAAA,EAEpD,SAAA,EAAW;AAAA,IACP,eAAA,EAAiB,KAAA;AAAA,IACjB,KAAA,EAAO,IAAA;AAAA,IACP,SAAA,EAAW,IAAA;AAAA,IACX,OAAA,EAAS;AAAA,GACb;AAAA,EACA,cAAc,CAAC,SAAA,KAAc,GAAA,CAAI,EAAE,WAAW,CAAA;AAAA,EAE9C,cAAA,EAAgB,IAAA;AAAA,EAChB,mBAAmB,CAAC,cAAA,KAAmB,GAAA,CAAI,EAAE,gBAAgB;AACjE,CAAA,CAAE;AClCF,IAAM,aAAaC,mBAAA,CAA+B;AAAA,EAC9C,MAAA,EAAQ,IAAA;AAAA,EACR,aAAA,EAAe;AACnB,CAAC,CAAA;AAOM,IAAM,WAAA,GAAc,CAAC,EAAE,MAAA,EAAQ,UAAS,KAAwB;AACnE,EAAA,MAAM,SAAA,GAAY,WAAA,CAAY,CAAC,KAAA,KAAU,MAAM,SAAS,CAAA;AACxD,EAAA,MAAM,cAAA,GAAiB,WAAA,CAAY,C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A;AAAA,IACf,OAAO,QAAA,CAAS;AAAA,GACpB;AACJ;AAQO,SAAS,gBAAA,GAA2C;AACvD,EAAA,MAAM,SAAS,YAAA,EAAa;AAC5B,EAAA,MAAM,cAAcE,yBAAAA,EAAe;AAEnC,EAAA,MAAM,WAAWF,sBAAAA,CAAY;AAAA,IACzB,YAAY,CAAC,EAAA,KAAe,MAAA,CAAO,OAAA,CAAQ,OAAO,EAAE,CAAA;AAAA,IACpD,SAAA,EAAW,CAAC,IAAA,KAAS;AACjB,MAAA,WAAA,CAAY,iBAAA,CAAkB,EAAE,QAAA,EAAU,WAAA,CAAY,OAAO,IAAA,CAAK,OAAA,CAAQ,UAAU,CAAA,EAAG,CAAA;AACvF,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,WAAA,CAAY,IAAA,IAAQ,CAAA;AAAA,IAClE;AAAA,GACH,CAAA;AAED,EAAA,OAAO;AAAA,IACH,eAAe,QAAA,CAAS,WAAA;AAAA,IACxB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GACpB;AACJ","file":"index.js","sourcesContent":["import { create } from 'zustand';\nimport type { UPSClient, WalletState, AuthState, Account } from '@gatewayfm/ups-sdk';\n\nexport interface UPSStore {\n // Client instance\n client: UPSClient | null;\n setClient: (client: UPSClient | null) => void;\n\n // Wallet state (synced from SDK)\n walletState: WalletState;\n setWalletState: (state: WalletState) => void;\n\n // Auth state (synced from SDK)\n authState: AuthState;\n setAuthState: (state: AuthState) => void;\n\n // Current user's account (after creation)\n currentAccount: Account | null;\n setCurrentAccount: (account: Account | null) => void;\n}\n\nexport const useUPSStore = create<UPSStore>((set) => ({\n client: null,\n setClient: (client) => set({ client }),\n\n walletState: {\n address: null,\n chainId: null,\n isConnected: false,\n provider: null,\n },\n setWalletState: (walletState) => set({ walletState }),\n\n authState: {\n isAuthenticated: false,\n token: null,\n expiresAt: null,\n address: null,\n },\n setAuthState: (authState) => set({ authState }),\n\n currentAccount: null,\n setCurrentAccount: (currentAccount) => set({ currentAccount }),\n}));\n","import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';\nimport { UPSClient, type UPSConfig } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from './store';\n\ninterface UPSContextValue {\n client: UPSClient | null;\n isInitialized: boolean;\n}\n\nconst UPSContext = createContext<UPSContextValue>({\n client: null,\n isInitialized: false,\n});\n\nexport interface UPSProviderProps {\n config: UPSConfig;\n children: React.ReactNode;\n}\n\nexport const UPSProvider = ({ config, children }: UPSProviderProps) => {\n const setClient = useUPSStore((state) => state.setClient);\n const setWalletState = useUPSStore((state) => state.setWalletState);\n const setAuthState = useUPSStore((state) => state.setAuthState);\n const [isInitialized, setIsInitialized] = useState(false);\n\n // Initialize client only once (or when config deep changes, but strictly speaking config shouldn't change often)\n // We use useMemo to hold the instance.\n const client = useMemo(() => {\n return new UPSClient(config);\n }, [JSON.stringify(config)]);\n\n useEffect(() => {\n setClient(client);\n\n // Subscribe to state changes\n const unsubWallet = client.wallet.onStateChange((state) => {\n setWalletState(state);\n });\n\n const unsubAuth = client.auth.onStateChange((state) => {\n setAuthState(state);\n });\n\n // Initial sync\n setWalletState(client.wallet.state);\n setAuthState(client.auth.state);\n\n setIsInitialized(true);\n\n return () => {\n unsubWallet();\n unsubAuth();\n client.destroy();\n setClient(null);\n };\n }, [client, setClient, setWalletState, setAuthState]);\n\n const value = useMemo(() => ({\n client,\n isInitialized\n }), [client, isInitialized]);\n\n return <UPSContext.Provider value={value}>{children}</UPSContext.Provider>;\n};\n\nexport const useUPSContext = () => useContext(UPSContext);\n\nexport const useUPSClient = () => {\n const { client } = useUPSContext();\n if (!client) {\n throw new Error('useUPSClient must be used within a UPSProvider');\n }\n return client;\n};\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type EIP1193Provider, type ConnectedWallet, type WalletState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseWalletReturn {\n // State\n state: WalletState;\n address: string | null;\n chainId: number | null;\n isConnected: boolean;\n\n // Actions (TanStack Query mutations)\n connect: UseMutationResult<ConnectedWallet, Error, EIP1193Provider>;\n disconnect: UseMutationResult<void, Error, void>;\n\n // Direct methods\n signMessage: (message: string) => Promise<string>;\n switchChain: (chainId: number) => Promise<void>;\n}\n\nexport function useWallet(): UseWalletReturn {\n const client = useUPSClient();\n const walletState = useUPSStore((state) => state.walletState);\n\n const connectMutation = useMutation({\n mutationFn: async (provider: EIP1193Provider) => {\n return await client.connect(provider);\n },\n });\n\n const disconnectMutation = useMutation({\n mutationFn: async () => {\n await client.disconnect();\n },\n });\n\n return {\n state: walletState,\n address: walletState.address,\n chainId: walletState.chainId,\n isConnected: walletState.isConnected,\n connect: connectMutation,\n disconnect: disconnectMutation,\n signMessage: (message: string) => client.wallet.signMessage(message),\n switchChain: (chainId: number) => client.wallet.switchChain(chainId),\n };\n}\n\nexport interface UseConnectReturn {\n connect: (provider?: EIP1193Provider) => Promise<ConnectedWallet>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useConnect(): UseConnectReturn {\n const { connect } = useWallet();\n\n const connectFn = async (provider?: EIP1193Provider) => {\n if (provider) {\n return connect.mutateAsync(provider);\n }\n\n // Default to window.ethereum\n if (typeof window !== 'undefined' && (window as unknown as { ethereum: EIP1193Provider }).ethereum) {\n return connect.mutateAsync((window as unknown as { ethereum: EIP1193Provider }).ethereum);\n }\n\n throw new Error('No EIP-1193 provider found (window.ethereum is undefined)');\n };\n\n return {\n connect: connectFn,\n isPending: connect.isPending,\n error: connect.error,\n };\n}\n\nexport interface UseDisconnectReturn {\n disconnect: () => Promise<void>;\n isPending: boolean;\n}\n\nexport function useDisconnect(): UseDisconnectReturn {\n const { disconnect } = useWallet();\n\n return {\n disconnect: async () => {\n await disconnect.mutateAsync();\n },\n isPending: disconnect.isPending,\n };\n}\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type AuthState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseAuthReturn {\n // State\n state: AuthState;\n isAuthenticated: boolean;\n\n // Actions\n authenticate: UseMutationResult<void, Error, void>;\n logout: () => void;\n}\n\nexport function useAuth(): UseAuthReturn {\n const client = useUPSClient();\n const authState = useUPSStore((state) => state.authState);\n\n const authenticateMutation = useMutation({\n mutationFn: async () => {\n await client.authenticate();\n },\n });\n\n return {\n state: authState,\n isAuthenticated: authState.isAuthenticated,\n authenticate: authenticateMutation,\n logout: () => client.auth.logout(),\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport { type Account, type CreateAccountParams, type CreateAccountResponse } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nconst accountKeys = {\n all: ['accounts'] as const,\n list: () => [...accountKeys.all, 'list'] as const,\n detail: (id: string) => [...accountKeys.all, 'detail', id] as const,\n byWallet: (address: string) => [...accountKeys.all, 'wallet', address] as const,\n};\n\nexport function useAccounts(): UseQueryResult<Account[], Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.list(),\n queryFn: () => client.account.list(),\n enabled: isAuthenticated,\n });\n}\n\nexport function useAccount(id: string): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.detail(id),\n queryFn: () => client.account.get(id),\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport function useAccountByWallet(address: string | null): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.byWallet(address || ''),\n queryFn: () => client.account.getByWallet(address!),\n enabled: isAuthenticated && !!address,\n });\n}\n\nexport interface UsePredictAddressReturn {\n predictAddress: (owner: string, salt: string) => Promise<string>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePredictAddress(): UsePredictAddressReturn {\n const client = useUPSClient();\n const mutation = useMutation({\n mutationFn: (params: { owner: string, salt: string }) =>\n client.account.predictAddress({ ownerAddress: params.owner, salt: params.salt }),\n });\n\n return {\n predictAddress: (owner, salt) => mutation.mutateAsync({ owner, salt }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UseCreateAccountReturn {\n createAccount: (params: CreateAccountParams) => Promise<CreateAccountResponse>;\n isPending: boolean;\n error: Error | null;\n data: CreateAccountResponse | undefined;\n reset: () => void;\n}\n\nexport function useCreateAccount(): UseCreateAccountReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n const setCurrentAccount = useUPSStore(state => state.setCurrentAccount);\n\n const mutation = useMutation({\n mutationFn: (params: CreateAccountParams) => client.account.create(params),\n onSuccess: (data) => {\n setCurrentAccount(data.account);\n queryClient.invalidateQueries({ queryKey: accountKeys.list() });\n },\n });\n\n return {\n createAccount: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport function useCurrentAccount(): Account | null {\n return useUPSStore(state => state.currentAccount);\n}\n\nexport function generateSalt(): string {\n const array = new Uint8Array(32);\n if (typeof window !== 'undefined' && window.crypto) {\n window.crypto.getRandomValues(array);\n } else {\n // Fallback for non-browser environments if needed (e.g. during build/test)\n for (let i = 0; i < 32; i++) {\n array[i] = Math.floor(Math.random() * 256);\n }\n }\n return '0x' + Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');\n}\n","import { useMutation } from '@tanstack/react-query';\nimport {\n type PaymentRequirements,\n type SignedAuthorization,\n type VerifyResponse,\n type SettleResponse,\n type Invoice\n} from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\n\nexport interface UsePaymentParams {\n requirements: PaymentRequirements;\n from: string; // Payer SmartAccount address\n}\n\n// PaymentResult is SettleResponse from SDK type\nexport interface UsePaymentReturn {\n pay: (params: UsePaymentParams) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n data: SettleResponse | undefined;\n reset: () => void;\n}\n\nexport function usePayment(): UsePaymentReturn {\n const client = useUPSClient();\n\n // client.payment.pay takes { requirements, from }\n const mutation = useMutation({\n mutationFn: (params: UsePaymentParams) => client.payment.pay({\n requirements: params.requirements,\n from: params.from\n }),\n });\n\n return {\n pay: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport interface UsePaymentVerifyReturn {\n verify: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<VerifyResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentVerify(): UsePaymentVerifyReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.verify(params.signed, params.requirements),\n });\n\n return {\n verify: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UsePaymentSettleReturn {\n settle: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentSettle(): UsePaymentSettleReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.settle(params.signed, params.requirements),\n });\n\n return {\n settle: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UsePayInvoiceParams {\n invoice: Invoice;\n paymentParams: {\n amount: string;\n asset: string;\n network: string;\n payTo?: string;\n from?: string;\n };\n}\n\nexport interface UsePayInvoiceReturn {\n payInvoice: (params: UsePayInvoiceParams) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n data: SettleResponse | undefined;\n}\n\nexport function usePayInvoice(): UsePayInvoiceReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: UsePayInvoiceParams) => client.payment.payInvoice(\n params.invoice,\n params.paymentParams\n ),\n });\n\n return {\n payInvoice: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport { type Escrow, type EscrowActionResponse } from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\nimport { useUPSStore } from '../store';\n\nconst escrowKeys = {\n all: ['escrows'] as const,\n detail: (id: string) => [...escrowKeys.all, 'detail', id] as const,\n};\n\nexport function useEscrow(id: string): UseQueryResult<Escrow, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: escrowKeys.detail(id),\n queryFn: () => client.escrow.get(id),\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport interface UseReleaseEscrowReturn {\n release: (id: string) => Promise<EscrowActionResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useReleaseEscrow(): UseReleaseEscrowReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (id: string) => client.escrow.release(id, client.config.network),\n onSuccess: (data, variables) => {\n // Invalidate using the ID passed to mutate (variables), not data.id because EscrowActionResponse might not have id or it might be different structure\n // EscrowActionResponse: { success, errorReason, transaction, network } - DOES NOT HAVE ID.\n // So we must use 'variables' (the id passed to mutate).\n queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });\n },\n });\n\n return {\n release: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UseRefundEscrowReturn {\n refund: (id: string) => Promise<EscrowActionResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useRefundEscrow(): UseRefundEscrowReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (id: string) => client.escrow.refund(id, client.config.network),\n onSuccess: (data, variables) => {\n queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });\n },\n });\n\n return {\n refund: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport {\n type Invoice,\n type CreateInvoiceRequest,\n type InvoiceResponse,\n type InvoiceListResponse\n} from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\nimport { useUPSStore } from '../store';\n\nconst invoiceKeys = {\n all: ['invoices'] as const,\n list: (params?: any) => [...invoiceKeys.all, 'list', params] as const,\n detail: (id: string) => [...invoiceKeys.all, 'detail', id] as const,\n};\n\nexport function useInvoice(id: string): UseQueryResult<Invoice, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: invoiceKeys.detail(id),\n queryFn: async () => {\n const response = await client.invoice.get(id);\n return response.invoice;\n },\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport interface UseInvoicesParams {\n merchant?: string;\n payer?: string;\n page_size?: number;\n page_token?: string;\n}\n\nexport function useInvoices(params: UseInvoicesParams = {}): UseQueryResult<InvoiceListResponse, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: invoiceKeys.list(params),\n queryFn: () => client.invoice.list(params),\n enabled: isAuthenticated,\n });\n}\n\nexport interface UseCreateInvoiceReturn {\n createInvoice: (request: CreateInvoiceRequest) => Promise<InvoiceResponse>;\n isPending: boolean;\n error: Error | null;\n data: InvoiceResponse | undefined;\n reset: () => void;\n}\n\nexport function useCreateInvoice(): UseCreateInvoiceReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (request: CreateInvoiceRequest) => client.invoice.create(request),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: invoiceKeys.all });\n },\n });\n\n return {\n createInvoice: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport interface UseCancelInvoiceReturn {\n cancelInvoice: (id: string) => Promise<InvoiceResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useCancelInvoice(): UseCancelInvoiceReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (id: string) => client.invoice.cancel(id),\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: invoiceKeys.detail(data.invoice.invoice_id) });\n queryClient.invalidateQueries({ queryKey: invoiceKeys.list() });\n },\n });\n\n return {\n cancelInvoice: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -249,7 +249,124 @@ function usePaymentSettle() {
|
|
|
249
249
|
error: mutation.error
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
+
function usePayInvoice() {
|
|
253
|
+
const client = useUPSClient();
|
|
254
|
+
const mutation = useMutation({
|
|
255
|
+
mutationFn: (params) => client.payment.payInvoice(
|
|
256
|
+
params.invoice,
|
|
257
|
+
params.paymentParams
|
|
258
|
+
)
|
|
259
|
+
});
|
|
260
|
+
return {
|
|
261
|
+
payInvoice: mutation.mutateAsync,
|
|
262
|
+
isPending: mutation.isPending,
|
|
263
|
+
error: mutation.error,
|
|
264
|
+
data: mutation.data
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
var escrowKeys = {
|
|
268
|
+
all: ["escrows"],
|
|
269
|
+
detail: (id) => [...escrowKeys.all, "detail", id]
|
|
270
|
+
};
|
|
271
|
+
function useEscrow(id) {
|
|
272
|
+
const client = useUPSClient();
|
|
273
|
+
const isAuthenticated = useUPSStore((state) => state.authState.isAuthenticated);
|
|
274
|
+
return useQuery({
|
|
275
|
+
queryKey: escrowKeys.detail(id),
|
|
276
|
+
queryFn: () => client.escrow.get(id),
|
|
277
|
+
enabled: isAuthenticated && !!id
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function useReleaseEscrow() {
|
|
281
|
+
const client = useUPSClient();
|
|
282
|
+
const queryClient = useQueryClient();
|
|
283
|
+
const mutation = useMutation({
|
|
284
|
+
mutationFn: (id) => client.escrow.release(id, client.config.network),
|
|
285
|
+
onSuccess: (data, variables) => {
|
|
286
|
+
queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
return {
|
|
290
|
+
release: mutation.mutateAsync,
|
|
291
|
+
isPending: mutation.isPending,
|
|
292
|
+
error: mutation.error
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function useRefundEscrow() {
|
|
296
|
+
const client = useUPSClient();
|
|
297
|
+
const queryClient = useQueryClient();
|
|
298
|
+
const mutation = useMutation({
|
|
299
|
+
mutationFn: (id) => client.escrow.refund(id, client.config.network),
|
|
300
|
+
onSuccess: (data, variables) => {
|
|
301
|
+
queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
refund: mutation.mutateAsync,
|
|
306
|
+
isPending: mutation.isPending,
|
|
307
|
+
error: mutation.error
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
var invoiceKeys = {
|
|
311
|
+
all: ["invoices"],
|
|
312
|
+
list: (params) => [...invoiceKeys.all, "list", params],
|
|
313
|
+
detail: (id) => [...invoiceKeys.all, "detail", id]
|
|
314
|
+
};
|
|
315
|
+
function useInvoice(id) {
|
|
316
|
+
const client = useUPSClient();
|
|
317
|
+
const isAuthenticated = useUPSStore((state) => state.authState.isAuthenticated);
|
|
318
|
+
return useQuery({
|
|
319
|
+
queryKey: invoiceKeys.detail(id),
|
|
320
|
+
queryFn: async () => {
|
|
321
|
+
const response = await client.invoice.get(id);
|
|
322
|
+
return response.invoice;
|
|
323
|
+
},
|
|
324
|
+
enabled: isAuthenticated && !!id
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
function useInvoices(params = {}) {
|
|
328
|
+
const client = useUPSClient();
|
|
329
|
+
const isAuthenticated = useUPSStore((state) => state.authState.isAuthenticated);
|
|
330
|
+
return useQuery({
|
|
331
|
+
queryKey: invoiceKeys.list(params),
|
|
332
|
+
queryFn: () => client.invoice.list(params),
|
|
333
|
+
enabled: isAuthenticated
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
function useCreateInvoice() {
|
|
337
|
+
const client = useUPSClient();
|
|
338
|
+
const queryClient = useQueryClient();
|
|
339
|
+
const mutation = useMutation({
|
|
340
|
+
mutationFn: (request) => client.invoice.create(request),
|
|
341
|
+
onSuccess: () => {
|
|
342
|
+
queryClient.invalidateQueries({ queryKey: invoiceKeys.all });
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
return {
|
|
346
|
+
createInvoice: mutation.mutateAsync,
|
|
347
|
+
isPending: mutation.isPending,
|
|
348
|
+
error: mutation.error,
|
|
349
|
+
data: mutation.data,
|
|
350
|
+
reset: mutation.reset
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function useCancelInvoice() {
|
|
354
|
+
const client = useUPSClient();
|
|
355
|
+
const queryClient = useQueryClient();
|
|
356
|
+
const mutation = useMutation({
|
|
357
|
+
mutationFn: (id) => client.invoice.cancel(id),
|
|
358
|
+
onSuccess: (data) => {
|
|
359
|
+
queryClient.invalidateQueries({ queryKey: invoiceKeys.detail(data.invoice.invoice_id) });
|
|
360
|
+
queryClient.invalidateQueries({ queryKey: invoiceKeys.list() });
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
return {
|
|
364
|
+
cancelInvoice: mutation.mutateAsync,
|
|
365
|
+
isPending: mutation.isPending,
|
|
366
|
+
error: mutation.error
|
|
367
|
+
};
|
|
368
|
+
}
|
|
252
369
|
|
|
253
|
-
export { UPSProvider, generateSalt, useAccount, useAccountByWallet, useAccounts, useAuth, useConnect, useCreateAccount, useCurrentAccount, useDisconnect, usePayment, usePaymentSettle, usePaymentVerify, usePredictAddress, useUPSClient, useUPSContext, useUPSStore, useWallet };
|
|
370
|
+
export { UPSProvider, generateSalt, useAccount, useAccountByWallet, useAccounts, useAuth, useCancelInvoice, useConnect, useCreateAccount, useCreateInvoice, useCurrentAccount, useDisconnect, useEscrow, useInvoice, useInvoices, usePayInvoice, usePayment, usePaymentSettle, usePaymentVerify, usePredictAddress, useRefundEscrow, useReleaseEscrow, useUPSClient, useUPSContext, useUPSStore, useWallet };
|
|
254
371
|
//# sourceMappingURL=index.mjs.map
|
|
255
372
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store.ts","../src/provider.tsx","../src/hooks/use-wallet.ts","../src/hooks/use-auth.ts","../src/hooks/use-account.ts","../src/hooks/use-payment.ts"],"names":["useMutation"],"mappings":";;;;;;;AAqBO,IAAM,WAAA,GAAc,MAAA,CAAiB,CAAC,GAAA,MAAS;AAAA,EAClD,MAAA,EAAQ,IAAA;AAAA,EACR,WAAW,CAAC,MAAA,KAAW,GAAA,CAAI,EAAE,QAAQ,CAAA;AAAA,EAErC,WAAA,EAAa;AAAA,IACT,OAAA,EAAS,IAAA;AAAA,IACT,OAAA,EAAS,IAAA;AAAA,IACT,WAAA,EAAa,KAAA;AAAA,IACb,QAAA,EAAU;AAAA,GACd;AAAA,EACA,gBAAgB,CAAC,WAAA,KAAgB,GAAA,CAAI,EAAE,aAAa,CAAA;AAAA,EAEpD,SAAA,EAAW;AAAA,IACP,eAAA,EAAiB,KAAA;AAAA,IACjB,KAAA,EAAO,IAAA;AAAA,IACP,SAAA,EAAW,IAAA;AAAA,IACX,OAAA,EAAS;AAAA,GACb;AAAA,EACA,cAAc,CAAC,SAAA,KAAc,GAAA,CAAI,EAAE,WAAW,CAAA;AA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AAQ,MAAA,CAAO,YAAY;AAAA,GAC/D,CAAA;AAED,EAAA,OAAO;AAAA,IACH,MAAA,EAAQ,CAAC,MAAA,EAAQ,YAAA,KAAiB,SAAS,WAAA,CAAY,EAAE,MAAA,EAAQ,YAAA,EAAc,CAAA;AAAA,IAC/E,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GACpB;AACJ","file":"index.mjs","sourcesContent":["import { create } from 'zustand';\nimport type { UPSClient, WalletState, AuthState, Account } from '@gatewayfm/ups-sdk';\n\nexport interface UPSStore {\n // Client instance\n client: UPSClient | null;\n setClient: (client: UPSClient | null) => void;\n\n // Wallet state (synced from SDK)\n walletState: WalletState;\n setWalletState: (state: WalletState) => void;\n\n // Auth state (synced from SDK)\n authState: AuthState;\n setAuthState: (state: AuthState) => void;\n\n // Current user's account (after creation)\n currentAccount: Account | null;\n setCurrentAccount: (account: Account | null) => void;\n}\n\nexport const useUPSStore = create<UPSStore>((set) => ({\n client: null,\n setClient: (client) => set({ client }),\n\n walletState: {\n address: null,\n chainId: null,\n isConnected: false,\n provider: null,\n },\n setWalletState: (walletState) => set({ walletState }),\n\n authState: {\n isAuthenticated: false,\n token: null,\n expiresAt: null,\n address: null,\n },\n setAuthState: (authState) => set({ authState }),\n\n currentAccount: null,\n setCurrentAccount: (currentAccount) => set({ currentAccount }),\n}));\n","import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';\nimport { UPSClient, type UPSConfig } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from './store';\n\ninterface UPSContextValue {\n client: UPSClient | null;\n isInitialized: boolean;\n}\n\nconst UPSContext = createContext<UPSContextValue>({\n client: null,\n isInitialized: false,\n});\n\nexport interface UPSProviderProps {\n config: UPSConfig;\n children: React.ReactNode;\n}\n\nexport const UPSProvider = ({ config, children }: UPSProviderProps) => {\n const setClient = useUPSStore((state) => state.setClient);\n const setWalletState = useUPSStore((state) => state.setWalletState);\n const setAuthState = useUPSStore((state) => state.setAuthState);\n const [isInitialized, setIsInitialized] = useState(false);\n\n // Initialize client only once (or when config deep changes, but strictly speaking config shouldn't change often)\n // We use useMemo to hold the instance.\n const client = useMemo(() => {\n return new UPSClient(config);\n }, [JSON.stringify(config)]);\n\n useEffect(() => {\n setClient(client);\n\n // Subscribe to state changes\n const unsubWallet = client.wallet.onStateChange((state) => {\n setWalletState(state);\n });\n\n const unsubAuth = client.auth.onStateChange((state) => {\n setAuthState(state);\n });\n\n // Initial sync\n setWalletState(client.wallet.state);\n setAuthState(client.auth.state);\n\n setIsInitialized(true);\n\n return () => {\n unsubWallet();\n unsubAuth();\n client.destroy();\n setClient(null);\n };\n }, [client, setClient, setWalletState, setAuthState]);\n\n const value = useMemo(() => ({\n client,\n isInitialized\n }), [client, isInitialized]);\n\n return <UPSContext.Provider value={value}>{children}</UPSContext.Provider>;\n};\n\nexport const useUPSContext = () => useContext(UPSContext);\n\nexport const useUPSClient = () => {\n const { client } = useUPSContext();\n if (!client) {\n throw new Error('useUPSClient must be used within a UPSProvider');\n }\n return client;\n};\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type EIP1193Provider, type ConnectedWallet, type WalletState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseWalletReturn {\n // State\n state: WalletState;\n address: string | null;\n chainId: number | null;\n isConnected: boolean;\n\n // Actions (TanStack Query mutations)\n connect: UseMutationResult<ConnectedWallet, Error, EIP1193Provider>;\n disconnect: UseMutationResult<void, Error, void>;\n\n // Direct methods\n signMessage: (message: string) => Promise<string>;\n switchChain: (chainId: number) => Promise<void>;\n}\n\nexport function useWallet(): UseWalletReturn {\n const client = useUPSClient();\n const walletState = useUPSStore((state) => state.walletState);\n\n const connectMutation = useMutation({\n mutationFn: async (provider: EIP1193Provider) => {\n return await client.connect(provider);\n },\n });\n\n const disconnectMutation = useMutation({\n mutationFn: async () => {\n await client.disconnect();\n },\n });\n\n return {\n state: walletState,\n address: walletState.address,\n chainId: walletState.chainId,\n isConnected: walletState.isConnected,\n connect: connectMutation,\n disconnect: disconnectMutation,\n signMessage: (message: string) => client.wallet.signMessage(message),\n switchChain: (chainId: number) => client.wallet.switchChain(chainId),\n };\n}\n\nexport interface UseConnectReturn {\n connect: (provider?: EIP1193Provider) => Promise<ConnectedWallet>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useConnect(): UseConnectReturn {\n const { connect } = useWallet();\n\n const connectFn = async (provider?: EIP1193Provider) => {\n if (provider) {\n return connect.mutateAsync(provider);\n }\n\n // Default to window.ethereum\n if (typeof window !== 'undefined' && (window as unknown as { ethereum: EIP1193Provider }).ethereum) {\n return connect.mutateAsync((window as unknown as { ethereum: EIP1193Provider }).ethereum);\n }\n\n throw new Error('No EIP-1193 provider found (window.ethereum is undefined)');\n };\n\n return {\n connect: connectFn,\n isPending: connect.isPending,\n error: connect.error,\n };\n}\n\nexport interface UseDisconnectReturn {\n disconnect: () => Promise<void>;\n isPending: boolean;\n}\n\nexport function useDisconnect(): UseDisconnectReturn {\n const { disconnect } = useWallet();\n\n return {\n disconnect: async () => {\n await disconnect.mutateAsync();\n },\n isPending: disconnect.isPending,\n };\n}\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type AuthState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseAuthReturn {\n // State\n state: AuthState;\n isAuthenticated: boolean;\n\n // Actions\n authenticate: UseMutationResult<void, Error, void>;\n logout: () => void;\n}\n\nexport function useAuth(): UseAuthReturn {\n const client = useUPSClient();\n const authState = useUPSStore((state) => state.authState);\n\n const authenticateMutation = useMutation({\n mutationFn: async () => {\n await client.authenticate();\n },\n });\n\n return {\n state: authState,\n isAuthenticated: authState.isAuthenticated,\n authenticate: authenticateMutation,\n logout: () => client.auth.logout(),\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport { type Account, type CreateAccountParams, type CreateAccountResponse } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nconst accountKeys = {\n all: ['accounts'] as const,\n list: () => [...accountKeys.all, 'list'] as const,\n detail: (id: string) => [...accountKeys.all, 'detail', id] as const,\n byWallet: (address: string) => [...accountKeys.all, 'wallet', address] as const,\n};\n\nexport function useAccounts(): UseQueryResult<Account[], Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.list(),\n queryFn: () => client.account.list(),\n enabled: isAuthenticated,\n });\n}\n\nexport function useAccount(id: string): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.detail(id),\n queryFn: () => client.account.get(id),\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport function useAccountByWallet(address: string | null): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.byWallet(address || ''),\n queryFn: () => client.account.getByWallet(address!),\n enabled: isAuthenticated && !!address,\n });\n}\n\nexport interface UsePredictAddressReturn {\n predictAddress: (owner: string, salt: string) => Promise<string>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePredictAddress(): UsePredictAddressReturn {\n const client = useUPSClient();\n const mutation = useMutation({\n mutationFn: (params: { owner: string, salt: string }) =>\n client.account.predictAddress({ ownerAddress: params.owner, salt: params.salt }),\n });\n\n return {\n predictAddress: (owner, salt) => mutation.mutateAsync({ owner, salt }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UseCreateAccountReturn {\n createAccount: (params: CreateAccountParams) => Promise<CreateAccountResponse>;\n isPending: boolean;\n error: Error | null;\n data: CreateAccountResponse | undefined;\n reset: () => void;\n}\n\nexport function useCreateAccount(): UseCreateAccountReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n const setCurrentAccount = useUPSStore(state => state.setCurrentAccount);\n\n const mutation = useMutation({\n mutationFn: (params: CreateAccountParams) => client.account.create(params),\n onSuccess: (data) => {\n setCurrentAccount(data.account);\n queryClient.invalidateQueries({ queryKey: accountKeys.list() });\n },\n });\n\n return {\n createAccount: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport function useCurrentAccount(): Account | null {\n return useUPSStore(state => state.currentAccount);\n}\n\nexport function generateSalt(): string {\n const array = new Uint8Array(32);\n if (typeof window !== 'undefined' && window.crypto) {\n window.crypto.getRandomValues(array);\n } else {\n // Fallback for non-browser environments if needed (e.g. during build/test)\n for (let i = 0; i < 32; i++) {\n array[i] = Math.floor(Math.random() * 256);\n }\n }\n return '0x' + Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');\n}\n","import { useMutation } from '@tanstack/react-query';\nimport {\n type PaymentRequirements,\n type SignedAuthorization,\n type VerifyResponse,\n type SettleResponse\n} from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\n\nexport interface UsePaymentParams {\n requirements: PaymentRequirements;\n from: string; // Payer SmartAccount address\n}\n\n// PaymentResult is SettleResponse from SDK type\nexport interface UsePaymentReturn {\n pay: (params: UsePaymentParams) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n data: SettleResponse | undefined;\n reset: () => void;\n}\n\nexport function usePayment(): UsePaymentReturn {\n const client = useUPSClient();\n\n // client.payment.pay takes { requirements, from }\n const mutation = useMutation({\n mutationFn: (params: UsePaymentParams) => client.payment.pay({\n requirements: params.requirements,\n from: params.from\n }),\n });\n\n return {\n pay: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport interface UsePaymentVerifyReturn {\n verify: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<VerifyResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentVerify(): UsePaymentVerifyReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.verify(params.signed, params.requirements),\n });\n\n return {\n verify: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UsePaymentSettleReturn {\n settle: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentSettle(): UsePaymentSettleReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.settle(params.signed, params.requirements),\n });\n\n return {\n settle: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/store.ts","../src/provider.tsx","../src/hooks/use-wallet.ts","../src/hooks/use-auth.ts","../src/hooks/use-account.ts","../src/hooks/use-payment.ts","../src/hooks/use-escrow.ts","../src/hooks/use-invoice.ts"],"names":["useMutation","useQuery","useQueryClient"],"mappings":";;;;;;;AAqBO,IAAM,WAAA,GAAc,MAAA,CAAiB,CAAC,GAAA,MAAS;AAAA,EAClD,MAAA,EAAQ,IAAA;AAAA,EACR,WAAW,CAAC,MAAA,KAAW,GAAA,CAAI,EAAE,QAAQ,CAAA;AAAA,EAErC,WAAA,EAAa;AAAA,IACT,OAAA,EAAS,IAAA;AAAA,IACT,OAAA,EAAS,IAAA;AAAA,IACT,WAAA,EAAa,KAAA;AAAA,IACb,QAAA,EAAU;AAAA,GACd;AAAA,EACA,gBAAgB,CAAC,WAAA,KAAgB,GAAA,CAAI,EAAE,aAAa,CAAA;AAAA,EAEpD,SAAA,EAAW;AAAA,IACP,eAAA,EAAiB,KAAA;AAAA,IACjB,KAAA,EAAO,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letState, AuthState, Account } from '@gatewayfm/ups-sdk';\n\nexport interface UPSStore {\n // Client instance\n client: UPSClient | null;\n setClient: (client: UPSClient | null) => void;\n\n // Wallet state (synced from SDK)\n walletState: WalletState;\n setWalletState: (state: WalletState) => void;\n\n // Auth state (synced from SDK)\n authState: AuthState;\n setAuthState: (state: AuthState) => void;\n\n // Current user's account (after creation)\n currentAccount: Account | null;\n setCurrentAccount: (account: Account | null) => void;\n}\n\nexport const useUPSStore = create<UPSStore>((set) => ({\n client: null,\n setClient: (client) => set({ client }),\n\n walletState: {\n address: null,\n chainId: null,\n isConnected: false,\n provider: null,\n },\n setWalletState: (walletState) => set({ walletState }),\n\n authState: {\n isAuthenticated: false,\n token: null,\n expiresAt: null,\n address: null,\n },\n setAuthState: (authState) => set({ authState }),\n\n currentAccount: null,\n setCurrentAccount: (currentAccount) => set({ currentAccount }),\n}));\n","import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';\nimport { UPSClient, type UPSConfig } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from './store';\n\ninterface UPSContextValue {\n client: UPSClient | null;\n isInitialized: boolean;\n}\n\nconst UPSContext = createContext<UPSContextValue>({\n client: null,\n isInitialized: false,\n});\n\nexport interface UPSProviderProps {\n config: UPSConfig;\n children: React.ReactNode;\n}\n\nexport const UPSProvider = ({ config, children }: UPSProviderProps) => {\n const setClient = useUPSStore((state) => state.setClient);\n const setWalletState = useUPSStore((state) => state.setWalletState);\n const setAuthState = useUPSStore((state) => state.setAuthState);\n const [isInitialized, setIsInitialized] = useState(false);\n\n // Initialize client only once (or when config deep changes, but strictly speaking config shouldn't change often)\n // We use useMemo to hold the instance.\n const client = useMemo(() => {\n return new UPSClient(config);\n }, [JSON.stringify(config)]);\n\n useEffect(() => {\n setClient(client);\n\n // Subscribe to state changes\n const unsubWallet = client.wallet.onStateChange((state) => {\n setWalletState(state);\n });\n\n const unsubAuth = client.auth.onStateChange((state) => {\n setAuthState(state);\n });\n\n // Initial sync\n setWalletState(client.wallet.state);\n setAuthState(client.auth.state);\n\n setIsInitialized(true);\n\n return () => {\n unsubWallet();\n unsubAuth();\n client.destroy();\n setClient(null);\n };\n }, [client, setClient, setWalletState, setAuthState]);\n\n const value = useMemo(() => ({\n client,\n isInitialized\n }), [client, isInitialized]);\n\n return <UPSContext.Provider value={value}>{children}</UPSContext.Provider>;\n};\n\nexport const useUPSContext = () => useContext(UPSContext);\n\nexport const useUPSClient = () => {\n const { client } = useUPSContext();\n if (!client) {\n throw new Error('useUPSClient must be used within a UPSProvider');\n }\n return client;\n};\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type EIP1193Provider, type ConnectedWallet, type WalletState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseWalletReturn {\n // State\n state: WalletState;\n address: string | null;\n chainId: number | null;\n isConnected: boolean;\n\n // Actions (TanStack Query mutations)\n connect: UseMutationResult<ConnectedWallet, Error, EIP1193Provider>;\n disconnect: UseMutationResult<void, Error, void>;\n\n // Direct methods\n signMessage: (message: string) => Promise<string>;\n switchChain: (chainId: number) => Promise<void>;\n}\n\nexport function useWallet(): UseWalletReturn {\n const client = useUPSClient();\n const walletState = useUPSStore((state) => state.walletState);\n\n const connectMutation = useMutation({\n mutationFn: async (provider: EIP1193Provider) => {\n return await client.connect(provider);\n },\n });\n\n const disconnectMutation = useMutation({\n mutationFn: async () => {\n await client.disconnect();\n },\n });\n\n return {\n state: walletState,\n address: walletState.address,\n chainId: walletState.chainId,\n isConnected: walletState.isConnected,\n connect: connectMutation,\n disconnect: disconnectMutation,\n signMessage: (message: string) => client.wallet.signMessage(message),\n switchChain: (chainId: number) => client.wallet.switchChain(chainId),\n };\n}\n\nexport interface UseConnectReturn {\n connect: (provider?: EIP1193Provider) => Promise<ConnectedWallet>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useConnect(): UseConnectReturn {\n const { connect } = useWallet();\n\n const connectFn = async (provider?: EIP1193Provider) => {\n if (provider) {\n return connect.mutateAsync(provider);\n }\n\n // Default to window.ethereum\n if (typeof window !== 'undefined' && (window as unknown as { ethereum: EIP1193Provider }).ethereum) {\n return connect.mutateAsync((window as unknown as { ethereum: EIP1193Provider }).ethereum);\n }\n\n throw new Error('No EIP-1193 provider found (window.ethereum is undefined)');\n };\n\n return {\n connect: connectFn,\n isPending: connect.isPending,\n error: connect.error,\n };\n}\n\nexport interface UseDisconnectReturn {\n disconnect: () => Promise<void>;\n isPending: boolean;\n}\n\nexport function useDisconnect(): UseDisconnectReturn {\n const { disconnect } = useWallet();\n\n return {\n disconnect: async () => {\n await disconnect.mutateAsync();\n },\n isPending: disconnect.isPending,\n };\n}\n","import { useMutation, UseMutationResult } from '@tanstack/react-query';\nimport { type AuthState } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nexport interface UseAuthReturn {\n // State\n state: AuthState;\n isAuthenticated: boolean;\n\n // Actions\n authenticate: UseMutationResult<void, Error, void>;\n logout: () => void;\n}\n\nexport function useAuth(): UseAuthReturn {\n const client = useUPSClient();\n const authState = useUPSStore((state) => state.authState);\n\n const authenticateMutation = useMutation({\n mutationFn: async () => {\n await client.authenticate();\n },\n });\n\n return {\n state: authState,\n isAuthenticated: authState.isAuthenticated,\n authenticate: authenticateMutation,\n logout: () => client.auth.logout(),\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport { type Account, type CreateAccountParams, type CreateAccountResponse } from '@gatewayfm/ups-sdk';\nimport { useUPSStore } from '../store';\nimport { useUPSClient } from '../provider';\n\nconst accountKeys = {\n all: ['accounts'] as const,\n list: () => [...accountKeys.all, 'list'] as const,\n detail: (id: string) => [...accountKeys.all, 'detail', id] as const,\n byWallet: (address: string) => [...accountKeys.all, 'wallet', address] as const,\n};\n\nexport function useAccounts(): UseQueryResult<Account[], Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.list(),\n queryFn: () => client.account.list(),\n enabled: isAuthenticated,\n });\n}\n\nexport function useAccount(id: string): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.detail(id),\n queryFn: () => client.account.get(id),\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport function useAccountByWallet(address: string | null): UseQueryResult<Account, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: accountKeys.byWallet(address || ''),\n queryFn: () => client.account.getByWallet(address!),\n enabled: isAuthenticated && !!address,\n });\n}\n\nexport interface UsePredictAddressReturn {\n predictAddress: (owner: string, salt: string) => Promise<string>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePredictAddress(): UsePredictAddressReturn {\n const client = useUPSClient();\n const mutation = useMutation({\n mutationFn: (params: { owner: string, salt: string }) =>\n client.account.predictAddress({ ownerAddress: params.owner, salt: params.salt }),\n });\n\n return {\n predictAddress: (owner, salt) => mutation.mutateAsync({ owner, salt }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UseCreateAccountReturn {\n createAccount: (params: CreateAccountParams) => Promise<CreateAccountResponse>;\n isPending: boolean;\n error: Error | null;\n data: CreateAccountResponse | undefined;\n reset: () => void;\n}\n\nexport function useCreateAccount(): UseCreateAccountReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n const setCurrentAccount = useUPSStore(state => state.setCurrentAccount);\n\n const mutation = useMutation({\n mutationFn: (params: CreateAccountParams) => client.account.create(params),\n onSuccess: (data) => {\n setCurrentAccount(data.account);\n queryClient.invalidateQueries({ queryKey: accountKeys.list() });\n },\n });\n\n return {\n createAccount: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport function useCurrentAccount(): Account | null {\n return useUPSStore(state => state.currentAccount);\n}\n\nexport function generateSalt(): string {\n const array = new Uint8Array(32);\n if (typeof window !== 'undefined' && window.crypto) {\n window.crypto.getRandomValues(array);\n } else {\n // Fallback for non-browser environments if needed (e.g. during build/test)\n for (let i = 0; i < 32; i++) {\n array[i] = Math.floor(Math.random() * 256);\n }\n }\n return '0x' + Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');\n}\n","import { useMutation } from '@tanstack/react-query';\nimport {\n type PaymentRequirements,\n type SignedAuthorization,\n type VerifyResponse,\n type SettleResponse,\n type Invoice\n} from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\n\nexport interface UsePaymentParams {\n requirements: PaymentRequirements;\n from: string; // Payer SmartAccount address\n}\n\n// PaymentResult is SettleResponse from SDK type\nexport interface UsePaymentReturn {\n pay: (params: UsePaymentParams) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n data: SettleResponse | undefined;\n reset: () => void;\n}\n\nexport function usePayment(): UsePaymentReturn {\n const client = useUPSClient();\n\n // client.payment.pay takes { requirements, from }\n const mutation = useMutation({\n mutationFn: (params: UsePaymentParams) => client.payment.pay({\n requirements: params.requirements,\n from: params.from\n }),\n });\n\n return {\n pay: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport interface UsePaymentVerifyReturn {\n verify: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<VerifyResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentVerify(): UsePaymentVerifyReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.verify(params.signed, params.requirements),\n });\n\n return {\n verify: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UsePaymentSettleReturn {\n settle: (signed: SignedAuthorization, requirements: PaymentRequirements) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function usePaymentSettle(): UsePaymentSettleReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: { signed: SignedAuthorization, requirements: PaymentRequirements }) =>\n client.payment.settle(params.signed, params.requirements),\n });\n\n return {\n settle: (signed, requirements) => mutation.mutateAsync({ signed, requirements }),\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UsePayInvoiceParams {\n invoice: Invoice;\n paymentParams: {\n amount: string;\n asset: string;\n network: string;\n payTo?: string;\n from?: string;\n };\n}\n\nexport interface UsePayInvoiceReturn {\n payInvoice: (params: UsePayInvoiceParams) => Promise<SettleResponse>;\n isPending: boolean;\n error: Error | null;\n data: SettleResponse | undefined;\n}\n\nexport function usePayInvoice(): UsePayInvoiceReturn {\n const client = useUPSClient();\n\n const mutation = useMutation({\n mutationFn: (params: UsePayInvoiceParams) => client.payment.payInvoice(\n params.invoice,\n params.paymentParams\n ),\n });\n\n return {\n payInvoice: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport { type Escrow, type EscrowActionResponse } from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\nimport { useUPSStore } from '../store';\n\nconst escrowKeys = {\n all: ['escrows'] as const,\n detail: (id: string) => [...escrowKeys.all, 'detail', id] as const,\n};\n\nexport function useEscrow(id: string): UseQueryResult<Escrow, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: escrowKeys.detail(id),\n queryFn: () => client.escrow.get(id),\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport interface UseReleaseEscrowReturn {\n release: (id: string) => Promise<EscrowActionResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useReleaseEscrow(): UseReleaseEscrowReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (id: string) => client.escrow.release(id, client.config.network),\n onSuccess: (data, variables) => {\n // Invalidate using the ID passed to mutate (variables), not data.id because EscrowActionResponse might not have id or it might be different structure\n // EscrowActionResponse: { success, errorReason, transaction, network } - DOES NOT HAVE ID.\n // So we must use 'variables' (the id passed to mutate).\n queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });\n },\n });\n\n return {\n release: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n\nexport interface UseRefundEscrowReturn {\n refund: (id: string) => Promise<EscrowActionResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useRefundEscrow(): UseRefundEscrowReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (id: string) => client.escrow.refund(id, client.config.network),\n onSuccess: (data, variables) => {\n queryClient.invalidateQueries({ queryKey: escrowKeys.detail(variables) });\n },\n });\n\n return {\n refund: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n","import { useQuery, useMutation, useQueryClient, UseQueryResult } from '@tanstack/react-query';\nimport {\n type Invoice,\n type CreateInvoiceRequest,\n type InvoiceResponse,\n type InvoiceListResponse\n} from '@gatewayfm/ups-sdk';\nimport { useUPSClient } from '../provider';\nimport { useUPSStore } from '../store';\n\nconst invoiceKeys = {\n all: ['invoices'] as const,\n list: (params?: any) => [...invoiceKeys.all, 'list', params] as const,\n detail: (id: string) => [...invoiceKeys.all, 'detail', id] as const,\n};\n\nexport function useInvoice(id: string): UseQueryResult<Invoice, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: invoiceKeys.detail(id),\n queryFn: async () => {\n const response = await client.invoice.get(id);\n return response.invoice;\n },\n enabled: isAuthenticated && !!id,\n });\n}\n\nexport interface UseInvoicesParams {\n merchant?: string;\n payer?: string;\n page_size?: number;\n page_token?: string;\n}\n\nexport function useInvoices(params: UseInvoicesParams = {}): UseQueryResult<InvoiceListResponse, Error> {\n const client = useUPSClient();\n const isAuthenticated = useUPSStore(state => state.authState.isAuthenticated);\n\n return useQuery({\n queryKey: invoiceKeys.list(params),\n queryFn: () => client.invoice.list(params),\n enabled: isAuthenticated,\n });\n}\n\nexport interface UseCreateInvoiceReturn {\n createInvoice: (request: CreateInvoiceRequest) => Promise<InvoiceResponse>;\n isPending: boolean;\n error: Error | null;\n data: InvoiceResponse | undefined;\n reset: () => void;\n}\n\nexport function useCreateInvoice(): UseCreateInvoiceReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (request: CreateInvoiceRequest) => client.invoice.create(request),\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: invoiceKeys.all });\n },\n });\n\n return {\n createInvoice: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n data: mutation.data,\n reset: mutation.reset,\n };\n}\n\nexport interface UseCancelInvoiceReturn {\n cancelInvoice: (id: string) => Promise<InvoiceResponse>;\n isPending: boolean;\n error: Error | null;\n}\n\nexport function useCancelInvoice(): UseCancelInvoiceReturn {\n const client = useUPSClient();\n const queryClient = useQueryClient();\n\n const mutation = useMutation({\n mutationFn: (id: string) => client.invoice.cancel(id),\n onSuccess: (data) => {\n queryClient.invalidateQueries({ queryKey: invoiceKeys.detail(data.invoice.invoice_id) });\n queryClient.invalidateQueries({ queryKey: invoiceKeys.list() });\n },\n });\n\n return {\n cancelInvoice: mutation.mutateAsync,\n isPending: mutation.isPending,\n error: mutation.error,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gatewayfm/ups-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "React hooks and providers for UPS x402 SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"zustand": "^5.0.10",
|
|
28
|
-
"@gatewayfm/ups-sdk": "0.1.
|
|
28
|
+
"@gatewayfm/ups-sdk": "0.1.16"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": "^19.2.4",
|
|
32
32
|
"@tanstack/react-query": "^5.0.0",
|
|
33
|
-
"@gatewayfm/ups-sdk": "0.1.
|
|
33
|
+
"@gatewayfm/ups-sdk": "0.1.16"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"react": "^19.2.4",
|