@djangocfg/ext-payments 1.0.14 → 1.0.19
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/config.cjs +5 -8
- package/dist/config.js +5 -8
- package/dist/index.cjs +1906 -1043
- package/dist/index.d.cts +644 -59
- package/dist/index.d.ts +644 -59
- package/dist/index.js +1886 -1040
- package/package.json +13 -16
- package/src/WalletPage.tsx +100 -0
- package/src/api/generated/ext_payments/CLAUDE.md +10 -4
- package/src/api/generated/ext_payments/_utils/fetchers/ext_payments__payments.ts +268 -5
- package/src/api/generated/ext_payments/_utils/hooks/ext_payments__payments.ts +102 -3
- package/src/api/generated/ext_payments/_utils/schemas/Balance.schema.ts +1 -1
- package/src/api/generated/ext_payments/_utils/schemas/PaginatedWithdrawalListList.schema.ts +24 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaymentCreateRequest.schema.ts +21 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaymentCreateResponse.schema.ts +22 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaymentDetail.schema.ts +3 -3
- package/src/api/generated/ext_payments/_utils/schemas/PaymentList.schema.ts +2 -2
- package/src/api/generated/ext_payments/_utils/schemas/Transaction.schema.ts +1 -1
- package/src/api/generated/ext_payments/_utils/schemas/WithdrawalCancelResponse.schema.ts +22 -0
- package/src/api/generated/ext_payments/_utils/schemas/WithdrawalCreateRequest.schema.ts +21 -0
- package/src/api/generated/ext_payments/_utils/schemas/WithdrawalCreateResponse.schema.ts +22 -0
- package/src/api/generated/ext_payments/_utils/schemas/WithdrawalDetail.schema.ts +42 -0
- package/src/api/generated/ext_payments/_utils/schemas/WithdrawalList.schema.ts +29 -0
- package/src/api/generated/ext_payments/_utils/schemas/index.ts +8 -0
- package/src/api/generated/ext_payments/client.ts +1 -1
- package/src/api/generated/ext_payments/enums.ts +36 -0
- package/src/api/generated/ext_payments/ext_payments__payments/client.ts +104 -6
- package/src/api/generated/ext_payments/ext_payments__payments/models.ts +168 -8
- package/src/api/generated/ext_payments/index.ts +1 -1
- package/src/api/generated/ext_payments/schema.json +752 -42
- package/src/components/ActivityItem.tsx +118 -0
- package/src/components/ActivityList.tsx +93 -0
- package/src/components/AddFundsSheet.tsx +342 -0
- package/src/components/BalanceHero.tsx +102 -0
- package/src/components/CurrencyCombobox.tsx +49 -0
- package/src/components/PaymentSheet.tsx +352 -0
- package/src/components/WithdrawSheet.tsx +355 -0
- package/src/components/WithdrawalSheet.tsx +332 -0
- package/src/components/index.ts +11 -0
- package/src/config.ts +1 -0
- package/src/contexts/WalletContext.tsx +356 -0
- package/src/contexts/index.ts +13 -42
- package/src/contexts/types.ts +43 -37
- package/src/hooks/index.ts +3 -20
- package/src/hooks/useCurrencyOptions.ts +79 -0
- package/src/hooks/useEstimate.ts +113 -0
- package/src/hooks/useWithdrawalEstimate.ts +117 -0
- package/src/index.ts +9 -18
- package/src/types/index.ts +78 -0
- package/src/utils/errors.ts +36 -0
- package/src/utils/format.ts +65 -0
- package/src/utils/index.ts +3 -0
- package/src/contexts/BalancesContext.tsx +0 -63
- package/src/contexts/CurrenciesContext.tsx +0 -64
- package/src/contexts/OverviewContext.tsx +0 -173
- package/src/contexts/PaymentsContext.tsx +0 -122
- package/src/contexts/PaymentsExtensionProvider.tsx +0 -56
- package/src/contexts/README.md +0 -201
- package/src/contexts/RootPaymentsContext.tsx +0 -66
- package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +0 -90
- package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +0 -274
- package/src/layouts/PaymentsLayout/components/PaymentDetailsDialog.tsx +0 -287
- package/src/layouts/PaymentsLayout/components/index.ts +0 -2
- package/src/layouts/PaymentsLayout/events.ts +0 -47
- package/src/layouts/PaymentsLayout/index.ts +0 -16
- package/src/layouts/PaymentsLayout/types.ts +0 -6
- package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +0 -121
- package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +0 -139
- package/src/layouts/PaymentsLayout/views/overview/components/index.ts +0 -2
- package/src/layouts/PaymentsLayout/views/overview/index.tsx +0 -21
- package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +0 -279
- package/src/layouts/PaymentsLayout/views/payments/components/index.ts +0 -1
- package/src/layouts/PaymentsLayout/views/payments/index.tsx +0 -18
- package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +0 -260
- package/src/layouts/PaymentsLayout/views/transactions/components/index.ts +0 -1
- package/src/layouts/PaymentsLayout/views/transactions/index.tsx +0 -18
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, { createContext, ReactNode, useContext } from 'react';
|
|
4
|
-
import { SWRConfig } from 'swr';
|
|
5
|
-
|
|
6
|
-
import { apiPayments } from '../api';
|
|
7
|
-
import {
|
|
8
|
-
useCreatePaymentsPaymentsCreateCreate, usePaymentsBalanceRetrieve, usePaymentsPaymentsList,
|
|
9
|
-
usePaymentsTransactionsList
|
|
10
|
-
} from '../api/generated/ext_payments/_utils/hooks';
|
|
11
|
-
|
|
12
|
-
import type {
|
|
13
|
-
PaginatedPaymentListList,
|
|
14
|
-
PaymentList,
|
|
15
|
-
} from './types';
|
|
16
|
-
|
|
17
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
18
|
-
// Context Type
|
|
19
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
20
|
-
|
|
21
|
-
export interface OverviewContextValue {
|
|
22
|
-
// Balance data
|
|
23
|
-
balance: any | undefined;
|
|
24
|
-
isLoadingBalance: boolean;
|
|
25
|
-
balanceError: Error | undefined;
|
|
26
|
-
refreshBalance: () => Promise<void>;
|
|
27
|
-
|
|
28
|
-
// Payments data
|
|
29
|
-
payments: PaginatedPaymentListList | undefined;
|
|
30
|
-
isLoadingPayments: boolean;
|
|
31
|
-
paymentsError: Error | undefined;
|
|
32
|
-
refreshPayments: () => Promise<void>;
|
|
33
|
-
|
|
34
|
-
// Transactions data
|
|
35
|
-
transactions: any | undefined;
|
|
36
|
-
isLoadingTransactions: boolean;
|
|
37
|
-
transactionsError: Error | undefined;
|
|
38
|
-
refreshTransactions: () => Promise<void>;
|
|
39
|
-
|
|
40
|
-
// Payment operations
|
|
41
|
-
createPayment: () => Promise<PaymentList>;
|
|
42
|
-
|
|
43
|
-
// Loading states
|
|
44
|
-
isLoadingOverview: boolean;
|
|
45
|
-
overviewError: Error | undefined;
|
|
46
|
-
|
|
47
|
-
// Operations
|
|
48
|
-
refreshOverview: () => Promise<void>;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
52
|
-
// Context
|
|
53
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
54
|
-
|
|
55
|
-
const OverviewContext = createContext<OverviewContextValue | undefined>(undefined);
|
|
56
|
-
|
|
57
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
58
|
-
// Provider
|
|
59
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
60
|
-
|
|
61
|
-
export function OverviewProvider({ children }: { children: ReactNode }) {
|
|
62
|
-
// SWR config for overview data - disable auto-revalidation
|
|
63
|
-
const swrConfig = {
|
|
64
|
-
revalidateOnFocus: false,
|
|
65
|
-
revalidateOnReconnect: false,
|
|
66
|
-
revalidateIfStale: false,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// Balance
|
|
70
|
-
const {
|
|
71
|
-
data: balance,
|
|
72
|
-
error: balanceError,
|
|
73
|
-
isLoading: isLoadingBalance,
|
|
74
|
-
mutate: mutateBalance,
|
|
75
|
-
} = usePaymentsBalanceRetrieve(apiPayments);
|
|
76
|
-
|
|
77
|
-
// Payments list
|
|
78
|
-
const {
|
|
79
|
-
data: payments,
|
|
80
|
-
error: paymentsError,
|
|
81
|
-
isLoading: isLoadingPayments,
|
|
82
|
-
mutate: mutatePayments,
|
|
83
|
-
} = usePaymentsPaymentsList({}, apiPayments);
|
|
84
|
-
|
|
85
|
-
// Transactions
|
|
86
|
-
const {
|
|
87
|
-
data: transactions,
|
|
88
|
-
error: transactionsError,
|
|
89
|
-
isLoading: isLoadingTransactions,
|
|
90
|
-
mutate: mutateTransactions,
|
|
91
|
-
} = usePaymentsTransactionsList({}, apiPayments);
|
|
92
|
-
|
|
93
|
-
// Payment mutations
|
|
94
|
-
const createPaymentMutation = useCreatePaymentsPaymentsCreateCreate();
|
|
95
|
-
|
|
96
|
-
const isLoadingOverview = isLoadingBalance || isLoadingPayments || isLoadingTransactions;
|
|
97
|
-
const overviewError = balanceError || paymentsError || transactionsError;
|
|
98
|
-
|
|
99
|
-
const refreshBalance = async () => {
|
|
100
|
-
await mutateBalance();
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const refreshPayments = async () => {
|
|
104
|
-
await mutatePayments();
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const refreshTransactions = async () => {
|
|
108
|
-
await mutateTransactions();
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const refreshOverview = async () => {
|
|
112
|
-
await Promise.all([
|
|
113
|
-
mutateBalance(),
|
|
114
|
-
mutatePayments(),
|
|
115
|
-
mutateTransactions(),
|
|
116
|
-
]);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// Create payment
|
|
120
|
-
const createPayment = async (): Promise<PaymentList> => {
|
|
121
|
-
const result = await createPaymentMutation(apiPayments);
|
|
122
|
-
// Refresh overview data to show new payment
|
|
123
|
-
await refreshOverview();
|
|
124
|
-
return result as PaymentList;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const value: OverviewContextValue = {
|
|
128
|
-
balance,
|
|
129
|
-
isLoadingBalance,
|
|
130
|
-
balanceError,
|
|
131
|
-
refreshBalance,
|
|
132
|
-
payments,
|
|
133
|
-
isLoadingPayments,
|
|
134
|
-
paymentsError,
|
|
135
|
-
refreshPayments,
|
|
136
|
-
transactions,
|
|
137
|
-
isLoadingTransactions,
|
|
138
|
-
transactionsError,
|
|
139
|
-
refreshTransactions,
|
|
140
|
-
createPayment,
|
|
141
|
-
isLoadingOverview,
|
|
142
|
-
overviewError,
|
|
143
|
-
refreshOverview,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<SWRConfig value={swrConfig}>
|
|
148
|
-
<OverviewContext.Provider value={value}>{children}</OverviewContext.Provider>
|
|
149
|
-
</SWRConfig>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
154
|
-
// Hook
|
|
155
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
156
|
-
|
|
157
|
-
export function useOverviewContext(): OverviewContextValue {
|
|
158
|
-
const context = useContext(OverviewContext);
|
|
159
|
-
if (!context) {
|
|
160
|
-
throw new Error('useOverviewContext must be used within OverviewProvider');
|
|
161
|
-
}
|
|
162
|
-
return context;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
166
|
-
// Re-export types
|
|
167
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
168
|
-
|
|
169
|
-
export type {
|
|
170
|
-
PaginatedPaymentListList,
|
|
171
|
-
PaymentList,
|
|
172
|
-
};
|
|
173
|
-
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, { createContext, ReactNode, useContext } from 'react';
|
|
4
|
-
|
|
5
|
-
import { apiPayments } from '../api';
|
|
6
|
-
import * as ExtPaymentsFetchers from '../api/generated/ext_payments/_utils/fetchers';
|
|
7
|
-
import {
|
|
8
|
-
useCreatePaymentsPaymentsConfirmCreate, useCreatePaymentsPaymentsCreateCreate,
|
|
9
|
-
usePaymentsPaymentsList
|
|
10
|
-
} from '../api/generated/ext_payments/_utils/hooks';
|
|
11
|
-
|
|
12
|
-
import type {
|
|
13
|
-
PaginatedPaymentListList,
|
|
14
|
-
PaymentDetail,
|
|
15
|
-
PaymentList,
|
|
16
|
-
} from './types';
|
|
17
|
-
|
|
18
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
19
|
-
// Context Type
|
|
20
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
export interface PaymentsContextValue {
|
|
23
|
-
// List
|
|
24
|
-
payments: PaginatedPaymentListList | undefined;
|
|
25
|
-
isLoadingPayments: boolean;
|
|
26
|
-
paymentsError: Error | undefined;
|
|
27
|
-
refreshPayments: () => Promise<void>;
|
|
28
|
-
|
|
29
|
-
// Operations
|
|
30
|
-
getPayment: (id: string) => Promise<PaymentDetail | undefined>;
|
|
31
|
-
createPayment: () => Promise<PaymentList>;
|
|
32
|
-
confirmPayment: (id: string) => Promise<PaymentList>;
|
|
33
|
-
checkPaymentStatus: (id: string) => Promise<PaymentList | undefined>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
37
|
-
// Context
|
|
38
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
39
|
-
|
|
40
|
-
const PaymentsContext = createContext<PaymentsContextValue | undefined>(undefined);
|
|
41
|
-
|
|
42
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
43
|
-
// Provider
|
|
44
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
45
|
-
|
|
46
|
-
export function PaymentsProvider({ children }: { children: ReactNode }) {
|
|
47
|
-
// List payments (first page only for count)
|
|
48
|
-
const {
|
|
49
|
-
data: payments,
|
|
50
|
-
error: paymentsError,
|
|
51
|
-
isLoading: isLoadingPayments,
|
|
52
|
-
mutate: mutatePayments,
|
|
53
|
-
} = usePaymentsPaymentsList({ page: 1, page_size: 1 }, apiPayments);
|
|
54
|
-
|
|
55
|
-
const refreshPayments = async () => {
|
|
56
|
-
await mutatePayments();
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Mutations
|
|
60
|
-
const createPaymentMutation = useCreatePaymentsPaymentsCreateCreate();
|
|
61
|
-
const confirmPaymentMutation = useCreatePaymentsPaymentsConfirmCreate();
|
|
62
|
-
|
|
63
|
-
// Get single payment
|
|
64
|
-
const getPayment = async (id: string): Promise<PaymentDetail | undefined> => {
|
|
65
|
-
return ExtPaymentsFetchers.getPaymentsPaymentsRetrieve(id, apiPayments);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// Create payment
|
|
69
|
-
const createPayment = async (): Promise<PaymentList> => {
|
|
70
|
-
const result = await createPaymentMutation(apiPayments);
|
|
71
|
-
await refreshPayments();
|
|
72
|
-
return result as PaymentList;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// Confirm payment (user clicked "I paid")
|
|
76
|
-
const confirmPayment = async (id: string): Promise<PaymentList> => {
|
|
77
|
-
const result = await confirmPaymentMutation(id, apiPayments);
|
|
78
|
-
await refreshPayments();
|
|
79
|
-
return result as PaymentList;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Check payment status
|
|
83
|
-
const checkPaymentStatus = async (id: string): Promise<PaymentList | undefined> => {
|
|
84
|
-
return ExtPaymentsFetchers.getPaymentsPaymentsStatusRetrieve(id, apiPayments);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const value: PaymentsContextValue = {
|
|
88
|
-
payments,
|
|
89
|
-
isLoadingPayments,
|
|
90
|
-
paymentsError,
|
|
91
|
-
refreshPayments,
|
|
92
|
-
getPayment,
|
|
93
|
-
createPayment,
|
|
94
|
-
confirmPayment,
|
|
95
|
-
checkPaymentStatus,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
return <PaymentsContext.Provider value={value}>{children}</PaymentsContext.Provider>;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
102
|
-
// Hook
|
|
103
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
104
|
-
|
|
105
|
-
export function usePaymentsContext(): PaymentsContextValue {
|
|
106
|
-
const context = useContext(PaymentsContext);
|
|
107
|
-
if (!context) {
|
|
108
|
-
throw new Error('usePaymentsContext must be used within PaymentsProvider');
|
|
109
|
-
}
|
|
110
|
-
return context;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
114
|
-
// Re-export types
|
|
115
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
116
|
-
|
|
117
|
-
export type {
|
|
118
|
-
PaginatedPaymentListList,
|
|
119
|
-
PaymentDetail,
|
|
120
|
-
PaymentList,
|
|
121
|
-
};
|
|
122
|
-
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main Payments Extension Provider
|
|
3
|
-
*
|
|
4
|
-
* Wraps all payments contexts with ExtensionProvider for proper registration
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use client';
|
|
8
|
-
|
|
9
|
-
import type { ReactNode } from 'react';
|
|
10
|
-
import { ExtensionProvider } from '@djangocfg/ext-base/hooks';
|
|
11
|
-
|
|
12
|
-
import { extensionConfig } from '../config';
|
|
13
|
-
import { BalancesProvider } from './BalancesContext';
|
|
14
|
-
import { CurrenciesProvider } from './CurrenciesContext';
|
|
15
|
-
import { OverviewProvider } from './OverviewContext';
|
|
16
|
-
import { PaymentsProvider } from './PaymentsContext';
|
|
17
|
-
import { RootPaymentsProvider } from './RootPaymentsContext';
|
|
18
|
-
|
|
19
|
-
interface PaymentsExtensionProviderProps {
|
|
20
|
-
children: ReactNode;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Main provider for Payments extension
|
|
25
|
-
*
|
|
26
|
-
* Provides all payments contexts:
|
|
27
|
-
* - Root payments context (currencies)
|
|
28
|
-
* - Payments context (payment operations)
|
|
29
|
-
* - Balances context (balance management)
|
|
30
|
-
* - Currencies context (currency operations)
|
|
31
|
-
* - Overview context (payment statistics)
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```tsx
|
|
35
|
-
* <PaymentsExtensionProvider>
|
|
36
|
-
* <YourApp />
|
|
37
|
-
* </PaymentsExtensionProvider>
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export function PaymentsExtensionProvider({ children }: PaymentsExtensionProviderProps) {
|
|
41
|
-
return (
|
|
42
|
-
<ExtensionProvider metadata={extensionConfig}>
|
|
43
|
-
<RootPaymentsProvider>
|
|
44
|
-
<PaymentsProvider>
|
|
45
|
-
<BalancesProvider>
|
|
46
|
-
<CurrenciesProvider>
|
|
47
|
-
<OverviewProvider>
|
|
48
|
-
{children}
|
|
49
|
-
</OverviewProvider>
|
|
50
|
-
</CurrenciesProvider>
|
|
51
|
-
</BalancesProvider>
|
|
52
|
-
</PaymentsProvider>
|
|
53
|
-
</RootPaymentsProvider>
|
|
54
|
-
</ExtensionProvider>
|
|
55
|
-
);
|
|
56
|
-
}
|
package/src/contexts/README.md
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
# Payments Contexts
|
|
2
|
-
|
|
3
|
-
Декомпозированные контексты для модуля Payments.
|
|
4
|
-
|
|
5
|
-
## Структура
|
|
6
|
-
|
|
7
|
-
### PaymentsContext
|
|
8
|
-
**Файл:** `PaymentsContext.tsx`
|
|
9
|
-
**Назначение:** Управление платежами
|
|
10
|
-
|
|
11
|
-
**API:**
|
|
12
|
-
- `payments: PaginatedPaymentListList` - список платежей (пагинированный)
|
|
13
|
-
- `isLoadingPayments: boolean` - статус загрузки
|
|
14
|
-
- `refreshPayments()` - обновить список
|
|
15
|
-
- `getPayment(id)` - получить конкретный платеж
|
|
16
|
-
- `createPayment(data)` - создать платеж
|
|
17
|
-
- `cancelPayment(id, data)` - отменить платеж
|
|
18
|
-
- `checkPaymentStatus(id, data)` - проверить статус платежа
|
|
19
|
-
|
|
20
|
-
**Использование:**
|
|
21
|
-
```tsx
|
|
22
|
-
import { PaymentsProvider, usePaymentsContext } from '@djangocfg/layouts/contexts';
|
|
23
|
-
|
|
24
|
-
function PaymentsList() {
|
|
25
|
-
const { payments, isLoadingPayments, refreshPayments } = usePaymentsContext();
|
|
26
|
-
// ...
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
### BalancesContext
|
|
33
|
-
**Файл:** `BalancesContext.tsx`
|
|
34
|
-
**Назначение:** Управление балансами пользователей (read-only)
|
|
35
|
-
|
|
36
|
-
**API:**
|
|
37
|
-
- `balances: PaginatedUserBalanceList` - список балансов
|
|
38
|
-
- `isLoadingBalances: boolean` - статус загрузки
|
|
39
|
-
- `refreshBalances()` - обновить список
|
|
40
|
-
- `getBalance(id)` - получить конкретный баланс
|
|
41
|
-
- `getBalanceSummary()` - получить сводку по балансу
|
|
42
|
-
|
|
43
|
-
**Использование:**
|
|
44
|
-
```tsx
|
|
45
|
-
import { BalancesProvider, useBalancesContext } from '@djangocfg/layouts/contexts';
|
|
46
|
-
|
|
47
|
-
function Balance() {
|
|
48
|
-
const { balances, getBalanceSummary } = useBalancesContext();
|
|
49
|
-
// ...
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
### CurrenciesContext
|
|
56
|
-
**Файл:** `CurrenciesContext.tsx`
|
|
57
|
-
**Назначение:** Управление валютами и курсами обмена (read-only)
|
|
58
|
-
|
|
59
|
-
**API:**
|
|
60
|
-
- `currencies: PaginatedCurrencyListList` - список валют
|
|
61
|
-
- `isLoadingCurrencies: boolean` - статус загрузки
|
|
62
|
-
- `refreshCurrencies()` - обновить список
|
|
63
|
-
- `getCurrency(id)` - получить конкретную валюту
|
|
64
|
-
- `getCurrencyRates(baseCurrency, currencies)` - получить курсы обмена
|
|
65
|
-
|
|
66
|
-
**Использование:**
|
|
67
|
-
```tsx
|
|
68
|
-
import { CurrenciesProvider, useCurrenciesContext } from '@djangocfg/layouts/contexts';
|
|
69
|
-
|
|
70
|
-
function CurrencySelector() {
|
|
71
|
-
const { currencies, getCurrencyRates } = useCurrenciesContext();
|
|
72
|
-
// ...
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
### ApiKeysContext
|
|
79
|
-
**Файл:** `ApiKeysContext.tsx`
|
|
80
|
-
**Назначение:** Управление API ключами
|
|
81
|
-
|
|
82
|
-
**API:**
|
|
83
|
-
- `apiKeys: PaginatedAPIKeyListList` - список API ключей
|
|
84
|
-
- `isLoadingApiKeys: boolean` - статус загрузки
|
|
85
|
-
- `refreshApiKeys()` - обновить список
|
|
86
|
-
- `getApiKey(id)` - получить конкретный ключ
|
|
87
|
-
- `createApiKey(data)` - создать ключ
|
|
88
|
-
- `deleteApiKey(id)` - удалить ключ
|
|
89
|
-
|
|
90
|
-
**Использование:**
|
|
91
|
-
```tsx
|
|
92
|
-
import { ApiKeysProvider, useApiKeysContext } from '@djangocfg/layouts/contexts';
|
|
93
|
-
|
|
94
|
-
function ApiKeysList() {
|
|
95
|
-
const { apiKeys, createApiKey, deleteApiKey } = useApiKeysContext();
|
|
96
|
-
// ...
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
### OverviewContext
|
|
103
|
-
**Файл:** `OverviewContext.tsx`
|
|
104
|
-
**Назначение:** Дашборд и метрики платежной системы (read-only)
|
|
105
|
-
|
|
106
|
-
**API:**
|
|
107
|
-
- `overview: PaymentsDashboardOverview` - общий обзор
|
|
108
|
-
- `metrics: PaymentsMetrics` - метрики
|
|
109
|
-
- `balanceOverview: BalanceOverview` - обзор баланса
|
|
110
|
-
- `apiKeysOverview: APIKeysOverview` - обзор API ключей
|
|
111
|
-
- `subscriptionOverview: SubscriptionOverview` - обзор подписок
|
|
112
|
-
- `chartData: PaymentsChartResponse` - данные для графиков
|
|
113
|
-
- `recentPayments: PaginatedRecentPaymentList` - последние платежи
|
|
114
|
-
- `recentTransactions: PaginatedRecentTransactionList` - последние транзакции
|
|
115
|
-
- `isLoadingOverview: boolean` - статус загрузки
|
|
116
|
-
- `refreshOverview()` - обновить все данные
|
|
117
|
-
|
|
118
|
-
**Использование:**
|
|
119
|
-
```tsx
|
|
120
|
-
import { OverviewProvider, useOverviewContext } from '@djangocfg/layouts/contexts';
|
|
121
|
-
|
|
122
|
-
function Dashboard() {
|
|
123
|
-
const { overview, metrics, chartData } = useOverviewContext();
|
|
124
|
-
// ...
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
---
|
|
129
|
-
|
|
130
|
-
## Композиция провайдеров
|
|
131
|
-
|
|
132
|
-
Если нужно использовать несколько контекстов:
|
|
133
|
-
|
|
134
|
-
```tsx
|
|
135
|
-
import {
|
|
136
|
-
PaymentsProvider,
|
|
137
|
-
BalancesProvider,
|
|
138
|
-
OverviewProvider
|
|
139
|
-
} from '@djangocfg/layouts/contexts';
|
|
140
|
-
|
|
141
|
-
function PaymentsDashboard() {
|
|
142
|
-
return (
|
|
143
|
-
<OverviewProvider>
|
|
144
|
-
<PaymentsProvider>
|
|
145
|
-
<BalancesProvider>
|
|
146
|
-
<YourComponent />
|
|
147
|
-
</BalancesProvider>
|
|
148
|
-
</PaymentsProvider>
|
|
149
|
-
</OverviewProvider>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
## Миграция со старого PaymentsContext
|
|
157
|
-
|
|
158
|
-
**Было:**
|
|
159
|
-
```tsx
|
|
160
|
-
import { PaymentsProvider, usePaymentsContext } from '@djangocfg/layouts/contexts';
|
|
161
|
-
|
|
162
|
-
const { payments, balances, apiKeys } = usePaymentsContext();
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
**Стало:**
|
|
166
|
-
```tsx
|
|
167
|
-
import {
|
|
168
|
-
PaymentsProvider, usePaymentsContext,
|
|
169
|
-
BalancesProvider, useBalancesContext,
|
|
170
|
-
ApiKeysProvider, useApiKeysContext
|
|
171
|
-
} from '@djangocfg/layouts/contexts';
|
|
172
|
-
|
|
173
|
-
// В разных компонентах или комбинируя:
|
|
174
|
-
const { payments } = usePaymentsContext();
|
|
175
|
-
const { balances } = useBalancesContext();
|
|
176
|
-
const { apiKeys } = useApiKeysContext();
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## Преимущества декомпозиции
|
|
182
|
-
|
|
183
|
-
1. **Модульность** - каждый контекст отвечает за свою область
|
|
184
|
-
2. **Производительность** - меньше ненужных ре-рендеров
|
|
185
|
-
3. **Гибкость** - можно использовать только нужные контексты
|
|
186
|
-
4. **Читаемость** - явное разделение зон ответственности
|
|
187
|
-
5. **Масштабируемость** - проще добавлять новую функциональность
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
## Не включенные сущности
|
|
192
|
-
|
|
193
|
-
В текущей декомпозиции **не включены** (могут быть добавлены позже):
|
|
194
|
-
- `SubscriptionsContext` - управление подписками (CRUD)
|
|
195
|
-
- `TransactionsContext` - история транзакций (read-only)
|
|
196
|
-
- `TariffsContext` - тарифные планы (read-only)
|
|
197
|
-
- `NetworksContext` - блокчейн сети (read-only)
|
|
198
|
-
- `AdminContext` - админ-функции (для админки)
|
|
199
|
-
|
|
200
|
-
Эти сущности можно добавить по мере необходимости, следуя той же структуре.
|
|
201
|
-
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, { createContext, ReactNode, useContext } from 'react';
|
|
4
|
-
|
|
5
|
-
import { apiPayments } from '../api';
|
|
6
|
-
import { usePaymentsCurrenciesList } from '../api/generated/ext_payments/_utils/hooks';
|
|
7
|
-
|
|
8
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
9
|
-
// Context Type
|
|
10
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
11
|
-
|
|
12
|
-
export interface RootPaymentsContextValue {
|
|
13
|
-
// Currencies - simplified to single endpoint
|
|
14
|
-
currencies: any | undefined;
|
|
15
|
-
isLoadingCurrencies: boolean;
|
|
16
|
-
currenciesError: Error | undefined;
|
|
17
|
-
refreshCurrencies: () => Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
21
|
-
// Context
|
|
22
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
const RootPaymentsContext = createContext<RootPaymentsContextValue | undefined>(undefined);
|
|
25
|
-
|
|
26
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
27
|
-
// Provider
|
|
28
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
29
|
-
|
|
30
|
-
export function RootPaymentsProvider({ children }: { children: ReactNode }) {
|
|
31
|
-
// Get currencies list from /cfg/payments/currencies/
|
|
32
|
-
// In v2.0, this returns all currencies with network info embedded
|
|
33
|
-
const {
|
|
34
|
-
data: currencies,
|
|
35
|
-
error: currenciesError,
|
|
36
|
-
isLoading: isLoadingCurrencies,
|
|
37
|
-
mutate: mutateCurrencies,
|
|
38
|
-
} = usePaymentsCurrenciesList(apiPayments);
|
|
39
|
-
|
|
40
|
-
const refreshCurrencies = async () => {
|
|
41
|
-
await mutateCurrencies();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const value: RootPaymentsContextValue = {
|
|
45
|
-
currencies,
|
|
46
|
-
isLoadingCurrencies,
|
|
47
|
-
currenciesError,
|
|
48
|
-
refreshCurrencies,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<RootPaymentsContext.Provider value={value}>{children}</RootPaymentsContext.Provider>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
57
|
-
// Hook
|
|
58
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
59
|
-
|
|
60
|
-
export function useRootPaymentsContext(): RootPaymentsContextValue {
|
|
61
|
-
const context = useContext(RootPaymentsContext);
|
|
62
|
-
if (!context) {
|
|
63
|
-
throw new Error('useRootPaymentsContext must be used within RootPaymentsProvider');
|
|
64
|
-
}
|
|
65
|
-
return context;
|
|
66
|
-
}
|