Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dialpad numbers input #21

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/dialpad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions app/lib/open-payments.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down
16 changes: 14 additions & 2 deletions app/routes/ilpay.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -22,7 +22,7 @@ export async function loader({ request }: LoaderFunctionArgs) {

export default function Ilpay() {
const data = useLoaderData<typeof loader>();
const { amountValue, setAssetCode } = useDialPadContext();
const { amountValue, setAmountValue, setAssetCode } = useDialPadContext();

useEffect(() => {
setAssetCode(data.assetCode);
Expand All @@ -42,6 +42,12 @@ export default function Ilpay() {
<Link
to={`/request`}
onClick={(e: React.MouseEvent<HTMLElement>) => {
if (
amountValue.indexOf(DialPadIds.Dot) === -1 ||
amountValue.endsWith(DialPadIds.Dot)
) {
setAmountValue(Number(amountValue).toFixed(2).toString());
}
if (Number(amountValue) === 0) e.preventDefault();
}}
>
Expand All @@ -57,6 +63,12 @@ export default function Ilpay() {
<Link
to={`/pay`}
onClick={(e: React.MouseEvent<HTMLElement>) => {
if (
amountValue.indexOf(DialPadIds.Dot) === -1 ||
amountValue.endsWith(DialPadIds.Dot)
) {
setAmountValue(Number(amountValue).toFixed(2).toString());
}
if (Number(amountValue) === 0) e.preventDefault();
}}
>
Expand Down