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

BG-1014: Fee presentation update #2626

Merged
merged 3 commits into from
Jan 4, 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
5 changes: 1 addition & 4 deletions src/components/donation/Steps/Submit/Breakdown/Breakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ export default function Breakdown({
if (estimate === "loading") {
return (
<>
<Row title="Transaction costs:">
<span>----</span>
</Row>
<Row title="TOTAL">
<span>
{token.symbol} {humanize(token.amount, 4)}
</span>
</Row>
<LoadingStatus classes="justify-self-center my-6">
Estimating transaction cost..
Simulating transaction...
</LoadingStatus>
</>
);
Expand Down
42 changes: 14 additions & 28 deletions src/components/donation/Steps/Submit/Breakdown/estimateDonation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,56 +120,42 @@ export async function estimateDonation({
if (!estimate) return null;

// ///////////// Sucessful simulation ///////////////
const [tokenUSD, feeUSD] = await Promise.all([
USD(token.coingecko_denom),
USD(estimate.fee.coinGeckoId),
]);
const amountUSDRate = await USD(token.coingecko_denom);

const tokenUSDDec = new Decimal(tokenUSD).mul(token.amount);
const amount: EstimateItem = {
const amountUSDDec = new Decimal(amountUSDRate).mul(token.amount);
const amountItem: EstimateItem = {
name: "Amount",
cryptoAmount: {
value: token.amount,
symbol: token.symbol,
},
fiatAmount: tokenUSDDec.toNumber(),
prettyFiatAmount: `$${humanize(tokenUSDDec, 4)}`,
fiatAmount: amountUSDDec.toNumber(),
prettyFiatAmount: `$${humanize(amountUSDDec, 4)}`,
};

const feeUSDDec = new Decimal(feeUSD).mul(estimate.fee.amount);
const baseFee = amountUSDDec.mul(BASE_FEE_RATE_PCT).div(100);
const cryptoFee = amountUSDDec.mul(CRYPTO_FEE_RATE_PCT).div(100);
const fiscalSponsorShipFee = fiscalSponsorShipFeeFn(amountUSDDec);

const baseFee = tokenUSDDec.mul(BASE_FEE_RATE_PCT).div(100);
const cryptoFee = tokenUSDDec.mul(CRYPTO_FEE_RATE_PCT).div(100);
const fiscalSponsorShipFee = fiscalSponsorShipFeeFn(tokenUSDDec);
//feeUSD is on top of tokenAmountUSD
const totalFeeDec = baseFee.add(cryptoFee).add(fiscalSponsorShipFee);
const totalPct = totalFeeDec.div(amountUSDDec).mul(100).toFixed(2);

const transactionFee: EstimateItem = {
name: "Transaction fee",
cryptoAmount: {
value: estimate.fee.amount.toString(),
symbol: estimate.fee.symbol,
},
fiatAmount: feeUSDDec.toNumber(),
prettyFiatAmount: prettyDollar(feeUSDDec),
};

const donationFee: EstimateItem = {
name: "Better Giving Fee",
const totalFeeItem: EstimateItem = {
name: `Platform Fee (${totalPct}) %`,
fiatAmount: totalFeeDec.toNumber(),
prettyFiatAmount: prettyDollar(totalFeeDec),
};

const totalDec = tokenUSDDec.sub(totalFeeDec);
const total: EstimateItem = {
const totalDec = amountUSDDec.sub(totalFeeDec);
const totalItem: EstimateItem = {
name: "Estimated proceeds",
fiatAmount: totalDec.toNumber(),
prettyFiatAmount: prettyDollar(totalDec),
};

return {
...estimate,
items: [amount, donationFee, transactionFee, total],
items: [amountItem, totalFeeItem, totalItem],
};
} catch (err) {
logger.error(err);
Expand Down