Skip to content

Commit

Permalink
Merge pull request #4950 from Giveth/add_estimated_timer
Browse files Browse the repository at this point in the history
Add estimated timer
  • Loading branch information
kkatusic authored Jan 20, 2025
2 parents a10b813 + 06acda5 commit 5713da6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
3 changes: 3 additions & 0 deletions pages/api/generate-sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const maxDuration = 300;
export const dynamic = 'force-dynamic';

import fs from 'fs';
import path from 'path';
import { NextApiRequest, NextApiResponse } from 'next';
Expand Down
13 changes: 11 additions & 2 deletions src/components/AmountInput/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export const AmountInput: FC<IAmountInput> = ({
const regex = /^0(\.0+)?$/;
const isZero = regex.test(displayAmount);
if (amount === 0n && isZero) return;

const maxDecimals = decimals === 8 ? 8 : decimals / 3;

const _displayAmount = truncateToDecimalPlaces(
formatUnits(amount, decimals),
decimals / 3,
maxDecimals,
).toString();
setDisplayAmount(_displayAmount);
}, [amount, decimals]);
Expand All @@ -74,7 +77,13 @@ export const AmountInput: FC<IAmountInput> = ({
const onUserInput = useCallback(
(value: string) => {
const [, _decimals] = value.split('.');
if (_decimals?.length > decimals / 3) return;

// Allow more decimals if token has 8 decimals
if (decimals === 8) {
if (_decimals?.length > 8) return; // Limit to 8 decimals
} else {
if (_decimals?.length > decimals / 3) return; // Limit to 6 or 2 decimals for other tokens
}
setDisplayAmount(value);
setActiveStep(0);

Expand Down
11 changes: 9 additions & 2 deletions src/components/views/donate/Recurring/RecurringDonationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ export const RecurringDonationCard = () => {
if (selectedRecurringToken.token.isSuperToken) {
setAmount(balance.value || 0n);
}
if (selectedRecurringToken.token.decimals === 6) {
if (
selectedRecurringToken.token.decimals === 6 ||
selectedRecurringToken.token.decimals === 8
) {
setAmount(0n);
setPerMonthAmount(0n);
}
Expand All @@ -151,7 +154,11 @@ export const RecurringDonationCard = () => {

// Introduce a scaling factor to handle tokens with different decimals
const scaleFactor =
selectedRecurringToken?.token.decimals === 6 ? 10000n : 1n;
selectedRecurringToken?.token.decimals === 6
? 10000n
: selectedRecurringToken?.token.decimals === 8
? 100n
: 1n;

// total means project + giveth
const totalPerSec = perMonthAmount / (ONE_MONTH_SECONDS / scaleFactor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,22 @@ const RecurringDonationInnerModal: FC<IRecurringDonationInnerModalProps> = ({
// This is a special case with tokens that have 6 decimals
// We need to convert the amount to 18 decimals for the upgrade operation
// And also for the flow rate calculation
if (selectedRecurringToken.token.decimals === 6) {
if (
selectedRecurringToken.token.decimals === 6 ||
selectedRecurringToken.token.decimals === 8
) {
const divisor = BigInt(
10 ** selectedRecurringToken.token.decimals,
);
const currentAmount = Number(amount) / Number(divisor);
newAmount = ethers.utils
.parseUnits(currentAmount.toString(), 18)
.parseUnits(currentAmount.toFixed(8), 18)
.toBigInt();

const currentPerMonth =
Number(perMonthAmount) / Number(divisor);
newPerMonthAmount = ethers.utils
.parseUnits(currentPerMonth.toString(), 18)
.parseUnits(currentPerMonth.toFixed(8), 18)
.toBigInt();
}

Expand Down
30 changes: 15 additions & 15 deletions src/config/production.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -638,21 +638,21 @@ const config: EnvConfig = {
isSuperToken: true,
coingeckoId: 'ethereum',
},
// {
// underlyingToken: {
// decimals: 8,
// id: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf',
// name: 'Coinbase Wrapped BTC',
// symbol: 'cbBTC',
// coingeckoId: 'bitcoin',
// },
// decimals: 18,
// id: '0xDFd428908909CB5E24F5e79E6aD6BDE10bdf2327',
// name: 'Coinbase wrapped BTC',
// symbol: 'cbBTCx',
// isSuperToken: true,
// coingeckoId: 'bitcoin',
// },
{
underlyingToken: {
decimals: 8,
id: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf',
name: 'Coinbase Wrapped BTC',
symbol: 'cbBTC',
coingeckoId: 'bitcoin',
},
decimals: 18,
id: '0xDFd428908909CB5E24F5e79E6aD6BDE10bdf2327',
name: 'Coinbase wrapped BTC',
symbol: 'cbBTCx',
isSuperToken: true,
coingeckoId: 'bitcoin',
},
{
underlyingToken: {
decimals: 18,
Expand Down

0 comments on commit 5713da6

Please sign in to comment.