Skip to content

Commit

Permalink
add resume auctions proposal template
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Jan 12, 2024
1 parent 1b20d7f commit a62e2b3
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 9 deletions.
3 changes: 3 additions & 0 deletions apps/web/src/components/Icon/assets/migrate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/web/src/components/Icon/assets/resume-template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/web/src/components/Icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -66,6 +68,7 @@ export const icons = {
handlebarCircle: HandlebarCircle,
'info-16': Info16,
globe: Globe,
migrate: Migrate,
move: Move,
newWindow: NewWindow,
nounsConnect: NounsConnect,
Expand All @@ -74,6 +77,7 @@ export const icons = {
play: Play,
plus: Plus,
refresh: Refresh,
resumeTemplate: ResumeTemplate,
trash: Trash,
twitter: Twitter,
warning: Warning,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<Box w={'100%'}>
{!paused ? (
<Box mb={'x8'}>
<Paragraph size="md" color="negative">
It looks like auctions are already resumed for this DAO.
</Paragraph>
</Box>
) : (
<Box mb={'x8'}>
<Paragraph size="md" color="text1">
No further input required for this transaction.
</Paragraph>
</Box>
)}
<Button
variant={'outline'}
borderRadius={'curved'}
w={'100%'}
type="button"
onClick={handleResumeAuctionsTransaction}
disabled={!paused}
>
Add Transaction to Queue
</Button>
</Box>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -33,6 +35,7 @@ export const TransactionForm = ({ type }: TransactionFormProps) => {
[TransactionType.DROPOSAL]: <Droposal />,
[TransactionType.SEND_ETH]: <SendEth />,
[TransactionType.PAUSE_AUCTIONS]: <PauseAuctions />,
[TransactionType.RESUME_AUCTIONS]: <ResumeAuctions />,
[TransactionType.REPLACE_ARTWORK]: <ReplaceArtwork />,
[TransactionType.MIGRATION]: <Migration />,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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
5 changes: 1 addition & 4 deletions apps/web/src/pages/api/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 18 additions & 4 deletions apps/web/src/pages/dao/[network]/[token]/proposal/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,13 +32,21 @@ 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<
TransactionFormType | undefined
>()
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)
Expand All @@ -60,9 +69,14 @@ const CreateProposalPage: NextPageWithLayout = () => {
icon: <TransactionTypeIcon transactionType={type} />,
})

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)

Expand Down

0 comments on commit a62e2b3

Please sign in to comment.