From 839b5a3a61dec2bc75d585c530a07d051656eb58 Mon Sep 17 00:00:00 2001 From: Johnny D Date: Fri, 27 Sep 2024 17:00:35 +1000 Subject: [PATCH] fix: more v4 settings bugs (#4469) --- .../ProjectHeader/ProjectHeaderPopupMenu.tsx | 70 +++++++++---------- src/locales/messages.pot | 6 -- src/packages/v4/hooks/useEditRulesetTx.ts | 14 ++-- src/packages/v4/utils/editRuleset.ts | 9 +-- src/packages/v4/utils/launchProject.ts | 4 +- .../V4ProjectDashboard/V4ProjectHeader.tsx | 6 +- .../useV4FormatConfigurationCycleSection.tsx | 15 +--- .../useV4FormatConfigurationTokenSection.ts | 8 +-- .../V4ReservedTokensSubPanel.tsx | 6 +- 9 files changed, 63 insertions(+), 75 deletions(-) diff --git a/src/components/Project/ProjectHeader/ProjectHeaderPopupMenu.tsx b/src/components/Project/ProjectHeader/ProjectHeaderPopupMenu.tsx index ff07259f6b..dbe189de07 100644 --- a/src/components/Project/ProjectHeader/ProjectHeaderPopupMenu.tsx +++ b/src/components/Project/ProjectHeader/ProjectHeaderPopupMenu.tsx @@ -1,8 +1,6 @@ import { WrenchScrewdriverIcon } from '@heroicons/react/24/outline' import { Trans } from '@lingui/macro' -import { BookmarkButtonIcon } from 'components/buttons/BookmarkButton/BookmarkButtonIcon' import { useBookmarkButton } from 'components/buttons/BookmarkButton/hooks/useBookmarkButton' -import { SubscribeButtonIcon } from 'components/buttons/SubscribeButton/SubscribeButtonIcon' import { useSubscribeButton } from 'components/buttons/SubscribeButton/hooks/useSubscribeButton' import { PV_V2 } from 'constants/pv' import useMobile from 'hooks/useMobile' @@ -54,42 +52,42 @@ export function ProjectHeaderPopupMenu({ href, })) : []), - { - id: 'subscribe', - label: ( - <> - + // { + // id: 'subscribe', + // label: ( + // <> + // - - Get notifications - - - ), - onClick: onSubscribeButtonClicked, - }, - { - id: 'bookmark', - label: ( - <> - - - Save project - - - ), - onClick(ev) { - ev.preventDefault() - ev.stopPropagation() + // + // Get notifications + // + // + // ), + // onClick: onSubscribeButtonClicked, + // }, + // { + // id: 'bookmark', + // label: ( + // <> + // + // + // Save project + // + // + // ), + // onClick(ev) { + // ev.preventDefault() + // ev.stopPropagation() - onBookmarkButtonClicked() - }, - }, + // onBookmarkButtonClicked() + // }, + // }, { id: 'tools', label: ( diff --git a/src/locales/messages.pot b/src/locales/messages.pot index a6d5c40ccf..08f3ebe39c 100644 --- a/src/locales/messages.pot +++ b/src/locales/messages.pot @@ -92,9 +92,6 @@ msgstr "" msgid "Claim {tokensLabel} as ERC-20" msgstr "" -msgid "Save project" -msgstr "" - msgid "Total issuance" msgstr "" @@ -2810,9 +2807,6 @@ msgstr "" msgid "We've disabled payments because the project has opted to reserve 100% of new tokens. You would receive no tokens from your payment." msgstr "" -msgid "Get notifications" -msgstr "" - msgid "Unarchiving your project has the following effects:" msgstr "" diff --git a/src/packages/v4/hooks/useEditRulesetTx.ts b/src/packages/v4/hooks/useEditRulesetTx.ts index 7d37933690..3728579a7d 100644 --- a/src/packages/v4/hooks/useEditRulesetTx.ts +++ b/src/packages/v4/hooks/useEditRulesetTx.ts @@ -1,7 +1,9 @@ +import { waitForTransactionReceipt } from '@wagmi/core' import { TxHistoryContext } from 'contexts/Transaction/TxHistoryContext' import { useWallet } from 'hooks/Wallet' import { NATIVE_TOKEN } from 'juice-sdk-core' import { useJBContractContext, useWriteJbControllerQueueRulesetsOf } from 'juice-sdk-react' +import { wagmiConfig } from 'packages/v4/wagmiConfig' import { useCallback, useContext } from 'react' import { transformEditCycleFormFieldsToTxArgs } from '../utils/editRuleset' import { EditCycleFormFields } from '../views/V4ProjectSettings/EditCyclePage/EditCycleFormFields' @@ -64,12 +66,12 @@ export function useEditRulesetTx() { onTransactionPendingCallback(hash) addTransaction?.('Edit Ruleset', { hash }) - // const transactionReceipt: WaitForTransactionReceiptReturnType = await waitForTransactionReceipt( - // wagmiConfig, - // { - // hash, - // }, - // ) + await waitForTransactionReceipt( + wagmiConfig, + { + hash, + }, + ) onTransactionConfirmedCallback() } catch (e) { diff --git a/src/packages/v4/utils/editRuleset.ts b/src/packages/v4/utils/editRuleset.ts index fd59448c66..ca46980f54 100644 --- a/src/packages/v4/utils/editRuleset.ts +++ b/src/packages/v4/utils/editRuleset.ts @@ -1,5 +1,6 @@ import { NATIVE_TOKEN } from "juice-sdk-core"; import round from "lodash/round"; +import { issuanceRateFrom } from "packages/v2v3/utils/math"; import { parseWad } from "utils/format/formatNumber"; import { otherUnitToSeconds } from "utils/format/formatTime"; import { EditCycleFormFields } from "../views/V4ProjectSettings/EditCyclePage/EditCycleFormFields"; @@ -22,8 +23,8 @@ export function transformEditCycleFormFieldsToTxArgs({ duration: formValues.duration, unit: formValues.durationUnit.value, }) - const weight = BigInt(formValues.issuanceRate); - const decayPercent = formValues.decayPercent; + const weight = BigInt(issuanceRateFrom(formValues.issuanceRate.toString())); + const decayPercent = round(formValues.decayPercent * 10000000); const approvalHook = formValues.approvalHook; const rulesetConfigurations = [ @@ -35,8 +36,8 @@ export function transformEditCycleFormFieldsToTxArgs({ approvalHook, metadata: { - reservedPercent: formValues.reservedPercent, - redemptionRate: formValues.redemptionRate, + reservedPercent: formValues.reservedPercent * 100, + redemptionRate: formValues.redemptionRate * 100, baseCurrency: 1, // Assuming base currency is a constant value, typically USD pausePay: formValues.pausePay, pauseRedeem: false, // Defaulting this value since it's not in formValues diff --git a/src/packages/v4/utils/launchProject.ts b/src/packages/v4/utils/launchProject.ts index c54df91405..21292b1834 100644 --- a/src/packages/v4/utils/launchProject.ts +++ b/src/packages/v4/utils/launchProject.ts @@ -1,4 +1,5 @@ import { NATIVE_TOKEN, NATIVE_TOKEN_DECIMALS, SplitGroup } from 'juice-sdk-core' +import round from 'lodash/round' import { V2FundingCycleMetadata } from 'packages/v2/models/fundingCycle' import { V2V3FundAccessConstraint, @@ -42,9 +43,10 @@ export function transformV2V3CreateArgsToV4({ ] = v2v3Args const mustStartAtOrAfterNum = parseInt(_mustStartAtOrAfter) + const now = round(new Date().getTime() / 1000) const ruleset = { - mustStartAtOrAfter: mustStartAtOrAfterNum ?? 0, // 0 denotes start immediately + mustStartAtOrAfter: mustStartAtOrAfterNum > now ? mustStartAtOrAfterNum : now, duration: _data.duration.toNumber(), weight: _data.weight.toBigInt(), decayPercent: _data.discountRate.toNumber(), diff --git a/src/packages/v4/views/V4ProjectDashboard/V4ProjectHeader.tsx b/src/packages/v4/views/V4ProjectDashboard/V4ProjectHeader.tsx index 1171fdfa41..db5bcef5f3 100644 --- a/src/packages/v4/views/V4ProjectDashboard/V4ProjectHeader.tsx +++ b/src/packages/v4/views/V4ProjectDashboard/V4ProjectHeader.tsx @@ -6,7 +6,6 @@ import EthereumAddress from 'components/EthereumAddress' import { GnosisSafeBadge } from 'components/Project/ProjectHeader/GnosisSafeBadge' import { useSocialLinks } from 'components/Project/ProjectHeader/hooks/useSocialLinks' import { ProjectHeaderLogo } from 'components/Project/ProjectHeader/ProjectHeaderLogo' -import { ProjectHeaderPopupMenu } from 'components/Project/ProjectHeader/ProjectHeaderPopupMenu' import { SocialLinkButton } from 'components/Project/ProjectHeader/SocialLinkButton' // import { Subtitle } from 'components/Project/ProjectHeader/Subtitle' import { TruncatedText } from 'components/TruncatedText' @@ -58,7 +57,8 @@ export const V4ProjectHeader = ({ className }: { className?: string }) => {
{projectId ? ( isMobile ? ( - + // + <> ) : ( <>
@@ -73,7 +73,7 @@ export const V4ProjectHeader = ({ className }: { className?: string }) => { /> ))}
- + {/* @v4todo: */} {canQueueRuleSets && ( { if (amount === undefined || amount === MAX_PAYOUT_LIMIT) return t`Unlimited` if (amount === 0n) return t`Zero (no payouts)` - return formatCurrencyAmount({ - amount: Number(amount) / 1e18, // Assuming fromWad - currency, - }) + return } const payoutsDatum: ConfigurationPanelDatum = useMemo(() => { const { amount, currency } = payoutLimitAmountCurrency ?? {} - const currentPayout = + const currentPayout = formatPayoutAmount(amount) if ( upcomingPayoutLimitAmountCurrency === null || @@ -97,13 +92,9 @@ export const useV4FormatConfigurationCycleSection = ({ upcomingPayoutLimitAmountCurrency?.amount !== undefined ? upcomingPayoutLimitAmountCurrency.amount : amount - const upcomingPayoutLimitCurrency = - upcomingPayoutLimitAmountCurrency?.currency !== undefined - ? upcomingPayoutLimitAmountCurrency.currency - : currency + const upcomingPayout = formatPayoutAmount( upcomingPayoutLimit, - upcomingPayoutLimitCurrency, ) return pairToDatum(t`Payouts`, currentPayout, upcomingPayout) diff --git a/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4CyclesPayoutsPanel/hooks/useV4FormatConfigurationTokenSection.ts b/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4CyclesPayoutsPanel/hooks/useV4FormatConfigurationTokenSection.ts index 9d9c1a41de..bca38922ca 100644 --- a/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4CyclesPayoutsPanel/hooks/useV4FormatConfigurationTokenSection.ts +++ b/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4CyclesPayoutsPanel/hooks/useV4FormatConfigurationTokenSection.ts @@ -41,7 +41,7 @@ export const useV4FormatConfigurationTokenSection = ({ : undefined const totalIssuanceRateDatum: ConfigurationPanelDatum = useMemo(() => { - const current = currentTotalIssuanceRate + const current = currentTotalIssuanceRate !== undefined ? `${currentTotalIssuanceRate} ${tokenSymbol}/ETH` : undefined @@ -49,7 +49,7 @@ export const useV4FormatConfigurationTokenSection = ({ return pairToDatum(t`Total issuance rate`, current, null) } - const queued = queuedTotalIssuanceRate + const queued = queuedTotalIssuanceRate !== undefined ? `${queuedTotalIssuanceRate} ${tokenSymbol}/ETH` : undefined @@ -74,7 +74,7 @@ export const useV4FormatConfigurationTokenSection = ({ currentTotalIssuanceRate * reservedPercentFloat : undefined - const current = currentPayerIssuanceRate + const current = currentPayerIssuanceRate !== undefined ? `${currentPayerIssuanceRate} ${tokenSymbol}/ETH` : undefined @@ -91,7 +91,7 @@ export const useV4FormatConfigurationTokenSection = ({ queuedTotalIssuanceRate && _reservedPercent ? queuedTotalIssuanceRate - queuedTotalIssuanceRate * _reservedPercent : undefined - const queued = queuedPayerIssuanceRate + const queued = queuedPayerIssuanceRate !== undefined ? `${queuedPayerIssuanceRate} ${tokenSymbol}/ETH` : undefined diff --git a/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4TokensPanel/V4ReservedTokensSubPanel.tsx b/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4TokensPanel/V4ReservedTokensSubPanel.tsx index fa13d73bc3..be5f9875a9 100644 --- a/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4TokensPanel/V4ReservedTokensSubPanel.tsx +++ b/src/packages/v4/views/V4ProjectDashboard/V4ProjectTabs/V4TokensPanel/V4ReservedTokensSubPanel.tsx @@ -53,9 +53,9 @@ export const V4ReservedTokensSubPanel = ({ {pendingReservedTokensFormatted || reservedPercent ||