2022-08-04 21:27:02 +00:00
|
|
|
import { Contract } from 'common/contract'
|
|
|
|
import { getBinaryProbPercent } from 'web/lib/firebase/contracts'
|
|
|
|
import { richTextToString } from 'common/util/parse'
|
|
|
|
import { contractTextDetails } from 'web/components/contract/contract-details'
|
2022-08-05 12:56:10 +00:00
|
|
|
import { getFormattedMappedValue } from 'common/pseudo-numeric'
|
|
|
|
import { getProbability } from 'common/calculate'
|
2022-08-04 21:27:02 +00:00
|
|
|
|
|
|
|
export const getOpenGraphProps = (contract: Contract) => {
|
|
|
|
const {
|
|
|
|
resolution,
|
|
|
|
question,
|
|
|
|
creatorName,
|
|
|
|
creatorUsername,
|
|
|
|
outcomeType,
|
|
|
|
creatorAvatarUrl,
|
|
|
|
description: desc,
|
|
|
|
} = contract
|
|
|
|
const probPercent =
|
|
|
|
outcomeType === 'BINARY' ? getBinaryProbPercent(contract) : undefined
|
|
|
|
|
2022-08-05 12:56:10 +00:00
|
|
|
const numericValue =
|
|
|
|
outcomeType === 'PSEUDO_NUMERIC'
|
|
|
|
? getFormattedMappedValue(contract)(getProbability(contract))
|
|
|
|
: undefined
|
|
|
|
|
2022-08-04 21:27:02 +00:00
|
|
|
const stringDesc = typeof desc === 'string' ? desc : richTextToString(desc)
|
|
|
|
|
|
|
|
const description = resolution
|
|
|
|
? `Resolved ${resolution}. ${stringDesc}`
|
|
|
|
: probPercent
|
|
|
|
? `${probPercent} chance. ${stringDesc}`
|
|
|
|
: stringDesc
|
|
|
|
|
|
|
|
return {
|
|
|
|
question,
|
|
|
|
probability: probPercent,
|
|
|
|
metadata: contractTextDetails(contract),
|
|
|
|
creatorName,
|
|
|
|
creatorUsername,
|
|
|
|
creatorAvatarUrl,
|
|
|
|
description,
|
2022-08-05 12:56:10 +00:00
|
|
|
numericValue,
|
2022-08-04 21:27:02 +00:00
|
|
|
}
|
|
|
|
}
|