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

Add select token modal #4358

Merged
merged 55 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
eadd1a1
rename cryptoDonation to OneTimeDonation
MohammadPCh Jun 30, 2024
cac9b1e
change to OneTimeDonationCard
MohammadPCh Jun 30, 2024
eabc2f2
organize donate files structure
MohammadPCh Jul 1, 2024
a6a4465
move totalDonation to onetime
MohammadPCh Jul 1, 2024
1eeaf8f
Merge branch 'develop' into add-select-token-modal
MohammadPCh Jul 1, 2024
dff775c
show incorrect_estimate toast on recurring donation
MohammadPCh Jul 1, 2024
fc2cd21
import recurring donation input
MohammadPCh Jul 1, 2024
12eb7f6
remove over-flow hidden
MohammadPCh Jul 1, 2024
4965350
init token modal
MohammadPCh Jul 2, 2024
d6b89ec
update TokenInfo to fetch balance in component
MohammadPCh Jul 2, 2024
eafd014
pass tokens to modal
MohammadPCh Jul 2, 2024
3f2de3c
fetch balance on visible
MohammadPCh Jul 2, 2024
c7aac06
remove unused sections
MohammadPCh Jul 2, 2024
3076859
add footer to modal
MohammadPCh Jul 2, 2024
f82726d
hide zero balance tokens
MohammadPCh Jul 2, 2024
94d2a6a
add footer
MohammadPCh Jul 2, 2024
4c5bee1
remove unused values
MohammadPCh Jul 2, 2024
b501958
Merge branch 'develop' into add-select-token-modal
MohammadPCh Jul 2, 2024
24545d4
add margin
MohammadPCh Jul 2, 2024
640dc63
add two type of selected token to donate context
MohammadPCh Jul 2, 2024
1bfbfe8
select token
MohammadPCh Jul 2, 2024
69476b2
show balance
MohammadPCh Jul 2, 2024
2904ed9
remove logs
MohammadPCh Jul 2, 2024
1e6dd42
fix solana ids
MohammadPCh Jul 3, 2024
7385c0c
revert solana ids
MohammadPCh Jul 3, 2024
77f94df
init useSolanaBalance
MohammadPCh Jul 3, 2024
07fc2ca
add solanaNativeAddress
MohammadPCh Jul 3, 2024
9363992
return all data
MohammadPCh Jul 3, 2024
d3efd38
remove logs
MohammadPCh Jul 3, 2024
3dc713d
update fetching balances
MohammadPCh Jul 3, 2024
0e0f41f
remove old inputbox
MohammadPCh Jul 3, 2024
f9c1849
remove old token picker
MohammadPCh Jul 3, 2024
8ad4f4f
remove unused parts
MohammadPCh Jul 3, 2024
32d6037
return bigint
MohammadPCh Jul 3, 2024
026543b
add solana balance to token info
MohammadPCh Jul 3, 2024
55bf7b6
fix useSolanaBalance
MohammadPCh Jul 3, 2024
a05a289
remove isMobile
MohammadPCh Jul 3, 2024
1f43736
fix decimals
MohammadPCh Jul 3, 2024
93e477c
add token symbol
MohammadPCh Jul 3, 2024
ed125b8
remove gemini modal
MohammadPCh Jul 3, 2024
7b811f4
remove unused parts
MohammadPCh Jul 3, 2024
9bff9e9
add formatCrypto
MohammadPCh Jul 3, 2024
de4dcf8
update calcDonationShare
MohammadPCh Jul 3, 2024
b7ea1ed
use bigint instead of numbers
MohammadPCh Jul 3, 2024
400bda1
prevent putting zeros
MohammadPCh Jul 3, 2024
1dacfcc
prevent removing decimals
MohammadPCh Jul 3, 2024
0dd1a7d
Merge branch 'develop' into add-select-token-modal
MohammadPCh Jul 3, 2024
3b15e6e
init searchbox
MohammadPCh Jul 4, 2024
1730713
add search
MohammadPCh Jul 4, 2024
fc4b534
handle isGivbackEligible
MohammadPCh Jul 4, 2024
865a0b2
init handle custom token
MohammadPCh Jul 4, 2024
e18c137
fetch token info
MohammadPCh Jul 4, 2024
6e3b4c6
add chainType
MohammadPCh Jul 4, 2024
23dfe6f
only add custom token if supported
MohammadPCh Jul 4, 2024
2321cf2
handle errors
MohammadPCh Jul 4, 2024
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
4 changes: 2 additions & 2 deletions src/apollo/types/gqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ export interface IMeGQL {

export interface IProjectAcceptedToken {
id?: string;
name: string;
symbol: string;
decimals: number;
networkId: number;
address: Address;
mainnetAddress?: Address;
name: string;
decimals: number;
isGivbackEligible?: boolean;
order: number;
chainType?: ChainType;
Expand Down
12 changes: 12 additions & 0 deletions src/components/AmountInput/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const AmountInput: FC<IAmountInput> = ({
const [displayAmount, setDisplayAmount] = useState('');

useEffect(() => {
//prevent changing 0.000 to 0
if (amount === 0n) return;
const _displayAmount = truncateToDecimalPlaces(
formatUnits(amount, decimals),
decimals / 3,
Expand Down Expand Up @@ -74,6 +76,16 @@ export const AmountInput: FC<IAmountInput> = ({
setDisplayAmount(value);
setActiveStep(0);

try {
if (parseFloat(value) === 0 && !value.includes('.')) {
setAmount(0n);
setDisplayAmount('0');
return;
}
} catch (error) {
console.error('Failed to parse input amount:', error);
}

try {
let valueBn = parseUnits(value, decimals);
setAmount(valueBn);
Expand Down
3 changes: 3 additions & 0 deletions src/components/modals/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface IModal {
children: ReactNode;
doNotCloseOnClickOutside?: boolean;
className?: string;
footer?: ReactNode;
}

export const Modal: FC<IModal> = ({
Expand All @@ -53,6 +54,7 @@ export const Modal: FC<IModal> = ({
fullScreen = false,
headerColor,
doNotCloseOnClickOutside,
footer,
className,
}) => {
const theme = useAppSelector(state => state.general.theme);
Expand Down Expand Up @@ -118,6 +120,7 @@ export const Modal: FC<IModal> = ({
>
{children}
</Scrollbars>
{footer && <div>{footer}</div>}
</ModalWrapper>
</Background>,
el.current,
Expand Down
1 change: 0 additions & 1 deletion src/components/modals/deactivateProject/WhyContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const WhyContent = ({
styles={selectCustomStyles}
value={selectedOption}
onChange={e => handleSelect(e)}
isMobile={false}
/>
<AnimatePresence>
{String(selectedOption?.value) === '5' && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { slugToSuccessView, slugToProjectView } from '@/lib/routeCreators';
import { EProjectStatus } from '@/apollo/types/gqlEnums';
import { CREATE_ANCHOR_CONTRACT_ADDRESS_QUERY } from '@/apollo/gql/gqlSuperfluid';
import { client } from '@/apollo/apolloClient';
import { extractContractAddressFromString } from '../../donate/AlloProtocolFirstDonationModal';
import { extractContractAddressFromString } from '../../donate/Recurring/AlloProtocolFirstDonationModal';
import { wagmiConfig } from '@/wagmiConfigs';
import createProfileABI from '@/artifacts/createProfile.json';
import { generateRandomNonce } from '@/lib/helpers';
Expand Down
4 changes: 1 addition & 3 deletions src/components/views/donate/DonateIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useRouter } from 'next/router';
import { useAccount } from 'wagmi';
import SocialBox from '../../DonateSocialBox';
import NiceBanner from './NiceBanner';
// import PurchaseXDAI from './PurchaseXDAIBanner';
import useDetectDevice from '@/hooks/useDetectDevice';
import { useIsSafeEnvironment } from '@/hooks/useSafeAutoConnect';
import { useDonateData } from '@/context/donate.context';
Expand Down Expand Up @@ -68,8 +67,7 @@ const DonateIndex: FC = () => {
<>
<DonateHeader />
<DonateContainer>
{/* <PurchaseXDAI /> */}
{alreadyDonated && !isRecurringTab && (
{alreadyDonated && (
<AlreadyDonatedWrapper>
<IconDonation24 />
<SublineBold>
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/donate/DonationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useIntl } from 'react-intl';
import { useRouter } from 'next/router';
import { isAddress } from 'viem';
import { Shadow } from '@/components/styled-components/Shadow';
import { RecurringDonationCard } from './RecurringDonationCard';
import CryptoDonation from './CryptoDonation';
import { RecurringDonationCard } from './Recurring/RecurringDonationCard';
import OneTimeDonationCard from './OnTime/OneTimeDonationCard';
import config from '@/configuration';
import { useDonateData } from '@/context/donate.context';
import { ChainType } from '@/types/config';
Expand Down Expand Up @@ -103,7 +103,7 @@ export const DonationCard = () => {
<EmptyTab />
</Flex>
<TabWrapper>
{tab === ETabs.ONE_TIME && <CryptoDonation />}
{tab === ETabs.ONE_TIME && <OneTimeDonationCard />}
{tab === ETabs.RECURRING && <RecurringDonationCard />}
</TabWrapper>
</DonationCardWrapper>
Expand Down
93 changes: 0 additions & 93 deletions src/components/views/donate/GeminiModal.tsx

This file was deleted.

114 changes: 0 additions & 114 deletions src/components/views/donate/InputBox.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { FETCH_GIVETH_PROJECT_BY_ID } from '@/apollo/gql/gqlProjects';

interface IDonateModalProps extends IModal {
token: IProjectAcceptedToken;
amount: number;
amount: bigint;
donationToGiveth: number;
MohammadPCh marked this conversation as resolved.
Show resolved Hide resolved
tokenPrice?: number;
anonymous?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@giveth/ui-design-system';
import React from 'react';
import { useIntl } from 'react-intl';
import { formatUnits } from 'viem';
import Divider from '@/components/Divider';
import { TooltipContent } from '@/components/modals/HarvestAll.sc';
import { IconWithTooltip } from '@/components/IconWithToolTip';
Expand All @@ -22,18 +23,18 @@ import {
import { IProjectAcceptedToken } from '@/apollo/types/gqlTypes';
import { useTokenPrice } from '@/hooks/useTokenPrice';
import { formatDonation } from '@/helpers/number';
import { formatBalance } from '@/lib/helpers';
import { formatBalance, truncateToDecimalPlaces } from '@/lib/helpers';

interface IEstimatedMatchingToast {
projectData: IProject;
amount: bigint;
token?: IProjectAcceptedToken;
amountTyped?: number;
}

const EstimatedMatchingToast: React.FC<IEstimatedMatchingToast> = ({
projectData,
token,
amountTyped,
amount,
}) => {
const { formatMessage, locale } = useIntl();
const { estimatedMatching, qfRounds } = projectData || {};
Expand All @@ -51,7 +52,11 @@ const EstimatedMatchingToast: React.FC<IEstimatedMatchingToast> = ({
maximumReward,
} = activeStartedRound || {};

const amountInUsd = (tokenPrice || 0) * (amountTyped || 0);
const decimals = token?.decimals || 18;

const amountInUsd =
(tokenPrice || 0) *
(truncateToDecimalPlaces(formatUnits(amount, decimals), decimals) || 0);

const esMatching = calculateEstimatedMatchingWithDonationAmount(
amountInUsd,
Expand Down
Loading
Loading