diff --git a/src/components/v2v3/V2V3Project/V2V3FundingCycleSection/FundingCycleDetails/TokenListItems/MintRateValue.tsx b/src/components/v2v3/V2V3Project/V2V3FundingCycleSection/FundingCycleDetails/TokenListItems/MintRateValue.tsx index 386ad25949..a19f2e8a0e 100644 --- a/src/components/v2v3/V2V3Project/V2V3FundingCycleSection/FundingCycleDetails/TokenListItems/MintRateValue.tsx +++ b/src/components/v2v3/V2V3Project/V2V3FundingCycleSection/FundingCycleDetails/TokenListItems/MintRateValue.tsx @@ -1,6 +1,7 @@ import { Trans } from '@lingui/macro' import { BigNumber } from 'ethers' import { formattedNum } from 'utils/format/formatNumber' +import { WEIGHT_UNCHANGED } from 'utils/v2v3/fundingCycle' import { formatIssuanceRate } from 'utils/v2v3/math' export function MintRateValue({ @@ -12,7 +13,7 @@ export function MintRateValue({ tokenSymbol: string zeroAsUnchanged?: boolean }) { - if (zeroAsUnchanged && value.eq(0)) { + if (zeroAsUnchanged && value.eq(WEIGHT_UNCHANGED)) { return Unchanged } diff --git a/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/ReviewConfirmModal/TokensSectionDiff.tsx b/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/ReviewConfirmModal/TokensSectionDiff.tsx index addc08b97f..beca5e99b2 100644 --- a/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/ReviewConfirmModal/TokensSectionDiff.tsx +++ b/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/ReviewConfirmModal/TokensSectionDiff.tsx @@ -69,7 +69,6 @@ export function TokensSectionDiff() { } oldValue={ diff --git a/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/useLoadEditCycleData.tsx b/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/useLoadEditCycleData.tsx index fd71a02b3c..757237afc3 100644 --- a/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/useLoadEditCycleData.tsx +++ b/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/useLoadEditCycleData.tsx @@ -11,12 +11,14 @@ import { } from 'utils/format/formatTime' import { V2V3CurrencyName } from 'utils/v2v3/currency' import { distributionLimitStringtoNumber } from 'utils/v2v3/distributions' +import { deriveNextIssuanceRate } from 'utils/v2v3/fundingCycle' import { formatDiscountRate, formatIssuanceRate, formatRedemptionRate, formatReservedRate, } from 'utils/v2v3/math' +import { deserializeV2V3FundingCycleData } from 'utils/v2v3/serializers' import { useInitialEditingData } from '../../ReconfigureFundingCycleSettingsPage/hooks/useInitialEditingData' import { EditCycleFormFields } from '../EditCycleFormFields' @@ -45,9 +47,16 @@ export const useLoadEditCycleData = () => { ).toNumber() const fundingCycleData = currentProjectData.fundingCycleData const fundingCycleMetadata = currentProjectData.fundingCycleMetadata - const mintRate = fundingCycleData?.weight - ? parseFloat(formatIssuanceRate(fundingCycleData.weight)) - : parseFloat(DefaultTokenSettings.initialMintRate) + const mintRate = parseFloat( + formatIssuanceRate( + deriveNextIssuanceRate({ + weight: BigNumber.from(0), + previousFC: deserializeV2V3FundingCycleData( + currentProjectData.fundingCycleData, + ), + }).toString(), + ), + ) const reservedTokens = fundingCycleMetadata.reservedRate ? parseFloat(formatReservedRate(fundingCycleMetadata.reservedRate)) : DefaultTokenSettings.reservedTokensPercentage diff --git a/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/usePrepareSaveEditCycleData.tsx b/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/usePrepareSaveEditCycleData.tsx index dbdc17570d..d2c52b43f5 100644 --- a/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/usePrepareSaveEditCycleData.tsx +++ b/src/components/v2v3/V2V3Project/V2V3ProjectSettings/pages/NewEditCyclePage/hooks/usePrepareSaveEditCycleData.tsx @@ -21,7 +21,6 @@ import { getV2V3CurrencyOption } from 'utils/v2v3/currency' import { MAX_DISTRIBUTION_LIMIT, discountRateFrom, - issuanceRateFrom, redemptionRateFrom, reservedRateFrom, } from 'utils/v2v3/math' @@ -31,12 +30,15 @@ import { } from '../../ReconfigureFundingCycleSettingsPage/hooks/useEditingFundingCycleConfig' import { useEditCycleFormContext } from '../EditCycleFormContext' import { EditCycleFormFields } from '../EditCycleFormFields' +import { useTokensSectionValues } from '../ReviewConfirmModal/hooks/useTokensSectionValues' export const usePrepareSaveEditCycleData = () => { // Use Redux to get current (pre-edit) project state since it's not changed by edit // Only using this to get values of FC parameters not supported in the FC form (e.g. allowTerminalMigration, etc.) const reduxConfig = useEditingFundingCycleConfig() + const { newMintRate, mintRateHasDiff } = useTokensSectionValues() + const { editCycleForm } = useEditCycleFormContext() const { contracts: { JBETHPaymentTerminal }, @@ -87,9 +89,9 @@ export const usePrepareSaveEditCycleData = () => { const editingFundingCycleData: V2V3FundingCycleData = { duration: BigNumber.from(durationSeconds), - weight: BigNumber.from( - issuanceRateFrom(formValues.mintRate?.toString() ?? '0'), - ), + weight: mintRateHasDiff + ? newMintRate + : reduxConfig.editingFundingCycleData.weight, discountRate: discountRateFrom(formValues.discountRate), ballot: formValues.ballot, } diff --git a/src/utils/v2v3/fundingCycle.ts b/src/utils/v2v3/fundingCycle.ts index 695e5bbf87..3affe13617 100644 --- a/src/utils/v2v3/fundingCycle.ts +++ b/src/utils/v2v3/fundingCycle.ts @@ -4,6 +4,7 @@ import { BigNumber } from 'ethers' import { V2V3FundAccessConstraint, V2V3FundingCycle, + V2V3FundingCycleData, V2V3FundingCycleMetadata, } from 'models/v2v3/fundingCycle' import { isZeroAddress } from 'utils/address' @@ -138,19 +139,21 @@ export const deriveNextIssuanceRate = ({ weight, previousFC, }: { - weight: BigNumber - previousFC: V2V3FundingCycle | undefined + weight?: BigNumber + previousFC: V2V3FundingCycle | V2V3FundingCycleData | undefined }) => { const previousWeight = previousFC?.weight - if (weight.eq(WEIGHT_ZERO)) { + const newWeight = weight ?? BigNumber.from(WEIGHT_UNCHANGED) + + if (newWeight.eq(WEIGHT_ZERO)) { return BigNumber.from(0) // If no previous FC exists, return given weight } else if (!previousWeight) { - return weight + return newWeight // If weight=0 passed, derive next weight from previous weight - } else if (weight.eq(WEIGHT_UNCHANGED)) { + } else if (newWeight.eq(WEIGHT_UNCHANGED)) { const weightNumber = parseFloat( formatIssuanceRate(previousWeight.toString()), ) @@ -162,7 +165,7 @@ export const deriveNextIssuanceRate = ({ return BigNumber.from(issuanceRateFrom(newWeightNumber.toString())) } - return weight + return newWeight } /**