diff --git a/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx b/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx index 917c90c5..0c8b0f63 100644 --- a/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx +++ b/src/app/components/transaction-screen/transaction-screen.transaction-form/components/transaction-screen.transaction-form/transaction-screen.transaction-form.tsx @@ -8,7 +8,8 @@ import { BitcoinTransactionConfirmationsContext } from '@providers/bitcoin-query import { BitcoinWalletContextState } from '@providers/bitcoin-wallet-context-provider'; import { useForm } from '@tanstack/react-form'; import Decimal from 'decimal.js'; -import { isEmpty } from 'ramda'; + +import { parseAssetAmount } from '@shared/utils'; import { TransactionFormNavigateButtonGroup } from './components/transaction-screen.transaction-form.navigate-button-group'; import { TransactionFormProgressStack } from './components/transaction-screen.transaction-form.progress-stack/components/transaction-screen.transaction-form.progress-stack'; @@ -141,16 +142,12 @@ export function VaultTransactionForm({ }, validators: { onChange: ({ value }) => { - const assetAmount = value.assetAmount; - setCurrentFieldValue(isEmpty(assetAmount) ? 0 : new Decimal(value.assetAmount).toNumber()); + const decimalValue = parseAssetAmount(value.assetAmount); + setCurrentFieldValue(decimalValue.toNumber()); + return { fields: { - assetAmount: validateFormAmount( - parseFloat(value.assetAmount), - flow, - depositLimit, - vault - ), + assetAmount: validateFormAmount(decimalValue.toNumber(), flow, depositLimit, vault), }, }; }, diff --git a/src/app/hooks/use-blockchain-height-query.ts b/src/app/hooks/use-blockchain-height-query.ts index 3d204876..306f698a 100644 --- a/src/app/hooks/use-blockchain-height-query.ts +++ b/src/app/hooks/use-blockchain-height-query.ts @@ -9,6 +9,7 @@ export function useBlockchainHeightQuery(): number | undefined { if (!response.ok) throw new Error('Network response was not ok'); return response.json(); } catch (error) { + // eslint-disable-next-line no-console console.error('Error fetching blockchain height', error); return undefined; } diff --git a/src/app/hooks/use-confirmation-checker.ts b/src/app/hooks/use-confirmation-checker.ts index 62054ee9..56cfb826 100644 --- a/src/app/hooks/use-confirmation-checker.ts +++ b/src/app/hooks/use-confirmation-checker.ts @@ -34,7 +34,8 @@ export function useConfirmationChecker(): [string, number][] { try { const bitcoinTransactionBlockHeight = await fetchBitcoinTransactionBlockHeight(vault); - return blockHeight - bitcoinTransactionBlockHeight; + const difference = blockHeight - bitcoinTransactionBlockHeight; + return Math.max(difference, 0); } catch (error) { return 0; } diff --git a/src/app/hooks/use-mint-burn-events.ts b/src/app/hooks/use-mint-burn-events.ts index b9cfdbdb..19c597b1 100644 --- a/src/app/hooks/use-mint-burn-events.ts +++ b/src/app/hooks/use-mint-burn-events.ts @@ -22,6 +22,7 @@ export function useMintBurnEvents(): UseMintBurnEventsReturnType { return await response.json(); } catch (error) { + // eslint-disable-next-line no-console console.error(`Error fetching mint burn events`, error); return []; } @@ -60,6 +61,7 @@ export function useMintBurnEvents(): UseMintBurnEventsReturnType { merchantMintBurnEvents: mintBurnEvents, }; } catch (error) { + // eslint-disable-next-line no-console console.error(`Error fetching mint burn events`, error); return undefined; } diff --git a/src/app/hooks/use-points.ts b/src/app/hooks/use-points.ts index 27200971..7f7187ae 100644 --- a/src/app/hooks/use-points.ts +++ b/src/app/hooks/use-points.ts @@ -25,6 +25,7 @@ export function usePoints(): UsePointsReturnType { return responseData.points; } catch (error) { + // eslint-disable-next-line no-console console.error(`Error fetching user: ${address} points`, error); return undefined; } diff --git a/src/app/hooks/use-proof-of-reserve.ts b/src/app/hooks/use-proof-of-reserve.ts index 5d353f49..0bfccaf2 100644 --- a/src/app/hooks/use-proof-of-reserve.ts +++ b/src/app/hooks/use-proof-of-reserve.ts @@ -29,6 +29,7 @@ export function useProofOfReserve(): UseProofOfReserveReturnType { return await response.json(); } catch (error) { + // eslint-disable-next-line no-console console.error('Error fetching Proof of Reserve', error); return 0; } diff --git a/src/app/hooks/use-total-supply.ts b/src/app/hooks/use-total-supply.ts index 0a61d161..ee0aaef2 100644 --- a/src/app/hooks/use-total-supply.ts +++ b/src/app/hooks/use-total-supply.ts @@ -19,6 +19,7 @@ export function useTotalSupply(): UseTotalSupplyReturnType { return responseData; } catch (error) { + // eslint-disable-next-line no-console console.error('Error fetching Total Supply', error); return undefined; } diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 53f98c03..91f22573 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -51,6 +51,19 @@ export function formatEvent(event: DetailedEvent): FormattedEvent { }; } +export function parseAssetAmount(assetAmount: string): Decimal { + const isValidNumber = /^-?\d*\.?\d*$/.test(assetAmount); + + if (isValidNumber) { + try { + return new Decimal(assetAmount); + } catch { + return new Decimal(0); + } + } + return new Decimal(0); +} + export function formatToFourDecimals(value: number): number { return parseFloat(value.toFixed(4)); }