Skip to content

Commit

Permalink
Implement donation distribution options
Browse files Browse the repository at this point in the history
  • Loading branch information
carina-akaia committed Sep 20, 2024
1 parent a70fe4a commit 29b19ce
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/modules/donation/components/DonationPotAllocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,34 @@ export const DonationPotAllocation: React.FC<DonationPotAllocationProps> = ({
const nearAmountUsdDisplayValue = useNearUsdDisplayValue(amount);

const handleDonationPlanChange = useCallback(
({ accountId }: ByAccountId): React.ChangeEventHandler<HTMLInputElement> =>
({ target: { value } }) =>
({
accountId,
}: ByAccountId): React.ChangeEventHandler<HTMLInputElement> => {
const isExistingEntry =
potDonationPlan !== undefined &&
(potDonationPlan.some(({ account_id }) => account_id === accountId) ??
false);

return ({ target: { value } }) =>
form.setValue(
"potDonationPlan",

potDonationPlan?.reduce(
(entries, entry) => {
if (entry.account_id === accountId) {
return entries?.concat([
{
...entry,
account_id: accountId,
amount: parseFloat(value),
},
]);
} else return entries ?? [];
},
isExistingEntry
? potDonationPlan.reduce(
(entries = [], entry) =>
entries.concat([
entry.account_id === accountId
? { ...entry, amount: parseFloat(value) }
: entry,
]),

[] as DonationInputs["potDonationPlan"],
),
),
[] as DonationInputs["potDonationPlan"],
)
: potDonationPlan?.concat([
{ account_id: accountId, amount: parseFloat(value) },
]),
);
},

[form, potDonationPlan],
);
Expand Down Expand Up @@ -255,9 +262,6 @@ export const DonationPotAllocation: React.FC<DonationPotAllocationProps> = ({
{...field}
type="number"
placeholder="0.00"
min={yoctoNearToFloat(
pot.min_matching_pool_donation_amount,
)}
max={balanceFloat ?? undefined}
step={0.01}
defaultValue={
Expand Down

0 comments on commit 29b19ce

Please sign in to comment.