@cranberry-money/shared-utils 4.5.0 → 4.7.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/badge-status.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/portfolio.d.ts +68 -0
- package/dist/portfolio.d.ts.map +1 -0
- package/dist/portfolio.js +87 -0
- package/dist/withdrawal.d.ts +97 -0
- package/dist/withdrawal.d.ts.map +1 -0
- package/dist/withdrawal.js +119 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badge-status.d.ts","sourceRoot":"","sources":["../src/badge-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EAKnB,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,EAC7B,6BAA6B,EAC7B,2BAA2B,EAM3B,gCAAgC,EAChC,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,sCAAsC,EACtC,yCAAyC,EACzC,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EAUxB,0BAA0B,EAC1B,iCAAiC,EACjC,2BAA2B,EAC3B,0BAA0B,EAC1B,yBAAyB,EAM1B,MAAM,mCAAmC,CAAC;AAE3C,OAAO,KAAK,EAAgB,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGnE;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,OAAO,qBAAqB,GAC5B,OAAO,oBAAoB,GAC3B,OAAO,sBAAsB,GAC7B,OAAO,mBAAmB,GAC1B,OAAO,2BAA2B,GAClC,OAAO,6BAA6B,GACpC,OAAO,2BAA2B,CAAC;AAEvC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ShortDate, formatTime, formatDateTime } from './date'
|
|
|
9
9
|
export { NUMBER_FORMAT_OPTIONS_CURRENCY, NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED, formatCurrency, parseCurrencyInput, formatCurrencyWithCode, formatDefaultCurrency, formatShares, } from './currency';
|
|
10
10
|
export type { BadgeVariant, BadgeSize, BadgeConfig, BadgeStyle } from './badge';
|
|
11
11
|
export { createBadge, BADGE_VARIANTS, BADGE_SIZES } from './badge';
|
|
12
|
-
export type { StatusBadgeStyle, TradeStatus, WithdrawalStatus, LiquidationStatus, TargetTradeStatus } from './badge-status';
|
|
12
|
+
export type { StatusBadgeStyle, TradeStatus, WithdrawalStatus, LiquidationStatus, TargetTradeStatus, } from './badge-status';
|
|
13
13
|
export { getTradeStatusBadge, getWithdrawalStatusBadge, getLiquidationStatusBadge, getTargetTradeStatusBadge, } from './badge-status';
|
|
14
|
+
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation } from './portfolio';
|
|
15
|
+
export type { LiquidationProgress } from './withdrawal';
|
|
16
|
+
export { formatWithdrawalAmount, formatLiquidationValue, formatSharesQuantity, calculateLiquidationProgress, getTotalEstimatedValue, } from './withdrawal';
|
|
14
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,EACrC,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGnE,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,EACrC,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGnE,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhH,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,3 +12,6 @@ export { formatDate, formatShortDate, formatTime, formatDateTime } from './date'
|
|
|
12
12
|
export { NUMBER_FORMAT_OPTIONS_CURRENCY, NUMBER_FORMAT_OPTIONS_CURRENCY_SIGNED, formatCurrency, parseCurrencyInput, formatCurrencyWithCode, formatDefaultCurrency, formatShares, } from './currency';
|
|
13
13
|
export { createBadge, BADGE_VARIANTS, BADGE_SIZES } from './badge';
|
|
14
14
|
export { getTradeStatusBadge, getWithdrawalStatusBadge, getLiquidationStatusBadge, getTargetTradeStatusBadge, } from './badge-status';
|
|
15
|
+
// Portfolio utilities
|
|
16
|
+
export { formatPortfolioValue, calculateTotalValue, getMarketAllocation, getCashAllocation } from './portfolio';
|
|
17
|
+
export { formatWithdrawalAmount, formatLiquidationValue, formatSharesQuantity, calculateLiquidationProgress, getTotalEstimatedValue, } from './withdrawal';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portfolio calculation and formatting utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for portfolio value calculations,
|
|
5
|
+
* allocations, and formatting. All functions handle string or number inputs
|
|
6
|
+
* for flexibility with API responses.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Formats a portfolio value as currency with AUD
|
|
10
|
+
*
|
|
11
|
+
* @param value - Portfolio value as string or number
|
|
12
|
+
* @returns Formatted currency string with AUD symbol
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* formatPortfolioValue(12345.67) // 'A$12,345.67'
|
|
17
|
+
* formatPortfolioValue('12345.67') // 'A$12,345.67'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatPortfolioValue(value: string | number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Calculates total portfolio value from market value and cash balance
|
|
23
|
+
*
|
|
24
|
+
* @param marketValue - Market value of holdings
|
|
25
|
+
* @param cashBalance - Cash balance in portfolio
|
|
26
|
+
* @returns Total portfolio value as number
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* calculateTotalValue(10000, 5000) // 15000
|
|
31
|
+
* calculateTotalValue('10000', '5000') // 15000
|
|
32
|
+
* calculateTotalValue('10000.50', 5000.25) // 15000.75
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function calculateTotalValue(marketValue: string | number, cashBalance: string | number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Calculates market allocation percentage in portfolio
|
|
38
|
+
*
|
|
39
|
+
* @param marketValue - Market value of holdings
|
|
40
|
+
* @param totalValue - Total portfolio value
|
|
41
|
+
* @returns Market allocation percentage (0-100)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* getMarketAllocation(7500, 10000) // 75
|
|
46
|
+
* getMarketAllocation('7500', '10000') // 75
|
|
47
|
+
* getMarketAllocation(0, 10000) // 0
|
|
48
|
+
* getMarketAllocation(100, 0) // 0 (prevents division by zero)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function getMarketAllocation(marketValue: string | number, totalValue: string | number): number;
|
|
52
|
+
/**
|
|
53
|
+
* Calculates cash allocation percentage in portfolio
|
|
54
|
+
*
|
|
55
|
+
* @param cashBalance - Cash balance in portfolio
|
|
56
|
+
* @param totalValue - Total portfolio value
|
|
57
|
+
* @returns Cash allocation percentage (0-100)
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* getCashAllocation(2500, 10000) // 25
|
|
62
|
+
* getCashAllocation('2500', '10000') // 25
|
|
63
|
+
* getCashAllocation(0, 10000) // 0
|
|
64
|
+
* getCashAllocation(100, 0) // 0 (prevents division by zero)
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function getCashAllocation(cashBalance: string | number, totalValue: string | number): number;
|
|
68
|
+
//# sourceMappingURL=portfolio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portfolio.d.ts","sourceRoot":"","sources":["../src/portfolio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAItG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIrG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAInG"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portfolio calculation and formatting utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for portfolio value calculations,
|
|
5
|
+
* allocations, and formatting. All functions handle string or number inputs
|
|
6
|
+
* for flexibility with API responses.
|
|
7
|
+
*/
|
|
8
|
+
import { LOCALE_AUSTRALIA, DEFAULT_NUMERIC_ZERO, DEFAULT_EMPTY_STRING, CURRENCY_AUD, } from '@cranberry-money/shared-constants';
|
|
9
|
+
import { NUMBER_FORMAT_OPTIONS_CURRENCY } from './currency';
|
|
10
|
+
/**
|
|
11
|
+
* Formats a portfolio value as currency with AUD
|
|
12
|
+
*
|
|
13
|
+
* @param value - Portfolio value as string or number
|
|
14
|
+
* @returns Formatted currency string with AUD symbol
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* formatPortfolioValue(12345.67) // 'A$12,345.67'
|
|
19
|
+
* formatPortfolioValue('12345.67') // 'A$12,345.67'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function formatPortfolioValue(value) {
|
|
23
|
+
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
24
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
25
|
+
...NUMBER_FORMAT_OPTIONS_CURRENCY,
|
|
26
|
+
currency: CURRENCY_AUD,
|
|
27
|
+
}).format(numValue);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calculates total portfolio value from market value and cash balance
|
|
31
|
+
*
|
|
32
|
+
* @param marketValue - Market value of holdings
|
|
33
|
+
* @param cashBalance - Cash balance in portfolio
|
|
34
|
+
* @returns Total portfolio value as number
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* calculateTotalValue(10000, 5000) // 15000
|
|
39
|
+
* calculateTotalValue('10000', '5000') // 15000
|
|
40
|
+
* calculateTotalValue('10000.50', 5000.25) // 15000.75
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function calculateTotalValue(marketValue, cashBalance) {
|
|
44
|
+
const market = typeof marketValue === 'string' ? parseFloat(marketValue || DEFAULT_EMPTY_STRING) : marketValue;
|
|
45
|
+
const cash = typeof cashBalance === 'string' ? parseFloat(cashBalance || DEFAULT_EMPTY_STRING) : cashBalance;
|
|
46
|
+
return market + cash;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Calculates market allocation percentage in portfolio
|
|
50
|
+
*
|
|
51
|
+
* @param marketValue - Market value of holdings
|
|
52
|
+
* @param totalValue - Total portfolio value
|
|
53
|
+
* @returns Market allocation percentage (0-100)
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* getMarketAllocation(7500, 10000) // 75
|
|
58
|
+
* getMarketAllocation('7500', '10000') // 75
|
|
59
|
+
* getMarketAllocation(0, 10000) // 0
|
|
60
|
+
* getMarketAllocation(100, 0) // 0 (prevents division by zero)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function getMarketAllocation(marketValue, totalValue) {
|
|
64
|
+
const market = typeof marketValue === 'string' ? parseFloat(marketValue || DEFAULT_EMPTY_STRING) : marketValue;
|
|
65
|
+
const total = typeof totalValue === 'string' ? parseFloat(totalValue || DEFAULT_EMPTY_STRING) : totalValue;
|
|
66
|
+
return total > DEFAULT_NUMERIC_ZERO ? (market / total) * 100 : DEFAULT_NUMERIC_ZERO;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Calculates cash allocation percentage in portfolio
|
|
70
|
+
*
|
|
71
|
+
* @param cashBalance - Cash balance in portfolio
|
|
72
|
+
* @param totalValue - Total portfolio value
|
|
73
|
+
* @returns Cash allocation percentage (0-100)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* getCashAllocation(2500, 10000) // 25
|
|
78
|
+
* getCashAllocation('2500', '10000') // 25
|
|
79
|
+
* getCashAllocation(0, 10000) // 0
|
|
80
|
+
* getCashAllocation(100, 0) // 0 (prevents division by zero)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function getCashAllocation(cashBalance, totalValue) {
|
|
84
|
+
const cash = typeof cashBalance === 'string' ? parseFloat(cashBalance || DEFAULT_EMPTY_STRING) : cashBalance;
|
|
85
|
+
const total = typeof totalValue === 'string' ? parseFloat(totalValue || DEFAULT_EMPTY_STRING) : totalValue;
|
|
86
|
+
return total > DEFAULT_NUMERIC_ZERO ? (cash / total) * 100 : DEFAULT_NUMERIC_ZERO;
|
|
87
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdrawal-related utility functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for formatting withdrawal amounts,
|
|
5
|
+
* calculating liquidation progress, and other withdrawal-related operations.
|
|
6
|
+
* Functions are designed to work with generic types to maintain flexibility.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Formats a withdrawal amount as currency
|
|
10
|
+
*
|
|
11
|
+
* @param amount - Withdrawal amount as string or number
|
|
12
|
+
* @returns Formatted currency string with AUD symbol
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* formatWithdrawalAmount(5000) // 'A$5,000.00'
|
|
17
|
+
* formatWithdrawalAmount('5000.50') // 'A$5,000.50'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatWithdrawalAmount(amount: string | number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Formats a liquidation value as currency
|
|
23
|
+
*
|
|
24
|
+
* @param value - Liquidation value as string or number
|
|
25
|
+
* @returns Formatted currency string with AUD symbol
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* formatLiquidationValue(10000) // 'A$10,000.00'
|
|
30
|
+
* formatLiquidationValue('10000.50') // 'A$10,000.50'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatLiquidationValue(value: string | number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Formats share quantity without decimal places
|
|
36
|
+
*
|
|
37
|
+
* @param shares - Number of shares
|
|
38
|
+
* @returns Formatted number string with thousands separators
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* formatSharesQuantity(1234) // '1,234'
|
|
43
|
+
* formatSharesQuantity(1234567) // '1,234,567'
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatSharesQuantity(shares: number): string;
|
|
47
|
+
/**
|
|
48
|
+
* Progress calculation result for liquidations
|
|
49
|
+
*/
|
|
50
|
+
export interface LiquidationProgress {
|
|
51
|
+
total: number;
|
|
52
|
+
pending: number;
|
|
53
|
+
inProgress: number;
|
|
54
|
+
completed: number;
|
|
55
|
+
failed: number;
|
|
56
|
+
completionRate: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Calculates liquidation progress statistics
|
|
60
|
+
*
|
|
61
|
+
* @param liquidations - Array of liquidation objects with liquidationStatus property
|
|
62
|
+
* @returns Progress statistics including counts and completion rate
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const liquidations = [
|
|
67
|
+
* { liquidationStatus: 'PENDING' },
|
|
68
|
+
* { liquidationStatus: 'SETTLED' },
|
|
69
|
+
* { liquidationStatus: 'FAILED' }
|
|
70
|
+
* ];
|
|
71
|
+
* calculateLiquidationProgress(liquidations)
|
|
72
|
+
* // Returns: { total: 3, pending: 1, inProgress: 0, completed: 1, failed: 1, completionRate: 33.33 }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function calculateLiquidationProgress<T extends {
|
|
76
|
+
liquidationStatus: string;
|
|
77
|
+
}>(liquidations: T[]): LiquidationProgress;
|
|
78
|
+
/**
|
|
79
|
+
* Calculates total estimated value from liquidations
|
|
80
|
+
*
|
|
81
|
+
* @param liquidations - Array of liquidation objects with estimatedValue property
|
|
82
|
+
* @returns Total estimated value as number
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const liquidations = [
|
|
87
|
+
* { estimatedValue: '1000.50' },
|
|
88
|
+
* { estimatedValue: '2000' },
|
|
89
|
+
* { estimatedValue: null }
|
|
90
|
+
* ];
|
|
91
|
+
* getTotalEstimatedValue(liquidations) // 3000.50
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function getTotalEstimatedValue<T extends {
|
|
95
|
+
estimatedValue?: string | null;
|
|
96
|
+
}>(liquidations: T[]): number;
|
|
97
|
+
//# sourceMappingURL=withdrawal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../src/withdrawal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS;IAAE,iBAAiB,EAAE,MAAM,CAAA;CAAE,EAClF,YAAY,EAAE,CAAC,EAAE,GAChB,mBAAmB,CAkBrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAAE,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACjF,YAAY,EAAE,CAAC,EAAE,GAChB,MAAM,CAIR"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdrawal-related utility functions
|
|
3
|
+
*
|
|
4
|
+
* This module provides pure functions for formatting withdrawal amounts,
|
|
5
|
+
* calculating liquidation progress, and other withdrawal-related operations.
|
|
6
|
+
* Functions are designed to work with generic types to maintain flexibility.
|
|
7
|
+
*/
|
|
8
|
+
import { LOCALE_AUSTRALIA, CURRENCY_AUD, LIQUIDATION_STATUS_PENDING, LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED, LIQUIDATION_STATUS_SETTLED, LIQUIDATION_STATUS_FAILED } from '@cranberry-money/shared-constants';
|
|
9
|
+
import { NUMBER_FORMAT_OPTIONS_CURRENCY } from './currency';
|
|
10
|
+
/**
|
|
11
|
+
* Formats a withdrawal amount as currency
|
|
12
|
+
*
|
|
13
|
+
* @param amount - Withdrawal amount as string or number
|
|
14
|
+
* @returns Formatted currency string with AUD symbol
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* formatWithdrawalAmount(5000) // 'A$5,000.00'
|
|
19
|
+
* formatWithdrawalAmount('5000.50') // 'A$5,000.50'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function formatWithdrawalAmount(amount) {
|
|
23
|
+
const numValue = typeof amount === 'string' ? parseFloat(amount) : amount;
|
|
24
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
25
|
+
...NUMBER_FORMAT_OPTIONS_CURRENCY,
|
|
26
|
+
currency: CURRENCY_AUD,
|
|
27
|
+
}).format(numValue);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Formats a liquidation value as currency
|
|
31
|
+
*
|
|
32
|
+
* @param value - Liquidation value as string or number
|
|
33
|
+
* @returns Formatted currency string with AUD symbol
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* formatLiquidationValue(10000) // 'A$10,000.00'
|
|
38
|
+
* formatLiquidationValue('10000.50') // 'A$10,000.50'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function formatLiquidationValue(value) {
|
|
42
|
+
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
43
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
44
|
+
...NUMBER_FORMAT_OPTIONS_CURRENCY,
|
|
45
|
+
currency: CURRENCY_AUD,
|
|
46
|
+
}).format(numValue);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Formats share quantity without decimal places
|
|
50
|
+
*
|
|
51
|
+
* @param shares - Number of shares
|
|
52
|
+
* @returns Formatted number string with thousands separators
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* formatSharesQuantity(1234) // '1,234'
|
|
57
|
+
* formatSharesQuantity(1234567) // '1,234,567'
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function formatSharesQuantity(shares) {
|
|
61
|
+
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
62
|
+
minimumFractionDigits: 0,
|
|
63
|
+
maximumFractionDigits: 0,
|
|
64
|
+
}).format(shares);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Calculates liquidation progress statistics
|
|
68
|
+
*
|
|
69
|
+
* @param liquidations - Array of liquidation objects with liquidationStatus property
|
|
70
|
+
* @returns Progress statistics including counts and completion rate
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const liquidations = [
|
|
75
|
+
* { liquidationStatus: 'PENDING' },
|
|
76
|
+
* { liquidationStatus: 'SETTLED' },
|
|
77
|
+
* { liquidationStatus: 'FAILED' }
|
|
78
|
+
* ];
|
|
79
|
+
* calculateLiquidationProgress(liquidations)
|
|
80
|
+
* // Returns: { total: 3, pending: 1, inProgress: 0, completed: 1, failed: 1, completionRate: 33.33 }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export function calculateLiquidationProgress(liquidations) {
|
|
84
|
+
const total = liquidations.length;
|
|
85
|
+
const pending = liquidations.filter((l) => l.liquidationStatus === LIQUIDATION_STATUS_PENDING).length;
|
|
86
|
+
const inProgress = liquidations.filter((l) => [LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED].includes(l.liquidationStatus)).length;
|
|
87
|
+
const completed = liquidations.filter((l) => l.liquidationStatus === LIQUIDATION_STATUS_SETTLED).length;
|
|
88
|
+
const failed = liquidations.filter((l) => l.liquidationStatus === LIQUIDATION_STATUS_FAILED).length;
|
|
89
|
+
const completionRate = total > 0 ? (completed / total) * 100 : 0;
|
|
90
|
+
return {
|
|
91
|
+
total,
|
|
92
|
+
pending,
|
|
93
|
+
inProgress,
|
|
94
|
+
completed,
|
|
95
|
+
failed,
|
|
96
|
+
completionRate,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Calculates total estimated value from liquidations
|
|
101
|
+
*
|
|
102
|
+
* @param liquidations - Array of liquidation objects with estimatedValue property
|
|
103
|
+
* @returns Total estimated value as number
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const liquidations = [
|
|
108
|
+
* { estimatedValue: '1000.50' },
|
|
109
|
+
* { estimatedValue: '2000' },
|
|
110
|
+
* { estimatedValue: null }
|
|
111
|
+
* ];
|
|
112
|
+
* getTotalEstimatedValue(liquidations) // 3000.50
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export function getTotalEstimatedValue(liquidations) {
|
|
116
|
+
return liquidations.reduce((total, liquidation) => {
|
|
117
|
+
return total + parseFloat(liquidation.estimatedValue || '0');
|
|
118
|
+
}, 0);
|
|
119
|
+
}
|