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 const previousValue = change.before.data() as Contract
if (previousValue.isResolved !== contract.isResolved) { 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( await createNotification(
contract.id, contract.id,
'contract', 'contract',
'resolved', 'resolved',
contractUpdater, contractUpdater,
eventId, eventId,
contract.resolution ?? contract.question, resolutionText,
contract contract
) )
} else if ( } else if (

View File

@ -30,8 +30,12 @@ import { UsersIcon } from '@heroicons/react/solid'
import { RelativeTimestamp } from 'web/components/relative-timestamp' import { RelativeTimestamp } from 'web/components/relative-timestamp'
import { Linkify } from 'web/components/linkify' import { Linkify } from 'web/components/linkify'
import { import {
BinaryOutcomeLabel,
CancelLabel,
FreeResponseOutcomeLabel, FreeResponseOutcomeLabel,
MultiLabel,
OutcomeLabel, OutcomeLabel,
ProbPercentLabel,
} from 'web/components/outcome-label' } from 'web/components/outcome-label'
import { import {
groupNotifications, groupNotifications,
@ -746,9 +750,21 @@ function NotificationTextLabel(props: {
sourceType, sourceType,
sourceUpdateType, sourceUpdateType,
contract 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') { if (contract.outcomeType === 'FREE_RESPONSE') {
return ( return (
<FreeResponseOutcomeLabel <FreeResponseOutcomeLabel
@ -766,6 +782,7 @@ function NotificationTextLabel(props: {
truncate={'long'} truncate={'long'}
/> />
) )
} else return <div />
} else if (sourceType === 'contract') { } else if (sourceType === 'contract') {
return ( return (
<div className={clsx('text-indigo-700 hover:underline', className)}> <div className={clsx('text-indigo-700 hover:underline', className)}>