From 4fa08c6a7f5c0a701d291254a08d6c4179fc9b99 Mon Sep 17 00:00:00 2001 From: Kirill Klimenko Date: Tue, 9 Apr 2024 13:21:19 +0200 Subject: [PATCH 1/2] If signature is empty - do not call encodeFunction but simply return 0x as calldata --- src/hooks/DAO/proposal/usePrepareProposal.ts | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/hooks/DAO/proposal/usePrepareProposal.ts b/src/hooks/DAO/proposal/usePrepareProposal.ts index e81a71463c..945150104b 100644 --- a/src/hooks/DAO/proposal/usePrepareProposal.ts +++ b/src/hooks/DAO/proposal/usePrepareProposal.ts @@ -10,19 +10,22 @@ export function usePrepareProposal() { async (values: CreateProposalForm) => { const { transactions, proposalMetadata } = values; const transactionsWithEncoding = transactions.map(tx => { + const signature = tx.parameters.map(parameter => parameter.signature.trim()).join(', '); + const parameters = tx.parameters + .map(parameter => + isValidUrl(parameter.value!.trim()) + ? encodeURIComponent(parameter.value!.trim()) // If parameter.value is valid URL with special symbols like ":" or "?" - decoding might fail, thus we need to encode URL + : parameter.value!.trim(), + ) + .join(', ') + return { ...tx, - encodedFunctionData: encodeFunction( + calldata: signature ? encodeFunction( tx.functionName, - tx.parameters.map(parameter => parameter.signature.trim()).join(', '), - tx.parameters - .map(parameter => - isValidUrl(parameter.value!.trim()) - ? encodeURIComponent(parameter.value!.trim()) // If parameter.value is valid URL with special symbols like ":" or "?" - decoding might fail, thus we need to encode URL - : parameter.value!.trim(), - ) - .join(', '), - ), + signature, + parameters, + ) : '0x', }; }); const targets = await Promise.all( @@ -33,11 +36,12 @@ export function usePrepareProposal() { return tx.targetAddress; }), ); + return { targets, values: transactionsWithEncoding.map(transaction => transaction.ethValue.bigNumberValue!), calldatas: transactionsWithEncoding.map( - transaction => transaction.encodedFunctionData || '', + transaction => transaction.calldata || '', ), metaData: { title: proposalMetadata.title, From 6886d707be026761079803ba3e705700ab4092f5 Mon Sep 17 00:00:00 2001 From: Kirill Klimenko Date: Tue, 9 Apr 2024 13:26:18 +0200 Subject: [PATCH 2/2] Validate based on function name and not signature. If function name not specified - immediately return transaction with calldata set to 0x --- src/hooks/DAO/proposal/usePrepareProposal.ts | 39 ++++++++++---------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/hooks/DAO/proposal/usePrepareProposal.ts b/src/hooks/DAO/proposal/usePrepareProposal.ts index 945150104b..d8ca234c08 100644 --- a/src/hooks/DAO/proposal/usePrepareProposal.ts +++ b/src/hooks/DAO/proposal/usePrepareProposal.ts @@ -10,23 +10,26 @@ export function usePrepareProposal() { async (values: CreateProposalForm) => { const { transactions, proposalMetadata } = values; const transactionsWithEncoding = transactions.map(tx => { - const signature = tx.parameters.map(parameter => parameter.signature.trim()).join(', '); - const parameters = tx.parameters - .map(parameter => - isValidUrl(parameter.value!.trim()) - ? encodeURIComponent(parameter.value!.trim()) // If parameter.value is valid URL with special symbols like ":" or "?" - decoding might fail, thus we need to encode URL - : parameter.value!.trim(), - ) - .join(', ') + if (!tx.functionName) { + return { + ...tx, + calldata: '0x', + }; + } else { + const signature = tx.parameters.map(parameter => parameter.signature.trim()).join(', '); + const parameters = tx.parameters + .map(parameter => + isValidUrl(parameter.value!.trim()) + ? encodeURIComponent(parameter.value!.trim()) // If parameter.value is valid URL with special symbols like ":" or "?" - decoding might fail, thus we need to encode URL + : parameter.value!.trim(), + ) + .join(', '); - return { - ...tx, - calldata: signature ? encodeFunction( - tx.functionName, - signature, - parameters, - ) : '0x', - }; + return { + ...tx, + calldata: encodeFunction(tx.functionName, signature, parameters), + }; + } }); const targets = await Promise.all( transactionsWithEncoding.map(tx => { @@ -40,9 +43,7 @@ export function usePrepareProposal() { return { targets, values: transactionsWithEncoding.map(transaction => transaction.ethValue.bigNumberValue!), - calldatas: transactionsWithEncoding.map( - transaction => transaction.calldata || '', - ), + calldatas: transactionsWithEncoding.map(transaction => transaction.calldata || ''), metaData: { title: proposalMetadata.title, description: proposalMetadata.description,