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

Add send assets action to roles proposal #2351

Merged
merged 29 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f49e0a1
Move call to submitProposal up into component
adamgall Sep 16, 2024
8858bee
Start to lay down some UI for sending assets from Role proposal
adamgall Sep 16, 2024
e9dc86a
Remove Send Assets modal from global thing, use it directly on Treasu…
adamgall Sep 16, 2024
2364277
Tighten up the typing in sendAssets proposal data creator helper
adamgall Sep 16, 2024
ee42148
Send Assets modal sends data back into Role Proposal component
adamgall Sep 16, 2024
93ade1a
Rename file/function and fix typing
adamgall Sep 17, 2024
ee38f25
Dependency inject the name of form submit button in Send Assets modal
adamgall Sep 17, 2024
06cba82
Use translation strings, not hardcoded english
adamgall Sep 17, 2024
35e2192
Add "actions" to the RoleFormValues formik form
adamgall Sep 17, 2024
c8f5e14
Add "send assets" actions to proposal data
adamgall Sep 17, 2024
26a186e
Function won't be undefined
adamgall Sep 17, 2024
a078b65
Only show button for Send Assets modal if Safe has fungible assets
adamgall Sep 17, 2024
0b68896
Conditionally show the Nonce Input on Send Assets modal
adamgall Sep 17, 2024
e511d0a
Fix icon color
adamgall Sep 17, 2024
414bc25
Make Send Assets row look nicer
adamgall Sep 17, 2024
ce5c0a7
Rename "Send Assets" to "Transfer Assets"
adamgall Sep 17, 2024
f5de870
Add more styling to new components
adamgall Sep 17, 2024
cc7b52f
More styling and localization updates
adamgall Sep 17, 2024
2b30993
move boxShadow to common; renamed
Da-Colon Sep 18, 2024
549a8bd
update action choice UI
Da-Colon Sep 18, 2024
773f7df
remove divide; update copy
Da-Colon Sep 18, 2024
a9ef496
adjust Action Card content
Da-Colon Sep 18, 2024
97ac521
pretty
Da-Colon Sep 18, 2024
bc80cd2
Always show the divider, for modal consistency
adamgall Sep 18, 2024
81072f4
Move file
adamgall Sep 19, 2024
c55a6c0
Narrow down "size" prop on ModuleBaseProps
adamgall Sep 19, 2024
074e861
Create new components for Actions Modal and stuff
adamgall Sep 19, 2024
b8273ad
Fix disabled UI of action cards
adamgall Sep 19, 2024
8373751
Make RoleCardShort have cursor when hovered
adamgall Sep 19, 2024
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
59 changes: 0 additions & 59 deletions src/components/pages/DAOTreasury/sendAssets.ts

This file was deleted.

7 changes: 5 additions & 2 deletions src/components/pages/Roles/RoleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ export function RoleCardShort({
handleRoleClick: () => void;
}) {
return (
<Card onClick={handleRoleClick}>
<Card
cursor={'pointer'}
onClick={handleRoleClick}
>
Da-Colon marked this conversation as resolved.
Show resolved Hide resolved
<Flex justifyContent="space-between">
<Text
textStyle="display-lg"
Expand All @@ -270,7 +273,7 @@ export function RoleCardShort({
<EditBadge editStatus={editStatus} />
<Icon
as={CaretCircleRight}
color="white-0"
color="lilac-0"
Da-Colon marked this conversation as resolved.
Show resolved Hide resolved
boxSize="1.5rem"
/>
</Flex>
Expand Down
17 changes: 9 additions & 8 deletions src/components/pages/Roles/RolePaymentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { Address, getAddress, Hex } from 'viem';
import { useAccount, usePublicClient } from 'wagmi';
import { NEUTRAL_2_82_TRANSPARENT, CARD_SHADOW } from '../../../constants/common';
import {
NEUTRAL_2_82_TRANSPARENT,
CARD_SHADOW,
DETAILS_BOX_SHADOW,
} from '../../../constants/common';
import { DAO_ROUTES } from '../../../constants/routes';
import { useFractal } from '../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
Expand All @@ -18,9 +22,6 @@ import { ModalType } from '../../ui/modals/ModalProvider';
import { useDecentModal } from '../../ui/modals/useDecentModal';
import { RoleFormValues } from './types';

const PAYMENT_DETAILS_BOX_SHADOW =
'0px 0px 0px 1px #100414, 0px 0px 0px 1px rgba(248, 244, 252, 0.04) inset, 0px 1px 0px 0px rgba(248, 244, 252, 0.04) inset';

function CancelStreamMenu({
streamId,
paymentIsCancelling,
Expand Down Expand Up @@ -76,7 +77,7 @@ function CancelStreamMenu({
return (
<Flex
justifyContent="flex-end"
boxShadow={PAYMENT_DETAILS_BOX_SHADOW}
boxShadow={DETAILS_BOX_SHADOW}
borderTopRadius="0.5rem"
w="full"
py="0.25rem"
Expand Down Expand Up @@ -293,7 +294,7 @@ export function RolePaymentDetails({
? {
bg: 'neutral-2',
sx: undefined,
boxShadow: PAYMENT_DETAILS_BOX_SHADOW,
boxShadow: DETAILS_BOX_SHADOW,
}
: {
sx: {
Expand Down Expand Up @@ -416,7 +417,7 @@ export function RolePaymentDetails({
borderLeft="1px solid"
borderColor="white-alpha-08"
h="full"
boxShadow={PAYMENT_DETAILS_BOX_SHADOW}
boxShadow={DETAILS_BOX_SHADOW}
w="0"
/>
</GridItem>
Expand All @@ -431,7 +432,7 @@ export function RolePaymentDetails({
borderLeft="1px solid"
borderColor="white-alpha-08"
h="full"
boxShadow={PAYMENT_DETAILS_BOX_SHADOW}
boxShadow={DETAILS_BOX_SHADOW}
w="0"
/>
</GridItem>
Expand Down
131 changes: 110 additions & 21 deletions src/components/pages/Roles/forms/RoleFormCreateProposal.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,83 @@
import { Box, Button, Flex, FormControl, Show } from '@chakra-ui/react';
import { Box, Button, Flex, FormControl, Show, Text, Icon } from '@chakra-ui/react';
import { SquaresFour, ArrowsDownUp, Trash } from '@phosphor-icons/react';
import { Field, FieldProps, useFormikContext } from 'formik';
import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { getAddress, Hex } from 'viem';
import { formatUnits, getAddress, Hex } from 'viem';
import { CARD_SHADOW } from '../../../../constants/common';
import { DAO_ROUTES } from '../../../../constants/routes';
import useDisplayName from '../../../../hooks/utils/useDisplayName';
import { useFractal } from '../../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider';
import { Card } from '../../../ui/cards/Card';
import { CustomNonceInput } from '../../../ui/forms/CustomNonceInput';
import { InputComponent, TextareaComponent } from '../../../ui/forms/InputComponent';
import LabelWrapper from '../../../ui/forms/LabelWrapper';
import { AddActions } from '../../../ui/modals/AddActions';
import { SendAssetsData } from '../../../ui/modals/SendAssetsModal';
import { RoleCardShort } from '../RoleCard';
import RolesDetailsDrawer from '../RolesDetailsDrawer';
import RolesDetailsDrawerMobile from '../RolesDetailsDrawerMobile';
import { EditedRole, RoleDetailsDrawerRoleHatProp, RoleFormValues } from '../types';

function SendAssetsAction({
index,
action,
onRemove,
}: {
index: number;
action: SendAssetsData;
onRemove: (index: number) => void;
}) {
const { t } = useTranslation('common');
const { displayName } = useDisplayName(action.destinationAddress);

return (
<Card my="1rem">
<Flex justifyContent="space-between">
<Flex
alignItems="center"
gap="0.5rem"
>
<Icon
as={ArrowsDownUp}
w="1.5rem"
h="1.5rem"
color="lilac-0"
/>
<Text>{t('transfer')}</Text>
<Text color="lilac-0">
{formatUnits(action.transferAmount, action.asset.decimals)} {action.asset.symbol}
</Text>
<Text>{t('to').toLowerCase()}</Text>
<Text color="lilac-0">{displayName}</Text>
</Flex>
<Button
color="red-0"
variant="tertiary"
size="sm"
onClick={() => {
onRemove(index);
}}
>
<Icon as={Trash} />
</Button>
</Flex>
</Card>
);
}

Da-Colon marked this conversation as resolved.
Show resolved Hide resolved
export default function RoleFormCreateProposal({ close }: { close: () => void }) {
const [drawerViewingRole, setDrawerViewingRole] = useState<RoleDetailsDrawerRoleHatProp>();
const { t } = useTranslation(['modals', 'common', 'proposal']);
const { values, isSubmitting, submitForm } = useFormikContext<RoleFormValues>();
const {
values,
setFieldValue: setFieldValueTopLevel,
isSubmitting,
submitForm,
} = useFormikContext<RoleFormValues>();

const editedRoles = useMemo<
(RoleDetailsDrawerRoleHatProp & {
editedRole: EditedRole;
Expand Down Expand Up @@ -80,6 +138,10 @@ export default function RoleFormCreateProposal({ close }: { close: () => void })

const handleCloseDrawer = () => setDrawerViewingRole(undefined);

const addSendAssetsAction = (sendAssetsAction: SendAssetsData) => {
setFieldValueTopLevel('actions', [...values.actions, sendAssetsAction]);
};

return (
<Box maxW="736px">
<Flex
Expand Down Expand Up @@ -155,25 +217,52 @@ export default function RoleFormCreateProposal({ close }: { close: () => void })
</Field>
</FormControl>
</Flex>
<Box
p="1rem"
bg="neutral-2"
boxShadow={CARD_SHADOW}
borderRadius="0.5rem"

<Flex
mt={4}
mb={2}
alignItems="center"
>
{editedRoles.map((role, index) => {
return (
<RoleCardShort
key={index}
name={role.name}
handleRoleClick={() => {
setDrawerViewingRole(role);
}}
editStatus={role.editedRole?.status}
/>
);
})}
</Box>
<Icon
as={SquaresFour}
w="1.5rem"
h="1.5rem"
/>
<Text
textStyle="display-lg"
ml={2}
>
{t('actions', { ns: 'actions' })}
</Text>
</Flex>
{editedRoles.map((role, index) => {
return (
<RoleCardShort
key={index}
name={role.name}
handleRoleClick={() => {
setDrawerViewingRole(role);
}}
editStatus={role.editedRole?.status}
/>
);
})}
{values.actions.map((action, index) => (
<SendAssetsAction
action={action}
key={index}
index={index}
onRemove={idx => {
setFieldValueTopLevel(
'actions',
values.actions.filter((_, i) => i !== idx),
);
}}
/>
))}
Da-Colon marked this conversation as resolved.
Show resolved Hide resolved

<AddActions addSendAssetsAction={addSendAssetsAction} />

<Flex
gap="1rem"
mt="1rem"
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/Roles/types.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address, Hex } from 'viem';
import { DecentRoleHat } from '../../../store/roles';
import { BigIntValuePair, CreateProposalMetadata } from '../../../types';
import { SendAssetsData } from '../../ui/modals/SendAssetsModal';

export interface SablierAsset {
address: Address;
Expand Down Expand Up @@ -131,6 +132,7 @@ export interface RoleFormValues {
hats: RoleHatFormValue[];
roleEditing?: RoleHatFormValue;
customNonce?: number;
actions: SendAssetsData[];
}

export type PreparedAddedHatsData = HatStruct & { id: bigint };
Expand Down
Loading