Skip to content

Commit

Permalink
Remove decimals fiat (#3367)
Browse files Browse the repository at this point in the history
* remoev decimals fiat

* git status
  • Loading branch information
ap-justin authored Oct 16, 2024
1 parent 3fe0b68 commit efbfb54
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/donation/Steps/DonateMethods/Daf/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function Form(props: Props) {
rate={usdOption.rate}
increments={props.init.config?.increments}
classes="mb-4"
precision={0}
/>

{(props.init.recipient.progDonationsAllowed ?? true) && (
Expand Down
3 changes: 2 additions & 1 deletion src/components/donation/Steps/DonateMethods/Daf/useRhf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { yupResolver } from "@hookform/resolvers/yup";
import { roundDown } from "helpers";
import { useController, useForm } from "react-hook-form";
import { schema, stringNumber } from "schemas/shape";
import type { OnIncrement } from "../../common/Incrementers";
Expand Down Expand Up @@ -40,7 +41,7 @@ export function useRhf(props: Props) {
const onIncrement: OnIncrement = (inc) => {
const amntNum = Number(getValues("amount"));
if (Number.isNaN(amntNum)) return trigger("amount", { shouldFocus: true });
setValue("amount", `${inc + amntNum}`);
setValue("amount", roundDown(inc + amntNum, 0));
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ describe("Stripe form test", () => {
await userEvent.clear(amountInput);
await userEvent.type(amountInput, "13");
await userEvent.click(incrementers[0]); // 50PHP * 40
expect(amountInput).toHaveDisplayValue("2013.00");
expect(amountInput).toHaveDisplayValue("2013");

await userEvent.click(incrementers[1]); // 50PHP * 100
expect(amountInput).toHaveDisplayValue("7013.00");
expect(amountInput).toHaveDisplayValue("7013");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function Form({ currencies, defaultCurr, ...props }: FormProps) {
code={rhf.currency.value.code}
rate={rhf.currency.value.rate}
increments={props.init.config?.increments}
precision={0}
/>
)}

Expand Down
5 changes: 2 additions & 3 deletions src/components/donation/Steps/DonateMethods/Stripe/useRhf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { yupResolver } from "@hookform/resolvers/yup";
import { centsDecimals, roundDown } from "helpers";
import { roundDown } from "helpers";
import { useController, useForm } from "react-hook-form";
import { schema, stringNumber } from "schemas/shape";
import { requiredString } from "schemas/string";
Expand Down Expand Up @@ -62,10 +62,9 @@ export function useRhf(props: Omit<FormProps, "currencies">) {
});

const onIncrement: OnIncrement = (inc) => {
const currency = getValues("currency");
const amntNum = Number(getValues("amount"));
if (Number.isNaN(amntNum)) return trigger("amount", { shouldFocus: true });
setValue("amount", roundDown(amntNum + inc, centsDecimals(currency.rate)));
setValue("amount", roundDown(amntNum + inc, 0));
};

return {
Expand Down

0 comments on commit efbfb54

Please sign in to comment.