FIX - polish banking interactions and transaction details

This commit is contained in:
Leon.Schmidt
2026-08-17 00:25:14 +02:00
parent 181206f3cf
commit 335b9a98b5
12 changed files with 482 additions and 111 deletions
+23
View File
@@ -0,0 +1,23 @@
import { describe, expect, it } from 'vitest'
import {
normalizeBankingAmountInput,
parseBankingAmount,
} from '@/utils/bankingAmount'
describe('banking amount input', () => {
it('uses a decimal comma and strips native number-input noise', () => {
expect(normalizeBankingAmountInput('1.')).toBe('1,')
expect(normalizeBankingAmountInput('12.00')).toBe('12,00')
expect(normalizeBankingAmountInput('EUR 12,00')).toBe('12,00')
expect(normalizeBankingAmountInput('12,0,0')).toBe('12,00')
})
it('keeps the server-authoritative whole-money contract', () => {
expect(parseBankingAmount('125')).toBe(125)
expect(parseBankingAmount('125,00')).toBe(125)
expect(parseBankingAmount('125,50')).toBeNull()
expect(parseBankingAmount('0')).toBeNull()
expect(parseBankingAmount('')).toBeNull()
})
})
+24
View File
@@ -0,0 +1,24 @@
export function normalizeBankingAmountInput(value: string): string {
const normalizedSeparators = value.replace(/\./g, ',')
const digitsAndSeparators = normalizedSeparators.replace(/[^\d,]/g, '')
const separatorIndex = digitsAndSeparators.indexOf(',')
if (separatorIndex < 0) return digitsAndSeparators
const whole = digitsAndSeparators.slice(0, separatorIndex)
const decimal = digitsAndSeparators
.slice(separatorIndex + 1)
.replace(/,/g, '')
.slice(0, 2)
return `${whole},${decimal}`
}
export function parseBankingAmount(value: string): number | null {
if (!/^\d+(?:,\d{1,2})?$/.test(value)) return null
const amount = Number(value.replace(',', '.'))
if (!Number.isSafeInteger(amount) || amount <= 0) return null
return amount
}