Skip to content

Commit

Permalink
Merge pull request #458 from mulfdev/main
Browse files Browse the repository at this point in the history
Add referral link
  • Loading branch information
neokry authored May 9, 2024
2 parents 85617b2 + b4b2e3d commit cf88f47
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/web/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

NEXT_PUBLIC_UPLOAD_API=https://upload-api.zora.co
NEXT_PUBLIC_IPFS_GATEWAY=https://ipfs.decentralized-content.com
NEXT_PUBLIC_NETWORK_TYPE=testnet
NEXT_PUBLIC_NETWORK_TYPE=testnet
3 changes: 3 additions & 0 deletions apps/web/src/components/Icon/assets/share.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/web/src/components/Icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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 Share from './assets/share.svg'
import Trash from './assets/trash.svg'
import Twitter from './assets/twitter.svg'
import Warning16 from './assets/warning-16.svg'
Expand Down Expand Up @@ -80,6 +81,7 @@ export const icons = {
resumeTemplate: ResumeTemplate,
trash: Trash,
twitter: Twitter,
share: Share,
warning: Warning,
'warning-16': Warning16,
}
Expand Down
78 changes: 63 additions & 15 deletions apps/web/src/modules/auction/components/CurrentAuction/PlaceBid.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Box, Button, Flex } from '@zoralabs/zord'
import { Box, Button, Flex, PopUp, Text } from '@zoralabs/zord'
import React, { Fragment, memo, useEffect, useState } from 'react'
import useSWR, { useSWRConfig } from 'swr'
import { formatEther, parseEther } from 'viem'
import { Address, useAccount, useBalance, useContractReads, useNetwork } from 'wagmi'
import { prepareWriteContract, waitForTransaction, writeContract } from 'wagmi/actions'

import { ContractButton } from 'src/components/ContractButton'
import { Icon } from 'src/components/Icon/Icon'
import AnimatedModal from 'src/components/Modal/AnimatedModal'
import { PUBLIC_IS_TESTNET } from 'src/constants/defaultChains'
import SWR_KEYS from 'src/constants/swrKeys'
import { auctionAbi } from 'src/data/contract/abis'
import { averageWinningBid } from 'src/data/subgraph/requests/averageWinningBid'
Expand Down Expand Up @@ -69,7 +71,7 @@ export const PlaceBid = ({
addresses.token
? [SWR_KEYS.AVERAGE_WINNING_BID, chain.id, addresses.token]
: undefined,
() => averageWinningBid(chain.id, addresses.token as Address)
() => averageWinningBid(chain.id, addresses.token as Address),
)

const isMinBid = Number(bidAmount) >= minBidAmount
Expand Down Expand Up @@ -122,11 +124,11 @@ export const PlaceBid = ({
if (tx?.hash) await waitForTransaction({ hash: tx.hash })

await mutate([SWR_KEYS.AUCTION_BIDS, chain.id, addresses.token, tokenId], () =>
getBids(chain.id, addresses.token!, tokenId)
getBids(chain.id, addresses.token!, tokenId),
)

await mutate([SWR_KEYS.AVERAGE_WINNING_BID, chain.id, addresses.token], () =>
averageWinningBid(chain.id, addresses.token as Address)
averageWinningBid(chain.id, addresses.token as Address),
)
} catch (error) {
console.error(error)
Expand All @@ -142,6 +144,8 @@ export const PlaceBid = ({

const isValidBid = bidAmount && isMinBid
const isValidChain = wagmiChain?.id === chain.id
const [showTooltip, setShowTooltip] = useState(false)
const [copied, setCopied] = useState(false)

return (
<Flex
Expand All @@ -164,7 +168,7 @@ export const PlaceBid = ({
) : null}

{!creatingBid ? (
<Fragment>
<Flex wrap="wrap">
<form className={bidForm}>
<Box position="relative" mr={{ '@initial': 'x0', '@768': 'x2' }}>
<input
Expand All @@ -182,16 +186,60 @@ export const PlaceBid = ({
</Box>
</Box>
</form>

<ContractButton
className={auctionActionButtonVariants['bid']}
handleClick={handleCreateBid}
disabled={address && isValidChain ? !isValidBid : false}
mt={{ '@initial': 'x2', '@768': 'x0' }}
>
Place bid
</ContractButton>
</Fragment>
<Flex w="100%" wrap="wrap" mt="x2">
<ContractButton
className={auctionActionButtonVariants['bid']}
handleClick={handleCreateBid}
disabled={address && isValidChain ? !isValidBid : false}
mt={{ '@initial': 'x2', '@768': 'x0' }}
>
Place bid
</ContractButton>
{chain.id !== 1 ? (
<Fragment>
<Box
cursor="pointer"
style={{ zIndex: 102 }}
onMouseOver={() => setShowTooltip(true)}
onMouseLeave={() => {
setShowTooltip(false)
setTimeout(() => {
setCopied(false)
}, 500)
}}
>
<ContractButton
className={auctionActionButtonVariants['bid']}
ml="x2"
mt={{ '@initial': 'x2', '@768': 'x0' }}
handleClick={async () => {
const network = PUBLIC_IS_TESTNET
? 'https://testnet.nouns.build'
: 'https://nouns.build'
const baseUrl = `${network}/dao/${chain.name.toLowerCase()}/${addresses.token}`
if (address === undefined) {
await navigator.clipboard.writeText(baseUrl)
return
}
const params = new URLSearchParams({
referral: address.toString(),
})
const fullUrl = `${baseUrl}?${params}`

await navigator.clipboard.writeText(fullUrl)
setCopied(true)
}}
>
<Icon size="md" id="share" />
</ContractButton>
</Box>
<PopUp open={showTooltip} trigger={<></>} placement="top">
<Text align="center">{copied ? 'Copied' : 'Copy Referral Link'}</Text>
</PopUp>
</Fragment>
) : null}
</Flex>
</Flex>
) : (
<Button className={auctionActionButtonVariants['bidding']} disabled>
placing {bidAmount} ETH bid
Expand Down

0 comments on commit cf88f47

Please sign in to comment.