From 84cb21bf24bfa1cc5673d1e2594eef1ee89b052a Mon Sep 17 00:00:00 2001 From: Kyrylo Klymenko Date: Fri, 20 Dec 2024 22:00:25 +0100 Subject: [PATCH] Extract reusable sablier proposal builder constants --- .../ProposalBuilder/ProposalDetails.tsx | 2 +- .../ProposalBuilder/ProposalStream.tsx | 16 +------- .../ProposalBuilder/ProposalStreams.tsx | 17 +------- .../ProposalBuilder/StepButtons.tsx | 4 +- src/components/ProposalBuilder/constants.ts | 39 ++++++++++++++++++- .../sablier/SafeSablierProposalCreatePage.tsx | 4 +- 6 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/components/ProposalBuilder/ProposalDetails.tsx b/src/components/ProposalBuilder/ProposalDetails.tsx index 2048100557..d946008676 100644 --- a/src/components/ProposalBuilder/ProposalDetails.tsx +++ b/src/components/ProposalBuilder/ProposalDetails.tsx @@ -25,7 +25,7 @@ export function TransactionValueContainer({ children }: PropsWithChildren<{}>) { ); } -export default function ProposalTemplateDetails({ +export default function ProposalDetails({ values, mode, }: FormikProps & { mode: ProposalBuilderMode }) { diff --git a/src/components/ProposalBuilder/ProposalStream.tsx b/src/components/ProposalBuilder/ProposalStream.tsx index fa7c3e2239..9f92f2c007 100644 --- a/src/components/ProposalBuilder/ProposalStream.tsx +++ b/src/components/ProposalBuilder/ProposalStream.tsx @@ -18,25 +18,13 @@ import { useTranslation } from 'react-i18next'; import { erc20Abi, formatUnits, getContract, isAddress } from 'viem'; import { usePublicClient } from 'wagmi'; import { useDaoInfoStore } from '../../store/daoInfo/useDaoInfoStore'; -import { Stream, Tranche } from '../../types/proposalBuilder'; +import { Stream } from '../../types/proposalBuilder'; import { scrollToBottom } from '../../utils/ui'; import { BigIntInput } from '../ui/forms/BigIntInput'; import ExampleLabel from '../ui/forms/ExampleLabel'; import { InputComponent, LabelComponent } from '../ui/forms/InputComponent'; import CeleryButtonWithIcon from '../ui/utils/CeleryButtonWithIcon'; - -const SECONDS_IN_DAY = 60 * 60 * 24; - -export const DEFAULT_TRANCHE: Tranche = { - amount: { - value: '0', - bigintValue: 0n, - }, - duration: { - value: (SECONDS_IN_DAY * 14).toString(), - bigintValue: BigInt(SECONDS_IN_DAY * 14), - }, -}; +import { DEFAULT_TRANCHE, SECONDS_IN_DAY } from './constants'; export function ProposalStream({ stream, diff --git a/src/components/ProposalBuilder/ProposalStreams.tsx b/src/components/ProposalBuilder/ProposalStreams.tsx index 1194513acb..790584759f 100644 --- a/src/components/ProposalBuilder/ProposalStreams.tsx +++ b/src/components/ProposalBuilder/ProposalStreams.tsx @@ -14,21 +14,8 @@ import { useTranslation } from 'react-i18next'; import { Stream } from '../../types/proposalBuilder'; import { scrollToBottom } from '../../utils/ui'; import CeleryButtonWithIcon from '../ui/utils/CeleryButtonWithIcon'; -import { DEFAULT_TRANCHE, ProposalStream } from './ProposalStream'; - -const DEFAULT_STREAM: Stream = { - type: 'tranched', - tokenAddress: '', - recipientAddress: '', - startDate: new Date(), - tranches: [DEFAULT_TRANCHE], - totalAmount: { - value: '0', - bigintValue: 0n, - }, - cancelable: true, - transferable: false, -}; +import { ProposalStream } from './ProposalStream'; +import { DEFAULT_STREAM } from './constants'; export function ProposalStreams({ pendingTransaction, diff --git a/src/components/ProposalBuilder/StepButtons.tsx b/src/components/ProposalBuilder/StepButtons.tsx index 274cbae5dc..cb3e2bd01e 100644 --- a/src/components/ProposalBuilder/StepButtons.tsx +++ b/src/components/ProposalBuilder/StepButtons.tsx @@ -36,8 +36,8 @@ export default function StepButtons(props: StepButtonsProps) { } // @dev these prevStepUrl and nextStepUrl calculation is done this way to universally build URL for the next/prev steps both for proposal builder and proposal template builder - const prevStepUrl = `${location.pathname.replace(`${CreateProposalSteps.TRANSACTIONS}`, `${CreateProposalSteps.METADATA}`)}${location.search}`; - const nextStepUrl = `${location.pathname.replace(`${CreateProposalSteps.METADATA}`, `${CreateProposalSteps.TRANSACTIONS}`)}${location.search}`; + const prevStepUrl = `${location.pathname.replace(`${mode === ProposalBuilderMode.SABLIER ? CreateProposalSteps.STREAMS : CreateProposalSteps.TRANSACTIONS}`, `${CreateProposalSteps.METADATA}`)}${location.search}`; + const nextStepUrl = `${location.pathname.replace(`${CreateProposalSteps.METADATA}`, `${mode === ProposalBuilderMode.SABLIER ? CreateProposalSteps.STREAMS : CreateProposalSteps.TRANSACTIONS}`)}${location.search}`; return (