@oxyhq/services 6.10.3 → 6.10.4
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/lib/commonjs/index.js +32 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/index.js +31 -0
- package/lib/commonjs/ui/hooks/queries/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/paymentTypes.js +2 -0
- package/lib/commonjs/ui/hooks/queries/paymentTypes.js.map +1 -0
- package/lib/commonjs/ui/hooks/queries/queryKeys.js +13 -0
- package/lib/commonjs/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/usePaymentQueries.js +140 -0
- package/lib/commonjs/ui/hooks/queries/usePaymentQueries.js.map +1 -0
- package/lib/commonjs/ui/hooks/queries/useServicesQueries.js +26 -1
- package/lib/commonjs/ui/hooks/queries/useServicesQueries.js.map +1 -1
- package/lib/commonjs/ui/hooks/queryClient.js +1 -1
- package/lib/commonjs/ui/hooks/queryClient.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/hooks/queries/index.js +7 -2
- package/lib/module/ui/hooks/queries/index.js.map +1 -1
- package/lib/module/ui/hooks/queries/paymentTypes.js +2 -0
- package/lib/module/ui/hooks/queries/paymentTypes.js.map +1 -0
- package/lib/module/ui/hooks/queries/queryKeys.js +13 -0
- package/lib/module/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/module/ui/hooks/queries/usePaymentQueries.js +132 -0
- package/lib/module/ui/hooks/queries/usePaymentQueries.js.map +1 -0
- package/lib/module/ui/hooks/queries/useServicesQueries.js +24 -0
- package/lib/module/ui/hooks/queries/useServicesQueries.js.map +1 -1
- package/lib/module/ui/hooks/queryClient.js +1 -1
- package/lib/module/ui/hooks/queryClient.js.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -1
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/index.d.ts +3 -1
- package/lib/typescript/commonjs/ui/hooks/queries/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/paymentTypes.d.ts +137 -0
- package/lib/typescript/commonjs/ui/hooks/queries/paymentTypes.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/queries/queryKeys.d.ts +11 -0
- package/lib/typescript/commonjs/ui/hooks/queries/queryKeys.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queries/usePaymentQueries.d.ts +63 -0
- package/lib/typescript/commonjs/ui/hooks/queries/usePaymentQueries.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/queries/useServicesQueries.d.ts +11 -1
- package/lib/typescript/commonjs/ui/hooks/queries/useServicesQueries.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/queryClient.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -1
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/index.d.ts +3 -1
- package/lib/typescript/module/ui/hooks/queries/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/paymentTypes.d.ts +137 -0
- package/lib/typescript/module/ui/hooks/queries/paymentTypes.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/queries/queryKeys.d.ts +11 -0
- package/lib/typescript/module/ui/hooks/queries/queryKeys.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queries/usePaymentQueries.d.ts +63 -0
- package/lib/typescript/module/ui/hooks/queries/usePaymentQueries.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/queries/useServicesQueries.d.ts +11 -1
- package/lib/typescript/module/ui/hooks/queries/useServicesQueries.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/queryClient.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +9 -0
- package/src/ui/hooks/queries/index.ts +25 -1
- package/src/ui/hooks/queries/paymentTypes.ts +141 -0
- package/src/ui/hooks/queries/queryKeys.ts +26 -0
- package/src/ui/hooks/queries/usePaymentQueries.ts +136 -0
- package/src/ui/hooks/queries/useServicesQueries.ts +26 -1
- package/src/ui/hooks/queryClient.ts +1 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment / wallet / subscription domain types.
|
|
3
|
+
*
|
|
4
|
+
* These model the JSON shapes the Oxy API actually returns for the
|
|
5
|
+
* payment-related read endpoints, so the corresponding query hooks
|
|
6
|
+
* (`useUserSubscription`, `useUserPayments`, `useUserWallet`,
|
|
7
|
+
* `useUserWalletTransactions`) expose precise types instead of `any`.
|
|
8
|
+
*
|
|
9
|
+
* Source of truth (API):
|
|
10
|
+
* - Subscription: GET /subscription/:userId -> `Subscription` model JSON,
|
|
11
|
+
* or the fallback `{ plan: 'basic' }` when none exists.
|
|
12
|
+
* - Payments: GET /payments/user -> `Payment[]` (sendSuccess).
|
|
13
|
+
* - Wallet: GET /wallet/:userId -> `Wallet` (sendSuccess).
|
|
14
|
+
* - Transactions: GET /wallet/transactions/:userId
|
|
15
|
+
* -> `WalletTransactionsResponse` (sendPaginated envelope).
|
|
16
|
+
*
|
|
17
|
+
* All `Date` columns are serialized as ISO-8601 strings over the wire.
|
|
18
|
+
*
|
|
19
|
+
* Note: `@oxyhq/services` deliberately does NOT re-export these from
|
|
20
|
+
* `@oxyhq/core`. They live here because they describe the return shape of
|
|
21
|
+
* the services-layer query hooks; consumers that need core domain types
|
|
22
|
+
* import those directly from `@oxyhq/core`.
|
|
23
|
+
*/
|
|
24
|
+
/** Subscription tier. Mirrors the `plan` enum on the API `Subscription` model. */
|
|
25
|
+
export type SubscriptionPlan = 'basic' | 'pro' | 'business';
|
|
26
|
+
/** Lifecycle state of a subscription. */
|
|
27
|
+
export type SubscriptionStatus = 'active' | 'canceled' | 'expired';
|
|
28
|
+
/** Feature flags toggled by the active subscription plan. */
|
|
29
|
+
export interface SubscriptionFeatures {
|
|
30
|
+
analytics: boolean;
|
|
31
|
+
premiumBadge: boolean;
|
|
32
|
+
unlimitedFollowing: boolean;
|
|
33
|
+
higherUploadLimits: boolean;
|
|
34
|
+
promotedPosts: boolean;
|
|
35
|
+
businessTools: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A user's subscription.
|
|
39
|
+
*
|
|
40
|
+
* When a user has never subscribed, the API returns the minimal fallback
|
|
41
|
+
* `{ plan: 'basic' }`; every other field is therefore optional so the type
|
|
42
|
+
* covers both the persisted document and the fallback.
|
|
43
|
+
*/
|
|
44
|
+
export interface Subscription {
|
|
45
|
+
plan: SubscriptionPlan;
|
|
46
|
+
status?: SubscriptionStatus;
|
|
47
|
+
/** Account this subscription belongs to (absent on the basic fallback). */
|
|
48
|
+
userId?: string;
|
|
49
|
+
/** ISO-8601 timestamp the current period started. */
|
|
50
|
+
startDate?: string;
|
|
51
|
+
/** ISO-8601 timestamp the current period ends / renews. */
|
|
52
|
+
endDate?: string;
|
|
53
|
+
autoRenew?: boolean;
|
|
54
|
+
paymentMethod?: string;
|
|
55
|
+
latestInvoice?: string;
|
|
56
|
+
features?: SubscriptionFeatures;
|
|
57
|
+
/** ISO-8601 creation timestamp. */
|
|
58
|
+
createdAt?: string;
|
|
59
|
+
/** ISO-8601 last-update timestamp. */
|
|
60
|
+
updatedAt?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A billing / payment history entry, derived from `deposit` and `purchase`
|
|
64
|
+
* transactions on the API side (`GET /payments/user`).
|
|
65
|
+
*/
|
|
66
|
+
export interface Payment {
|
|
67
|
+
id: string;
|
|
68
|
+
userId: string;
|
|
69
|
+
type: string;
|
|
70
|
+
amount: number;
|
|
71
|
+
status: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
itemId?: string;
|
|
74
|
+
itemType?: string;
|
|
75
|
+
/** ISO-8601 timestamp the payment was created (maps to `createdAt`). */
|
|
76
|
+
timestamp?: string;
|
|
77
|
+
/** ISO-8601 timestamp the payment settled, when applicable. */
|
|
78
|
+
completedAt?: string;
|
|
79
|
+
}
|
|
80
|
+
/** FairCoin wallet balance for a user (`GET /wallet/:userId`). */
|
|
81
|
+
export interface Wallet {
|
|
82
|
+
userId: string;
|
|
83
|
+
balance: number;
|
|
84
|
+
/** On-chain withdrawal address, `null` until one is set. */
|
|
85
|
+
address: string | null;
|
|
86
|
+
}
|
|
87
|
+
/** Direction/category of a wallet transaction. */
|
|
88
|
+
export type WalletTransactionType = 'deposit' | 'withdrawal' | 'transfer' | 'purchase';
|
|
89
|
+
/** Settlement state of a wallet transaction. */
|
|
90
|
+
export type WalletTransactionStatus = 'pending' | 'completed' | 'failed' | 'cancelled';
|
|
91
|
+
/**
|
|
92
|
+
* A single wallet ledger entry returned by the transaction-history endpoint.
|
|
93
|
+
*
|
|
94
|
+
* The populated `userId` / `recipientId` may arrive either as a bare id
|
|
95
|
+
* string or as a `{ _id, username }` object depending on Mongoose
|
|
96
|
+
* population, so both shapes are modelled.
|
|
97
|
+
*/
|
|
98
|
+
export interface WalletTransaction {
|
|
99
|
+
id: string;
|
|
100
|
+
userId: string | {
|
|
101
|
+
_id: string;
|
|
102
|
+
username?: string;
|
|
103
|
+
};
|
|
104
|
+
type: WalletTransactionType;
|
|
105
|
+
amount: number;
|
|
106
|
+
status: WalletTransactionStatus;
|
|
107
|
+
description?: string;
|
|
108
|
+
recipientId?: string | {
|
|
109
|
+
_id: string;
|
|
110
|
+
username?: string;
|
|
111
|
+
} | null;
|
|
112
|
+
itemId?: string;
|
|
113
|
+
itemType?: string;
|
|
114
|
+
/** ISO-8601 creation timestamp (maps to `createdAt`). */
|
|
115
|
+
timestamp?: string;
|
|
116
|
+
/** ISO-8601 settlement timestamp, when applicable. */
|
|
117
|
+
completedAt?: string;
|
|
118
|
+
}
|
|
119
|
+
/** Pagination metadata attached to a paginated list response. */
|
|
120
|
+
export interface WalletPagination {
|
|
121
|
+
total: number;
|
|
122
|
+
limit: number;
|
|
123
|
+
offset: number;
|
|
124
|
+
hasMore: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Paginated envelope returned by `GET /wallet/transactions/:userId`.
|
|
128
|
+
*
|
|
129
|
+
* The HTTP layer preserves the `{ data, pagination }` shape for paginated
|
|
130
|
+
* responses (it only unwraps the plain `{ data }` success envelope), so
|
|
131
|
+
* callers receive the list under `data`.
|
|
132
|
+
*/
|
|
133
|
+
export interface WalletTransactionsResponse {
|
|
134
|
+
data: WalletTransaction[];
|
|
135
|
+
pagination: WalletPagination;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=paymentTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentTypes.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/hooks/queries/paymentTypes.ts"],"names":[],"mappings":"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"}
|
|
@@ -50,6 +50,17 @@ export declare const queryKeys: {
|
|
|
50
50
|
readonly recent: (limit: number) => readonly ["security", "recent", number];
|
|
51
51
|
readonly infinite: (limit: number, eventType?: string) => readonly ["security", "infinite", number, string | undefined];
|
|
52
52
|
};
|
|
53
|
+
readonly storage: {
|
|
54
|
+
readonly all: readonly ["storage"];
|
|
55
|
+
readonly usage: () => readonly ["storage", "usage"];
|
|
56
|
+
};
|
|
57
|
+
readonly payments: {
|
|
58
|
+
readonly all: readonly ["payments"];
|
|
59
|
+
readonly subscription: (userId?: string) => readonly ["payments", "subscription", string];
|
|
60
|
+
readonly history: (userId?: string) => readonly ["payments", "history", string];
|
|
61
|
+
readonly wallet: (userId?: string) => readonly ["payments", "wallet", string];
|
|
62
|
+
readonly walletTransactions: (limit?: number, offset?: number, userId?: string) => readonly ["payments", "wallet", string, "transactions", number | undefined, number | undefined];
|
|
63
|
+
};
|
|
53
64
|
};
|
|
54
65
|
/**
|
|
55
66
|
* Helper to invalidate all account-related queries
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryKeys.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/hooks/queries/queryKeys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS;;;;oCAKC,MAAM,EAAE;;qCAEP,MAAM;;;;;;;iCASV,MAAM,EAAE;;kCAEP,MAAM;sCACF,MAAM;;;;;iCAOX,MAAM;;qCAEF,MAAM;;oCAEP,MAAM;;;;;iCAOT,MAAM;;oCAEH,MAAM;;;;qCAML,MAAM;;;;oCAMP,MAAM,WAAW,MAAM,cAAc,MAAM;iCAE9C,MAAM;mCAEJ,MAAM,cAAc,MAAM;;
|
|
1
|
+
{"version":3,"file":"queryKeys.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/hooks/queries/queryKeys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS;;;;oCAKC,MAAM,EAAE;;qCAEP,MAAM;;;;;;;iCASV,MAAM,EAAE;;kCAEP,MAAM;sCACF,MAAM;;;;;iCAOX,MAAM;;qCAEF,MAAM;;oCAEP,MAAM;;;;;iCAOT,MAAM;;oCAEH,MAAM;;;;qCAML,MAAM;;;;oCAMP,MAAM,WAAW,MAAM,cAAc,MAAM;iCAE9C,MAAM;mCAEJ,MAAM,cAAc,MAAM;;;;;;;;yCAapB,MAAM;oCAEX,MAAM;mCAEP,MAAM;8CAEK,MAAM,WAAW,MAAM,WAAW,MAAM;;CAU/D,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,aAAa,GAAG,SAExD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,aAAa,GAAG,SAErD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,aAAa,GAAG,SAExD,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Subscription, Payment, Wallet, WalletTransactionsResponse } from './paymentTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Payment / wallet / subscription query hooks.
|
|
4
|
+
*
|
|
5
|
+
* These replace the imperative `oxyServices.*` + `Promise.allSettled` +
|
|
6
|
+
* `useEffect` pattern used in app screens. Each hook:
|
|
7
|
+
* - is gated on `isAuthenticated` (the underlying SDK methods read the
|
|
8
|
+
* current user id off the access token and throw when unauthenticated),
|
|
9
|
+
* - routes through `authenticatedApiCall` so a stale token is refreshed and
|
|
10
|
+
* auth errors are handled consistently (matches `useUserDevices` /
|
|
11
|
+
* `usePrivacySettings`),
|
|
12
|
+
* - keeps its `queryFn` pure — no store writes, no side effects.
|
|
13
|
+
*
|
|
14
|
+
* The wrapped SDK methods (`@oxyhq/core` payment mixin) return `any`; the
|
|
15
|
+
* generic on `authenticatedApiCall<T>` pins the resolved value to the
|
|
16
|
+
* precise domain type so consumers get full typing.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Get the current user's subscription.
|
|
20
|
+
*
|
|
21
|
+
* Wraps `oxyServices.getCurrentUserSubscription()`
|
|
22
|
+
* (`GET /subscription/:userId`). Returns the persisted subscription or the
|
|
23
|
+
* API's `{ plan: 'basic' }` fallback when the user has never subscribed.
|
|
24
|
+
*/
|
|
25
|
+
export declare const useUserSubscription: (options?: {
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
}) => import("@tanstack/react-query").UseQueryResult<NoInfer<Subscription>, Error>;
|
|
28
|
+
/**
|
|
29
|
+
* Get the current user's payment / billing history.
|
|
30
|
+
*
|
|
31
|
+
* Wraps `oxyServices.getUserPayments()` (`GET /payments/user`), which
|
|
32
|
+
* returns the user's `deposit` and `purchase` transactions newest-first.
|
|
33
|
+
*/
|
|
34
|
+
export declare const useUserPayments: (options?: {
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
}) => import("@tanstack/react-query").UseQueryResult<NoInfer<Payment[]>, Error>;
|
|
37
|
+
/**
|
|
38
|
+
* Get the current user's FairCoin wallet balance.
|
|
39
|
+
*
|
|
40
|
+
* Wraps `oxyServices.getCurrentUserWallet()` (`GET /wallet/:userId`).
|
|
41
|
+
* Balance changes frequently, so the fresh window is intentionally short.
|
|
42
|
+
*/
|
|
43
|
+
export declare const useUserWallet: (options?: {
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
}) => import("@tanstack/react-query").UseQueryResult<NoInfer<Wallet>, Error>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the current user's wallet transaction history (paginated).
|
|
48
|
+
*
|
|
49
|
+
* Wraps `oxyServices.getCurrentUserWalletTransactions(options)`
|
|
50
|
+
* (`GET /wallet/transactions/:userId`). The API responds with a
|
|
51
|
+
* `{ data, pagination }` envelope, preserved here as
|
|
52
|
+
* `WalletTransactionsResponse`.
|
|
53
|
+
*
|
|
54
|
+
* @param params - Optional `limit` / `offset` pagination controls. These are
|
|
55
|
+
* part of the query key, so distinct pages cache independently.
|
|
56
|
+
*/
|
|
57
|
+
export declare const useUserWalletTransactions: (params?: {
|
|
58
|
+
limit?: number;
|
|
59
|
+
offset?: number;
|
|
60
|
+
}, options?: {
|
|
61
|
+
enabled?: boolean;
|
|
62
|
+
}) => import("@tanstack/react-query").UseQueryResult<NoInfer<WalletTransactionsResponse>, Error>;
|
|
63
|
+
//# sourceMappingURL=usePaymentQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePaymentQueries.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/hooks/queries/usePaymentQueries.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EACZ,OAAO,EACP,MAAM,EACN,0BAA0B,EAC3B,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,iFAiBlE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,8EAiB9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,2EAgB5D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GACpC,SAAS;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAC5C,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,+FAmBhC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClientSession } from '@oxyhq/core';
|
|
1
|
+
import type { AccountStorageUsageResponse, ClientSession } from '@oxyhq/core';
|
|
2
2
|
/**
|
|
3
3
|
* Get all active sessions for the current user
|
|
4
4
|
*/
|
|
@@ -31,4 +31,14 @@ export declare const useSecurityInfo: (options?: {
|
|
|
31
31
|
}) => import("@tanstack/react-query").UseQueryResult<NoInfer<{
|
|
32
32
|
recoveryEmail: string | null;
|
|
33
33
|
}>, Error>;
|
|
34
|
+
/**
|
|
35
|
+
* Get account storage usage (server-aggregated usage across assets, mail,
|
|
36
|
+
* recordings, etc.). Wraps `oxyServices.getAccountStorageUsage()` in a
|
|
37
|
+
* TanStack query so consumers get caching, background refetch, and a
|
|
38
|
+
* consistent `isLoading` / `refetch` surface instead of hand-rolled
|
|
39
|
+
* `useEffect` fetches.
|
|
40
|
+
*/
|
|
41
|
+
export declare const useAccountStorageUsage: (options?: {
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
}) => import("@tanstack/react-query").UseQueryResult<NoInfer<AccountStorageUsageResponse>, Error>;
|
|
34
44
|
//# sourceMappingURL=useServicesQueries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useServicesQueries.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/hooks/queries/useServicesQueries.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"useServicesQueries.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/hooks/queries/useServicesQueries.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK9E;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,oFAqB3E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,WAAW,MAAM,GAAG,IAAI,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,kFA6BnF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,0EAgBhE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,0EAgB7D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;;UAY9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,gGAgBrE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryClient.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/queryClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,WAAW,EAA4C,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"queryClient.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/queryClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,WAAW,EAA4C,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAoEhE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,QAAO,WA6CpC,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,wEAAwE;IACxE,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GACjC,aAAa,WAAW,EACxB,SAAS,gBAAgB,GAAG,IAAI,GAAG,SAAS,KAC3C,uBA+BF,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAU,SAAS,gBAAgB,KAAG,OAAO,CAAC,IAAI,CAa7E,CAAC;AAEF;;GAEG;AACH,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -63,7 +63,16 @@ export {
|
|
|
63
63
|
useUserById, useUserByUsername, useUsersBySessions,
|
|
64
64
|
usePrivacySettings, useSessions, useSession,
|
|
65
65
|
useDeviceSessions, useUserDevices, useSecurityInfo,
|
|
66
|
+
useAccountStorageUsage,
|
|
66
67
|
useSecurityActivity, useRecentSecurityActivity, useInfiniteSecurityActivity,
|
|
68
|
+
useUserSubscription, useUserPayments, useUserWallet, useUserWalletTransactions,
|
|
69
|
+
} from './ui/hooks/queries';
|
|
70
|
+
|
|
71
|
+
// Payment / wallet / subscription domain types
|
|
72
|
+
export type {
|
|
73
|
+
Subscription, SubscriptionPlan, SubscriptionStatus, SubscriptionFeatures,
|
|
74
|
+
Payment, Wallet, WalletTransaction, WalletTransactionType,
|
|
75
|
+
WalletTransactionStatus, WalletPagination, WalletTransactionsResponse,
|
|
67
76
|
} from './ui/hooks/queries';
|
|
68
77
|
|
|
69
78
|
// Mutation hooks
|
|
@@ -16,13 +16,14 @@ export {
|
|
|
16
16
|
usePrivacySettings,
|
|
17
17
|
} from './useAccountQueries';
|
|
18
18
|
|
|
19
|
-
// Service query hooks (sessions, devices, security)
|
|
19
|
+
// Service query hooks (sessions, devices, security, storage)
|
|
20
20
|
export {
|
|
21
21
|
useSessions,
|
|
22
22
|
useSession,
|
|
23
23
|
useDeviceSessions,
|
|
24
24
|
useUserDevices,
|
|
25
25
|
useSecurityInfo,
|
|
26
|
+
useAccountStorageUsage,
|
|
26
27
|
} from './useServicesQueries';
|
|
27
28
|
|
|
28
29
|
// Security activity query hooks
|
|
@@ -32,6 +33,29 @@ export {
|
|
|
32
33
|
useInfiniteSecurityActivity,
|
|
33
34
|
} from './useSecurityQueries';
|
|
34
35
|
|
|
36
|
+
// Payment / wallet / subscription query hooks
|
|
37
|
+
export {
|
|
38
|
+
useUserSubscription,
|
|
39
|
+
useUserPayments,
|
|
40
|
+
useUserWallet,
|
|
41
|
+
useUserWalletTransactions,
|
|
42
|
+
} from './usePaymentQueries';
|
|
43
|
+
|
|
44
|
+
// Payment / wallet / subscription domain types
|
|
45
|
+
export type {
|
|
46
|
+
Subscription,
|
|
47
|
+
SubscriptionPlan,
|
|
48
|
+
SubscriptionStatus,
|
|
49
|
+
SubscriptionFeatures,
|
|
50
|
+
Payment,
|
|
51
|
+
Wallet,
|
|
52
|
+
WalletTransaction,
|
|
53
|
+
WalletTransactionType,
|
|
54
|
+
WalletTransactionStatus,
|
|
55
|
+
WalletPagination,
|
|
56
|
+
WalletTransactionsResponse,
|
|
57
|
+
} from './paymentTypes';
|
|
58
|
+
|
|
35
59
|
// Query keys and invalidation helpers (for advanced usage)
|
|
36
60
|
export { queryKeys, invalidateAccountQueries, invalidateUserQueries, invalidateSessionQueries } from './queryKeys';
|
|
37
61
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment / wallet / subscription domain types.
|
|
3
|
+
*
|
|
4
|
+
* These model the JSON shapes the Oxy API actually returns for the
|
|
5
|
+
* payment-related read endpoints, so the corresponding query hooks
|
|
6
|
+
* (`useUserSubscription`, `useUserPayments`, `useUserWallet`,
|
|
7
|
+
* `useUserWalletTransactions`) expose precise types instead of `any`.
|
|
8
|
+
*
|
|
9
|
+
* Source of truth (API):
|
|
10
|
+
* - Subscription: GET /subscription/:userId -> `Subscription` model JSON,
|
|
11
|
+
* or the fallback `{ plan: 'basic' }` when none exists.
|
|
12
|
+
* - Payments: GET /payments/user -> `Payment[]` (sendSuccess).
|
|
13
|
+
* - Wallet: GET /wallet/:userId -> `Wallet` (sendSuccess).
|
|
14
|
+
* - Transactions: GET /wallet/transactions/:userId
|
|
15
|
+
* -> `WalletTransactionsResponse` (sendPaginated envelope).
|
|
16
|
+
*
|
|
17
|
+
* All `Date` columns are serialized as ISO-8601 strings over the wire.
|
|
18
|
+
*
|
|
19
|
+
* Note: `@oxyhq/services` deliberately does NOT re-export these from
|
|
20
|
+
* `@oxyhq/core`. They live here because they describe the return shape of
|
|
21
|
+
* the services-layer query hooks; consumers that need core domain types
|
|
22
|
+
* import those directly from `@oxyhq/core`.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** Subscription tier. Mirrors the `plan` enum on the API `Subscription` model. */
|
|
26
|
+
export type SubscriptionPlan = 'basic' | 'pro' | 'business';
|
|
27
|
+
|
|
28
|
+
/** Lifecycle state of a subscription. */
|
|
29
|
+
export type SubscriptionStatus = 'active' | 'canceled' | 'expired';
|
|
30
|
+
|
|
31
|
+
/** Feature flags toggled by the active subscription plan. */
|
|
32
|
+
export interface SubscriptionFeatures {
|
|
33
|
+
analytics: boolean;
|
|
34
|
+
premiumBadge: boolean;
|
|
35
|
+
unlimitedFollowing: boolean;
|
|
36
|
+
higherUploadLimits: boolean;
|
|
37
|
+
promotedPosts: boolean;
|
|
38
|
+
businessTools: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A user's subscription.
|
|
43
|
+
*
|
|
44
|
+
* When a user has never subscribed, the API returns the minimal fallback
|
|
45
|
+
* `{ plan: 'basic' }`; every other field is therefore optional so the type
|
|
46
|
+
* covers both the persisted document and the fallback.
|
|
47
|
+
*/
|
|
48
|
+
export interface Subscription {
|
|
49
|
+
plan: SubscriptionPlan;
|
|
50
|
+
status?: SubscriptionStatus;
|
|
51
|
+
/** Account this subscription belongs to (absent on the basic fallback). */
|
|
52
|
+
userId?: string;
|
|
53
|
+
/** ISO-8601 timestamp the current period started. */
|
|
54
|
+
startDate?: string;
|
|
55
|
+
/** ISO-8601 timestamp the current period ends / renews. */
|
|
56
|
+
endDate?: string;
|
|
57
|
+
autoRenew?: boolean;
|
|
58
|
+
paymentMethod?: string;
|
|
59
|
+
latestInvoice?: string;
|
|
60
|
+
features?: SubscriptionFeatures;
|
|
61
|
+
/** ISO-8601 creation timestamp. */
|
|
62
|
+
createdAt?: string;
|
|
63
|
+
/** ISO-8601 last-update timestamp. */
|
|
64
|
+
updatedAt?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A billing / payment history entry, derived from `deposit` and `purchase`
|
|
69
|
+
* transactions on the API side (`GET /payments/user`).
|
|
70
|
+
*/
|
|
71
|
+
export interface Payment {
|
|
72
|
+
id: string;
|
|
73
|
+
userId: string;
|
|
74
|
+
type: string;
|
|
75
|
+
amount: number;
|
|
76
|
+
status: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
itemId?: string;
|
|
79
|
+
itemType?: string;
|
|
80
|
+
/** ISO-8601 timestamp the payment was created (maps to `createdAt`). */
|
|
81
|
+
timestamp?: string;
|
|
82
|
+
/** ISO-8601 timestamp the payment settled, when applicable. */
|
|
83
|
+
completedAt?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** FairCoin wallet balance for a user (`GET /wallet/:userId`). */
|
|
87
|
+
export interface Wallet {
|
|
88
|
+
userId: string;
|
|
89
|
+
balance: number;
|
|
90
|
+
/** On-chain withdrawal address, `null` until one is set. */
|
|
91
|
+
address: string | null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Direction/category of a wallet transaction. */
|
|
95
|
+
export type WalletTransactionType = 'deposit' | 'withdrawal' | 'transfer' | 'purchase';
|
|
96
|
+
|
|
97
|
+
/** Settlement state of a wallet transaction. */
|
|
98
|
+
export type WalletTransactionStatus = 'pending' | 'completed' | 'failed' | 'cancelled';
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A single wallet ledger entry returned by the transaction-history endpoint.
|
|
102
|
+
*
|
|
103
|
+
* The populated `userId` / `recipientId` may arrive either as a bare id
|
|
104
|
+
* string or as a `{ _id, username }` object depending on Mongoose
|
|
105
|
+
* population, so both shapes are modelled.
|
|
106
|
+
*/
|
|
107
|
+
export interface WalletTransaction {
|
|
108
|
+
id: string;
|
|
109
|
+
userId: string | { _id: string; username?: string };
|
|
110
|
+
type: WalletTransactionType;
|
|
111
|
+
amount: number;
|
|
112
|
+
status: WalletTransactionStatus;
|
|
113
|
+
description?: string;
|
|
114
|
+
recipientId?: string | { _id: string; username?: string } | null;
|
|
115
|
+
itemId?: string;
|
|
116
|
+
itemType?: string;
|
|
117
|
+
/** ISO-8601 creation timestamp (maps to `createdAt`). */
|
|
118
|
+
timestamp?: string;
|
|
119
|
+
/** ISO-8601 settlement timestamp, when applicable. */
|
|
120
|
+
completedAt?: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Pagination metadata attached to a paginated list response. */
|
|
124
|
+
export interface WalletPagination {
|
|
125
|
+
total: number;
|
|
126
|
+
limit: number;
|
|
127
|
+
offset: number;
|
|
128
|
+
hasMore: boolean;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Paginated envelope returned by `GET /wallet/transactions/:userId`.
|
|
133
|
+
*
|
|
134
|
+
* The HTTP layer preserves the `{ data, pagination }` shape for paginated
|
|
135
|
+
* responses (it only unwraps the plain `{ data }` success envelope), so
|
|
136
|
+
* callers receive the list under `data`.
|
|
137
|
+
*/
|
|
138
|
+
export interface WalletTransactionsResponse {
|
|
139
|
+
data: WalletTransaction[];
|
|
140
|
+
pagination: WalletPagination;
|
|
141
|
+
}
|
|
@@ -65,6 +65,32 @@ export const queryKeys = {
|
|
|
65
65
|
infinite: (limit: number, eventType?: string) =>
|
|
66
66
|
[...queryKeys.security.all, 'infinite', limit, eventType] as const,
|
|
67
67
|
},
|
|
68
|
+
|
|
69
|
+
// Storage usage queries
|
|
70
|
+
storage: {
|
|
71
|
+
all: ['storage'] as const,
|
|
72
|
+
usage: () => [...queryKeys.storage.all, 'usage'] as const,
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
// Payment / wallet / subscription queries
|
|
76
|
+
payments: {
|
|
77
|
+
all: ['payments'] as const,
|
|
78
|
+
subscription: (userId?: string) =>
|
|
79
|
+
[...queryKeys.payments.all, 'subscription', userId || 'current'] as const,
|
|
80
|
+
history: (userId?: string) =>
|
|
81
|
+
[...queryKeys.payments.all, 'history', userId || 'current'] as const,
|
|
82
|
+
wallet: (userId?: string) =>
|
|
83
|
+
[...queryKeys.payments.all, 'wallet', userId || 'current'] as const,
|
|
84
|
+
walletTransactions: (limit?: number, offset?: number, userId?: string) =>
|
|
85
|
+
[
|
|
86
|
+
...queryKeys.payments.all,
|
|
87
|
+
'wallet',
|
|
88
|
+
userId || 'current',
|
|
89
|
+
'transactions',
|
|
90
|
+
limit,
|
|
91
|
+
offset,
|
|
92
|
+
] as const,
|
|
93
|
+
},
|
|
68
94
|
} as const;
|
|
69
95
|
|
|
70
96
|
/**
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { authenticatedApiCall } from '@oxyhq/core';
|
|
3
|
+
import { queryKeys } from './queryKeys';
|
|
4
|
+
import { useOxy } from '../../context/OxyContext';
|
|
5
|
+
import type {
|
|
6
|
+
Subscription,
|
|
7
|
+
Payment,
|
|
8
|
+
Wallet,
|
|
9
|
+
WalletTransactionsResponse,
|
|
10
|
+
} from './paymentTypes';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Payment / wallet / subscription query hooks.
|
|
14
|
+
*
|
|
15
|
+
* These replace the imperative `oxyServices.*` + `Promise.allSettled` +
|
|
16
|
+
* `useEffect` pattern used in app screens. Each hook:
|
|
17
|
+
* - is gated on `isAuthenticated` (the underlying SDK methods read the
|
|
18
|
+
* current user id off the access token and throw when unauthenticated),
|
|
19
|
+
* - routes through `authenticatedApiCall` so a stale token is refreshed and
|
|
20
|
+
* auth errors are handled consistently (matches `useUserDevices` /
|
|
21
|
+
* `usePrivacySettings`),
|
|
22
|
+
* - keeps its `queryFn` pure — no store writes, no side effects.
|
|
23
|
+
*
|
|
24
|
+
* The wrapped SDK methods (`@oxyhq/core` payment mixin) return `any`; the
|
|
25
|
+
* generic on `authenticatedApiCall<T>` pins the resolved value to the
|
|
26
|
+
* precise domain type so consumers get full typing.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the current user's subscription.
|
|
31
|
+
*
|
|
32
|
+
* Wraps `oxyServices.getCurrentUserSubscription()`
|
|
33
|
+
* (`GET /subscription/:userId`). Returns the persisted subscription or the
|
|
34
|
+
* API's `{ plan: 'basic' }` fallback when the user has never subscribed.
|
|
35
|
+
*/
|
|
36
|
+
export const useUserSubscription = (options?: { enabled?: boolean }) => {
|
|
37
|
+
const { oxyServices, isAuthenticated, activeSessionId } = useOxy();
|
|
38
|
+
|
|
39
|
+
return useQuery({
|
|
40
|
+
queryKey: queryKeys.payments.subscription(),
|
|
41
|
+
queryFn: async () => {
|
|
42
|
+
return authenticatedApiCall<Subscription>(
|
|
43
|
+
oxyServices,
|
|
44
|
+
activeSessionId,
|
|
45
|
+
() => oxyServices.getCurrentUserSubscription(),
|
|
46
|
+
);
|
|
47
|
+
},
|
|
48
|
+
enabled: (options?.enabled !== false) && isAuthenticated,
|
|
49
|
+
// Subscription state changes rarely; tolerate a longer fresh window.
|
|
50
|
+
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
51
|
+
gcTime: 30 * 60 * 1000, // 30 minutes
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get the current user's payment / billing history.
|
|
57
|
+
*
|
|
58
|
+
* Wraps `oxyServices.getUserPayments()` (`GET /payments/user`), which
|
|
59
|
+
* returns the user's `deposit` and `purchase` transactions newest-first.
|
|
60
|
+
*/
|
|
61
|
+
export const useUserPayments = (options?: { enabled?: boolean }) => {
|
|
62
|
+
const { oxyServices, isAuthenticated, activeSessionId } = useOxy();
|
|
63
|
+
|
|
64
|
+
return useQuery({
|
|
65
|
+
queryKey: queryKeys.payments.history(),
|
|
66
|
+
queryFn: async () => {
|
|
67
|
+
return authenticatedApiCall<Payment[]>(
|
|
68
|
+
oxyServices,
|
|
69
|
+
activeSessionId,
|
|
70
|
+
() => oxyServices.getUserPayments(),
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
enabled: (options?.enabled !== false) && isAuthenticated,
|
|
74
|
+
// Billing history is append-mostly; a short fresh window is fine.
|
|
75
|
+
staleTime: 2 * 60 * 1000, // 2 minutes
|
|
76
|
+
gcTime: 30 * 60 * 1000, // 30 minutes
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get the current user's FairCoin wallet balance.
|
|
82
|
+
*
|
|
83
|
+
* Wraps `oxyServices.getCurrentUserWallet()` (`GET /wallet/:userId`).
|
|
84
|
+
* Balance changes frequently, so the fresh window is intentionally short.
|
|
85
|
+
*/
|
|
86
|
+
export const useUserWallet = (options?: { enabled?: boolean }) => {
|
|
87
|
+
const { oxyServices, isAuthenticated, activeSessionId } = useOxy();
|
|
88
|
+
|
|
89
|
+
return useQuery({
|
|
90
|
+
queryKey: queryKeys.payments.wallet(),
|
|
91
|
+
queryFn: async () => {
|
|
92
|
+
return authenticatedApiCall<Wallet>(
|
|
93
|
+
oxyServices,
|
|
94
|
+
activeSessionId,
|
|
95
|
+
() => oxyServices.getCurrentUserWallet(),
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
enabled: (options?.enabled !== false) && isAuthenticated,
|
|
99
|
+
staleTime: 60 * 1000, // 1 minute (balance moves often)
|
|
100
|
+
gcTime: 10 * 60 * 1000, // 10 minutes
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the current user's wallet transaction history (paginated).
|
|
106
|
+
*
|
|
107
|
+
* Wraps `oxyServices.getCurrentUserWalletTransactions(options)`
|
|
108
|
+
* (`GET /wallet/transactions/:userId`). The API responds with a
|
|
109
|
+
* `{ data, pagination }` envelope, preserved here as
|
|
110
|
+
* `WalletTransactionsResponse`.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Optional `limit` / `offset` pagination controls. These are
|
|
113
|
+
* part of the query key, so distinct pages cache independently.
|
|
114
|
+
*/
|
|
115
|
+
export const useUserWalletTransactions = (
|
|
116
|
+
params?: { limit?: number; offset?: number },
|
|
117
|
+
options?: { enabled?: boolean },
|
|
118
|
+
) => {
|
|
119
|
+
const { oxyServices, isAuthenticated, activeSessionId } = useOxy();
|
|
120
|
+
const limit = params?.limit;
|
|
121
|
+
const offset = params?.offset;
|
|
122
|
+
|
|
123
|
+
return useQuery({
|
|
124
|
+
queryKey: queryKeys.payments.walletTransactions(limit, offset),
|
|
125
|
+
queryFn: async () => {
|
|
126
|
+
return authenticatedApiCall<WalletTransactionsResponse>(
|
|
127
|
+
oxyServices,
|
|
128
|
+
activeSessionId,
|
|
129
|
+
() => oxyServices.getCurrentUserWalletTransactions({ limit, offset }),
|
|
130
|
+
);
|
|
131
|
+
},
|
|
132
|
+
enabled: (options?.enabled !== false) && isAuthenticated,
|
|
133
|
+
staleTime: 60 * 1000, // 1 minute (ledger updates frequently)
|
|
134
|
+
gcTime: 10 * 60 * 1000, // 10 minutes
|
|
135
|
+
});
|
|
136
|
+
};
|