Skip to content

Commit

Permalink
make submission expiration time more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
torztomasz committed Apr 13, 2023
1 parent 0ca66d7 commit 3b84cc0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ function tradeMatchesOffer(
offer.collateralAmount === trade.collateralAmount &&
offer.syntheticAmount === trade.syntheticAmount &&
offer.isABuyingSynthetic === trade.isABuyingSynthetic &&
Timestamp.toHours(offer.accepted.submissionExpirationTime) ===
Timestamp.toHours(trade.submissionExpirationTime) &&
offer.accepted.submissionExpirationTime ===
trade.submissionExpirationTime &&
offer.accepted.nonce === trade.nonce &&
offer.accepted.signature === trade.signature &&
offer.accepted.premiumCost === trade.premiumCost
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/api/controllers/utils/offerForms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export function getAcceptForm(
): AcceptForm | undefined {
const isAcceptable = !offer.accepted && !offer.cancelledAt
const shouldRenderForm = isAcceptable && user.positionId !== offer.positionIdA
const submissionExpirationTime = Timestamp(
BigInt(Math.floor(Date.now() + THREE_DAYS_IN_MILLIS))
const submissionExpirationTime = Timestamp.roundDownToHours(
Timestamp(Math.floor(Date.now() + THREE_DAYS_IN_MILLIS))
)
if (!shouldRenderForm) {
return undefined
Expand Down
8 changes: 8 additions & 0 deletions packages/types/src/Timestamp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ describe(Timestamp.name, () => {
expect(Timestamp.toSeconds(Timestamp(7_200_000n))).toEqual(7200n)
})
})

describe(Timestamp.roundDownToHours.name, () => {
it('rounds down to hours', () => {
const timestamp = Timestamp(new Date().setHours(12, 35))
const expectedTimestamp = Timestamp(new Date().setHours(12, 0, 0, 0))
expect(Timestamp.roundDownToHours(timestamp)).toEqual(expectedTimestamp)
})
})
})
4 changes: 4 additions & 0 deletions packages/types/src/Timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ Timestamp.toHours = function toHours(timestamp: Timestamp) {
Timestamp.toSeconds = function toSeconds(timestamp: Timestamp) {
return timestamp.valueOf() / 1000n
}

Timestamp.roundDownToHours = function roundUpToHours(timestamp: Timestamp) {
return Timestamp.fromHours(Timestamp.toHours(timestamp))
}

0 comments on commit 3b84cc0

Please sign in to comment.