huge refactor on web-api and web-app
This commit is contained in:
parent
1d299e52d4
commit
265e10a658
23 changed files with 1545 additions and 1233 deletions
35
apps/web-app/src/features/exchanges/utils/formatters.ts
Normal file
35
apps/web-app/src/features/exchanges/utils/formatters.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { ProviderMapping } from '../types';
|
||||
|
||||
export function formatDate(dateString: string): string {
|
||||
return new Date(dateString).toLocaleDateString();
|
||||
}
|
||||
|
||||
export function formatProviderMapping(mapping: ProviderMapping): string {
|
||||
return `${mapping.provider.toLowerCase()}(${mapping.provider_exchange_code})`;
|
||||
}
|
||||
|
||||
export function getProviderMappingColor(mapping: ProviderMapping): string {
|
||||
return mapping.active ? 'text-green-500' : 'text-text-muted';
|
||||
}
|
||||
|
||||
export function sortProviderMappings(mappings: ProviderMapping[]): ProviderMapping[] {
|
||||
return [...mappings].sort((a, b) => {
|
||||
// Active mappings first
|
||||
if (a.active && !b.active) {
|
||||
return -1;
|
||||
}
|
||||
if (!a.active && b.active) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Then by provider name
|
||||
return a.provider.localeCompare(b.provider);
|
||||
});
|
||||
}
|
||||
|
||||
export function truncateText(text: string, maxLength: number): string {
|
||||
if (text.length <= maxLength) {
|
||||
return text;
|
||||
}
|
||||
return text.substring(0, maxLength) + '...';
|
||||
}
|
||||
38
apps/web-app/src/features/exchanges/utils/validation.ts
Normal file
38
apps/web-app/src/features/exchanges/utils/validation.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { FormErrors } from '../types';
|
||||
|
||||
export function validateExchangeForm(data: {
|
||||
code: string;
|
||||
name: string;
|
||||
country: string;
|
||||
currency: string;
|
||||
}): FormErrors {
|
||||
const errors: FormErrors = {};
|
||||
|
||||
if (!data.code.trim()) {
|
||||
errors.code = 'Exchange code is required';
|
||||
} else if (data.code.length > 10) {
|
||||
errors.code = 'Exchange code must be 10 characters or less';
|
||||
}
|
||||
|
||||
if (!data.name.trim()) {
|
||||
errors.name = 'Exchange name is required';
|
||||
}
|
||||
|
||||
if (!data.country.trim()) {
|
||||
errors.country = 'Country is required';
|
||||
} else if (data.country.length !== 2) {
|
||||
errors.country = 'Country must be exactly 2 characters (e.g., US, CA, GB)';
|
||||
}
|
||||
|
||||
if (!data.currency.trim()) {
|
||||
errors.currency = 'Currency is required';
|
||||
} else if (data.currency.length !== 3) {
|
||||
errors.currency = 'Currency must be exactly 3 characters (e.g., USD, EUR, CAD)';
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
export function hasValidationErrors(errors: FormErrors): boolean {
|
||||
return Object.keys(errors).length > 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue