huge refactor on web-api and web-app

This commit is contained in:
Boki 2025-06-18 10:20:05 -04:00
parent 1d299e52d4
commit 265e10a658
23 changed files with 1545 additions and 1233 deletions

View 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) + '...';
}

View 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;
}