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

feat: only show goal elements if project has one, new comp for no goal #147

Merged
merged 7 commits into from
May 20, 2022
8 changes: 6 additions & 2 deletions src/components/molecules/LiveProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ export const LiveProject = ({ project}: ILiveProject) => {
<Wrap >
<Text fontSize="18px">Raised: </Text>
<SatoshiAmount wrapperClassName={classes.satoshiText} fontSize="18px" marginTop="2px !important">{project.balance}</SatoshiAmount>
<Text fontSize="18px">{`, ${percentage} % `}</Text>
<Text fontSize="18px">of goal</Text>
{project.fundingGoal
&& <>
<Text fontSize="18px">{`, ${percentage} % `}</Text>
<Text fontSize="18px">of goal</Text>
</>
}
</Wrap>
</VStack>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { SatoshiIcon } from '../icons';
import { createUseStyles } from 'react-jss';
import { commaFormatted } from '../../utils/helperFunctions';

interface ICircularFundProgress {
amount: number;
interface IProjectBalanceCircularProgress {
balance: number;
goal: number;
rate: number
loading: boolean;
Expand All @@ -34,21 +34,25 @@ const useStyles = createUseStyles({
},
});

export const CircularFundProgress = ({ goal, rate, amount, loading }: ICircularFundProgress) => {
const classes = useStyles();
const BTCBalance = ({ balance }: { balance: number }) => {
const isDark = isDarkMode();
const amountUSD = (amount * rate).toFixed(2);
const percentage = (parseFloat(amountUSD) / goal) * 100;

const [display, setDisplay] = useState(false);
const classes = useStyles();
const displaySatoshis = balance < 1000000;

let bitCoins = 0;
return (
displaySatoshis
? <><SatoshiIcon isDark={isDark} className={classes.satoshi} /> {commaFormatted(balance)}</>
: <><BsCurrencyBitcoin fontSize="30px" />{parseFloat((balance / 100000000).toFixed(4))}</>
);
};

if (amount >= 1000000) {
bitCoins = parseFloat((amount / 100000000).toFixed(4));
}
export const ProjectBalanceCircularProgress = ({ goal, rate, balance, loading }: IProjectBalanceCircularProgress) => {
const classes = useStyles();
const isDark = isDarkMode();
const balanceUSD = (balance * rate).toFixed(2);
const percentage = (parseFloat(balanceUSD) / goal) * 100;

// Const percentage = 100;
const [display, setDisplay] = useState(false);

const getDisplayPercent = (percent: number) => {
if (percent < 1) {
Expand All @@ -71,20 +75,11 @@ export const CircularFundProgress = ({ goal, rate, amount, loading }: ICircularF

const getStat = () => (
<Stat textAlign="center" borderRadius="50%" >
<StatLabel fontSize="12px" color={isDark ? 'brand.textWhite' : 'brand.textGrey'}>Funded</StatLabel>
<StatLabel fontSize="12px" color={isDark ? 'brand.textWhite' : 'brand.textGrey'}>Raised</StatLabel>
<StatNumber className="amount-label-sat" position="relative" display={!display ? 'flex' : 'none'}>
{
bitCoins ? <>
<BsCurrencyBitcoin fontSize="30px" />{bitCoins}
</>
: <>
<SatoshiIcon isDark={isDark} className={classes.satoshi} /> {commaFormatted(amount)}
</>

}

<BTCBalance balance={balance}/>
</StatNumber>
<StatNumber className="amount-label-usd" display={display ? 'block' : 'none'} position="relative">{'$'}{amountUSD} </StatNumber>
<StatNumber className="amount-label-usd" display={display ? 'block' : 'none'} position="relative">{'$'}{balanceUSD} </StatNumber>
<StatHelpText fontSize="12px" color={isDark ? 'brand.textWhite' : 'brand.textGrey'}>{`${getDisplayPercent(percentage)}% of $${commaFormatted(goal)}`}</StatHelpText>
</Stat>
);
Expand Down
43 changes: 43 additions & 0 deletions src/components/molecules/ProjectBalance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React, { useState } from 'react';
import { Box, Text } from '@chakra-ui/layout';
import { SatoshiIcon } from '../icons';
import { commaFormatted } from '../../utils/helperFunctions';
import { BsCurrencyBitcoin } from 'react-icons/bs';

interface IProjectBalance {
balance: number,
rate: number,
}

const USDBalance = ({ balance }: { balance: number }) => (
<>
<Text color="brand.primary" fontSize="40px" mr={1}>$</Text><Text color="brand.primary" fontWeight="bold" fontSize="5xl">{(balance).toFixed(2)}</Text>
</>
);

const BTCBalance = ({ balance }: { balance: number }) => {
// Let bitcoins = 0;
const displaySatoshis = balance < 1000000;

return (
displaySatoshis
? <><SatoshiIcon scale={1.5} color="brand.primary" mr={1} /><Text color="brand.primary" fontWeight="bold" fontSize="5xl">{commaFormatted(balance)}</Text></>
: <><BsCurrencyBitcoin fontSize="40px" color="#20ECC7" /><Text color="brand.primary" fontWeight="bold" fontSize="5xl">{parseFloat((balance / 100000000).toFixed(4))}</Text></>
);
};

export const ProjectBalance = ({balance, rate}: IProjectBalance) => {
const [hover, setHover] = useState(false);

return (
<Box>
<Box display="flex" justifyContent="center" alignItems="center" onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}>
{hover ? <USDBalance balance={balance * rate}/> : <BTCBalance balance={balance}/>

}
</Box>
<Text color="brand.textGrey" fontSize="xs" textAlign="center">RAISED</Text>
</Box>

);
};
4 changes: 3 additions & 1 deletion src/components/molecules/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export const ProjectCard = ({ title, imgSrc, open, name, className, project, ...
<Text fontSize="16px" fontWeight={600}>{title}</Text>
</HStack>
<HStack alignItems="center" justifyContent={'space-between'} width="100%">
<CircularProgress
{project.fundingGoal
&& <CircularProgress
className={classes.circularProgress}
value={percentage}
size="55px"
Expand All @@ -152,6 +153,7 @@ export const ProjectCard = ({ title, imgSrc, open, name, className, project, ...
<Text fontSize="12px">{`${percentage}%`}</Text>
</Box>
</CircularProgress>
}
<VStack alignItems="center" justifyContent="center" spacing="0">
<Text fontSize="14px" fontWeight={600}>{getProjectBackers()}</Text>
<Text fontSize="12px">backers</Text>
Expand Down
3 changes: 2 additions & 1 deletion src/components/molecules/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './IdComponent';
export * from './CircularFundProgress';
export * from './ProjecBalanceCircularProgress';
export * from './IdBar';
export * from './ConnectTwitter';
export * from './ProjectCard';
Expand All @@ -11,3 +11,4 @@ export * from './AddSponsor';
export * from './LiveProject';
export * from './ProjectBars';
export * from './SwipeLiveProject';
export * from './ProjectBalance';
2 changes: 1 addition & 1 deletion src/pages/project/Activity/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export const Countdown = ({ endDate }: { endDate: string }) => {
}, [endDate]);

return (
<Text>{`${countDown}`}</Text>
<Text textAlign="center">{`${countDown}`}</Text>
);
};
9 changes: 5 additions & 4 deletions src/pages/project/Activity/InfoPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Text, VStack } from '@chakra-ui/layout';
import React from 'react';
import { SatoshiIcon } from '../../../components/icons';
import { CircularFundProgress } from '../../../components/molecules';
import { ProjectBalanceCircularProgress, ProjectBalance } from '../../../components/molecules';
import { IdBar } from '../../../components/molecules/IdBar';
import { ButtonComponent, FundingStatus } from '../../../components/ui';
import { isMobileMode } from '../../../utils';
Expand Down Expand Up @@ -44,9 +44,10 @@ export const InfoPage = ({
{isMobile && <Button className={classes.fundButton} onClick={handleFundClick}>
<Text fontSize="12px">Project</Text>
</Button>}
<FundingStatus open={project.active} />
{showCountdown() && <Countdown endDate={project.expiresAt}/>}
<CircularFundProgress loading={loading} rate={btcRate} goal={project.fundingGoal} amount={project.balance} />
{project.fundingGoal
? <ProjectBalanceCircularProgress loading={loading} rate={btcRate} goal={project.fundingGoal} balance={project.balance} />
: <ProjectBalance balance={project.balance} rate={btcRate}/>
}
{project.active && <ButtonComponent
primary
standard
Expand Down