Skip to content

Commit

Permalink
add NEAR fallback if USD not available
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Nov 6, 2023
1 parent f816e25 commit d3fda9f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
19 changes: 15 additions & 4 deletions apps/potlock/widget/Cart/BreakdownSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ return (
<Title>Breakdown summary</Title>
<CurrencyHeader>
<CurrencyHeaderText>Currency</CurrencyHeaderText>
<CurrencyHeaderText>USD</CurrencyHeaderText>
<CurrencyHeaderText>{props.nearToUsd ? "USD" : "NEAR"}</CurrencyHeaderText>
</CurrencyHeader>
{Object.entries(amountsByFt).map(([ft, amount]) => {
const amountFloat = parseFloat(amount || 0);
Expand All @@ -194,21 +194,32 @@ return (
</BreakdownItemLeft>
<BreakdownItemRight>
<BreakdownItemText>
${!props.nearToUsd ? "-" : (amountFloat * props.nearToUsd).toFixed(2)}
{props.nearToUsd
? `$${(amountFloat * props.nearToUsd).toFixed(2)}`
: `${amountFloat.toFixed(2)} N`}
</BreakdownItemText>
</BreakdownItemRight>
</BreakdownItemContainer>
);
})}
<TotalContainer>
<TotalText>Total</TotalText>
<TotalText>${!props.nearToUsd ? "-" : (totalAmount * props.nearToUsd).toFixed(2)}</TotalText>
<TotalText>
{props.nearToUsd
? `$${(totalAmount * props.nearToUsd).toFixed(2)}`
: `${totalAmount.toFixed(2)} N`}
</TotalText>
</TotalContainer>
<Widget
src={`${ownerId}/widget/Buttons.ActionButton`}
props={{
type: "primary",
text: `Donate $${(totalAmount * props.nearToUsd || 0).toFixed(2)}`,
// text: `Donate $${(totalAmount * props.nearToUsd || 0).toFixed(2)}`,
text: `Donate ${
props.nearToUsd
? `$${(totalAmount * props.nearToUsd).toFixed(2)}`
: `${totalAmount.toFixed(2)} N`
}`,
disabled: !Object.keys(props.cart).length || donationTooSmall || !context.accountId,
onClick: handleDonate,
style: {
Expand Down
6 changes: 4 additions & 2 deletions apps/potlock/widget/Project/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ const [totalAmount, totalDonors] = useMemo(() => {
totalDonationAmount = totalDonationAmount.plus(new Big(donation.total_amount));
}
return [
props.nearToUsd ? (props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2) : "-",
props.nearToUsd
? (props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2)
: totalDonationAmount.div(1e24).toNumber().toFixed(2),
donors.length,
];
}, [donationsForProject]);
Expand Down Expand Up @@ -153,7 +155,7 @@ return (
<SubTitle>{totalDonors === 1 ? "Donor" : "Donors"}</SubTitle>
</DonationsInfoItem>
<DonationsInfoItem>
<Title>${totalAmount || "-"}</Title>
<Title>{props.nearToUsd ? `$${totalAmount}` : `${totalAmount} N`}</Title>
<SubTitle>Raised</SubTitle>
</DonationsInfoItem>
</DonationsInfoContainer>
Expand Down
19 changes: 15 additions & 4 deletions build/potlock/src/Cart/BreakdownSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ return (
<Title>Breakdown summary</Title>
<CurrencyHeader>
<CurrencyHeaderText>Currency</CurrencyHeaderText>
<CurrencyHeaderText>USD</CurrencyHeaderText>
<CurrencyHeaderText>{props.nearToUsd ? "USD" : "NEAR"}</CurrencyHeaderText>
</CurrencyHeader>
{Object.entries(amountsByFt).map(([ft, amount]) => {
const amountFloat = parseFloat(amount || 0);
Expand All @@ -194,21 +194,32 @@ return (
</BreakdownItemLeft>
<BreakdownItemRight>
<BreakdownItemText>
${!props.nearToUsd ? "-" : (amountFloat * props.nearToUsd).toFixed(2)}
{props.nearToUsd
? `$${(amountFloat * props.nearToUsd).toFixed(2)}`
: `${amountFloat.toFixed(2)} N`}
</BreakdownItemText>
</BreakdownItemRight>
</BreakdownItemContainer>
);
})}
<TotalContainer>
<TotalText>Total</TotalText>
<TotalText>${!props.nearToUsd ? "-" : (totalAmount * props.nearToUsd).toFixed(2)}</TotalText>
<TotalText>
{props.nearToUsd
? `$${(totalAmount * props.nearToUsd).toFixed(2)}`
: `${totalAmount.toFixed(2)} N`}
</TotalText>
</TotalContainer>
<Widget
src={`${ownerId}/widget/Buttons.ActionButton`}
props={{
type: "primary",
text: `Donate $${(totalAmount * props.nearToUsd || 0).toFixed(2)}`,
// text: `Donate $${(totalAmount * props.nearToUsd || 0).toFixed(2)}`,
text: `Donate ${
props.nearToUsd
? `$${(totalAmount * props.nearToUsd).toFixed(2)}`
: `${totalAmount.toFixed(2)} N`
}`,
disabled: !Object.keys(props.cart).length || donationTooSmall || !context.accountId,
onClick: handleDonate,
style: {
Expand Down
6 changes: 4 additions & 2 deletions build/potlock/src/Project/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ const [totalAmount, totalDonors] = useMemo(() => {
totalDonationAmount = totalDonationAmount.plus(new Big(donation.total_amount));
}
return [
props.nearToUsd ? (props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2) : "-",
props.nearToUsd
? (props.nearToUsd * totalDonationAmount.div(1e24).toNumber()).toFixed(2)
: totalDonationAmount.div(1e24).toNumber().toFixed(2),
donors.length,
];
}, [donationsForProject]);
Expand Down Expand Up @@ -153,7 +155,7 @@ return (
<SubTitle>{totalDonors === 1 ? "Donor" : "Donors"}</SubTitle>
</DonationsInfoItem>
<DonationsInfoItem>
<Title>${totalAmount || "-"}</Title>
<Title>{props.nearToUsd ? `$${totalAmount}` : `${totalAmount} N`}</Title>
<SubTitle>Raised</SubTitle>
</DonationsInfoItem>
</DonationsInfoContainer>
Expand Down

0 comments on commit d3fda9f

Please sign in to comment.