@@ -6,7 +6,11 @@ import { Controller, useForm } from 'react-hook-form';
66import { FiChevronDown } from 'react-icons/fi' ;
77
88import { 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' ;
1014import { resolveUri } from 'utils/url' ;
1115import { ActionEditorProps } from '..' ;
1216import { useTokenList } from 'hooks/Guilds/tokens/useTokenList' ;
@@ -45,6 +49,7 @@ interface FormValues {
4549const 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' ) ,
0 commit comments