@cranberry-money/shared-services 3.0.1 → 4.1.0
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.ts +0 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -115
- package/package.json +4 -3
- package/dist/api/functional-client.d.ts +0 -66
- package/dist/api/functional-client.d.ts.map +0 -1
- package/dist/api/functional-client.js +0 -165
- package/dist/auth/functional/auth-operations.d.ts +0 -116
- package/dist/auth/functional/auth-operations.d.ts.map +0 -1
- package/dist/auth/functional/auth-operations.js +0 -246
- package/dist/auth/functional/auth-state.d.ts +0 -38
- package/dist/auth/functional/auth-state.d.ts.map +0 -1
- package/dist/auth/functional/auth-state.js +0 -87
- package/dist/auth/functional/token-storage.d.ts +0 -44
- package/dist/auth/functional/token-storage.d.ts.map +0 -1
- package/dist/auth/functional/token-storage.js +0 -178
- package/dist/auth/react/AuthProvider.d.ts +0 -92
- package/dist/auth/react/AuthProvider.d.ts.map +0 -1
- package/dist/auth/react/AuthProvider.js +0 -207
- package/dist/integration/blueberry-integration.d.ts +0 -21
- package/dist/integration/blueberry-integration.d.ts.map +0 -1
- package/dist/integration/blueberry-integration.js +0 -109
- package/dist/integration/index.d.ts +0 -8
- package/dist/integration/index.d.ts.map +0 -1
- package/dist/integration/index.js +0 -18
- package/dist/services/accounts.d.ts +0 -220
- package/dist/services/accounts.d.ts.map +0 -1
- package/dist/services/accounts.js +0 -175
- package/dist/services/banks.d.ts +0 -123
- package/dist/services/banks.d.ts.map +0 -1
- package/dist/services/banks.js +0 -151
- package/dist/services/cash-accounts.d.ts +0 -112
- package/dist/services/cash-accounts.d.ts.map +0 -1
- package/dist/services/cash-accounts.js +0 -222
- package/dist/services/documents.d.ts +0 -143
- package/dist/services/documents.d.ts.map +0 -1
- package/dist/services/documents.js +0 -253
- package/dist/services/factories/account-factory.d.ts +0 -16
- package/dist/services/factories/account-factory.d.ts.map +0 -1
- package/dist/services/factories/account-factory.js +0 -79
- package/dist/services/factories/auth-factory.d.ts +0 -23
- package/dist/services/factories/auth-factory.d.ts.map +0 -1
- package/dist/services/factories/auth-factory.js +0 -75
- package/dist/services/factories/bank-factory.d.ts +0 -16
- package/dist/services/factories/bank-factory.d.ts.map +0 -1
- package/dist/services/factories/bank-factory.js +0 -72
- package/dist/services/factories/cash-account-factory.d.ts +0 -16
- package/dist/services/factories/cash-account-factory.d.ts.map +0 -1
- package/dist/services/factories/cash-account-factory.js +0 -74
- package/dist/services/factories/document-factory.d.ts +0 -16
- package/dist/services/factories/document-factory.d.ts.map +0 -1
- package/dist/services/factories/document-factory.js +0 -85
- package/dist/services/factories/index.d.ts +0 -21
- package/dist/services/factories/index.d.ts.map +0 -1
- package/dist/services/factories/index.js +0 -40
- package/dist/services/factories/instrument-factory.d.ts +0 -16
- package/dist/services/factories/instrument-factory.d.ts.map +0 -1
- package/dist/services/factories/instrument-factory.js +0 -68
- package/dist/services/factories/master-factory.d.ts +0 -74
- package/dist/services/factories/master-factory.d.ts.map +0 -1
- package/dist/services/factories/master-factory.js +0 -183
- package/dist/services/factories/portfolio-factory.d.ts +0 -16
- package/dist/services/factories/portfolio-factory.d.ts.map +0 -1
- package/dist/services/factories/portfolio-factory.js +0 -74
- package/dist/services/factories/portfolio-template-factory.d.ts +0 -16
- package/dist/services/factories/portfolio-template-factory.d.ts.map +0 -1
- package/dist/services/factories/portfolio-template-factory.js +0 -76
- package/dist/services/factories/reference-data-factory.d.ts +0 -16
- package/dist/services/factories/reference-data-factory.d.ts.map +0 -1
- package/dist/services/factories/reference-data-factory.js +0 -86
- package/dist/services/factories/tax-residency-factory.d.ts +0 -16
- package/dist/services/factories/tax-residency-factory.d.ts.map +0 -1
- package/dist/services/factories/tax-residency-factory.js +0 -73
- package/dist/services/factories/trade-factory.d.ts +0 -16
- package/dist/services/factories/trade-factory.d.ts.map +0 -1
- package/dist/services/factories/trade-factory.js +0 -79
- package/dist/services/factories/types.d.ts +0 -250
- package/dist/services/factories/types.d.ts.map +0 -1
- package/dist/services/factories/types.js +0 -32
- package/dist/services/factories/withdrawal-factory.d.ts +0 -16
- package/dist/services/factories/withdrawal-factory.d.ts.map +0 -1
- package/dist/services/factories/withdrawal-factory.js +0 -78
- package/dist/services/instruments.d.ts +0 -138
- package/dist/services/instruments.d.ts.map +0 -1
- package/dist/services/instruments.js +0 -178
- package/dist/services/portfolio-templates.d.ts +0 -142
- package/dist/services/portfolio-templates.d.ts.map +0 -1
- package/dist/services/portfolio-templates.js +0 -201
- package/dist/services/portfolios.d.ts +0 -157
- package/dist/services/portfolios.d.ts.map +0 -1
- package/dist/services/portfolios.js +0 -144
- package/dist/services/reference-data.d.ts +0 -185
- package/dist/services/reference-data.d.ts.map +0 -1
- package/dist/services/reference-data.js +0 -245
- package/dist/services/tax-residencies.d.ts +0 -83
- package/dist/services/tax-residencies.d.ts.map +0 -1
- package/dist/services/tax-residencies.js +0 -179
- package/dist/services/trades.d.ts +0 -190
- package/dist/services/trades.d.ts.map +0 -1
- package/dist/services/trades.js +0 -207
- package/dist/services/withdrawals.d.ts +0 -236
- package/dist/services/withdrawals.d.ts.map +0 -1
- package/dist/services/withdrawals.js +0 -345
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Withdrawal Services - Pure Functional Implementation
|
|
4
|
-
*
|
|
5
|
-
* Complete withdrawal request and liquidation workflow system.
|
|
6
|
-
* Pure functions with explicit dependencies for withdrawal management.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.canProcessWithdrawal = exports.canCreateLiquidations = exports.isWithdrawalCancellable = exports.isWithdrawalEditable = exports.formatSharesQuantity = exports.getTotalEstimatedValue = exports.calculateLiquidationProgress = exports.getLiquidationStatusColor = exports.getWithdrawalStatusColor = exports.formatWithdrawalAmount = exports.LIQUIDATION_STATUS_LABELS = exports.LIQUIDATION_STATUS = exports.WITHDRAWAL_REASON_LABELS = exports.WITHDRAWAL_REASON = exports.WITHDRAWAL_TYPE_LABELS = exports.WITHDRAWAL_TYPE = exports.WITHDRAWAL_STATUS_LABELS = exports.WITHDRAWAL_STATUS = exports.executeLiquidationTrades = exports.createTradesForLiquidation = exports.getLiquidationsByWithdrawalRequest = exports.deleteWithdrawalLiquidation = exports.updateWithdrawalLiquidation = exports.createWithdrawalLiquidation = exports.getWithdrawalLiquidation = exports.getWithdrawalLiquidations = exports.processWithdrawalRequest = exports.cancelWithdrawalRequest = exports.rejectWithdrawalRequest = exports.approveWithdrawalRequest = exports.deleteWithdrawalRequest = exports.updateWithdrawalRequest = exports.createWithdrawalRequest = exports.getWithdrawalRequest = exports.getWithdrawalRequests = void 0;
|
|
10
|
-
// =============================
|
|
11
|
-
// WITHDRAWAL REQUEST OPERATIONS
|
|
12
|
-
// =============================
|
|
13
|
-
const getWithdrawalRequests = async ({ apiClient }, filters) => {
|
|
14
|
-
const params = {};
|
|
15
|
-
if (filters?.account)
|
|
16
|
-
params.account = filters.account;
|
|
17
|
-
if (filters?.status)
|
|
18
|
-
params.status = filters.status;
|
|
19
|
-
if (filters?.withdrawalType)
|
|
20
|
-
params.withdrawal_type = filters.withdrawalType;
|
|
21
|
-
if (filters?.startDate)
|
|
22
|
-
params.start_date = filters.startDate;
|
|
23
|
-
if (filters?.endDate)
|
|
24
|
-
params.end_date = filters.endDate;
|
|
25
|
-
if (filters?.minAmount)
|
|
26
|
-
params.min_amount = filters.minAmount;
|
|
27
|
-
if (filters?.maxAmount)
|
|
28
|
-
params.max_amount = filters.maxAmount;
|
|
29
|
-
if (filters?.ordering)
|
|
30
|
-
params.order_by = filters.ordering;
|
|
31
|
-
if (filters?.page)
|
|
32
|
-
params.page = String(filters.page);
|
|
33
|
-
if (filters?.pageSize)
|
|
34
|
-
params.page_size = String(filters.pageSize);
|
|
35
|
-
return apiClient.get('/api/withdrawal-requests/', { params });
|
|
36
|
-
};
|
|
37
|
-
exports.getWithdrawalRequests = getWithdrawalRequests;
|
|
38
|
-
const getWithdrawalRequest = async ({ apiClient }, uuid) => {
|
|
39
|
-
if (!uuid?.trim()) {
|
|
40
|
-
throw new Error('Withdrawal request UUID is required');
|
|
41
|
-
}
|
|
42
|
-
return apiClient.get(`/api/withdrawal-requests/${uuid}/`);
|
|
43
|
-
};
|
|
44
|
-
exports.getWithdrawalRequest = getWithdrawalRequest;
|
|
45
|
-
const createWithdrawalRequest = async ({ apiClient }, data) => {
|
|
46
|
-
// Validation
|
|
47
|
-
if (!data.account?.trim()) {
|
|
48
|
-
throw new Error('Account UUID is required');
|
|
49
|
-
}
|
|
50
|
-
if (!data.requestedAmount || parseFloat(data.requestedAmount) <= 0) {
|
|
51
|
-
throw new Error('Requested amount must be greater than 0');
|
|
52
|
-
}
|
|
53
|
-
return apiClient.post('/api/withdrawal-requests/', data);
|
|
54
|
-
};
|
|
55
|
-
exports.createWithdrawalRequest = createWithdrawalRequest;
|
|
56
|
-
const updateWithdrawalRequest = async ({ apiClient }, uuid, data) => {
|
|
57
|
-
if (!uuid?.trim()) {
|
|
58
|
-
throw new Error('Withdrawal request UUID is required');
|
|
59
|
-
}
|
|
60
|
-
if (data.requestedAmount && parseFloat(data.requestedAmount) <= 0) {
|
|
61
|
-
throw new Error('Requested amount must be greater than 0');
|
|
62
|
-
}
|
|
63
|
-
return apiClient.patch(`/api/withdrawal-requests/${uuid}/`, data);
|
|
64
|
-
};
|
|
65
|
-
exports.updateWithdrawalRequest = updateWithdrawalRequest;
|
|
66
|
-
const deleteWithdrawalRequest = async ({ apiClient }, uuid) => {
|
|
67
|
-
if (!uuid?.trim()) {
|
|
68
|
-
throw new Error('Withdrawal request UUID is required');
|
|
69
|
-
}
|
|
70
|
-
await apiClient.delete(`/api/withdrawal-requests/${uuid}/`);
|
|
71
|
-
};
|
|
72
|
-
exports.deleteWithdrawalRequest = deleteWithdrawalRequest;
|
|
73
|
-
// Workflow operations
|
|
74
|
-
const approveWithdrawalRequest = async ({ apiClient }, uuid) => {
|
|
75
|
-
if (!uuid?.trim()) {
|
|
76
|
-
throw new Error('Withdrawal request UUID is required');
|
|
77
|
-
}
|
|
78
|
-
return apiClient.post(`/api/withdrawal-requests/${uuid}/approve/`, {});
|
|
79
|
-
};
|
|
80
|
-
exports.approveWithdrawalRequest = approveWithdrawalRequest;
|
|
81
|
-
const rejectWithdrawalRequest = async ({ apiClient }, uuid, reason) => {
|
|
82
|
-
if (!uuid?.trim()) {
|
|
83
|
-
throw new Error('Withdrawal request UUID is required');
|
|
84
|
-
}
|
|
85
|
-
return apiClient.post(`/api/withdrawal-requests/${uuid}/reject/`, { reason });
|
|
86
|
-
};
|
|
87
|
-
exports.rejectWithdrawalRequest = rejectWithdrawalRequest;
|
|
88
|
-
const cancelWithdrawalRequest = async ({ apiClient }, uuid) => {
|
|
89
|
-
if (!uuid?.trim()) {
|
|
90
|
-
throw new Error('Withdrawal request UUID is required');
|
|
91
|
-
}
|
|
92
|
-
return apiClient.post(`/api/withdrawal-requests/${uuid}/cancel/`, {});
|
|
93
|
-
};
|
|
94
|
-
exports.cancelWithdrawalRequest = cancelWithdrawalRequest;
|
|
95
|
-
const processWithdrawalRequest = async ({ apiClient }, uuid) => {
|
|
96
|
-
if (!uuid?.trim()) {
|
|
97
|
-
throw new Error('Withdrawal request UUID is required');
|
|
98
|
-
}
|
|
99
|
-
return apiClient.post(`/api/withdrawal-requests/${uuid}/process/`, {});
|
|
100
|
-
};
|
|
101
|
-
exports.processWithdrawalRequest = processWithdrawalRequest;
|
|
102
|
-
// =============================
|
|
103
|
-
// WITHDRAWAL LIQUIDATION OPERATIONS
|
|
104
|
-
// =============================
|
|
105
|
-
const getWithdrawalLiquidations = async ({ apiClient }, filters) => {
|
|
106
|
-
const params = {};
|
|
107
|
-
if (filters?.withdrawalRequest)
|
|
108
|
-
params.withdrawal_request = filters.withdrawalRequest;
|
|
109
|
-
if (filters?.assetHolding)
|
|
110
|
-
params.asset_holding = filters.assetHolding;
|
|
111
|
-
if (filters?.liquidationStatus)
|
|
112
|
-
params.liquidation_status = filters.liquidationStatus;
|
|
113
|
-
if (filters?.targetCompletionStartDate)
|
|
114
|
-
params.target_completion_start_date = filters.targetCompletionStartDate;
|
|
115
|
-
if (filters?.targetCompletionEndDate)
|
|
116
|
-
params.target_completion_end_date = filters.targetCompletionEndDate;
|
|
117
|
-
if (filters?.expectedSettlementStartDate)
|
|
118
|
-
params.expected_settlement_start_date = filters.expectedSettlementStartDate;
|
|
119
|
-
if (filters?.expectedSettlementEndDate)
|
|
120
|
-
params.expected_settlement_end_date = filters.expectedSettlementEndDate;
|
|
121
|
-
if (filters?.targetTrade)
|
|
122
|
-
params.target_trade = filters.targetTrade;
|
|
123
|
-
if (filters?.minValue)
|
|
124
|
-
params.min_value = filters.minValue;
|
|
125
|
-
if (filters?.maxValue)
|
|
126
|
-
params.max_value = filters.maxValue;
|
|
127
|
-
if (filters?.ordering)
|
|
128
|
-
params.order_by = filters.ordering;
|
|
129
|
-
if (filters?.page)
|
|
130
|
-
params.page = String(filters.page);
|
|
131
|
-
if (filters?.pageSize)
|
|
132
|
-
params.page_size = String(filters.pageSize);
|
|
133
|
-
return apiClient.get('/api/withdrawal-liquidations/', { params });
|
|
134
|
-
};
|
|
135
|
-
exports.getWithdrawalLiquidations = getWithdrawalLiquidations;
|
|
136
|
-
const getWithdrawalLiquidation = async ({ apiClient }, uuid) => {
|
|
137
|
-
if (!uuid?.trim()) {
|
|
138
|
-
throw new Error('Withdrawal liquidation UUID is required');
|
|
139
|
-
}
|
|
140
|
-
return apiClient.get(`/api/withdrawal-liquidations/${uuid}/`);
|
|
141
|
-
};
|
|
142
|
-
exports.getWithdrawalLiquidation = getWithdrawalLiquidation;
|
|
143
|
-
const createWithdrawalLiquidation = async ({ apiClient }, data) => {
|
|
144
|
-
// Validation
|
|
145
|
-
if (!data.withdrawalRequest?.trim()) {
|
|
146
|
-
throw new Error('Withdrawal request UUID is required');
|
|
147
|
-
}
|
|
148
|
-
if (!data.assetHolding?.trim()) {
|
|
149
|
-
throw new Error('Asset holding UUID is required');
|
|
150
|
-
}
|
|
151
|
-
if (!data.sharesToLiquidate || data.sharesToLiquidate <= 0) {
|
|
152
|
-
throw new Error('Shares to liquidate must be greater than 0');
|
|
153
|
-
}
|
|
154
|
-
if (!data.estimatedValue || parseFloat(data.estimatedValue) <= 0) {
|
|
155
|
-
throw new Error('Estimated value must be greater than 0');
|
|
156
|
-
}
|
|
157
|
-
return apiClient.post('/api/withdrawal-liquidations/', data);
|
|
158
|
-
};
|
|
159
|
-
exports.createWithdrawalLiquidation = createWithdrawalLiquidation;
|
|
160
|
-
const updateWithdrawalLiquidation = async ({ apiClient }, uuid, data) => {
|
|
161
|
-
if (!uuid?.trim()) {
|
|
162
|
-
throw new Error('Withdrawal liquidation UUID is required');
|
|
163
|
-
}
|
|
164
|
-
if (data.sharesToLiquidate !== undefined && data.sharesToLiquidate <= 0) {
|
|
165
|
-
throw new Error('Shares to liquidate must be greater than 0');
|
|
166
|
-
}
|
|
167
|
-
if (data.estimatedValue !== undefined && parseFloat(data.estimatedValue) <= 0) {
|
|
168
|
-
throw new Error('Estimated value must be greater than 0');
|
|
169
|
-
}
|
|
170
|
-
return apiClient.patch(`/api/withdrawal-liquidations/${uuid}/`, data);
|
|
171
|
-
};
|
|
172
|
-
exports.updateWithdrawalLiquidation = updateWithdrawalLiquidation;
|
|
173
|
-
const deleteWithdrawalLiquidation = async ({ apiClient }, uuid) => {
|
|
174
|
-
if (!uuid?.trim()) {
|
|
175
|
-
throw new Error('Withdrawal liquidation UUID is required');
|
|
176
|
-
}
|
|
177
|
-
await apiClient.delete(`/api/withdrawal-liquidations/${uuid}/`);
|
|
178
|
-
};
|
|
179
|
-
exports.deleteWithdrawalLiquidation = deleteWithdrawalLiquidation;
|
|
180
|
-
// Helper functions
|
|
181
|
-
const getLiquidationsByWithdrawalRequest = async ({ apiClient }, withdrawalRequestUuid) => {
|
|
182
|
-
if (!withdrawalRequestUuid?.trim()) {
|
|
183
|
-
throw new Error('Withdrawal request UUID is required');
|
|
184
|
-
}
|
|
185
|
-
return (0, exports.getWithdrawalLiquidations)({ apiClient }, {
|
|
186
|
-
withdrawalRequest: withdrawalRequestUuid,
|
|
187
|
-
ordering: '-created_at',
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
exports.getLiquidationsByWithdrawalRequest = getLiquidationsByWithdrawalRequest;
|
|
191
|
-
const createTradesForLiquidation = async ({ apiClient }, uuid) => {
|
|
192
|
-
if (!uuid?.trim()) {
|
|
193
|
-
throw new Error('Withdrawal liquidation UUID is required');
|
|
194
|
-
}
|
|
195
|
-
return apiClient.post(`/api/withdrawal-liquidations/${uuid}/create-trades/`, {});
|
|
196
|
-
};
|
|
197
|
-
exports.createTradesForLiquidation = createTradesForLiquidation;
|
|
198
|
-
const executeLiquidationTrades = async ({ apiClient }, uuid) => {
|
|
199
|
-
if (!uuid?.trim()) {
|
|
200
|
-
throw new Error('Withdrawal liquidation UUID is required');
|
|
201
|
-
}
|
|
202
|
-
return apiClient.post(`/api/withdrawal-liquidations/${uuid}/execute-trades/`, {});
|
|
203
|
-
};
|
|
204
|
-
exports.executeLiquidationTrades = executeLiquidationTrades;
|
|
205
|
-
// =============================
|
|
206
|
-
// UTILITY FUNCTIONS & CONSTANTS
|
|
207
|
-
// =============================
|
|
208
|
-
// Status constants
|
|
209
|
-
exports.WITHDRAWAL_STATUS = {
|
|
210
|
-
PENDING_REVIEW: 'PENDING_REVIEW',
|
|
211
|
-
APPROVED: 'APPROVED',
|
|
212
|
-
REJECTED: 'REJECTED',
|
|
213
|
-
PROCESSING: 'PROCESSING',
|
|
214
|
-
AWAITING_LIQUIDATION: 'AWAITING_LIQUIDATION',
|
|
215
|
-
LIQUIDATION_IN_PROGRESS: 'LIQUIDATION_IN_PROGRESS',
|
|
216
|
-
COMPLETED: 'COMPLETED',
|
|
217
|
-
CANCELLED: 'CANCELLED',
|
|
218
|
-
FAILED: 'FAILED',
|
|
219
|
-
};
|
|
220
|
-
exports.WITHDRAWAL_STATUS_LABELS = {
|
|
221
|
-
PENDING_REVIEW: 'Pending Review',
|
|
222
|
-
APPROVED: 'Approved',
|
|
223
|
-
REJECTED: 'Rejected',
|
|
224
|
-
PROCESSING: 'Processing',
|
|
225
|
-
AWAITING_LIQUIDATION: 'Awaiting Liquidation',
|
|
226
|
-
LIQUIDATION_IN_PROGRESS: 'Liquidation In Progress',
|
|
227
|
-
COMPLETED: 'Completed',
|
|
228
|
-
CANCELLED: 'Cancelled',
|
|
229
|
-
FAILED: 'Failed',
|
|
230
|
-
};
|
|
231
|
-
exports.WITHDRAWAL_TYPE = {
|
|
232
|
-
FULL_CASH: 'FULL_CASH',
|
|
233
|
-
PARTIAL_CASH: 'PARTIAL_CASH',
|
|
234
|
-
};
|
|
235
|
-
exports.WITHDRAWAL_TYPE_LABELS = {
|
|
236
|
-
FULL_CASH: 'Full Cash Withdrawal',
|
|
237
|
-
PARTIAL_CASH: 'Partial Cash Withdrawal',
|
|
238
|
-
};
|
|
239
|
-
exports.WITHDRAWAL_REASON = {
|
|
240
|
-
INVESTMENT_STRATEGY: 'INVESTMENT_STRATEGY',
|
|
241
|
-
PERSONAL_EXPENSES: 'PERSONAL_EXPENSES',
|
|
242
|
-
EMERGENCY: 'EMERGENCY',
|
|
243
|
-
OTHER: 'OTHER',
|
|
244
|
-
};
|
|
245
|
-
exports.WITHDRAWAL_REASON_LABELS = {
|
|
246
|
-
INVESTMENT_STRATEGY: 'Investment Strategy',
|
|
247
|
-
PERSONAL_EXPENSES: 'Personal Expenses',
|
|
248
|
-
EMERGENCY: 'Emergency',
|
|
249
|
-
OTHER: 'Other',
|
|
250
|
-
};
|
|
251
|
-
exports.LIQUIDATION_STATUS = {
|
|
252
|
-
PENDING: 'PENDING',
|
|
253
|
-
TRADES_CREATED: 'TRADES_CREATED',
|
|
254
|
-
EXECUTED: 'EXECUTED',
|
|
255
|
-
SETTLED: 'SETTLED',
|
|
256
|
-
FAILED: 'FAILED',
|
|
257
|
-
};
|
|
258
|
-
exports.LIQUIDATION_STATUS_LABELS = {
|
|
259
|
-
PENDING: 'Pending',
|
|
260
|
-
TRADES_CREATED: 'Trades Created',
|
|
261
|
-
EXECUTED: 'Executed',
|
|
262
|
-
SETTLED: 'Settled',
|
|
263
|
-
FAILED: 'Failed',
|
|
264
|
-
};
|
|
265
|
-
// Utility functions
|
|
266
|
-
const formatWithdrawalAmount = (amount) => {
|
|
267
|
-
const numValue = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
268
|
-
return new Intl.NumberFormat('en-AU', {
|
|
269
|
-
style: 'currency',
|
|
270
|
-
currency: 'AUD',
|
|
271
|
-
}).format(numValue);
|
|
272
|
-
};
|
|
273
|
-
exports.formatWithdrawalAmount = formatWithdrawalAmount;
|
|
274
|
-
const getWithdrawalStatusColor = (status) => {
|
|
275
|
-
const statusColors = {
|
|
276
|
-
PENDING_REVIEW: 'text-warning-600',
|
|
277
|
-
APPROVED: 'text-success-600',
|
|
278
|
-
REJECTED: 'text-error-600',
|
|
279
|
-
PROCESSING: 'text-primary-600',
|
|
280
|
-
AWAITING_LIQUIDATION: 'text-warning-600',
|
|
281
|
-
LIQUIDATION_IN_PROGRESS: 'text-primary-600',
|
|
282
|
-
COMPLETED: 'text-success-600',
|
|
283
|
-
CANCELLED: 'text-content-muted',
|
|
284
|
-
FAILED: 'text-error-600',
|
|
285
|
-
};
|
|
286
|
-
return statusColors[status] || 'text-content-muted';
|
|
287
|
-
};
|
|
288
|
-
exports.getWithdrawalStatusColor = getWithdrawalStatusColor;
|
|
289
|
-
const getLiquidationStatusColor = (status) => {
|
|
290
|
-
const statusColors = {
|
|
291
|
-
PENDING: 'text-warning-600',
|
|
292
|
-
TRADES_CREATED: 'text-primary-600',
|
|
293
|
-
EXECUTED: 'text-accent-secondary',
|
|
294
|
-
SETTLED: 'text-success-600',
|
|
295
|
-
FAILED: 'text-error-600',
|
|
296
|
-
};
|
|
297
|
-
return statusColors[status] || 'text-content-muted';
|
|
298
|
-
};
|
|
299
|
-
exports.getLiquidationStatusColor = getLiquidationStatusColor;
|
|
300
|
-
const calculateLiquidationProgress = (liquidations) => {
|
|
301
|
-
const total = liquidations.length;
|
|
302
|
-
const pending = liquidations.filter(l => l.liquidationStatus === 'PENDING').length;
|
|
303
|
-
const inProgress = liquidations.filter(l => ['TRADES_CREATED', 'EXECUTED'].includes(l.liquidationStatus)).length;
|
|
304
|
-
const completed = liquidations.filter(l => l.liquidationStatus === 'SETTLED').length;
|
|
305
|
-
const failed = liquidations.filter(l => l.liquidationStatus === 'FAILED').length;
|
|
306
|
-
const completionRate = total > 0 ? (completed / total) * 100 : 0;
|
|
307
|
-
return {
|
|
308
|
-
total,
|
|
309
|
-
pending,
|
|
310
|
-
inProgress,
|
|
311
|
-
completed,
|
|
312
|
-
failed,
|
|
313
|
-
completionRate,
|
|
314
|
-
};
|
|
315
|
-
};
|
|
316
|
-
exports.calculateLiquidationProgress = calculateLiquidationProgress;
|
|
317
|
-
const getTotalEstimatedValue = (liquidations) => {
|
|
318
|
-
return liquidations.reduce((total, liquidation) => {
|
|
319
|
-
return total + parseFloat(liquidation.estimatedValue || '0');
|
|
320
|
-
}, 0);
|
|
321
|
-
};
|
|
322
|
-
exports.getTotalEstimatedValue = getTotalEstimatedValue;
|
|
323
|
-
const formatSharesQuantity = (shares) => {
|
|
324
|
-
return new Intl.NumberFormat('en-AU', {
|
|
325
|
-
minimumFractionDigits: 0,
|
|
326
|
-
maximumFractionDigits: 4,
|
|
327
|
-
}).format(shares);
|
|
328
|
-
};
|
|
329
|
-
exports.formatSharesQuantity = formatSharesQuantity;
|
|
330
|
-
const isWithdrawalEditable = (status) => {
|
|
331
|
-
return ['PENDING_REVIEW', 'APPROVED'].includes(status);
|
|
332
|
-
};
|
|
333
|
-
exports.isWithdrawalEditable = isWithdrawalEditable;
|
|
334
|
-
const isWithdrawalCancellable = (status) => {
|
|
335
|
-
return ['PENDING_REVIEW', 'APPROVED', 'AWAITING_LIQUIDATION'].includes(status);
|
|
336
|
-
};
|
|
337
|
-
exports.isWithdrawalCancellable = isWithdrawalCancellable;
|
|
338
|
-
const canCreateLiquidations = (status) => {
|
|
339
|
-
return status === 'AWAITING_LIQUIDATION';
|
|
340
|
-
};
|
|
341
|
-
exports.canCreateLiquidations = canCreateLiquidations;
|
|
342
|
-
const canProcessWithdrawal = (status) => {
|
|
343
|
-
return status === 'APPROVED';
|
|
344
|
-
};
|
|
345
|
-
exports.canProcessWithdrawal = canProcessWithdrawal;
|