From 113b93cf03619116b9664427e6de99ff18bf0790 Mon Sep 17 00:00:00 2001 From: selankon Date: Thu, 8 Feb 2024 15:06:14 +0100 Subject: [PATCH] Fix gasless endate --- src/context/createProposal.tsx | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/context/createProposal.tsx b/src/context/createProposal.tsx index 438431757..c0c2855cb 100644 --- a/src/context/createProposal.tsx +++ b/src/context/createProposal.tsx @@ -621,12 +621,27 @@ const CreateProposalWrapper: React.FC = ({ ( params: CreateMajorityVotingProposalParams ): GaslessProposalCreationParams => { - const gaslessEndDate = new Date(params.endDate!); - gaslessEndDate.setMinutes(params.endDate!.getMinutes() + 1); + // If the onchain end date is too close to the minimum end date, the estimation or either the transaction will fail + // Above all if we are using days or hours to create the proposal, at the time that we are calculating the end date + // it will take the beginning of the actual minute, causing the estimation to be some seconds ahead of the calculated + // date. + // To avoid this, in order to have a concordance between onchain and ofchain endates, we add an offset to the end date + const endDateOffset = 5; // Minutes + const finalEndDate = new Date(params.endDate!); // We ensure that the onchain endate is not undefined, during the calculation of the CreateMajorityVotingProposalParams + finalEndDate.setMinutes(params.endDate!.getMinutes() + endDateOffset); + + // The offchain offset is used to ensure that the offchain proposal is enough long to don't overlap the onchain proposal + // limits. As both chains don't use the same clock, and we are calculating the times using blocks, we ensure that + // the times will be properly set to let the voters vote between the onchain proposal limits. + const offchainOffsets = 1; // Minutes + const gaslessEndDate = new Date(finalEndDate); + gaslessEndDate.setMinutes(finalEndDate.getMinutes() + offchainOffsets); let gaslessStartDate; if (params.startDate) { gaslessStartDate = new Date(params.startDate); - gaslessStartDate.setMinutes(params.startDate.getMinutes() - 1); + gaslessStartDate.setMinutes( + params.startDate.getMinutes() - offchainOffsets + ); } return { ...params, @@ -635,8 +650,7 @@ const CreateProposalWrapper: React.FC = ({ // We could define a different expiration date for this proposal but is not designed // to do this at ux level. (kon) tallyEndDate: undefined, - // We ensure that the onchain endate is not undefined, during the calculation of the CreateMajorityVotingProposalParams - endDate: params.endDate!, + endDate: finalEndDate, // Add offset to the end date to avoid onchain proposal finish before the offchain proposal gaslessEndDate, // Add offset to ensure offchain is started when proposal starts @@ -1004,13 +1018,6 @@ const CreateProposalWrapper: React.FC = ({ async function setProposalData() { if (showTxModal && creationProcessState === TransactionState.WAITING) { if (gasless) { - // const {params} = await getProposalCreationParams(); - // // console.log( - // // 'XXXXXXXXXXXXXXXXX', - // // (await getProposalCreationParams()).params.endDate, - // // gaslessParamsxx.endDate, - // // getOffChainProposalParams(gaslessParamsxx).endDate - // // ); setProposalCreationData( getOffChainProposalParams( (await getProposalCreationParams()).params