Add more info to limit order notif
This commit is contained in:
parent
c183315d52
commit
a2d912bb5a
|
@ -247,6 +247,8 @@ export type BetFillData = {
|
||||||
creatorOutcome: string
|
creatorOutcome: string
|
||||||
probability: number
|
probability: number
|
||||||
fillAmount: number
|
fillAmount: number
|
||||||
|
limitOrderTotal?: number
|
||||||
|
limitOrderRemaining?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ContractResolutionData = {
|
export type ContractResolutionData = {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { User } from '../../common/user'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { getPrivateUser, getValues } from './utils'
|
import { getPrivateUser, getValues } from './utils'
|
||||||
import { Comment } from '../../common/comment'
|
import { Comment } from '../../common/comment'
|
||||||
import { groupBy, uniq } from 'lodash'
|
import { groupBy, sum, uniq } from 'lodash'
|
||||||
import { Bet, LimitBet } from '../../common/bet'
|
import { Bet, LimitBet } from '../../common/bet'
|
||||||
import { Answer } from '../../common/answer'
|
import { Answer } from '../../common/answer'
|
||||||
import { getContractBetMetrics } from '../../common/calculate'
|
import { getContractBetMetrics } from '../../common/calculate'
|
||||||
|
@ -480,7 +480,7 @@ export const createBetFillNotification = async (
|
||||||
fromUser: User,
|
fromUser: User,
|
||||||
toUser: User,
|
toUser: User,
|
||||||
bet: Bet,
|
bet: Bet,
|
||||||
userBet: LimitBet,
|
limitBet: LimitBet,
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
idempotencyKey: string
|
idempotencyKey: string
|
||||||
) => {
|
) => {
|
||||||
|
@ -492,8 +492,10 @@ export const createBetFillNotification = async (
|
||||||
)
|
)
|
||||||
if (!sendToBrowser) return
|
if (!sendToBrowser) return
|
||||||
|
|
||||||
const fill = userBet.fills.find((fill) => fill.matchedBetId === bet.id)
|
const fill = limitBet.fills.find((fill) => fill.matchedBetId === bet.id)
|
||||||
const fillAmount = fill?.amount ?? 0
|
const fillAmount = fill?.amount ?? 0
|
||||||
|
const remainingAmount =
|
||||||
|
limitBet.orderAmount - sum(limitBet.fills.map((f) => f.amount))
|
||||||
|
|
||||||
const notificationRef = firestore
|
const notificationRef = firestore
|
||||||
.collection(`/users/${toUser.id}/notifications`)
|
.collection(`/users/${toUser.id}/notifications`)
|
||||||
|
@ -504,7 +506,7 @@ export const createBetFillNotification = async (
|
||||||
reason: 'bet_fill',
|
reason: 'bet_fill',
|
||||||
createdTime: Date.now(),
|
createdTime: Date.now(),
|
||||||
isSeen: false,
|
isSeen: false,
|
||||||
sourceId: userBet.id,
|
sourceId: limitBet.id,
|
||||||
sourceType: 'bet',
|
sourceType: 'bet',
|
||||||
sourceUpdateType: 'updated',
|
sourceUpdateType: 'updated',
|
||||||
sourceUserName: fromUser.name,
|
sourceUserName: fromUser.name,
|
||||||
|
@ -517,9 +519,11 @@ export const createBetFillNotification = async (
|
||||||
sourceContractId: contract.id,
|
sourceContractId: contract.id,
|
||||||
data: {
|
data: {
|
||||||
betOutcome: bet.outcome,
|
betOutcome: bet.outcome,
|
||||||
creatorOutcome: userBet.outcome,
|
creatorOutcome: limitBet.outcome,
|
||||||
fillAmount,
|
fillAmount,
|
||||||
probability: userBet.limitProb,
|
probability: limitBet.limitProb,
|
||||||
|
limitOrderTotal: limitBet.orderAmount,
|
||||||
|
limitOrderRemaining: remainingAmount,
|
||||||
} as BetFillData,
|
} as BetFillData,
|
||||||
}
|
}
|
||||||
return await notificationRef.set(removeUndefinedProps(notification))
|
return await notificationRef.set(removeUndefinedProps(notification))
|
||||||
|
|
|
@ -98,7 +98,7 @@ export function groupNotifications(notifications: Notification[]) {
|
||||||
const notificationGroup: NotificationGroup = {
|
const notificationGroup: NotificationGroup = {
|
||||||
notifications: notificationsForContractId,
|
notifications: notificationsForContractId,
|
||||||
groupedById: contractId,
|
groupedById: contractId,
|
||||||
isSeen: notificationsForContractId[0].isSeen,
|
isSeen: notificationsForContractId.some((n) => !n.isSeen),
|
||||||
timePeriod: day,
|
timePeriod: day,
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
}
|
}
|
||||||
|
|
|
@ -904,25 +904,30 @@ function BetFillNotification(props: {
|
||||||
}) {
|
}) {
|
||||||
const { notification, isChildOfGroup, highlighted, justSummary } = props
|
const { notification, isChildOfGroup, highlighted, justSummary } = props
|
||||||
const { sourceText, data } = notification
|
const { sourceText, data } = notification
|
||||||
const { creatorOutcome, probability } = (data as BetFillData) ?? {}
|
const { creatorOutcome, probability, limitOrderTotal, limitOrderRemaining } =
|
||||||
|
(data as BetFillData) ?? {}
|
||||||
const subtitle = 'bet against you'
|
const subtitle = 'bet against you'
|
||||||
const amount = formatMoney(parseInt(sourceText ?? '0'))
|
const amount = formatMoney(parseInt(sourceText ?? '0'))
|
||||||
const description =
|
const description =
|
||||||
creatorOutcome && probability ? (
|
creatorOutcome && probability ? (
|
||||||
<span>
|
<span>
|
||||||
of your{' '}
|
of your {limitOrderTotal ? formatMoney(limitOrderTotal) : ''}
|
||||||
<span
|
<span
|
||||||
className={
|
className={clsx(
|
||||||
|
'mx-1',
|
||||||
creatorOutcome === 'YES'
|
creatorOutcome === 'YES'
|
||||||
? 'text-primary'
|
? 'text-primary'
|
||||||
: creatorOutcome === 'NO'
|
: creatorOutcome === 'NO'
|
||||||
? 'text-red-500'
|
? 'text-red-500'
|
||||||
: 'text-blue-500'
|
: 'text-blue-500'
|
||||||
}
|
)}
|
||||||
>
|
>
|
||||||
{creatorOutcome}{' '}
|
{creatorOutcome}
|
||||||
</span>
|
</span>
|
||||||
limit order at {Math.round(probability * 100)}% was filled
|
limit order at {Math.round(probability * 100)}% was filled{' '}
|
||||||
|
{limitOrderRemaining
|
||||||
|
? `(${formatMoney(limitOrderRemaining)} remaining)`
|
||||||
|
: ''}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span>of your limit order was filled</span>
|
<span>of your limit order was filled</span>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user