Skip to content

Commit 9fa0cff

Browse files
authored
Merge 25ebace into 18a1cac
2 parents 18a1cac + 25ebace commit 9fa0cff

File tree

9 files changed

+108
-27
lines changed

9 files changed

+108
-27
lines changed

src/components/ActionsBuilder/Action/Action.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface ActionViewProps {
2929
call?: Call;
3030
decodedAction?: DecodedAction;
3131
isEditable?: boolean;
32-
onEdit?: (updatedCall: DecodedAction) => void;
32+
onEdit?: (updatedCall: DecodedAction | DecodedAction[]) => void;
3333
onRemove?: (updatedCall: DecodedAction) => void;
3434
}
3535

@@ -178,6 +178,7 @@ export const ActionRow: React.FC<ActionViewProps> = ({
178178
setIsOpen={setIsEditActionModalOpen}
179179
action={decodedAction}
180180
onAddAction={onEdit}
181+
isEditable={isEditable}
181182
/>
182183
)}
183184
</CardWrapperWithMargin>

src/components/ActionsBuilder/Option/Option.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,21 @@ export const OptionRow: React.FC<OptionRowProps> = ({
4343
} = useSortable({ id: option.id });
4444
const [isActionsModalOpen, setIsActionsModalOpen] = useState(false);
4545

46-
function addAction(action: DecodedAction) {
46+
function addAction(action: DecodedAction | DecodedAction[]) {
47+
const newActions = Array.isArray(action) ? action : [action];
48+
4749
onChange({
4850
...option,
49-
decodedActions: [...option.decodedActions, action],
51+
decodedActions: [...option.decodedActions, ...newActions],
5052
});
5153
}
5254

53-
function updateAction(index: number, action: DecodedAction) {
55+
function updateAction(
56+
index: number,
57+
action: DecodedAction | DecodedAction[]
58+
) {
59+
if (Array.isArray(action)) return;
60+
5461
const updatedActions = option?.decodedActions.map((a, i) =>
5562
index === i ? action : a
5663
);
@@ -141,6 +148,7 @@ export const OptionRow: React.FC<OptionRowProps> = ({
141148
addAction(action);
142149
setIsActionsModalOpen(false);
143150
}}
151+
isEditable={false}
144152
/>
145153
</OptionWrapper>
146154
);

src/components/ActionsBuilder/SupportedActions/SetPermissions/SetPermissionsEditor.tsx

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { Controller, useForm } from 'react-hook-form';
66
import { FiChevronDown } from 'react-icons/fi';
77

88
import { ParsedDataInterface, TABS } from './types';
9-
import { ANY_FUNC_SIGNATURE, ERC20_TRANSFER_SIGNATURE } from 'utils';
9+
import {
10+
ANY_FUNC_SIGNATURE,
11+
ERC20_TRANSFER_SIGNATURE,
12+
ERC20_APPROVE_SIGNATURE,
13+
} from 'utils';
1014
import { resolveUri } from 'utils/url';
1115
import { ActionEditorProps } from '..';
1216
import { useTokenList } from 'hooks/Guilds/tokens/useTokenList';
@@ -45,6 +49,7 @@ interface FormValues {
4549
const Permissions: React.FC<ActionEditorProps> = ({
4650
decodedCall,
4751
onSubmit,
52+
isEdit,
4853
}) => {
4954
const parsedData = useMemo<ParsedDataInterface>(() => {
5055
if (!decodedCall) return null;
@@ -111,30 +116,78 @@ const Permissions: React.FC<ActionEditorProps> = ({
111116
updateFunctionSignature(value);
112117
};
113118

114-
const submitAction = (values: FormValues) => {
115-
const isAssetTransferCall = activeTab === TABS.ASSET_TRANSFER;
119+
const submitAssetTransfer = (values: FormValues) => {
120+
const baseCall = {
121+
...decodedCall,
122+
args: {
123+
...decodedCall.args,
124+
to: values.tokenAddress,
125+
valueAllowed: BigNumber.from(0),
126+
// "from" field set by default previously as guild id
127+
},
128+
optionalProps: {
129+
asset: values.tokenAddress,
130+
tab: TABS.ASSET_TRANSFER,
131+
},
132+
};
133+
const newAssetTransferCall: DecodedCall = {
134+
...baseCall,
135+
args: {
136+
...baseCall.args,
137+
functionSignature: ERC20_TRANSFER_SIGNATURE,
138+
},
139+
optionalProps: {
140+
...baseCall.optionalProps,
141+
functionName: '',
142+
},
143+
};
116144

145+
const newApprovalAssetCall = {
146+
...decodedCall,
147+
args: {
148+
...decodedCall.args,
149+
functionSignature: ERC20_APPROVE_SIGNATURE,
150+
},
151+
optionalProps: {
152+
...baseCall.optionalProps,
153+
functionName: 'approve',
154+
},
155+
};
156+
157+
if (isEdit) {
158+
// in case of edit mode we submit only one action that is being edited
159+
return parsedData.functionSignature === ERC20_APPROVE_SIGNATURE
160+
? onSubmit(newApprovalAssetCall)
161+
: onSubmit(newAssetTransferCall);
162+
}
163+
return onSubmit([newAssetTransferCall, newApprovalAssetCall]);
164+
};
165+
166+
const submitFunctionCall = (values: FormValues) => {
117167
const newCall: DecodedCall = {
118168
...decodedCall,
119169
args: {
120170
...decodedCall.args,
121-
to: isAssetTransferCall ? values.tokenAddress : values.toAddress,
171+
to: values.toAddress,
122172
// native value allowed
123-
valueAllowed: isAssetTransferCall ? BigNumber.from(0) : values.amount,
124-
functionSignature: isAssetTransferCall
125-
? ERC20_TRANSFER_SIGNATURE
126-
: values.functionSignature,
173+
valueAllowed: values.amount,
174+
functionSignature: values.functionSignature,
127175
// "from" field set by default previously as guild id
128176
},
129177
optionalProps: {
130-
functionName: isAssetTransferCall ? '' : values.functionName,
131-
asset: isAssetTransferCall ? values.tokenAddress : '',
178+
functionName: values.functionName,
179+
asset: '',
132180
tab: activeTab,
133181
},
134182
};
135183
onSubmit(newCall);
136184
};
137185

186+
const submitAction = (values: FormValues) => {
187+
const isAssetTransferCall = activeTab === TABS.ASSET_TRANSFER;
188+
(isAssetTransferCall ? submitAssetTransfer : submitFunctionCall)(values);
189+
};
190+
138191
const tabArray = [
139192
{
140193
title: t('assetTransfer'),

src/components/ActionsBuilder/SupportedActions/SetPermissions/SetPermissionsInfoLine.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import { Flex } from 'components/primitives/Layout';
99
import { useNetwork } from 'wagmi';
1010
import { useTokenList } from 'hooks/Guilds/tokens/useTokenList';
1111
import { resolveUri } from 'utils/url';
12-
import { shortenAddress } from 'utils';
12+
import {
13+
shortenAddress,
14+
ERC20_TRANSFER_SIGNATURE,
15+
ERC20_APPROVE_SIGNATURE,
16+
} from 'utils';
1317

1418
const SetPermissionsInfoLine: React.FC<ActionViewProps> = ({
1519
decodedCall,
@@ -48,7 +52,15 @@ const SetPermissionsInfoLine: React.FC<ActionViewProps> = ({
4852
<Segment>
4953
<BiCheckShield size={16} />
5054
</Segment>
51-
<Segment>{t('setPermissionsFor')}</Segment>
55+
<Segment>
56+
{t(
57+
parsedData?.functionSignature === ERC20_APPROVE_SIGNATURE
58+
? 'setApprovalPermissionsFor'
59+
: parsedData?.functionSignature === ERC20_TRANSFER_SIGNATURE
60+
? 'setTransferPermissionsFor'
61+
: 'setPermissionsFor'
62+
)}
63+
</Segment>
5264
<Segment>
5365
{currentToken && currentToken.address ? (
5466
<>

src/components/ActionsBuilder/SupportedActions/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export interface ActionViewProps {
3232

3333
export interface ActionEditorProps extends ActionViewProps {
3434
updateCall?: (updatedCall: DecodedCall) => void;
35-
onSubmit: (decodedCall: DecodedCall) => void;
35+
onSubmit: (decodedCall: DecodedCall | DecodedCall[]) => void;
36+
isEdit?: boolean;
3637
}
3738

3839
type SupportedActionViews = {

src/components/ActionsModal/ActionsModal.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const ActionModal: React.FC<ActionModalProps> = ({
3333
isOpen,
3434
setIsOpen,
3535
onAddAction,
36+
isEditable,
3637
}) => {
3738
const { t } = useTranslation();
3839
const { guildId } = useTypedParams();
@@ -160,7 +161,8 @@ const ActionModal: React.FC<ActionModalProps> = ({
160161
<Editor
161162
decodedCall={data}
162163
updateCall={setData}
163-
onSubmit={saveSupportedAction}
164+
onSubmit={handleEditorSubmit}
165+
isEdit={isEditable}
164166
/>
165167
</EditorWrapper>
166168
);
@@ -207,20 +209,23 @@ const ActionModal: React.FC<ActionModalProps> = ({
207209
setSelectedAction(action);
208210
}
209211

210-
function saveSupportedAction(call?: DecodedCall) {
211-
const decodedCall = call ?? data;
212-
212+
function buildAction(decodedCall: DecodedCall): DecodedAction {
213+
if (!decodedCall) return null;
213214
const defaultDecodedAction = defaultValues[decodedCall.callType];
214215

215-
if (!selectedAction || !decodedCall) return;
216-
217216
const decodedAction: DecodedAction = {
218217
id: `action-${Math.random()}`,
219218
decodedCall,
220219
contract: defaultDecodedAction.contract,
221220
};
221+
return decodedAction;
222+
}
222223

223-
onAddAction(decodedAction);
224+
function handleEditorSubmit(calls?: DecodedCall[] | DecodedCall) {
225+
if (!calls) return;
226+
onAddAction(
227+
Array.isArray(calls) ? calls.map(buildAction) : buildAction(calls)
228+
);
224229
handleClose();
225230
}
226231

src/components/ActionsModal/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DecodedAction } from 'components/ActionsBuilder/types';
33
export interface ActionModalProps {
44
isOpen: boolean;
55
setIsOpen: (isOpen: boolean) => void;
6-
onAddAction: (action: DecodedAction) => void;
6+
onAddAction: (action: DecodedAction | DecodedAction[]) => void;
77
action?: DecodedAction;
8+
isEditable?: boolean;
89
}

src/hooks/Guilds/ens/useENSPublicResolverContract.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export function useENSAvatarUri(ensName: string, chainId?: number) {
1313
const supportedChainId = isAvailableOnENS(chainId) ? chainId : MAINNET_ID;
1414
const { resolver } = useENSResolver(ensName, supportedChainId);
1515
const { nameHash, error } = convertToNameHash(ensName);
16-
debugger;
1716
const { data, ...rest } = useContractRead({
1817
enabled: !error,
1918
addressOrName: resolver?.address,
@@ -32,7 +31,6 @@ export function useENSContentHash(ensName: string, chainId?: number) {
3231
const supportedChainId = isAvailableOnENS(chainId) ? chainId : MAINNET_ID;
3332
const { resolver, ...rest } = useENSResolver(ensName, supportedChainId);
3433
const { nameHash, error } = convertToNameHash(ensName);
35-
debugger;
3634
const { data } = useContractRead({
3735
enabled: !error,
3836
addressOrName: resolver?.address,

src/locales/en/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
"permission": "Permission",
7979
"setPermissions": "Set Permissions",
8080
"setPermissionsFor": "Set permissions for",
81+
"setApprovalPermissionsFor": "Set approval permissions for",
82+
"setTransferPermissionsFor": "Set transfer permissions for",
8183
"unknownAction": "Unknown Action",
8284
"default": "Default",
8385
"edit": "Edit",

0 commit comments

Comments
 (0)