diff --git a/src/routes/transfer/+page.svelte b/src/routes/transfer/+page.svelte index 0c900e1..ee1fb13 100644 --- a/src/routes/transfer/+page.svelte +++ b/src/routes/transfer/+page.svelte @@ -112,20 +112,28 @@ } // Helper function to get the name of the parent category - function getCardName(cardId: number) { - if (cardId === 0) return "None"; - const card = cards.find((card) => card.id === cardId); - return card ? card.name : "Unknown"; + function doesCurrentTransferHasSameCurrencies(): boolean { + if (currentTransfer.from_card_id == 0 || currentTransfer.to_card_id == 0) { + return true; + } + return ( + cards.find((card) => card.id == currentTransfer.from_card_id) + ?.currency_id == + cards.find((card) => card.id == currentTransfer.to_card_id)?.currency_id + ); } - function handleValueInput( - event: Event & { currentTarget: EventTarget & HTMLInputElement }, - ): void { - const target = event.target as HTMLInputElement; - const rawValue = target.value.replace(/[^0-9]/g, ""); - currentTransfer.value = parseInt(rawValue || "0"); - target.value = NumberToFPA(currentTransfer.value); let valueRef: HTMLInputElement | null = $state(null); + function createHandleValueInput(field: "value" | "from_value" | "to_value") { + return function ( + event: Event & { currentTarget: EventTarget & HTMLInputElement }, + ): void { + const target = event.target as HTMLInputElement; + const rawValue = target.value.replace(/[^0-9]/g, ""); + const parsedValue = parseInt(rawValue || "0"); + currentTransfer[field] = parsedValue; + target.value = NumberToFPA(parsedValue); + }; } const constructedTime = $derived(`${mutateDate}T${selectedTime}Z`); @@ -174,15 +182,39 @@ - + {#if doesCurrentTransferHasSameCurrencies()} + + {:else} + + + {/if}