Save resolved values in notifs (#470)

* Save resolved values in notifs

* Clean up
This commit is contained in:
Ian Philips 2022-06-09 10:30:26 -06:00 committed by GitHub
parent 64f04185d4
commit 8634af702a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 15 deletions

View File

@ -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 (

View File

@ -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,9 +750,21 @@ function NotificationTextLabel(props: {
sourceType,
sourceUpdateType,
contract
) &&
contract?.resolution
)
) {
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
@ -766,6 +782,7 @@ function NotificationTextLabel(props: {
truncate={'long'}
/>
)
} else return <div />
} else if (sourceType === 'contract') {
return (
<div className={clsx('text-indigo-700 hover:underline', className)}>