@cranberry-money/shared-utils 8.19.7 → 8.19.9
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/allocations.d.ts +0 -15
- package/dist/allocations.d.ts.map +1 -1
- package/dist/allocations.js +0 -16
- package/dist/allocations.js.map +1 -1
- package/dist/badge-status.d.ts +0 -58
- package/dist/badge-status.d.ts.map +1 -1
- package/dist/badge-status.js +0 -60
- package/dist/badge-status.js.map +1 -1
- package/dist/badge.d.ts +0 -36
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +0 -46
- package/dist/badge.js.map +1 -1
- package/dist/cash-account.d.ts +0 -36
- package/dist/cash-account.d.ts.map +1 -1
- package/dist/cash-account.js +0 -33
- package/dist/cash-account.js.map +1 -1
- package/dist/currency.d.ts +0 -82
- package/dist/currency.d.ts.map +1 -1
- package/dist/currency.js +0 -82
- package/dist/currency.js.map +1 -1
- package/dist/dashboard.d.ts +0 -48
- package/dist/dashboard.d.ts.map +1 -1
- package/dist/dashboard.js +2 -52
- package/dist/dashboard.js.map +1 -1
- package/dist/date.d.ts +0 -59
- package/dist/date.d.ts.map +1 -1
- package/dist/date.js +0 -59
- package/dist/date.js.map +1 -1
- package/dist/downloads.d.ts +0 -10
- package/dist/downloads.d.ts.map +1 -1
- package/dist/downloads.js +0 -10
- package/dist/downloads.js.map +1 -1
- package/dist/filters.d.ts +0 -74
- package/dist/filters.d.ts.map +1 -1
- package/dist/filters.js +0 -74
- package/dist/filters.js.map +1 -1
- package/dist/holdings.d.ts +0 -13
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +0 -13
- package/dist/holdings.js.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/instruments.d.ts +0 -14
- package/dist/instruments.d.ts.map +1 -1
- package/dist/instruments.js +1 -15
- package/dist/instruments.js.map +1 -1
- package/dist/numbers.d.ts +0 -14
- package/dist/numbers.d.ts.map +1 -1
- package/dist/numbers.js +0 -14
- package/dist/numbers.js.map +1 -1
- package/dist/portfolio-template.d.ts +0 -50
- package/dist/portfolio-template.d.ts.map +1 -1
- package/dist/portfolio-template.js +0 -47
- package/dist/portfolio-template.js.map +1 -1
- package/dist/portfolio-validation.d.ts +0 -28
- package/dist/portfolio-validation.d.ts.map +1 -1
- package/dist/portfolio-validation.js +0 -25
- package/dist/portfolio-validation.js.map +1 -1
- package/dist/portfolio.d.ts +0 -63
- package/dist/portfolio.d.ts.map +1 -1
- package/dist/portfolio.js +0 -63
- package/dist/portfolio.js.map +1 -1
- package/dist/text.d.ts +0 -20
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +0 -20
- package/dist/text.js.map +1 -1
- package/dist/validation.d.ts +0 -79
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +0 -82
- package/dist/validation.js.map +1 -1
- package/dist/withdrawal-status.d.ts +0 -60
- package/dist/withdrawal-status.d.ts.map +1 -1
- package/dist/withdrawal-status.js +11 -71
- package/dist/withdrawal-status.js.map +1 -1
- package/dist/withdrawal.d.ts +0 -40
- package/dist/withdrawal.d.ts.map +1 -1
- package/dist/withdrawal.js +0 -40
- package/dist/withdrawal.js.map +1 -1
- package/package.json +1 -1
package/dist/portfolio.js
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
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
1
|
import { LOCALE_AUSTRALIA, DEFAULT_NUMERIC_ZERO, DEFAULT_EMPTY_STRING, CURRENCY_AUD, } from '@cranberry-money/shared-constants';
|
|
9
2
|
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
3
|
export function formatPortfolioValue(value) {
|
|
23
4
|
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
24
5
|
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
@@ -26,60 +7,16 @@ export function formatPortfolioValue(value) {
|
|
|
26
7
|
currency: CURRENCY_AUD,
|
|
27
8
|
}).format(numValue);
|
|
28
9
|
}
|
|
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
10
|
export function calculateTotalValue(marketValue, cashBalance) {
|
|
44
11
|
const market = typeof marketValue === 'string' ? parseFloat(marketValue || DEFAULT_EMPTY_STRING) : marketValue;
|
|
45
12
|
const cash = typeof cashBalance === 'string' ? parseFloat(cashBalance || DEFAULT_EMPTY_STRING) : cashBalance;
|
|
46
13
|
return market + cash;
|
|
47
14
|
}
|
|
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
15
|
export function getMarketAllocation(marketValue, totalValue) {
|
|
64
16
|
const market = typeof marketValue === 'string' ? parseFloat(marketValue || DEFAULT_EMPTY_STRING) : marketValue;
|
|
65
17
|
const total = typeof totalValue === 'string' ? parseFloat(totalValue || DEFAULT_EMPTY_STRING) : totalValue;
|
|
66
18
|
return total > DEFAULT_NUMERIC_ZERO ? (market / total) * 100 : DEFAULT_NUMERIC_ZERO;
|
|
67
19
|
}
|
|
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
20
|
export function getCashAllocation(cashBalance, totalValue) {
|
|
84
21
|
const cash = typeof cashBalance === 'string' ? parseFloat(cashBalance || DEFAULT_EMPTY_STRING) : cashBalance;
|
|
85
22
|
const total = typeof totalValue === 'string' ? parseFloat(totalValue || DEFAULT_EMPTY_STRING) : totalValue;
|
package/dist/portfolio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portfolio.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UAAU,CAAC,UAAU,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAC3G,OAAO,KAAK,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAA4B,EAAE,UAA2B;IACzF,MAAM,IAAI,GAAG,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IAC7G,MAAM,KAAK,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAC3G,OAAO,KAAK,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACpF,CAAC"}
|
package/dist/text.d.ts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text manipulation utility functions
|
|
3
|
-
*
|
|
4
|
-
* This module provides pure functions for common text operations
|
|
5
|
-
* such as truncation, formatting, and manipulation.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
9
|
-
*
|
|
10
|
-
* @param text - The text to truncate
|
|
11
|
-
* @param maxLength - The maximum length of the text (default: 30)
|
|
12
|
-
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* truncateText('This is a very long text', 10) // 'This is a...'
|
|
17
|
-
* truncateText('Short', 10) // 'Short'
|
|
18
|
-
* truncateText('', 10) // ''
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
1
|
export declare function truncateText(text: string, maxLength?: number): string;
|
|
22
2
|
//# sourceMappingURL=text.d.ts.map
|
package/dist/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,MAAM,CAGzE"}
|
package/dist/text.js
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text manipulation utility functions
|
|
3
|
-
*
|
|
4
|
-
* This module provides pure functions for common text operations
|
|
5
|
-
* such as truncation, formatting, and manipulation.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
9
|
-
*
|
|
10
|
-
* @param text - The text to truncate
|
|
11
|
-
* @param maxLength - The maximum length of the text (default: 30)
|
|
12
|
-
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* truncateText('This is a very long text', 10) // 'This is a...'
|
|
17
|
-
* truncateText('Short', 10) // 'Short'
|
|
18
|
-
* truncateText('', 10) // ''
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
1
|
export function truncateText(text, maxLength = 30) {
|
|
22
2
|
if (text.length <= maxLength)
|
|
23
3
|
return text;
|
package/dist/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,YAAoB,EAAE;IAC/D,IAAI,IAAI,CAAC,MAAM,IAAI,SAAS;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC;AAC9C,CAAC"}
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,93 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation utility functions
|
|
3
|
-
*/
|
|
4
1
|
import type { PasswordValidation, EmailConfirmationValidation } from '@cranberry-money/shared-types';
|
|
5
|
-
/**
|
|
6
|
-
* Checks if a string contains only numeric characters
|
|
7
|
-
* @param str - The string to validate
|
|
8
|
-
* @returns true if the string contains only digits, false otherwise
|
|
9
|
-
*/
|
|
10
2
|
export declare function isNumericOnly(str: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Validates password strength based on minimum requirements
|
|
13
|
-
* @param password - The password to validate
|
|
14
|
-
* @param minLength - Minimum password length (default: 8)
|
|
15
|
-
* @returns An object containing validation results
|
|
16
|
-
*/
|
|
17
3
|
export declare function validatePassword(password: string, minLength?: number): PasswordValidation;
|
|
18
|
-
/**
|
|
19
|
-
* Validates if a verification token is in the expected format
|
|
20
|
-
* @param token - The verification token to validate
|
|
21
|
-
* @param minLength - Minimum token length (default: 6)
|
|
22
|
-
* @returns true if token appears to be valid format, false otherwise
|
|
23
|
-
*/
|
|
24
4
|
export declare function isValidTokenFormat(token: string, minLength?: number): boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Formats a verification token by removing whitespace and converting to uppercase
|
|
27
|
-
* @param token - The token to format
|
|
28
|
-
* @returns The formatted token
|
|
29
|
-
*/
|
|
30
5
|
export declare function formatVerificationToken(token: string): string;
|
|
31
|
-
/**
|
|
32
|
-
* Validates email confirmation form data
|
|
33
|
-
* @param token - The verification token
|
|
34
|
-
* @param minLength - Minimum token length (default: 6)
|
|
35
|
-
* @returns An object containing validation results
|
|
36
|
-
*/
|
|
37
6
|
export declare function validateEmailConfirmation(token: string, minLength?: number): EmailConfirmationValidation;
|
|
38
|
-
/**
|
|
39
|
-
* Validates if a phone number appears to be in a valid format (less strict)
|
|
40
|
-
* @param phoneNumber - The phone number to validate
|
|
41
|
-
* @param minLength - Minimum length for the phone number (default: 8)
|
|
42
|
-
* @returns true if phone number appears valid, false otherwise
|
|
43
|
-
*/
|
|
44
7
|
export declare function isValidPhoneFormat(phoneNumber: string, minLength?: number): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Validates if a full name contains at least first and last name
|
|
47
|
-
* @param fullName - The full name to validate
|
|
48
|
-
* @param minParts - Minimum number of name parts required (default: 2)
|
|
49
|
-
* @returns true if appears to contain required name parts, false otherwise
|
|
50
|
-
*/
|
|
51
8
|
export declare function isValidFullName(fullName: string, minParts?: 2): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Validates if a date is a valid date of birth (not in future, reasonable age range)
|
|
54
|
-
* @param dateOfBirth - The date string in YYYY-MM-DD format
|
|
55
|
-
* @param minAge - Minimum age requirement (default: 13)
|
|
56
|
-
* @param maxAge - Maximum reasonable age (default: 120)
|
|
57
|
-
* @returns true if valid date of birth, false otherwise
|
|
58
|
-
*/
|
|
59
9
|
export declare function isValidDateOfBirth(dateOfBirth: string, minAge?: 13, maxAge?: 120): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Formats a phone number by removing extra spaces and standardizing format
|
|
62
|
-
* @param phoneNumber - The phone number to format
|
|
63
|
-
* @returns The formatted phone number
|
|
64
|
-
*/
|
|
65
10
|
export declare function formatPhoneNumber(phoneNumber: string): string;
|
|
66
|
-
/**
|
|
67
|
-
* Validates if investment amount is within acceptable range
|
|
68
|
-
* @param amount - The investment amount to validate
|
|
69
|
-
* @param minAmount - Minimum investment amount (default: 100)
|
|
70
|
-
* @param maxAmount - Maximum investment amount (default: 10000000)
|
|
71
|
-
* @returns true if amount is within range, false otherwise
|
|
72
|
-
*/
|
|
73
11
|
export declare function isValidInvestmentAmount(amount: number, minAmount?: 100, maxAmount?: 10000000): boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Validates if at least one source of funds is selected
|
|
76
|
-
* @param sources - Array of selected source of funds
|
|
77
|
-
* @param minSources - Minimum number of sources required (default: from constants)
|
|
78
|
-
* @returns true if at least minimum sources are selected, false otherwise
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* isValidSourceOfFunds(['salary']); // returns true (if min is 1)
|
|
82
|
-
* isValidSourceOfFunds([]); // returns false
|
|
83
|
-
* isValidSourceOfFunds(['salary', 'savings']); // returns true
|
|
84
|
-
*/
|
|
85
12
|
export declare function isValidSourceOfFunds(sources: string[], minSources?: 1): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Validates if at least minimum number of items are selected
|
|
88
|
-
* @param items - Array of selected items
|
|
89
|
-
* @param minItems - Minimum number of items required (default: 1)
|
|
90
|
-
* @returns true if minimum items are selected, false otherwise
|
|
91
|
-
*/
|
|
92
13
|
export declare function hasMinimumSelection<T>(items: T[], minItems?: number): boolean;
|
|
93
14
|
//# sourceMappingURL=validation.d.ts.map
|
package/dist/validation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAGrG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,kBAAkB,CAQpF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,OAAO,CAGxE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,2BAA2B,CAQnG;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,OAAO,CAG9E;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAyC,GAAG,OAAO,CAI5G;AAED,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,MAAM,KAAkC,EACxC,MAAM,MAAkC,GACvC,OAAO,CAaT;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,SAAS,MAA0D,EACnE,SAAS,WAA0D,GAClE,OAAO,CAET;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,IAAwD,GACjE,OAAO,CAET;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,SAAI,GAAG,OAAO,CAExE"}
|
package/dist/validation.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validation utility functions
|
|
3
|
-
*/
|
|
4
1
|
import { USER_PROFILE_VALIDATION, INVESTMENT_PREFERENCES_VALIDATION } from '@cranberry-money/shared-constants';
|
|
5
|
-
/**
|
|
6
|
-
* Checks if a string contains only numeric characters
|
|
7
|
-
* @param str - The string to validate
|
|
8
|
-
* @returns true if the string contains only digits, false otherwise
|
|
9
|
-
*/
|
|
10
2
|
export function isNumericOnly(str) {
|
|
11
3
|
return /^\d+$/.test(str);
|
|
12
4
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Validates password strength based on minimum requirements
|
|
15
|
-
* @param password - The password to validate
|
|
16
|
-
* @param minLength - Minimum password length (default: 8)
|
|
17
|
-
* @returns An object containing validation results
|
|
18
|
-
*/
|
|
19
5
|
export function validatePassword(password, minLength = 8) {
|
|
20
6
|
const lengthValid = password.length >= minLength;
|
|
21
7
|
const notNumeric = !isNumericOnly(password);
|
|
@@ -25,31 +11,13 @@ export function validatePassword(password, minLength = 8) {
|
|
|
25
11
|
notNumeric,
|
|
26
12
|
};
|
|
27
13
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Validates if a verification token is in the expected format
|
|
30
|
-
* @param token - The verification token to validate
|
|
31
|
-
* @param minLength - Minimum token length (default: 6)
|
|
32
|
-
* @returns true if token appears to be valid format, false otherwise
|
|
33
|
-
*/
|
|
34
14
|
export function isValidTokenFormat(token, minLength = 6) {
|
|
35
15
|
const trimmedToken = token.trim();
|
|
36
|
-
// Assuming tokens are alphanumeric and meet minimum length
|
|
37
16
|
return trimmedToken.length >= minLength && /^[a-zA-Z0-9]+$/.test(trimmedToken);
|
|
38
17
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Formats a verification token by removing whitespace and converting to uppercase
|
|
41
|
-
* @param token - The token to format
|
|
42
|
-
* @returns The formatted token
|
|
43
|
-
*/
|
|
44
18
|
export function formatVerificationToken(token) {
|
|
45
19
|
return token.trim().toUpperCase();
|
|
46
20
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Validates email confirmation form data
|
|
49
|
-
* @param token - The verification token
|
|
50
|
-
* @param minLength - Minimum token length (default: 6)
|
|
51
|
-
* @returns An object containing validation results
|
|
52
|
-
*/
|
|
53
21
|
export function validateEmailConfirmation(token, minLength = 6) {
|
|
54
22
|
const formattedToken = formatVerificationToken(token);
|
|
55
23
|
return {
|
|
@@ -58,35 +26,15 @@ export function validateEmailConfirmation(token, minLength = 6) {
|
|
|
58
26
|
isValidFormat: isValidTokenFormat(formattedToken, minLength),
|
|
59
27
|
};
|
|
60
28
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Validates if a phone number appears to be in a valid format (less strict)
|
|
63
|
-
* @param phoneNumber - The phone number to validate
|
|
64
|
-
* @param minLength - Minimum length for the phone number (default: 8)
|
|
65
|
-
* @returns true if phone number appears valid, false otherwise
|
|
66
|
-
*/
|
|
67
29
|
export function isValidPhoneFormat(phoneNumber, minLength = 8) {
|
|
68
30
|
const trimmedPhone = phoneNumber.trim();
|
|
69
|
-
// Basic validation: must contain digits and common phone number characters
|
|
70
31
|
return trimmedPhone.length >= minLength && /^[+\-\s\d()]+$/.test(trimmedPhone);
|
|
71
32
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Validates if a full name contains at least first and last name
|
|
74
|
-
* @param fullName - The full name to validate
|
|
75
|
-
* @param minParts - Minimum number of name parts required (default: 2)
|
|
76
|
-
* @returns true if appears to contain required name parts, false otherwise
|
|
77
|
-
*/
|
|
78
33
|
export function isValidFullName(fullName, minParts = USER_PROFILE_VALIDATION.MIN_NAME_PARTS) {
|
|
79
34
|
const trimmedName = fullName.trim();
|
|
80
35
|
const nameParts = trimmedName.split(/\s+/);
|
|
81
36
|
return nameParts.length >= minParts && nameParts.every(part => part.length > 0);
|
|
82
37
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Validates if a date is a valid date of birth (not in future, reasonable age range)
|
|
85
|
-
* @param dateOfBirth - The date string in YYYY-MM-DD format
|
|
86
|
-
* @param minAge - Minimum age requirement (default: 13)
|
|
87
|
-
* @param maxAge - Maximum reasonable age (default: 120)
|
|
88
|
-
* @returns true if valid date of birth, false otherwise
|
|
89
|
-
*/
|
|
90
38
|
export function isValidDateOfBirth(dateOfBirth, minAge = USER_PROFILE_VALIDATION.MIN_AGE, maxAge = USER_PROFILE_VALIDATION.MAX_AGE) {
|
|
91
39
|
if (!dateOfBirth)
|
|
92
40
|
return false;
|
|
@@ -95,48 +43,18 @@ export function isValidDateOfBirth(dateOfBirth, minAge = USER_PROFILE_VALIDATION
|
|
|
95
43
|
const age = today.getFullYear() - birthDate.getFullYear();
|
|
96
44
|
const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
97
45
|
const dayDiff = today.getDate() - birthDate.getDate();
|
|
98
|
-
// Adjust age if birthday hasn't occurred this year
|
|
99
46
|
const actualAge = monthDiff < 0 || (monthDiff === 0 && dayDiff < 0) ? age - 1 : age;
|
|
100
47
|
return actualAge >= minAge && actualAge <= maxAge && birthDate <= today;
|
|
101
48
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Formats a phone number by removing extra spaces and standardizing format
|
|
104
|
-
* @param phoneNumber - The phone number to format
|
|
105
|
-
* @returns The formatted phone number
|
|
106
|
-
*/
|
|
107
49
|
export function formatPhoneNumber(phoneNumber) {
|
|
108
50
|
return phoneNumber.trim();
|
|
109
51
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Validates if investment amount is within acceptable range
|
|
112
|
-
* @param amount - The investment amount to validate
|
|
113
|
-
* @param minAmount - Minimum investment amount (default: 100)
|
|
114
|
-
* @param maxAmount - Maximum investment amount (default: 10000000)
|
|
115
|
-
* @returns true if amount is within range, false otherwise
|
|
116
|
-
*/
|
|
117
52
|
export function isValidInvestmentAmount(amount, minAmount = INVESTMENT_PREFERENCES_VALIDATION.MIN_INVESTMENT_AMOUNT, maxAmount = INVESTMENT_PREFERENCES_VALIDATION.MAX_INVESTMENT_AMOUNT) {
|
|
118
53
|
return amount >= minAmount && amount <= maxAmount;
|
|
119
54
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Validates if at least one source of funds is selected
|
|
122
|
-
* @param sources - Array of selected source of funds
|
|
123
|
-
* @param minSources - Minimum number of sources required (default: from constants)
|
|
124
|
-
* @returns true if at least minimum sources are selected, false otherwise
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* isValidSourceOfFunds(['salary']); // returns true (if min is 1)
|
|
128
|
-
* isValidSourceOfFunds([]); // returns false
|
|
129
|
-
* isValidSourceOfFunds(['salary', 'savings']); // returns true
|
|
130
|
-
*/
|
|
131
55
|
export function isValidSourceOfFunds(sources, minSources = INVESTMENT_PREFERENCES_VALIDATION.MIN_SOURCE_OF_FUNDS) {
|
|
132
56
|
return sources && sources.length >= minSources;
|
|
133
57
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Validates if at least minimum number of items are selected
|
|
136
|
-
* @param items - Array of selected items
|
|
137
|
-
* @param minItems - Minimum number of items required (default: 1)
|
|
138
|
-
* @returns true if minimum items are selected, false otherwise
|
|
139
|
-
*/
|
|
140
58
|
export function hasMinimumSelection(items, minItems = 1) {
|
|
141
59
|
return items && items.length >= minItems;
|
|
142
60
|
}
|
package/dist/validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AAE/G,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,SAAS,GAAG,CAAC;IAC9D,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,IAAI,SAAS,CAAC;IACjD,MAAM,UAAU,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO;QACL,OAAO,EAAE,WAAW,IAAI,UAAU;QAClC,WAAW;QACX,UAAU;KACX,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,SAAS,GAAG,CAAC;IAC7D,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAClC,OAAO,YAAY,CAAC,MAAM,IAAI,SAAS,IAAI,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACpC,CAAC;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C,WAAW,EAAE,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IAC1D,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IAEtD,MAAM,SAAS,GAAG,SAAS,GAAG,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAEpF,OAAO,SAAS,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,IAAI,SAAS,IAAI,KAAK,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,OAAO,WAAW,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,MAAc,EACd,SAAS,GAAG,iCAAiC,CAAC,qBAAqB,EACnE,SAAS,GAAG,iCAAiC,CAAC,qBAAqB;IAEnE,OAAO,MAAM,IAAI,SAAS,IAAI,MAAM,IAAI,SAAS,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAAiB,EACjB,UAAU,GAAG,iCAAiC,CAAC,mBAAmB;IAElE,OAAO,OAAO,IAAI,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAI,KAAU,EAAE,QAAQ,GAAG,CAAC;IAC7D,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC;AAC3C,CAAC"}
|
|
@@ -1,68 +1,8 @@
|
|
|
1
1
|
import type { WithdrawalStatus, WithdrawalType, WithdrawalReason, LiquidationStatus } from '@cranberry-money/shared-types';
|
|
2
|
-
/**
|
|
3
|
-
* Get the color class for a withdrawal status
|
|
4
|
-
*
|
|
5
|
-
* @param status - The withdrawal status
|
|
6
|
-
* @returns The corresponding color class string
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* getStatusColor('pending_review'); // returns 'text-warning-600'
|
|
10
|
-
* getStatusColor('completed'); // returns 'text-success-600'
|
|
11
|
-
*/
|
|
12
2
|
export declare const getStatusColor: (status: WithdrawalStatus) => string;
|
|
13
|
-
/**
|
|
14
|
-
* Get the display label for a withdrawal status
|
|
15
|
-
*
|
|
16
|
-
* @param status - The withdrawal status
|
|
17
|
-
* @returns The human-readable label
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* getStatusLabel('pending_review'); // returns 'Pending Review'
|
|
21
|
-
* getStatusLabel('liquidation_in_progress'); // returns 'Liquidation in Progress'
|
|
22
|
-
*/
|
|
23
3
|
export declare const getStatusLabel: (status: WithdrawalStatus) => string;
|
|
24
|
-
/**
|
|
25
|
-
* Get the display label for a withdrawal type
|
|
26
|
-
*
|
|
27
|
-
* @param type - The withdrawal type
|
|
28
|
-
* @returns The human-readable label
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* getWithdrawalTypeLabel('full_cash'); // returns 'Full Cash'
|
|
32
|
-
* getWithdrawalTypeLabel('partial_cash'); // returns 'Partial Cash'
|
|
33
|
-
*/
|
|
34
4
|
export declare const getWithdrawalTypeLabel: (type: WithdrawalType) => string;
|
|
35
|
-
/**
|
|
36
|
-
* Get the display label for a withdrawal reason
|
|
37
|
-
*
|
|
38
|
-
* @param reason - The withdrawal reason (optional)
|
|
39
|
-
* @returns The human-readable label
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* getReasonLabel('investment_strategy'); // returns 'Investment Strategy'
|
|
43
|
-
* getReasonLabel(null); // returns 'Not specified'
|
|
44
|
-
*/
|
|
45
5
|
export declare const getReasonLabel: (reason: WithdrawalReason | null | undefined) => string;
|
|
46
|
-
/**
|
|
47
|
-
* Get the color class for a liquidation status
|
|
48
|
-
*
|
|
49
|
-
* @param status - The liquidation status
|
|
50
|
-
* @returns The corresponding color class string
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* getLiquidationStatusColor('pending'); // returns 'text-warning-600'
|
|
54
|
-
* getLiquidationStatusColor('settled'); // returns 'text-success-600'
|
|
55
|
-
*/
|
|
56
6
|
export declare const getLiquidationStatusColor: (status: LiquidationStatus) => string;
|
|
57
|
-
/**
|
|
58
|
-
* Get the display label for a liquidation status
|
|
59
|
-
*
|
|
60
|
-
* @param status - The liquidation status
|
|
61
|
-
* @returns The human-readable label
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* getLiquidationStatusLabel('trades_created'); // returns 'Trades Created'
|
|
65
|
-
* getLiquidationStatusLabel('executed'); // returns 'Executed'
|
|
66
|
-
*/
|
|
67
7
|
export declare const getLiquidationStatusLabel: (status: LiquidationStatus) => string;
|
|
68
8
|
//# sourceMappingURL=withdrawal-status.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawal-status.d.ts","sourceRoot":"","sources":["../src/withdrawal-status.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withdrawal-status.d.ts","sourceRoot":"","sources":["../src/withdrawal-status.ts"],"names":[],"mappings":"AA2CA,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAEvC,eAAO,MAAM,cAAc,GAAI,QAAQ,gBAAgB,KAAG,MAazD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,gBAAgB,KAAG,MAazD,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,MAAM,cAAc,KAAG,MAM7D,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,gBAAgB,GAAG,IAAI,GAAG,SAAS,KAAG,MAU5E,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,QAAQ,iBAAiB,KAAG,MASrE,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,QAAQ,iBAAiB,KAAG,MASrE,CAAC"}
|
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* Get the color class for a withdrawal status
|
|
4
|
-
*
|
|
5
|
-
* @param status - The withdrawal status
|
|
6
|
-
* @returns The corresponding color class string
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* getStatusColor('pending_review'); // returns 'text-warning-600'
|
|
10
|
-
* getStatusColor('completed'); // returns 'text-success-600'
|
|
11
|
-
*/
|
|
1
|
+
import { UNIFIED_STATUS_COLORS, WITHDRAWAL_STATUS_PENDING_REVIEW, WITHDRAWAL_STATUS_APPROVED, WITHDRAWAL_STATUS_REJECTED, WITHDRAWAL_STATUS_PROCESSING, WITHDRAWAL_STATUS_AWAITING_LIQUIDATION, WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS, WITHDRAWAL_STATUS_COMPLETED, WITHDRAWAL_STATUS_CANCELLED, WITHDRAWAL_STATUS_FAILED, WITHDRAWAL_STATUS_LABEL_PENDING_REVIEW, WITHDRAWAL_STATUS_LABEL_APPROVED, WITHDRAWAL_STATUS_LABEL_REJECTED, WITHDRAWAL_STATUS_LABEL_PROCESSING, WITHDRAWAL_STATUS_LABEL_AWAITING_LIQUIDATION, WITHDRAWAL_STATUS_LABEL_LIQUIDATION_IN_PROGRESS, WITHDRAWAL_STATUS_LABEL_COMPLETED, WITHDRAWAL_STATUS_LABEL_CANCELLED, WITHDRAWAL_STATUS_LABEL_FAILED, WITHDRAWAL_TYPE_FULL_CASH, WITHDRAWAL_TYPE_PARTIAL_CASH, WITHDRAWAL_TYPE_LABEL_FULL_CASH, WITHDRAWAL_TYPE_LABEL_PARTIAL_CASH, WITHDRAWAL_REASON_INVESTMENT_STRATEGY, WITHDRAWAL_REASON_PERSONAL_EXPENSES, WITHDRAWAL_REASON_EMERGENCY, WITHDRAWAL_REASON_OTHER, WITHDRAWAL_REASON_LABEL_INVESTMENT_STRATEGY, WITHDRAWAL_REASON_LABEL_PERSONAL_EXPENSES, WITHDRAWAL_REASON_LABEL_EMERGENCY, WITHDRAWAL_REASON_LABEL_OTHER, LIQUIDATION_STATUS_PENDING, LIQUIDATION_STATUS_TRADES_CREATED, LIQUIDATION_STATUS_EXECUTED, LIQUIDATION_STATUS_SETTLED, LIQUIDATION_STATUS_FAILED, LIQUIDATION_STATUS_LABEL_PENDING, LIQUIDATION_STATUS_LABEL_TRADES_CREATED, LIQUIDATION_STATUS_LABEL_EXECUTED, LIQUIDATION_STATUS_LABEL_SETTLED, LIQUIDATION_STATUS_LABEL_FAILED, } from '@cranberry-money/shared-constants';
|
|
12
2
|
export const getStatusColor = (status) => {
|
|
13
3
|
const statusColors = {
|
|
14
|
-
[WITHDRAWAL_STATUS_PENDING_REVIEW]:
|
|
15
|
-
[WITHDRAWAL_STATUS_APPROVED]:
|
|
16
|
-
[WITHDRAWAL_STATUS_REJECTED]:
|
|
17
|
-
[WITHDRAWAL_STATUS_PROCESSING]:
|
|
18
|
-
[WITHDRAWAL_STATUS_AWAITING_LIQUIDATION]:
|
|
19
|
-
[WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS]:
|
|
20
|
-
[WITHDRAWAL_STATUS_COMPLETED]:
|
|
21
|
-
[WITHDRAWAL_STATUS_CANCELLED]:
|
|
22
|
-
[WITHDRAWAL_STATUS_FAILED]:
|
|
4
|
+
[WITHDRAWAL_STATUS_PENDING_REVIEW]: UNIFIED_STATUS_COLORS.pending,
|
|
5
|
+
[WITHDRAWAL_STATUS_APPROVED]: UNIFIED_STATUS_COLORS.approved,
|
|
6
|
+
[WITHDRAWAL_STATUS_REJECTED]: UNIFIED_STATUS_COLORS.rejected,
|
|
7
|
+
[WITHDRAWAL_STATUS_PROCESSING]: UNIFIED_STATUS_COLORS.processing,
|
|
8
|
+
[WITHDRAWAL_STATUS_AWAITING_LIQUIDATION]: UNIFIED_STATUS_COLORS.awaiting,
|
|
9
|
+
[WITHDRAWAL_STATUS_LIQUIDATION_IN_PROGRESS]: UNIFIED_STATUS_COLORS.in_progress,
|
|
10
|
+
[WITHDRAWAL_STATUS_COMPLETED]: UNIFIED_STATUS_COLORS.completed,
|
|
11
|
+
[WITHDRAWAL_STATUS_CANCELLED]: UNIFIED_STATUS_COLORS.cancelled,
|
|
12
|
+
[WITHDRAWAL_STATUS_FAILED]: UNIFIED_STATUS_COLORS.failed,
|
|
23
13
|
};
|
|
24
|
-
return statusColors[status] ||
|
|
14
|
+
return statusColors[status] || UNIFIED_STATUS_COLORS.default;
|
|
25
15
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Get the display label for a withdrawal status
|
|
28
|
-
*
|
|
29
|
-
* @param status - The withdrawal status
|
|
30
|
-
* @returns The human-readable label
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* getStatusLabel('pending_review'); // returns 'Pending Review'
|
|
34
|
-
* getStatusLabel('liquidation_in_progress'); // returns 'Liquidation in Progress'
|
|
35
|
-
*/
|
|
36
16
|
export const getStatusLabel = (status) => {
|
|
37
17
|
const statusLabels = {
|
|
38
18
|
[WITHDRAWAL_STATUS_PENDING_REVIEW]: WITHDRAWAL_STATUS_LABEL_PENDING_REVIEW,
|
|
@@ -47,16 +27,6 @@ export const getStatusLabel = (status) => {
|
|
|
47
27
|
};
|
|
48
28
|
return statusLabels[status] || status;
|
|
49
29
|
};
|
|
50
|
-
/**
|
|
51
|
-
* Get the display label for a withdrawal type
|
|
52
|
-
*
|
|
53
|
-
* @param type - The withdrawal type
|
|
54
|
-
* @returns The human-readable label
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* getWithdrawalTypeLabel('full_cash'); // returns 'Full Cash'
|
|
58
|
-
* getWithdrawalTypeLabel('partial_cash'); // returns 'Partial Cash'
|
|
59
|
-
*/
|
|
60
30
|
export const getWithdrawalTypeLabel = (type) => {
|
|
61
31
|
const typeLabels = {
|
|
62
32
|
[WITHDRAWAL_TYPE_FULL_CASH]: WITHDRAWAL_TYPE_LABEL_FULL_CASH,
|
|
@@ -64,16 +34,6 @@ export const getWithdrawalTypeLabel = (type) => {
|
|
|
64
34
|
};
|
|
65
35
|
return typeLabels[type] || type;
|
|
66
36
|
};
|
|
67
|
-
/**
|
|
68
|
-
* Get the display label for a withdrawal reason
|
|
69
|
-
*
|
|
70
|
-
* @param reason - The withdrawal reason (optional)
|
|
71
|
-
* @returns The human-readable label
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* getReasonLabel('investment_strategy'); // returns 'Investment Strategy'
|
|
75
|
-
* getReasonLabel(null); // returns 'Not specified'
|
|
76
|
-
*/
|
|
77
37
|
export const getReasonLabel = (reason) => {
|
|
78
38
|
if (!reason)
|
|
79
39
|
return 'Not specified';
|
|
@@ -85,16 +45,6 @@ export const getReasonLabel = (reason) => {
|
|
|
85
45
|
};
|
|
86
46
|
return reasonLabels[reason] || reason;
|
|
87
47
|
};
|
|
88
|
-
/**
|
|
89
|
-
* Get the color class for a liquidation status
|
|
90
|
-
*
|
|
91
|
-
* @param status - The liquidation status
|
|
92
|
-
* @returns The corresponding color class string
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* getLiquidationStatusColor('pending'); // returns 'text-warning-600'
|
|
96
|
-
* getLiquidationStatusColor('settled'); // returns 'text-success-600'
|
|
97
|
-
*/
|
|
98
48
|
export const getLiquidationStatusColor = (status) => {
|
|
99
49
|
const statusColors = {
|
|
100
50
|
[LIQUIDATION_STATUS_PENDING]: 'text-warning-600',
|
|
@@ -105,16 +55,6 @@ export const getLiquidationStatusColor = (status) => {
|
|
|
105
55
|
};
|
|
106
56
|
return statusColors[status] || 'text-content-muted';
|
|
107
57
|
};
|
|
108
|
-
/**
|
|
109
|
-
* Get the display label for a liquidation status
|
|
110
|
-
*
|
|
111
|
-
* @param status - The liquidation status
|
|
112
|
-
* @returns The human-readable label
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* getLiquidationStatusLabel('trades_created'); // returns 'Trades Created'
|
|
116
|
-
* getLiquidationStatusLabel('executed'); // returns 'Executed'
|
|
117
|
-
*/
|
|
118
58
|
export const getLiquidationStatusLabel = (status) => {
|
|
119
59
|
const statusLabels = {
|
|
120
60
|
[LIQUIDATION_STATUS_PENDING]: LIQUIDATION_STATUS_LABEL_PENDING,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdrawal-status.js","sourceRoot":"","sources":["../src/withdrawal-status.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"withdrawal-status.js","sourceRoot":"","sources":["../src/withdrawal-status.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,sCAAsC,EACtC,yCAAyC,EACzC,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,sCAAsC,EACtC,gCAAgC,EAChC,gCAAgC,EAChC,kCAAkC,EAClC,4CAA4C,EAC5C,+CAA+C,EAC/C,iCAAiC,EACjC,iCAAiC,EACjC,8BAA8B,EAC9B,yBAAyB,EACzB,4BAA4B,EAC5B,+BAA+B,EAC/B,kCAAkC,EAClC,qCAAqC,EACrC,mCAAmC,EACnC,2BAA2B,EAC3B,uBAAuB,EACvB,2CAA2C,EAC3C,yCAAyC,EACzC,iCAAiC,EACjC,6BAA6B,EAC7B,0BAA0B,EAC1B,iCAAiC,EACjC,2BAA2B,EAC3B,0BAA0B,EAC1B,yBAAyB,EACzB,gCAAgC,EAChC,uCAAuC,EACvC,iCAAiC,EACjC,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAQ3C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAwB,EAAU,EAAE;IACjE,MAAM,YAAY,GAAqC;QACrD,CAAC,gCAAgC,CAAC,EAAE,qBAAqB,CAAC,OAAO;QACj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