From a9121a805d111268cb7604be28408694dd68d86e Mon Sep 17 00:00:00 2001 From: Mateo Daza Date: Tue, 26 Jul 2022 17:18:16 -0500 Subject: [PATCH] Update ProjectTotalFundCard.tsx --- .../views/project/ProjectTotalFundCard.tsx | 98 +++++++++++++++++-- 1 file changed, 88 insertions(+), 10 deletions(-) diff --git a/src/components/views/project/ProjectTotalFundCard.tsx b/src/components/views/project/ProjectTotalFundCard.tsx index 0d194458f3..df8a2792f2 100644 --- a/src/components/views/project/ProjectTotalFundCard.tsx +++ b/src/components/views/project/ProjectTotalFundCard.tsx @@ -1,3 +1,4 @@ +import { useEffect, useState } from 'react'; import Image from 'next/image'; import styled from 'styled-components'; import { @@ -12,13 +13,78 @@ import WalletIcon from '/public/images/wallet_donate_tab.svg'; import { Shadow } from '@/components/styled-components/Shadow'; import { IProject } from '@/apollo/types/types'; +import { IconGnosisChain } from '@/components/Icons/GnosisChain'; +import { IconEthereum } from '@/components/Icons/Eth'; + +import config from '@/configuration'; + +const { SECONDARY_NETWORK } = config; +const gnosisId = SECONDARY_NETWORK.id; + +interface IAddressRender { + item: any; + index?: number; + isSharedAddress?: boolean; +} + const ProjectTotalFundCard = (props: { project?: IProject }) => { - const { - totalDonations, - walletAddress, - traceCampaignId, - totalTraceDonations, - } = props.project || {}; + const { totalDonations, addresses, traceCampaignId, totalTraceDonations } = + props.project || {}; + + const [sharedAddress, setSharedAddress] = useState( + undefined, + ); + + const renderAddress = ({ + item, + index, + isSharedAddress, + }: IAddressRender) => { + // we may need to change this in the future if we allow more networks config for addresses + return ( + + wallet icon + + {isSharedAddress ? ( + <> + {item.address} + + + + ) : ( + <> + {item.address} + {item.networkId === gnosisId ? ( + + ) : ( + // defaults to eth icon while we add more networks + + )} + + )} + + + ); + }; + + const checkAddresses = () => { + // We should change this check if more networks are added in the future + const onlyAddresses = addresses?.map(item => { + if (item.isRecipient) { + return item.address; + } + }); + const addressesDuplicated = onlyAddresses?.some((item, index) => { + return onlyAddresses.indexOf(item) != index; + }); + if (addressesDuplicated) { + setSharedAddress(addresses && addresses[0].address); + } + }; + + useEffect(() => { + checkAddresses(); + }, [props.project]); return ( @@ -34,10 +100,14 @@ const ProjectTotalFundCard = (props: { project?: IProject }) => { )} - - wallet icon - {walletAddress} - + {sharedAddress + ? renderAddress({ + item: { address: sharedAddress }, + isSharedAddress: true, + }) + : addresses?.map((item, index) => { + return renderAddress({ item, index }); + })} ); }; @@ -75,4 +145,12 @@ const BottomSection = styled.div` color: ${neutralColors.gray[500]}; `; +const AddressContainer = styled.div` + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-around; + gap: 8px; +`; + export default ProjectTotalFundCard;