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: Implement dynamic generic function editor form. #763

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
76 changes: 28 additions & 48 deletions src/components/Guilds/ActionsModal/ContractActionsList.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
import styled from 'styled-components';
import { Flex } from '../common/Layout';
import { ContainerText } from '../common/Layout/Text';
import { Button } from '../common/Button';
import { RegistryContract } from 'hooks/Guilds/contracts/useContractRegistry';

const Wrapper = styled(Flex)`
margin: 16px auto;
`;
const WrapperText = styled(ContainerText).attrs(() => ({
variant: 'bold',
}))`
justify-content: left;
flex-direction: row;
width: 85%;
margin: 8px auto;
color: ${({ theme }) => theme.colors.proposalText.grey};
`;

const ExternalWrapper = styled(Flex)`
width: 100%;
margin: 8px auto;
`;

const ButtonText = styled(ContainerText).attrs(() => ({
variant: 'medium',
}))`
justify-content: space-between;
flex-direction: row;
`;

const ActionsButton = styled(Button)`
width: 90%;
margin: 6px 0;
flex-direction: column;
justify-content: left;
border-radius: 10px;
&:active,
&:focus {
border: 2px solid ${({ theme }) => theme.colors.text};
}
`;

import {
ActionsButton,
ButtonDetail,
ButtonLabel,
SectionTitle,
SectionWrapper,
Wrapper,
} from './styles';
interface ContractActionsListProps {
contract: RegistryContract;
onSelect: (functionName: string) => void;
Expand All @@ -52,18 +18,32 @@ const ContractActionsList: React.FC<ContractActionsListProps> = ({
}) => {
return (
<Wrapper>
<ExternalWrapper>
<WrapperText>6 Actions</WrapperText>
<SectionWrapper>
<SectionTitle>
{contract.functions.length}{' '}
{contract.functions.length >= 2 ? 'Actions' : 'Action'}
</SectionTitle>
{contract.functions.map(contractFunction => (
<ActionsButton
variant="secondary"
vertical
onClick={() => onSelect(contractFunction.functionName)}
>
{contractFunction.title}
<ButtonText>{contractFunction.functionName}</ButtonText>
<ButtonLabel>{contractFunction.title}</ButtonLabel>
<ButtonDetail vertical>
{contractFunction.functionName}(
{contractFunction.params.reduce(
(acc, cur, i) =>
acc.concat(
cur.type,
i === contractFunction.params.length - 1 ? '' : ', '
),
''
)}
)
</ButtonDetail>
</ActionsButton>
))}
</ExternalWrapper>
</SectionWrapper>
</Wrapper>
);
};
Expand Down
91 changes: 23 additions & 68 deletions src/components/Guilds/ActionsModal/ContractsList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import React from 'react';
import styled from 'styled-components';
import { Flex } from '../common/Layout';
import { ContainerText } from '../common/Layout/Text';
import { Button } from '../common/Button';
import { ReactComponent as Vector } from '../../../assets/images/vector.svg';
import StyledIcon from '../common/SVG';
import {
Expand All @@ -11,57 +7,14 @@ import {
} from 'hooks/Guilds/contracts/useContractRegistry';
import { useWeb3React } from '@web3-react/core';
import { SupportedAction } from '../ActionsBuilder/types';

const CoreWrapper = styled(Flex)`
width: 100%;
margin-bottom: 16px;
`;

const ExternalWrapper = styled(Flex)`
width: 100%;
`;

const Wrapper = styled(Flex)`
width: 100%;
margin: 24px auto;
`;

const ActionsButton = styled(Button).attrs(() => ({
variant: 'secondary',
}))`
width: 90%;
height: 40px;
margin: 6px 0;
flex-direction: row;
justify-content: left;
&:active,
&:focus {
border: 2px solid ${({ theme }) => theme.colors.text};
}
`;

const WrapperText = styled(ContainerText).attrs(() => ({
variant: 'bold',
}))`
justify-content: left;
flex-direction: row;
width: 85%;
color: ${({ theme }) => theme.colors.proposalText.grey};
`;

const ButtonText = styled(ContainerText).attrs(() => ({
variant: 'medium',
}))`
justify-content: space-between;
flex-direction: row;
color: ${({ theme }) => theme.colors.proposalText.grey};
`;

const ExternalButton = styled(ActionsButton).attrs(() => ({
variant: 'secondary',
}))`
justify-content: space-between;
`;
import {
ActionsButton,
ButtonDetail,
ButtonLabel,
SectionTitle,
SectionWrapper,
Wrapper,
} from './styles';

interface ContractsListProps {
onSelect: (contract: RegistryContract) => void;
Expand All @@ -77,29 +30,31 @@ const ContractsList: React.FC<ContractsListProps> = ({

return (
<Wrapper>
<CoreWrapper>
<WrapperText>Core</WrapperText>
<SectionWrapper>
<SectionTitle>Core</SectionTitle>
<ActionsButton
onClick={() =>
onSupportedActionSelect(SupportedAction.ERC20_TRANSFER)
}
>
<StyledIcon src={Vector} />
Transfer & Mint
<ButtonLabel>
<StyledIcon src={Vector} />
Transfer & Mint
</ButtonLabel>
</ActionsButton>
</CoreWrapper>
<ExternalWrapper>
<WrapperText>External Contracts</WrapperText>
</SectionWrapper>
<SectionWrapper>
<SectionTitle>External Contracts</SectionTitle>
{contracts?.map(contract => (
<ExternalButton onClick={() => onSelect(contract)}>
{contract.title}
<ButtonText>
<ActionsButton onClick={() => onSelect(contract)}>
<ButtonLabel>{contract.title}</ButtonLabel>
<ButtonDetail>
{contract.functions?.length}{' '}
{contract.functions?.length > 1 ? 'Actions' : 'Action'}
</ButtonText>
</ExternalButton>
</ButtonDetail>
</ActionsButton>
))}
</ExternalWrapper>
</SectionWrapper>
</Wrapper>
);
};
Expand Down
69 changes: 0 additions & 69 deletions src/components/Guilds/ActionsModal/MintRepModal.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions src/components/Guilds/ActionsModal/ParamsModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import styled from 'styled-components';
import { Input } from '../common/Form';
import { useState } from 'react';
import { ActionsButton, FormElement, FormLabel, Wrapper } from './styles';
import { RegistryContractFunction } from 'hooks/Guilds/contracts/useContractRegistry';

const SubmitButton = styled(ActionsButton).attrs(() => ({
variant: 'primary',
}))`
background-color: ${({ theme }) => theme.colors.button.primary};
justify-content: center;
`;

interface ParamsModalProps {
fn: RegistryContractFunction;
}

const ParamsModal: React.FC<ParamsModalProps> = ({ fn }) => {
const [address, setAddress] = useState('');

return (
<Wrapper>
{fn.params.map(param => (
<FormElement>
<FormLabel>{param.description}</FormLabel>
<Input
placeholder={param.defaultValue}
value={address}
onChange={e => setAddress(e.target.value)}
size={24}
/>
</FormElement>
))}

<FormElement>
<SubmitButton>Add action</SubmitButton>
</FormElement>
</Wrapper>
);
};

export default ParamsModal;
9 changes: 8 additions & 1 deletion src/components/Guilds/ActionsModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DecodedAction, SupportedAction } from '../ActionsBuilder/types';
import { Modal } from '../common/Modal';
import ContractActionsList from './ContractActionsList';
import ContractsList from './ContractsList';
import ParamsModal from './ParamsModal';

interface ActionModalProps {
isOpen: boolean;
Expand Down Expand Up @@ -40,7 +41,13 @@ const ActionModal: React.FC<ActionModalProps> = ({

function getContent() {
if (selectedFunction) {
return null;
return (
<ParamsModal
fn={selectedContract.functions.find(
fn => fn.functionName === selectedFunction
)}
/>
);
}

if (selectedContract) {
Expand Down
Loading