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

Update receiving addresses #2985

Merged
merged 27 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4aca56b
removed isSameAddress functionality and checkbox
alireza-sharifpour Jul 25, 2023
f943027
Made isSame address value false on walletAddressInput
alireza-sharifpour Jul 25, 2023
b011613
Created CreateProjectAddAddressModal
alireza-sharifpour Jul 25, 2023
1916a33
Added walletAddressInput to CreateProjectAddAddressModal
alireza-sharifpour Jul 26, 2023
f596bbb
Removed Active checkbox from WalletAddressInput
alireza-sharifpour Jul 26, 2023
ed494bd
removed extra codes
alireza-sharifpour Jul 26, 2023
469e210
removed extra codes
alireza-sharifpour Jul 26, 2023
8d9ae9f
added CreateProjectAddAddressModal for Mainnet
alireza-sharifpour Jul 31, 2023
672e717
Added AddressContainer
alireza-sharifpour Jul 31, 2023
230f1d3
Created AddressInterface component
alireza-sharifpour Jul 31, 2023
010fbb6
Added Middle section
alireza-sharifpour Jul 31, 2023
c71f6a0
added modals
alireza-sharifpour Jul 31, 2023
6cbe643
added new props
alireza-sharifpour Jul 31, 2023
3c555c0
added resolvedENS to mainnet
alireza-sharifpour Aug 1, 2023
7105294
added resolvedENS
alireza-sharifpour Aug 1, 2023
e31618a
changed hasAddress condition
alireza-sharifpour Aug 1, 2023
a64bb91
added onsubmit condition
alireza-sharifpour Aug 1, 2023
8cb789e
added onsubmit
alireza-sharifpour Aug 1, 2023
b3d7711
Added ButtonWrapper
alireza-sharifpour Aug 1, 2023
8ebbc23
changed min-height
alireza-sharifpour Aug 1, 2023
9a6b48b
fixed addresses array issue
alireza-sharifpour Aug 3, 2023
4670f1a
removed unused comments
alireza-sharifpour Aug 3, 2023
a34788e
Increased min-height for modal
alireza-sharifpour Aug 3, 2023
aa388df
fixed overflow issue
alireza-sharifpour Aug 3, 2023
7b44ebb
fixed overflow issue
alireza-sharifpour Aug 3, 2023
d31b37c
changed Modal handling
alireza-sharifpour Aug 3, 2023
3b99072
changed CreateProjectAddAddressModal for handling new modal
alireza-sharifpour Aug 3, 2023
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
196 changes: 196 additions & 0 deletions src/components/views/create/AddressInterface.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import { useFormContext } from 'react-hook-form';
import { useIntl } from 'react-intl';
import styled from 'styled-components';
import {
Button,
GLink,
IconArrowRight16,
neutralColors,
} from '@giveth/ui-design-system';
import config from '@/configuration';
import { EInputs } from '@/components/views/create/CreateProject';
import { networksParams } from '@/helpers/blockchain';
import { IconEthereum } from '@/components/Icons/Eth';
import { IconGnosisChain } from '@/components/Icons/GnosisChain';
import NetworkLogo from '@/components/NetworkLogo';
import { Shadow } from '@/components/styled-components/Shadow';
import { Flex } from '@/components/styled-components/Flex';

interface IAddressInterfaceProps {
networkId: number;
address?: string;
onButtonClick?: () => void;
}

const AddressInterface = ({
networkId,
address,
onButtonClick,
}: IAddressInterfaceProps) => {
const {
formState: { errors },
getValues,
} = useFormContext();

const isMainnet = networkId === config.MAINNET_NETWORK_NUMBER;
const isGnosis = networkId === config.XDAI_NETWORK_NUMBER;
const isPolygon = networkId === config.POLYGON_NETWORK_NUMBER;
const isCelo = networkId === config.CELO_NETWORK_NUMBER;
const isOptimism = networkId === config.OPTIMISM_NETWORK_NUMBER;
const inputName = isGnosis
? EInputs.gnosisAddress
: isPolygon
? EInputs.polygonAddress
: isCelo
? EInputs.celoAddress
: isOptimism
? EInputs.optimismAddress
: EInputs.mainAddress;
const value = getValues(inputName);
const { formatMessage } = useIntl();

const hasAddress = !!address && !errors[inputName]?.message;

let caption: string = '';
if (!value) {
caption = `${formatMessage({
id: 'label.you_can_enter_a_new_address',
})} ${
isGnosis
? 'Gnosis Chain'
: isPolygon
? 'Polygon Mainnet'
: isCelo
? 'Celo Mainnet'
: isOptimism
? 'Optimism'
: 'Mainnet'
}.`;
}

const NetworkIcon = isGnosis ? (
<GnosisIcon />
) : isPolygon ? (
<PolygonIcon />
) : isCelo ? (
<CeloIcon />
) : isOptimism ? (
<OptimismIcon />
) : (
<MainnetIcon />
);

return (
<Container>
<TopContainer>
<Flex justifyContent='space-between'>
<Flex gap='8px'>
{NetworkIcon}
{formatMessage(
{ id: 'label.chain_address' },
{
chainName: networksParams[networkId].chainName,
},
)}
</Flex>
<Button
buttonType='texty-secondary'
label={hasAddress ? 'Edit Address' : 'Add Address'}
icon={<IconArrowRight16 />}
onClick={onButtonClick}
/>
</Flex>
</TopContainer>
<MiddleContainer>
{hasAddress && (
<GLink>
{formatMessage(
{
id: 'label.receiving_address_on',
},
{
chainName: isGnosis
? 'Gnosis Chain'
: isPolygon
? 'Polygon Mainnet'
: isCelo
? 'Celo Mainnet'
: isOptimism
? 'Optimism Mainnet'
: 'Mainnet',
},
)}
</GLink>
)}
<AddressContainer hasAddress={hasAddress}>
{hasAddress ? address : 'No address added yet!'}
</AddressContainer>
</MiddleContainer>
</Container>
);
};

const OptimismIcon = () => (
<ChainIconShadow>
<NetworkLogo logoSize={24} chainId={config.OPTIMISM_NETWORK_NUMBER} />
</ChainIconShadow>
);

const CeloIcon = () => (
<ChainIconShadow>
<NetworkLogo logoSize={24} chainId={config.CELO_NETWORK_NUMBER} />
</ChainIconShadow>
);

const PolygonIcon = () => (
<ChainIconShadow>
<NetworkLogo logoSize={24} chainId={config.POLYGON_NETWORK_NUMBER} />
</ChainIconShadow>
);

const GnosisIcon = () => (
<ChainIconShadow>
<IconGnosisChain size={24} />
</ChainIconShadow>
);

const MainnetIcon = () => (
<ChainIconShadow>
<IconEthereum size={24} />
</ChainIconShadow>
);

const Container = styled.div`
margin-top: 25px;
background: ${neutralColors.gray[100]};
border-radius: 12px;
padding: 16px;
`;

const ChainIconShadow = styled.div`
height: 24px;
width: fit-content;
border-radius: 50%;
box-shadow: ${Shadow.Giv[400]};
`;

const TopContainer = styled.div`
border-bottom: 1px solid ${neutralColors.gray[300]};
`;

const MiddleContainer = styled.div`
padding: 24px 0;
`;

const AddressContainer = styled.div<{ hasAddress: boolean }>`
border: 2px solid ${neutralColors.gray[300]};
background-color: ${props =>
props.hasAddress ? neutralColors.gray[100] : neutralColors.gray[300]};
border-radius: 8px;
color: ${props =>
props.hasAddress ? neutralColors.gray[900] : neutralColors.gray[500]};
padding: 16px;
overflow-x: auto;
`;

export default AddressInterface;
Loading
Loading