Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw committed Oct 17, 2023
1 parent 8634471 commit 293a067
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import { formatDateTime, formatDurationShort } from '@/utils/time'

export const RevenueShareStateWidget = ({ endsAtBlock }: { endsAtBlock?: number }) => {
const { convertBlockToMsTimestamp } = useBlockTimeEstimation()
const status: 'active' | 'past' | 'inactive' = !endsAtBlock ? 'inactive' : endsAtBlock < 0 ? 'past' : 'active'
const endingBlockTimestamp = convertBlockToMsTimestamp(endsAtBlock ?? 0)
const endingDate = endingBlockTimestamp ? new Date(endingBlockTimestamp) : new Date()
const endingDate = endingBlockTimestamp ? new Date(endingBlockTimestamp) : null
const status: 'active' | 'past' | 'inactive' = !endingBlockTimestamp
? 'inactive'
: endingBlockTimestamp < Date.now()
? 'past'
: 'active'

return (
<WidgetTile
title={
Expand All @@ -22,15 +27,15 @@ export const RevenueShareStateWidget = ({ endsAtBlock }: { endsAtBlock?: number
status !== 'inactive' && endsAtBlock ? (
status === 'past' ? (
<Text variant="h500" as="h5" margin={{ bottom: 4 }}>
{formatDateTime(endingDate).replace(',', ' at')}
{endingDate ? formatDateTime(endingDate).replace(',', ' at') : 'N/A'}
</Text>
) : (
<FlexBox flow="column">
<Text variant="h500" as="h5">
{formatDurationShort(Math.round((endingDate.getTime() - Date.now()) / 1000))}
{endingDate ? formatDurationShort(Math.round((endingDate.getTime() - Date.now()) / 1000)) : 'N/A'}
</Text>
<Text variant="t100" as="p" color="colorText">
{formatDateTime(endingDate).replace(',', ' at')}
{endingDate ? formatDateTime(endingDate).replace(',', ' at') : 'N/A'}
</Text>
</FlexBox>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ export const StartRevenueShare = ({ tokenId, onClose, show }: StartRevenueShareP
data.endDate?.type === 'date'
? convertMsTimestampToBlock(data.endDate.date.getTime())
: data.endDate?.durationDays
? convertMsTimestampToBlock(addDaysToDate(data.endDate.durationDays, rawStartDate).getTime())
? (convertMsTimestampToBlock(addDaysToDate(data.endDate.durationDays, rawStartDate).getTime()) ?? 0) -
startBlock
: null

if (typeof duration !== 'number') {
if (typeof duration !== 'number' || duration < 0) {
displaySnackbar({ title: 'Failed to parse ending date', iconType: 'error', description: 'Please try again.' })
return
}
Expand Down

0 comments on commit 293a067

Please sign in to comment.