Skip to content

Commit

Permalink
Merge pull request #1206 from Giveth/hotfix/shows-multiple-address-on…
Browse files Browse the repository at this point in the history
…-project-view

HOTFIX: Shows multiple addresses on project view
  • Loading branch information
mateodaza authored Jul 26, 2022
2 parents c6518ec + a9121a8 commit effcef9
Showing 1 changed file with 88 additions and 10 deletions.
98 changes: 88 additions & 10 deletions src/components/views/project/ProjectTotalFundCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import Image from 'next/image';
import styled from 'styled-components';
import {
Expand All @@ -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<string | undefined>(
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 (
<BottomSection>
<Image src={WalletIcon} alt='wallet icon' />
<AddressContainer key={index}>
{isSharedAddress ? (
<>
<Subline>{item.address}</Subline>
<IconEthereum size={16} />
<IconGnosisChain size={16} />
</>
) : (
<>
<Subline>{item.address}</Subline>
{item.networkId === gnosisId ? (
<IconGnosisChain size={16} />
) : (
// defaults to eth icon while we add more networks
<IconEthereum size={16} />
)}
</>
)}
</AddressContainer>
</BottomSection>
);
};

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 (
<Wrapper>
Expand All @@ -34,10 +100,14 @@ const ProjectTotalFundCard = (props: { project?: IProject }) => {
</div>
)}
</UpperSection>
<BottomSection>
<Image src={WalletIcon} alt='wallet icon' />
<Subline>{walletAddress}</Subline>
</BottomSection>
{sharedAddress
? renderAddress({
item: { address: sharedAddress },
isSharedAddress: true,
})
: addresses?.map((item, index) => {
return renderAddress({ item, index });
})}
</Wrapper>
);
};
Expand Down Expand Up @@ -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;

1 comment on commit effcef9

@vercel
Copy link

@vercel vercel bot commented on effcef9 Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

giveth-dapps-v2 – ./

giveth.io
giveth-dapps-v2-git-main-givethio.vercel.app
www.giveth.io
giveth-dapps-v2-givethio.vercel.app

Please sign in to comment.