Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
carina-akaia committed Jun 16, 2024
1 parent 1d13b98 commit b8a7023
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/modules/donation/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const DONATION_MIN_AMOUNT = 0.0001;
export const DONATION_MIN_NEAR_AMOUNT = 0.1;

export const DONATION_MAX_MESSAGE_LENGTH = 100;
10 changes: 7 additions & 3 deletions src/modules/donation/hooks/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback } from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { SubmitHandler, useForm } from "react-hook-form";

import { dispatch } from "@/app/_store";
import { NEAR_TOKEN_DENOM } from "@/common/constants";
import useIsHuman from "@/modules/core/hooks/useIsHuman";

Expand All @@ -18,9 +19,12 @@ export const useDonationForm = (_: DonationFormParameters) => {
const isFtDonation = watch("tokenId") !== NEAR_TOKEN_DENOM;
const isSenderHumanVerified = useIsHuman(watch("recipientAccountId"));

const onSubmit: SubmitHandler<DonationInputs> = useCallback((data) => {
console.table(data);
}, []);
const onSubmit: SubmitHandler<DonationInputs> = useCallback(
(data) => dispatch.donation.submit(data),
[],
);

console.table(form.getValues());

return {
isFtDonation,
Expand Down
24 changes: 15 additions & 9 deletions src/modules/donation/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { NEAR_TOKEN_DENOM } from "@/common/constants";
import { donateNearDirectly } from "@/common/contracts/potlock/donate";
import { DirectDonation } from "@/common/contracts/potlock/interfaces/donate.interfaces";

import { DONATION_MAX_MESSAGE_LENGTH, DONATION_MIN_AMOUNT } from "./constants";
import {
DONATION_MAX_MESSAGE_LENGTH,
DONATION_MIN_NEAR_AMOUNT,
} from "./constants";

export type DonationParameters = ByAccountId | ByPotId;

Expand Down Expand Up @@ -61,7 +64,10 @@ export const donationSchema = object({
amount: number()
.positive()
.finite()
.min(DONATION_MIN_AMOUNT)
.min(
DONATION_MIN_NEAR_AMOUNT,
`The minimum donation amount is ${DONATION_MIN_NEAR_AMOUNT} NEAR.`,
)
.refine(
(n) => !number().int().safeParse(n).success,
"Must be a floating point number.",
Expand All @@ -75,7 +81,9 @@ export const donationSchema = object({
bypassProtocolFee: boolean().default(false),

bypassChefFee: boolean().default(false),
});
}).refine(({ tokenId, amount }) => {
return tokenId === NEAR_TOKEN_DENOM || amount > 0.0;
}, "Incorrect donation amount");

export type DonationInputs = FromSchema<typeof donationSchema>;

Expand Down Expand Up @@ -128,17 +136,15 @@ export const donationModel = createModel<RootModel>()({
},

effects: (dispatch) => ({
submitDonation({
amount,
donationType,
recipientAccountId,
}: DonationInputs) {
submit({ amount, donationType, recipientAccountId }: DonationInputs) {
switch (donationType) {
case DonationType.direct:
return donateNearDirectly(
{ recipient_id: recipientAccountId },
amount,
);
)
.then(dispatch.success)
.catch(dispatch.failure);
}
},
}),
Expand Down

0 comments on commit b8a7023

Please sign in to comment.