Skip to content

Commit

Permalink
⏰ Update displaying deadlines (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-tarczynski authored Jul 10, 2024
1 parent d4ea79d commit c001538
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const useReadAuctionParams = () => {
raffleWinnersCount: data ? Number(data[3]) : undefined,
minimumBid: data?.[4],
minimumBidIncrement: data?.[5],
claimingEndTime: data?.[6],
isLoading,
}),
[data, isLoading],
Expand All @@ -41,4 +42,5 @@ const params = [
'raffleWinnersCount',
'reservePrice',
'minBidIncrement',
'claimingEndTime',
] as const
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const REDEEM_PERIOD = BigInt(moment.unix(0).add(48, 'h').unix())
export function useVoucherRedeemDeadline() {
const { biddingEndTime } = useReadAuctionParams()
return useMemo(() => {
if (biddingEndTime) {
return biddingEndTime + REDEEM_PERIOD
if (environment.voucherRedeemDeadline) {
return BigInt(environment.voucherRedeemDeadline)
}
return environment.voucherRedeemDeadline ? BigInt(environment.voucherRedeemDeadline) : undefined
return biddingEndTime ? biddingEndTime + REDEEM_PERIOD : undefined
}, [biddingEndTime])
}
16 changes: 10 additions & 6 deletions packages/frontend/src/components/info/VoucherTimeLeft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import { useReadAuctionParams } from '@/blockchain/hooks/useReadAuctionParams'
import { MediaQueries } from '@/styles/mediaQueries'

export const VoucherTimeLeft = () => {
const { biddingEndTime } = useReadAuctionParams()
const { claimingEndTime } = useReadAuctionParams()
const redeemTimestamp = useVoucherRedeemDeadline()
const isPeriodExpired = redeemTimestamp ? redeemTimestamp * BigInt(1000) < Date.now() : false
const isRedeemingExpired = redeemTimestamp ? redeemTimestamp * BigInt(1000) < Date.now() : false
const isClaimingExpired = claimingEndTime ? claimingEndTime * BigInt(1000) < Date.now() : false

return (
<VoucherTimeBox isPeriodExpired={isPeriodExpired}>
<TimeRow isPeriodExpired={isPeriodExpired}>
<span>{isPeriodExpired ? 'Voucher redeem period expired on ' : 'Voucher redeem period: '}</span>
{!isPeriodExpired && <RemainingTime>{formatDate(biddingEndTime)} - </RemainingTime>}
<VoucherTimeBox isPeriodExpired={isRedeemingExpired}>
<TimeRow isPeriodExpired={isClaimingExpired}>
<span>{isClaimingExpired ? 'Refund claiming expired on ' : 'Refund claiming ends: '}</span>
<RemainingTime>{formatDate(claimingEndTime)}</RemainingTime>
</TimeRow>
<TimeRow isPeriodExpired={isRedeemingExpired}>
<span>{isRedeemingExpired ? 'Voucher redemption expired on ' : 'Voucher redemption ends: '}</span>
<RemainingTime>{formatDate(redeemTimestamp)}</RemainingTime>
</TimeRow>
</VoucherTimeBox>
Expand Down
6 changes: 1 addition & 5 deletions packages/frontend/src/config/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const environment = {
voucherRedeemDeadline: getDateEnv(process.env.NEXT_PUBLIC_VOUCHER_REDEEM_DEADLINE),
voucherRedeemDeadline: process.env.NEXT_PUBLIC_VOUCHER_REDEEM_DEADLINE,
walletConnectProjectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID ?? '',
infuraKey: process.env.NEXT_PUBLIC_INFURA_KEY,
gitcoinRequiredScore: Number(process.env.NEXT_PUBLIC_GITCOIN_REQUIRED_SCORE),
Expand All @@ -18,7 +18,3 @@ export const environment = {
},
nonceExpiry: Number(process.env.NONCE_EXPIRY),
}

function getDateEnv(envValue: string | undefined): number | undefined {
return envValue ? Math.floor(new Date(envValue).getTime() / 1000) : undefined
}

0 comments on commit c001538

Please sign in to comment.