2022-08-05 05:22:45 +00:00
|
|
|
|
import { LinkIcon } from '@heroicons/react/outline'
|
|
|
|
|
import toast from 'react-hot-toast'
|
|
|
|
|
|
|
|
|
|
import { Contract } from 'common/contract'
|
|
|
|
|
import { contractPath } from 'web/lib/firebase/contracts'
|
|
|
|
|
import { Col } from '../layout/col'
|
|
|
|
|
import { Modal } from '../layout/modal'
|
|
|
|
|
import { Row } from '../layout/row'
|
|
|
|
|
import { ShareEmbedButton } from '../share-embed-button'
|
|
|
|
|
import { Title } from '../title'
|
|
|
|
|
import { TweetButton } from '../tweet-button'
|
|
|
|
|
import { DuplicateContractButton } from '../copy-contract-button'
|
|
|
|
|
import { Button } from '../button'
|
|
|
|
|
import { copyToClipboard } from 'web/lib/util/copy'
|
2022-09-06 13:57:52 +00:00
|
|
|
|
import { track, withTracking } from 'web/lib/service/analytics'
|
2022-08-05 05:22:45 +00:00
|
|
|
|
import { ENV_CONFIG } from 'common/envs/constants'
|
2022-08-22 05:37:26 +00:00
|
|
|
|
import { User } from 'common/user'
|
2022-08-10 02:51:01 +00:00
|
|
|
|
import { SiteLink } from '../site-link'
|
|
|
|
|
import { formatMoney } from 'common/util/format'
|
2022-08-22 05:37:26 +00:00
|
|
|
|
import { REFERRAL_AMOUNT } from 'common/economy'
|
2022-09-06 13:57:52 +00:00
|
|
|
|
import { CreateChallengeModal } from 'web/components/challenges/create-challenge-modal'
|
2022-08-30 23:13:25 +00:00
|
|
|
|
import { useState } from 'react'
|
2022-09-06 13:57:52 +00:00
|
|
|
|
import { CHALLENGES_ENABLED } from 'common/challenge'
|
2022-08-05 05:22:45 +00:00
|
|
|
|
|
|
|
|
|
export function ShareModal(props: {
|
|
|
|
|
contract: Contract
|
|
|
|
|
user: User | undefined | null
|
|
|
|
|
isOpen: boolean
|
|
|
|
|
setOpen: (open: boolean) => void
|
|
|
|
|
}) {
|
|
|
|
|
const { contract, user, isOpen, setOpen } = props
|
2022-09-06 13:57:52 +00:00
|
|
|
|
const { outcomeType, resolution } = contract
|
2022-08-05 05:22:45 +00:00
|
|
|
|
|
2022-09-06 13:57:52 +00:00
|
|
|
|
const [openCreateChallengeModal, setOpenCreateChallengeModal] =
|
|
|
|
|
useState(false)
|
2022-08-05 05:22:45 +00:00
|
|
|
|
const linkIcon = <LinkIcon className="mr-2 h-6 w-6" aria-hidden="true" />
|
2022-09-06 13:57:52 +00:00
|
|
|
|
const showChallenge =
|
|
|
|
|
user && outcomeType === 'BINARY' && !resolution && CHALLENGES_ENABLED
|
|
|
|
|
|
2022-08-10 02:51:01 +00:00
|
|
|
|
const shareUrl = `https://${ENV_CONFIG.domain}${contractPath(contract)}${
|
2022-08-05 05:22:45 +00:00
|
|
|
|
user?.username && contract.creatorUsername !== user?.username
|
|
|
|
|
? '?referrer=' + user?.username
|
|
|
|
|
: ''
|
|
|
|
|
}`
|
|
|
|
|
|
|
|
|
|
return (
|
2022-08-10 02:51:01 +00:00
|
|
|
|
<Modal open={isOpen} setOpen={setOpen} size="md">
|
2022-09-06 13:57:52 +00:00
|
|
|
|
<Col className="gap-2.5 rounded bg-white p-4 sm:gap-4">
|
2022-08-10 02:51:01 +00:00
|
|
|
|
<Title className="!mt-0 !mb-2" text="Share this market" />
|
|
|
|
|
<p>
|
|
|
|
|
Earn{' '}
|
|
|
|
|
<SiteLink href="/referrals">
|
|
|
|
|
{formatMoney(REFERRAL_AMOUNT)} referral bonus
|
|
|
|
|
</SiteLink>{' '}
|
|
|
|
|
if a new user signs up using the link!
|
|
|
|
|
</p>
|
2022-08-05 05:22:45 +00:00
|
|
|
|
<Button
|
|
|
|
|
size="2xl"
|
|
|
|
|
color="gradient"
|
2022-09-06 13:57:52 +00:00
|
|
|
|
className={'flex max-w-xs self-center'}
|
2022-08-05 05:22:45 +00:00
|
|
|
|
onClick={() => {
|
2022-08-15 05:03:05 +00:00
|
|
|
|
copyToClipboard(shareUrl)
|
|
|
|
|
toast.success('Link copied!', {
|
|
|
|
|
icon: linkIcon,
|
|
|
|
|
})
|
2022-08-05 05:22:45 +00:00
|
|
|
|
track('copy share link')
|
|
|
|
|
}}
|
|
|
|
|
>
|
2022-08-10 02:59:40 +00:00
|
|
|
|
{linkIcon} Copy link
|
2022-08-05 05:22:45 +00:00
|
|
|
|
</Button>
|
2022-09-06 13:57:52 +00:00
|
|
|
|
<Row className={'justify-center'}>or</Row>
|
|
|
|
|
{showChallenge && (
|
|
|
|
|
<Button
|
|
|
|
|
size="2xl"
|
|
|
|
|
color="gradient"
|
|
|
|
|
className={'mb-2 flex max-w-xs self-center'}
|
|
|
|
|
onClick={withTracking(
|
|
|
|
|
() => setOpenCreateChallengeModal(true),
|
|
|
|
|
'click challenge button'
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<span>⚔️ Challenge</span>
|
|
|
|
|
<CreateChallengeModal
|
|
|
|
|
isOpen={openCreateChallengeModal}
|
|
|
|
|
setOpen={(open) => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
setOpenCreateChallengeModal(false)
|
|
|
|
|
setOpen(false)
|
|
|
|
|
} else setOpenCreateChallengeModal(open)
|
|
|
|
|
}}
|
|
|
|
|
user={user}
|
|
|
|
|
contract={contract}
|
|
|
|
|
/>
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2022-08-30 23:13:25 +00:00
|
|
|
|
<Row className="z-0 flex-wrap justify-center gap-4 self-center">
|
2022-08-05 05:22:45 +00:00
|
|
|
|
<TweetButton
|
|
|
|
|
className="self-start"
|
2022-08-10 02:51:01 +00:00
|
|
|
|
tweetText={getTweetText(contract, shareUrl)}
|
2022-08-05 05:22:45 +00:00
|
|
|
|
/>
|
2022-08-15 05:03:05 +00:00
|
|
|
|
<ShareEmbedButton contract={contract} />
|
2022-08-05 05:22:45 +00:00
|
|
|
|
<DuplicateContractButton contract={contract} />
|
|
|
|
|
</Row>
|
|
|
|
|
</Col>
|
|
|
|
|
</Modal>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 02:51:01 +00:00
|
|
|
|
const getTweetText = (contract: Contract, url: string) => {
|
2022-08-05 05:22:45 +00:00
|
|
|
|
const { question, resolution } = contract
|
|
|
|
|
const tweetDescription = resolution ? `\n\nResolved ${resolution}!` : ''
|
|
|
|
|
|
|
|
|
|
return `${question}\n\n${url}${tweetDescription}`
|
|
|
|
|
}
|