From a62e2b38a6932799e6e93b12ea13f98b5669df4d Mon Sep 17 00:00:00 2001 From: neokry Date: Thu, 11 Jan 2024 16:34:21 -0800 Subject: [PATCH] add resume auctions proposal template --- .../src/components/Icon/assets/migrate.svg | 3 + .../Icon/assets/resume-template.svg | 1 + apps/web/src/components/Icon/icons.ts | 4 ++ .../ResumeAuctions/ResumeAuctions.tsx | 68 +++++++++++++++++++ .../TransactionForm/TransactionForm.tsx | 3 + .../constants/transactionType.tsx | 9 ++- apps/web/src/pages/api/simulate.ts | 5 +- .../dao/[network]/[token]/proposal/create.tsx | 22 ++++-- 8 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 apps/web/src/components/Icon/assets/migrate.svg create mode 100644 apps/web/src/components/Icon/assets/resume-template.svg create mode 100644 apps/web/src/modules/create-proposal/components/TransactionForm/ResumeAuctions/ResumeAuctions.tsx diff --git a/apps/web/src/components/Icon/assets/migrate.svg b/apps/web/src/components/Icon/assets/migrate.svg new file mode 100644 index 000000000..6a083c0ce --- /dev/null +++ b/apps/web/src/components/Icon/assets/migrate.svg @@ -0,0 +1,3 @@ + + + diff --git a/apps/web/src/components/Icon/assets/resume-template.svg b/apps/web/src/components/Icon/assets/resume-template.svg new file mode 100644 index 000000000..696a60a9f --- /dev/null +++ b/apps/web/src/components/Icon/assets/resume-template.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/apps/web/src/components/Icon/icons.ts b/apps/web/src/components/Icon/icons.ts index 81729b375..ad21397e1 100644 --- a/apps/web/src/components/Icon/icons.ts +++ b/apps/web/src/components/Icon/icons.ts @@ -25,6 +25,7 @@ import Github from './assets/github.svg' import Globe from './assets/globe.svg' import HandlebarCircle from './assets/handlebar-circle.svg' import Info16 from './assets/info-16.svg' +import Migrate from './assets/migrate.svg' import Move from './assets/move.svg' import NewWindow from './assets/new-window.svg' import NounsConnect from './assets/nouns-connect.svg' @@ -33,6 +34,7 @@ import Pause from './assets/pause.svg' import Play from './assets/play.svg' import Plus from './assets/plus.svg' import Refresh from './assets/refresh.svg' +import ResumeTemplate from './assets/resume-template.svg' import Trash from './assets/trash.svg' import Twitter from './assets/twitter.svg' import Warning16 from './assets/warning-16.svg' @@ -66,6 +68,7 @@ export const icons = { handlebarCircle: HandlebarCircle, 'info-16': Info16, globe: Globe, + migrate: Migrate, move: Move, newWindow: NewWindow, nounsConnect: NounsConnect, @@ -74,6 +77,7 @@ export const icons = { play: Play, plus: Plus, refresh: Refresh, + resumeTemplate: ResumeTemplate, trash: Trash, twitter: Twitter, warning: Warning, diff --git a/apps/web/src/modules/create-proposal/components/TransactionForm/ResumeAuctions/ResumeAuctions.tsx b/apps/web/src/modules/create-proposal/components/TransactionForm/ResumeAuctions/ResumeAuctions.tsx new file mode 100644 index 000000000..50f8d18f6 --- /dev/null +++ b/apps/web/src/modules/create-proposal/components/TransactionForm/ResumeAuctions/ResumeAuctions.tsx @@ -0,0 +1,68 @@ +import { Box, Button, Paragraph } from '@zoralabs/zord' +import { encodeFunctionData } from 'viem' +import { useContractRead } from 'wagmi' + +import { auctionAbi } from 'src/data/contract/abis' +import { TransactionType } from 'src/modules/create-proposal/constants' +import { useProposalStore } from 'src/modules/create-proposal/stores' +import { useDaoStore } from 'src/modules/dao' +import { useChainStore } from 'src/stores/useChainStore' +import { AddressType } from 'src/typings' + +export const ResumeAuctions = () => { + const { auction } = useDaoStore((state) => state.addresses) + const addTransaction = useProposalStore((state) => state.addTransaction) + const chain = useChainStore((x) => x.chain) + const { data: paused } = useContractRead({ + abi: auctionAbi, + address: auction, + chainId: chain.id, + functionName: 'paused', + }) + + const handleResumeAuctionsTransaction = () => { + const pause = { + target: auction as AddressType, + functionSignature: 'unpause()', + calldata: encodeFunctionData({ + abi: auctionAbi, + functionName: 'unpause', + }), + value: '', + } + + addTransaction({ + type: TransactionType.RESUME_AUCTIONS, + summary: 'Resume auctions', + transactions: [pause], + }) + } + + return ( + + {!paused ? ( + + + It looks like auctions are already resumed for this DAO. + + + ) : ( + + + No further input required for this transaction. + + + )} + + + ) +} diff --git a/apps/web/src/modules/create-proposal/components/TransactionForm/TransactionForm.tsx b/apps/web/src/modules/create-proposal/components/TransactionForm/TransactionForm.tsx index 683c2e1b4..9f9306ff9 100644 --- a/apps/web/src/modules/create-proposal/components/TransactionForm/TransactionForm.tsx +++ b/apps/web/src/modules/create-proposal/components/TransactionForm/TransactionForm.tsx @@ -8,6 +8,7 @@ import { Droposal } from './Droposal' import { Migration } from './Migration' import { PauseAuctions } from './PauseAuctions' import { ReplaceArtwork } from './ReplaceArtwork' +import { ResumeAuctions } from './ResumeAuctions/ResumeAuctions' import { SendEth } from './SendEth' interface TransactionFormProps { @@ -20,6 +21,7 @@ export const TRANSACTION_FORM_OPTIONS = [ TransactionType.SEND_ETH, TransactionType.AIRDROP, TransactionType.PAUSE_AUCTIONS, + TransactionType.RESUME_AUCTIONS, TransactionType.REPLACE_ARTWORK, TransactionType.DROPOSAL, TransactionType.MIGRATION, @@ -33,6 +35,7 @@ export const TransactionForm = ({ type }: TransactionFormProps) => { [TransactionType.DROPOSAL]: , [TransactionType.SEND_ETH]: , [TransactionType.PAUSE_AUCTIONS]: , + [TransactionType.RESUME_AUCTIONS]: , [TransactionType.REPLACE_ARTWORK]: , [TransactionType.MIGRATION]: , } diff --git a/apps/web/src/modules/create-proposal/constants/transactionType.tsx b/apps/web/src/modules/create-proposal/constants/transactionType.tsx index 2fffa4059..d9118e263 100644 --- a/apps/web/src/modules/create-proposal/constants/transactionType.tsx +++ b/apps/web/src/modules/create-proposal/constants/transactionType.tsx @@ -9,6 +9,7 @@ export enum TransactionType { CUSTOM = 'custom', UPGRADE = 'upgrade', PAUSE_AUCTIONS = 'pause-auctions', + RESUME_AUCTIONS = 'resume-auctions', UPDATE_MINTER = 'update-minter', REPLACE_ARTWORK = 'replace-artwork', MIGRATION = 'migration', @@ -57,6 +58,12 @@ export const TRANSACTION_TYPES = { icon: 'pauseTemplate', iconBackdrop: 'rgba(236, 113, 75, 0.1)', }, + [TransactionType.RESUME_AUCTIONS]: { + title: 'Resume Auctions', + subTitle: 'Create a proposal to resume auctions', + icon: 'resumeTemplate', + iconBackdrop: 'rgba(236, 113, 75, 0.1)', + }, [TransactionType.REPLACE_ARTWORK]: { title: 'Replace Artwork', subTitle: 'Create a proposal to replace your artwork', @@ -72,7 +79,7 @@ export const TRANSACTION_TYPES = { [TransactionType.MIGRATION]: { title: 'Migration', subTitle: 'Migrate from L1 to L2', - icon: 'download', + icon: 'migrate', iconBackdrop: 'rgba(350,100,0,.1)', }, } as TransactionTypesPropsMap diff --git a/apps/web/src/pages/api/simulate.ts b/apps/web/src/pages/api/simulate.ts index ac75f6210..b24521951 100644 --- a/apps/web/src/pages/api/simulate.ts +++ b/apps/web/src/pages/api/simulate.ts @@ -2,10 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next' import { ErrorResult } from 'src/services/errorResult' import { InvalidRequestError } from 'src/services/errors' -import { - SimulationResult, - simulate, -} from 'src/services/simulationService' +import { SimulationResult, simulate } from 'src/services/simulationService' export default async function handler( req: NextApiRequest, diff --git a/apps/web/src/pages/dao/[network]/[token]/proposal/create.tsx b/apps/web/src/pages/dao/[network]/[token]/proposal/create.tsx index 6003b5af2..a3e6ad5bf 100644 --- a/apps/web/src/pages/dao/[network]/[token]/proposal/create.tsx +++ b/apps/web/src/pages/dao/[network]/[token]/proposal/create.tsx @@ -2,10 +2,11 @@ import { Flex, Stack } from '@zoralabs/zord' import { GetServerSideProps } from 'next' import { useRouter } from 'next/router' import React, { useEffect, useState } from 'react' -import { useAccount } from 'wagmi' +import { useAccount, useContractRead } from 'wagmi' import { CACHE_TIMES } from 'src/constants/cacheTimes' import { PUBLIC_DEFAULT_CHAINS } from 'src/constants/defaultChains' +import { auctionAbi } from 'src/data/contract/abis' import { L1_CHAINS } from 'src/data/contract/chains' import getDAOAddresses from 'src/data/contract/requests/getDAOAddresses' import { useVotes } from 'src/hooks' @@ -31,6 +32,7 @@ import { AddressType } from 'src/typings' const CreateProposalPage: NextPageWithLayout = () => { const router = useRouter() + const { auction } = useDaoStore((x) => x.addresses) const chain = useChainStore((x) => x.chain) const { query } = router const [transactionType, setTransactionType] = useState< @@ -38,6 +40,13 @@ const CreateProposalPage: NextPageWithLayout = () => { >() const transactions = useProposalStore((state) => state.transactions) + const { data: paused } = useContractRead({ + abi: auctionAbi, + address: auction, + functionName: 'paused', + chainId: chain.id, + }) + useEffect(() => { if (transactions.length && !transactionType) { setTransactionType(transactions[0].type as TransactionFormType) @@ -60,9 +69,14 @@ const CreateProposalPage: NextPageWithLayout = () => { icon: , }) - const TRANSACTION_FORM_OPTIONS_FILTERED = TRANSACTION_FORM_OPTIONS.filter((x) => - L1_CHAINS.find((x) => x === chain.id) ? true : x !== TransactionType.MIGRATION - ) + const isL1Chain = L1_CHAINS.find((l1ChainIds) => l1ChainIds === chain.id) + + const TRANSACTION_FORM_OPTIONS_FILTERED = TRANSACTION_FORM_OPTIONS.filter((x) => { + if (x === TransactionType.MIGRATION && !isL1Chain) return false + if (x === TransactionType.PAUSE_AUCTIONS && paused) return false + if (x === TransactionType.RESUME_AUCTIONS && !paused) return false + return true + }) const options = TRANSACTION_FORM_OPTIONS_FILTERED.map(createSelectOption)