From eba62505be1b0eb140890838c1f0a718f3a74ac3 Mon Sep 17 00:00:00 2001 From: Tymmmy <117268143+Tymmmy@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:04:22 +0300 Subject: [PATCH] Fix dialpad numbers input --- app/components/dialpad.tsx | 2 +- app/lib/open-payments.server.ts | 8 ++++++-- app/routes/ilpay.tsx | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/components/dialpad.tsx b/app/components/dialpad.tsx index 09e1670..8f91eb4 100644 --- a/app/components/dialpad.tsx +++ b/app/components/dialpad.tsx @@ -3,7 +3,7 @@ import { cn } from "~/lib/cn"; import { useDialPadContext } from "~/lib/context/dialpad"; import { getCurrencySymbol } from "~/utils/helpers"; -enum DialPadIds { +export enum DialPadIds { Backspace = "Backspace", Dot = ".", Zero = "0", diff --git a/app/lib/open-payments.server.ts b/app/lib/open-payments.server.ts index 884f567..685dd59 100644 --- a/app/lib/open-payments.server.ts +++ b/app/lib/open-payments.server.ts @@ -33,7 +33,9 @@ export async function fetchQuote( const walletAddress = await getWalletAddress(args.walletAddress, opClient); const amountObj = { - value: BigInt(args.amount * 10 ** walletAddress.assetScale).toString(), + value: BigInt( + (args.amount * 10 ** walletAddress.assetScale).toFixed() + ).toString(), assetCode: walletAddress.assetCode, assetScale: walletAddress.assetScale, }; @@ -166,7 +168,9 @@ export async function createRequestPayment(args: { const walletAddress = await getWalletAddress(args.walletAddress, opClient); const amountObj = { - value: BigInt(args.amount * 10 ** walletAddress.assetScale).toString(), + value: BigInt( + (args.amount * 10 ** walletAddress.assetScale).toFixed() + ).toString(), assetCode: walletAddress.assetCode, assetScale: walletAddress.assetScale, }; diff --git a/app/routes/ilpay.tsx b/app/routes/ilpay.tsx index 81e6a2d..1cd3be1 100644 --- a/app/routes/ilpay.tsx +++ b/app/routes/ilpay.tsx @@ -1,5 +1,5 @@ import { Button } from "~/components/ui/button"; -import { DialPad } from "~/components/dialpad"; +import { DialPad, DialPadIds } from "~/components/dialpad"; import { Header } from "~/components/header"; import { Link, useLoaderData } from "@remix-run/react"; import { useDialPadContext } from "~/lib/context/dialpad"; @@ -22,7 +22,7 @@ export async function loader({ request }: LoaderFunctionArgs) { export default function Ilpay() { const data = useLoaderData(); - const { amountValue, setAssetCode } = useDialPadContext(); + const { amountValue, setAmountValue, setAssetCode } = useDialPadContext(); useEffect(() => { setAssetCode(data.assetCode); @@ -42,6 +42,12 @@ export default function Ilpay() { ) => { + if ( + amountValue.indexOf(DialPadIds.Dot) === -1 || + amountValue.endsWith(DialPadIds.Dot) + ) { + setAmountValue(Number(amountValue).toFixed(2).toString()); + } if (Number(amountValue) === 0) e.preventDefault(); }} > @@ -57,6 +63,12 @@ export default function Ilpay() { ) => { + if ( + amountValue.indexOf(DialPadIds.Dot) === -1 || + amountValue.endsWith(DialPadIds.Dot) + ) { + setAmountValue(Number(amountValue).toFixed(2).toString()); + } if (Number(amountValue) === 0) e.preventDefault(); }} >