From 1985c3319520186dbc3c1e12ad123b779947b506 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Thu, 14 Mar 2024 11:29:16 -0400 Subject: [PATCH] fix bad expiration date on citizenship --- .env.example | 3 +-- components/hooks/useGetUnlockNFT.ts | 15 ++++----------- lib/protocol-config.ts | 7 ++----- scripts/postgres-import.ts | 3 ++- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 2a5397ff..6dd32db0 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,4 @@ # Public -NEXT_PUBLIC_APP_ENV="dev" # dev | prod -NEXT_PUBLIC_ALCHEMY_APP_NAME="Cabin Census" NEXT_PUBLIC_VERCEL_URL='localhost:3000' NEXT_PUBLIC_GOOGLE_MAPS_API_KEY="" # See README for instructions NEXT_PUBLIC_IPFS_GATEWAY='https://ipfs.io/ipfs/' @@ -17,6 +15,7 @@ IRON_SESSION_PASSWORD="complex_password_at_least_32_characters_long" SIGNER_PRIVATE_KEY="key" # Alchemy Providers (Testnets when develop) +NEXT_PUBLIC_ALCHEMY_APP_NAME="Cabin Census" NEXT_PUBLIC_ETH_ALCHEMY_ID="key" # Pinata diff --git a/components/hooks/useGetUnlockNFT.ts b/components/hooks/useGetUnlockNFT.ts index 55d54bef..1affd7ba 100644 --- a/components/hooks/useGetUnlockNFT.ts +++ b/components/hooks/useGetUnlockNFT.ts @@ -11,16 +11,6 @@ export const useGetUnlockNFT = () => { const { user: profile } = useProfile() const config = useConfig() - const getDateFromBigint = (bi: bigint) => { - try { - return new Date(Number(bi) * 1000) - } catch (error) { - // Example invalid date: '115792089237316195423570985008687907853269984665640564039457584007913129639935' - console.error('Invalid date', error) - return null - } - } - useEffect(() => { const getNFT = async () => { if (!profile?.walletAddress || !profile.citizenshipMintedAt) { @@ -51,7 +41,10 @@ export const useGetUnlockNFT = () => { setActiveNFT({ tokenId: tokenId.toString(), mintedDate: new Date(profile.citizenshipMintedAt), - expirationDate: getDateFromBigint(expirationTimestamp), + expirationDate: + expirationTimestamp > BigInt(4102462800) + ? null + : new Date(Number(expirationTimestamp) * 1000), image: DEFAULT_NFT_IMAGE, }) } diff --git a/lib/protocol-config.ts b/lib/protocol-config.ts index 99c7d28e..6c06fcb0 100644 --- a/lib/protocol-config.ts +++ b/lib/protocol-config.ts @@ -1,4 +1,5 @@ import { NetworkName } from '@/lib/chains' +import { isProd } from '@/utils/dev' interface GetConfigArgs extends Record { dev: T @@ -6,11 +7,7 @@ interface GetConfigArgs extends Record { } const getAppConfig = (args: GetConfigArgs): T => { - const appEnv = process.env.NEXT_PUBLIC_APP_ENV - if (!appEnv) { - throw new Error('NEXT_PUBLIC_APP_ENV is not set') - } - + const appEnv = isProd ? 'prod' : 'dev' const config = args[appEnv] if (!config) { throw new Error(`No config for app env: ${appEnv}`) diff --git a/scripts/postgres-import.ts b/scripts/postgres-import.ts index 1af4ad02..6372a42e 100644 --- a/scripts/postgres-import.ts +++ b/scripts/postgres-import.ts @@ -5,6 +5,7 @@ import { Decimal, PrismaClientKnownRequestError, } from '@prisma/client/runtime/library' +import { isLocalDev } from '@/utils/dev' // TODO: check that every field in the existing data is imported @@ -115,7 +116,7 @@ async function postgresImport() { console.log(`finished parsing ${fullPath}`) } - if (process.env.NEXT_PUBLIC_APP_ENV === 'dev') { + if (isLocalDev) { console.log('updating profile privyDID and externId FOR DEV ENV') await prisma.profile.update({ data: {