From c0015388642d79a2b5c66681815c5a587d97abb2 Mon Sep 17 00:00:00 2001 From: Bartlomiej Tarczynski <51199571+b-tarczynski@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:27:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8F=B0=20Update=20displaying=20deadlines=20(?= =?UTF-8?q?#88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/blockchain/hooks/useReadAuctionParams.ts | 2 ++ .../blockchain/hooks/useVoucherRedeemDeadline.ts | 6 +++--- .../src/components/info/VoucherTimeLeft.tsx | 16 ++++++++++------ packages/frontend/src/config/environment.ts | 6 +----- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/frontend/src/blockchain/hooks/useReadAuctionParams.ts b/packages/frontend/src/blockchain/hooks/useReadAuctionParams.ts index 06c8d95c1..a44a89198 100644 --- a/packages/frontend/src/blockchain/hooks/useReadAuctionParams.ts +++ b/packages/frontend/src/blockchain/hooks/useReadAuctionParams.ts @@ -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], @@ -41,4 +42,5 @@ const params = [ 'raffleWinnersCount', 'reservePrice', 'minBidIncrement', + 'claimingEndTime', ] as const diff --git a/packages/frontend/src/blockchain/hooks/useVoucherRedeemDeadline.ts b/packages/frontend/src/blockchain/hooks/useVoucherRedeemDeadline.ts index 74c01e9a5..a568b2f45 100644 --- a/packages/frontend/src/blockchain/hooks/useVoucherRedeemDeadline.ts +++ b/packages/frontend/src/blockchain/hooks/useVoucherRedeemDeadline.ts @@ -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]) } diff --git a/packages/frontend/src/components/info/VoucherTimeLeft.tsx b/packages/frontend/src/components/info/VoucherTimeLeft.tsx index 4e632031b..353a6f3f1 100644 --- a/packages/frontend/src/components/info/VoucherTimeLeft.tsx +++ b/packages/frontend/src/components/info/VoucherTimeLeft.tsx @@ -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 ( - - - {isPeriodExpired ? 'Voucher redeem period expired on ' : 'Voucher redeem period: '} - {!isPeriodExpired && {formatDate(biddingEndTime)} - } + + + {isClaimingExpired ? 'Refund claiming expired on ' : 'Refund claiming ends: '} + {formatDate(claimingEndTime)} + + + {isRedeemingExpired ? 'Voucher redemption expired on ' : 'Voucher redemption ends: '} {formatDate(redeemTimestamp)} diff --git a/packages/frontend/src/config/environment.ts b/packages/frontend/src/config/environment.ts index 6f8a96ba4..b80016b9b 100644 --- a/packages/frontend/src/config/environment.ts +++ b/packages/frontend/src/config/environment.ts @@ -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), @@ -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 -}