Save resolved values in notifs (#470)
* Save resolved values in notifs * Clean up
This commit is contained in:
parent
64f04185d4
commit
8634af702a
|
@ -14,13 +14,25 @@ export const onUpdateContract = functions.firestore
|
|||
|
||||
const previousValue = change.before.data() as Contract
|
||||
if (previousValue.isResolved !== contract.isResolved) {
|
||||
let resolutionText = contract.resolution ?? contract.question
|
||||
if (contract.outcomeType === 'FREE_RESPONSE') {
|
||||
const answerText = contract.answers.find(
|
||||
(answer) => answer.id === contract.resolution
|
||||
)?.text
|
||||
if (answerText) resolutionText = answerText
|
||||
} else if (contract.outcomeType === 'BINARY') {
|
||||
if (resolutionText === 'MKT' && contract.resolutionProbability)
|
||||
resolutionText = `${contract.resolutionProbability}%`
|
||||
else if (resolutionText === 'MKT') resolutionText = 'PROB'
|
||||
}
|
||||
|
||||
await createNotification(
|
||||
contract.id,
|
||||
'contract',
|
||||
'resolved',
|
||||
contractUpdater,
|
||||
eventId,
|
||||
contract.resolution ?? contract.question,
|
||||
resolutionText,
|
||||
contract
|
||||
)
|
||||
} else if (
|
||||
|
|
|
@ -30,8 +30,12 @@ import { UsersIcon } from '@heroicons/react/solid'
|
|||
import { RelativeTimestamp } from 'web/components/relative-timestamp'
|
||||
import { Linkify } from 'web/components/linkify'
|
||||
import {
|
||||
BinaryOutcomeLabel,
|
||||
CancelLabel,
|
||||
FreeResponseOutcomeLabel,
|
||||
MultiLabel,
|
||||
OutcomeLabel,
|
||||
ProbPercentLabel,
|
||||
} from 'web/components/outcome-label'
|
||||
import {
|
||||
groupNotifications,
|
||||
|
@ -746,26 +750,39 @@ function NotificationTextLabel(props: {
|
|||
sourceType,
|
||||
sourceUpdateType,
|
||||
contract
|
||||
) &&
|
||||
contract?.resolution
|
||||
)
|
||||
) {
|
||||
if (contract.outcomeType === 'FREE_RESPONSE') {
|
||||
if (sourceText) {
|
||||
if (sourceText === 'YES' || sourceText == 'NO') {
|
||||
return <BinaryOutcomeLabel outcome={sourceText as any} />
|
||||
}
|
||||
if (sourceText.includes('%'))
|
||||
return (
|
||||
<ProbPercentLabel prob={parseFloat(sourceText.replace('%', ''))} />
|
||||
)
|
||||
if (sourceText === 'CANCEL') return <CancelLabel />
|
||||
if (sourceText === 'MKT' || sourceText === 'PROB') return <MultiLabel />
|
||||
// Show free response answer text
|
||||
return <span>{sourceText}</span>
|
||||
} else if (contract?.resolution) {
|
||||
if (contract.outcomeType === 'FREE_RESPONSE') {
|
||||
return (
|
||||
<FreeResponseOutcomeLabel
|
||||
contract={contract}
|
||||
resolution={contract.resolution}
|
||||
truncate={'long'}
|
||||
answerClassName={className}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<FreeResponseOutcomeLabel
|
||||
<OutcomeLabel
|
||||
contract={contract}
|
||||
resolution={contract.resolution}
|
||||
outcome={contract.resolution}
|
||||
truncate={'long'}
|
||||
answerClassName={className}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<OutcomeLabel
|
||||
contract={contract}
|
||||
outcome={contract.resolution}
|
||||
truncate={'long'}
|
||||
/>
|
||||
)
|
||||
} else return <div />
|
||||
} else if (sourceType === 'contract') {
|
||||
return (
|
||||
<div className={clsx('text-indigo-700 hover:underline', className)}>
|
||||
|
|
Loading…
Reference in New Issue
Block a user