Skip to content

Commit

Permalink
fix: more v4 settings bugs (#4469)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyd-eth authored Sep 27, 2024
1 parent d5e6d8c commit 839b5a3
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 75 deletions.
70 changes: 34 additions & 36 deletions src/components/Project/ProjectHeader/ProjectHeaderPopupMenu.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -54,42 +52,42 @@ export function ProjectHeaderPopupMenu({
href,
}))
: []),
{
id: 'subscribe',
label: (
<>
<SubscribeButtonIcon
isSubscribed={isSubscribed}
className="h-5 w-5"
/>
// {
// id: 'subscribe',
// label: (
// <>
// <SubscribeButtonIcon
// isSubscribed={isSubscribed}
// className="h-5 w-5"
// />

<span className="whitespace-nowrap text-sm font-medium">
<Trans>Get notifications</Trans>
</span>
</>
),
onClick: onSubscribeButtonClicked,
},
{
id: 'bookmark',
label: (
<>
<BookmarkButtonIcon
isBookmarked={isBookmarked}
className="h-5 w-5"
/>
<span className="whitespace-nowrap text-sm font-medium">
<Trans>Save project</Trans>
</span>
</>
),
onClick(ev) {
ev.preventDefault()
ev.stopPropagation()
// <span className="whitespace-nowrap text-sm font-medium">
// <Trans>Get notifications</Trans>
// </span>
// </>
// ),
// onClick: onSubscribeButtonClicked,
// },
// {
// id: 'bookmark',
// label: (
// <>
// <BookmarkButtonIcon
// isBookmarked={isBookmarked}
// className="h-5 w-5"
// />
// <span className="whitespace-nowrap text-sm font-medium">
// <Trans>Save project</Trans>
// </span>
// </>
// ),
// onClick(ev) {
// ev.preventDefault()
// ev.stopPropagation()

onBookmarkButtonClicked()
},
},
// onBookmarkButtonClicked()
// },
// },
{
id: 'tools',
label: (
Expand Down
6 changes: 0 additions & 6 deletions src/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ msgstr ""
msgid "Claim {tokensLabel} as ERC-20"
msgstr ""

msgid "Save project"
msgstr ""

msgid "Total issuance"
msgstr ""

Expand Down Expand Up @@ -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 ""

Expand Down
14 changes: 8 additions & 6 deletions src/packages/v4/hooks/useEditRulesetTx.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions src/packages/v4/utils/editRuleset.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 = [
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/packages/v4/utils/launchProject.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions src/packages/v4/views/V4ProjectDashboard/V4ProjectHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -58,7 +57,8 @@ export const V4ProjectHeader = ({ className }: { className?: string }) => {
<div className="flex items-center justify-end gap-4">
{projectId ? (
isMobile ? (
<ProjectHeaderPopupMenu projectId={projectId} />
// <ProjectHeaderPopupMenu projectId={projectId} />
<></>
) : (
<>
<div className="flex items-center gap-6">
Expand All @@ -73,7 +73,7 @@ export const V4ProjectHeader = ({ className }: { className?: string }) => {
/>
))}
</div>
<ProjectHeaderPopupMenu projectId={projectId} />
{/* @v4todo: <ProjectHeaderPopupMenu projectId={projectId} /> */}
{canQueueRuleSets && (
<Link
href={settingsPagePath({ projectId, chainId }, undefined)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { JBRulesetData } from 'juice-sdk-core'
import { NativeTokenValue } from 'juice-sdk-react'
import { V4CurrencyOption } from 'packages/v4/models/v4CurrencyOption'
import { getApprovalStrategyByAddress } from 'packages/v4/utils/approvalHooks'
import { formatCurrencyAmount } from 'packages/v4/utils/formatCurrencyAmount'
import { MAX_PAYOUT_LIMIT } from 'packages/v4/utils/math'
import { useMemo } from 'react'
import { formatTime } from 'utils/format/formatTime'
Expand Down Expand Up @@ -72,19 +71,15 @@ export const useV4FormatConfigurationCycleSection = ({

const formatPayoutAmount = (
amount: bigint | undefined,
currency: V4CurrencyOption | undefined,
) => {
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 <NativeTokenValue wei={amount ?? 0n} />
}

const payoutsDatum: ConfigurationPanelDatum = useMemo(() => {
const { amount, currency } = payoutLimitAmountCurrency ?? {}
const currentPayout = <NativeTokenValue wei={amount ?? 0n} />
const currentPayout = formatPayoutAmount(amount)

if (
upcomingPayoutLimitAmountCurrency === null ||
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export const useV4FormatConfigurationTokenSection = ({
: undefined

const totalIssuanceRateDatum: ConfigurationPanelDatum = useMemo(() => {
const current = currentTotalIssuanceRate
const current = currentTotalIssuanceRate !== undefined
? `${currentTotalIssuanceRate} ${tokenSymbol}/ETH`
: undefined

if (upcomingRuleset === null || upcomingRulesetLoading) {
return pairToDatum(t`Total issuance rate`, current, null)
}

const queued = queuedTotalIssuanceRate
const queued = queuedTotalIssuanceRate !== undefined
? `${queuedTotalIssuanceRate} ${tokenSymbol}/ETH`
: undefined

Expand All @@ -74,7 +74,7 @@ export const useV4FormatConfigurationTokenSection = ({
currentTotalIssuanceRate * reservedPercentFloat
: undefined

const current = currentPayerIssuanceRate
const current = currentPayerIssuanceRate !== undefined
? `${currentPayerIssuanceRate} ${tokenSymbol}/ETH`
: undefined

Expand All @@ -91,7 +91,7 @@ export const useV4FormatConfigurationTokenSection = ({
queuedTotalIssuanceRate && _reservedPercent
? queuedTotalIssuanceRate - queuedTotalIssuanceRate * _reservedPercent
: undefined
const queued = queuedPayerIssuanceRate
const queued = queuedPayerIssuanceRate !== undefined
? `${queuedPayerIssuanceRate} ${tokenSymbol}/ETH`
: undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export const V4ReservedTokensSubPanel = ({
<TitleDescriptionDisplayCard
className="w-full"
title={t`Reserved tokens list`}
kebabMenu={{
items: kebabMenuItems,
}}
// kebabMenu={{
// items: kebabMenuItems,
// }}
>
{pendingReservedTokensFormatted ||
reservedPercent ||
Expand Down

0 comments on commit 839b5a3

Please sign in to comment.