2022-07-05 23:26:58 +00:00
|
|
|
import { DuplicateIcon } from '@heroicons/react/outline'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
import { Contract } from 'common/contract'
|
2022-07-06 17:39:19 +00:00
|
|
|
import { ENV_CONFIG } from 'common/envs/constants'
|
2022-07-05 23:26:58 +00:00
|
|
|
import { getMappedValue } from 'common/pseudo-numeric'
|
2022-07-06 17:39:19 +00:00
|
|
|
import { contractPath } from 'web/lib/firebase/contracts'
|
2022-07-05 23:26:58 +00:00
|
|
|
import { trackCallback } from 'web/lib/service/analytics'
|
|
|
|
|
|
|
|
export function DuplicateContractButton(props: {
|
|
|
|
contract: Contract
|
|
|
|
className?: string
|
|
|
|
}) {
|
|
|
|
const { contract, className } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
className={clsx('btn btn-xs flex-nowrap normal-case', className)}
|
|
|
|
style={{
|
|
|
|
backgroundColor: 'white',
|
|
|
|
border: '2px solid #a78bfa',
|
|
|
|
// violet-400
|
|
|
|
color: '#a78bfa',
|
|
|
|
}}
|
|
|
|
href={duplicateContractHref(contract)}
|
|
|
|
onClick={trackCallback('duplicate market')}
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
<DuplicateIcon className="mr-1.5 h-4 w-4" aria-hidden="true" />
|
|
|
|
<div>Duplicate</div>
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass along the Uri to create a new contract
|
|
|
|
function duplicateContractHref(contract: Contract) {
|
|
|
|
const params = {
|
|
|
|
q: contract.question,
|
|
|
|
closeTime: contract.closeTime || 0,
|
2022-07-06 17:39:19 +00:00
|
|
|
description:
|
|
|
|
(contract.description ? `${contract.description}\n\n` : '') +
|
|
|
|
`(Copied from https://${ENV_CONFIG.domain}${contractPath(contract)})`,
|
2022-07-05 23:26:58 +00:00
|
|
|
outcomeType: contract.outcomeType,
|
|
|
|
} as Record<string, any>
|
|
|
|
|
|
|
|
if (contract.outcomeType === 'PSEUDO_NUMERIC') {
|
|
|
|
params.min = contract.min
|
|
|
|
params.max = contract.max
|
|
|
|
params.isLogScale = contract.isLogScale
|
|
|
|
params.initValue = getMappedValue(contract)(contract.initialProbability)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
`/create?` +
|
|
|
|
Object.entries(params)
|
|
|
|
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
|
|
.join('&')
|
|
|
|
)
|
|
|
|
}
|