From 0590673579abcda93e647a1d3e1f870ea611e2f5 Mon Sep 17 00:00:00 2001 From: dan13ram Date: Thu, 2 May 2024 13:01:06 +0530 Subject: [PATCH] support latest sdk & sepolia --- .../QuestChain/QuestChainV2Page/index.tsx | 20 +++--- components/UserDisplay.tsx | 9 ++- hooks/useFeaturedQuestChains.ts | 2 +- hooks/useFilteredQuestChains.ts | 2 +- ...atestCreatedQuestChainsDataForAllChains.ts | 2 +- hooks/useNFTsToMintForAllChains.ts | 2 +- hooks/useQuestChainSearchForAllChains.ts | 2 +- hooks/useQuestsToReviewForAllChains.ts | 2 +- hooks/useUserBadgesForAllChains.ts | 2 +- hooks/useUserProgressForAllChains.ts | 2 +- hooks/useUserQuestsRejectedForAllChains.ts | 2 +- hooks/useUserRolesForAllChains.ts | 2 +- lib/mongodb/client.ts | 6 +- package.json | 2 +- pages/[network]/[address]/index.tsx | 9 ++- pages/[network]/[address]/review.tsx | 2 +- sample.env | 6 +- utils/constants.ts | 20 +----- web3/networks.ts | 66 +++++++++---------- yarn.lock | 8 +-- 20 files changed, 71 insertions(+), 97 deletions(-) diff --git a/components/QuestChain/QuestChainV2Page/index.tsx b/components/QuestChain/QuestChainV2Page/index.tsx index bb90afd2..583b1388 100644 --- a/components/QuestChain/QuestChainV2Page/index.tsx +++ b/components/QuestChain/QuestChainV2Page/index.tsx @@ -12,7 +12,6 @@ import { IconButton, Image, Input, - Link as ChakraLink, Modal, ModalBody, ModalCloseButton, @@ -1054,18 +1053,15 @@ export const QuestChainV2Page: React.FC = ({ href={`/${ AVAILABLE_NETWORK_INFO[questChain.chainId].urlName }/[address]/review`} - passHref > - - - Review Submissions - - + + Review Submissions + )} diff --git a/components/UserDisplay.tsx b/components/UserDisplay.tsx index 0d8294d5..ab5aad34 100644 --- a/components/UserDisplay.tsx +++ b/components/UserDisplay.tsx @@ -1,4 +1,4 @@ -import { Button, HStack, Link, Text } from '@chakra-ui/react'; +import { Button, HStack, Text } from '@chakra-ui/react'; import NextLink from 'next/link'; import { useMemo } from 'react'; @@ -57,6 +57,7 @@ export const UserDisplay: React.FC<{ size={size} height={8} px={2} + borderRadius="full" _hover={noLink ? {} : undefined} > @@ -71,10 +72,8 @@ export const UserDisplay: React.FC<{ return noLink ? ( inner ) : ( - - - {inner} - + + {inner} ); }; diff --git a/hooks/useFeaturedQuestChains.ts b/hooks/useFeaturedQuestChains.ts index 23abb406..80fbc1a3 100644 --- a/hooks/useFeaturedQuestChains.ts +++ b/hooks/useFeaturedQuestChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; const featuredQuestChains = [ { diff --git a/hooks/useFilteredQuestChains.ts b/hooks/useFilteredQuestChains.ts index d7ce9ff9..698ffc4d 100644 --- a/hooks/useFilteredQuestChains.ts +++ b/hooks/useFilteredQuestChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; const { OrderDirection, QuestChain_OrderBy } = graphql; diff --git a/hooks/useLatestCreatedQuestChainsDataForAllChains.ts b/hooks/useLatestCreatedQuestChainsDataForAllChains.ts index 7c5aafe9..a3b36996 100644 --- a/hooks/useLatestCreatedQuestChainsDataForAllChains.ts +++ b/hooks/useLatestCreatedQuestChainsDataForAllChains.ts @@ -2,8 +2,8 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; import { useRefresh } from '@/hooks/useRefresh'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; import { useWallet } from '@/web3'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; export const useLatestCreatedQuestChainsDataForAllChains = (): { questChains: graphql.QuestChainDisplayFragment[]; diff --git a/hooks/useNFTsToMintForAllChains.ts b/hooks/useNFTsToMintForAllChains.ts index 76b18b81..586d04a6 100644 --- a/hooks/useNFTsToMintForAllChains.ts +++ b/hooks/useNFTsToMintForAllChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; import { useRefresh } from './useRefresh'; diff --git a/hooks/useQuestChainSearchForAllChains.ts b/hooks/useQuestChainSearchForAllChains.ts index af4db86f..53272eb8 100644 --- a/hooks/useQuestChainSearchForAllChains.ts +++ b/hooks/useQuestChainSearchForAllChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; export const useQuestChainSearchForAllChains = ( search: graphql.QuestChainFiltersInfo, diff --git a/hooks/useQuestsToReviewForAllChains.ts b/hooks/useQuestsToReviewForAllChains.ts index 29cb9629..2dc8032a 100644 --- a/hooks/useQuestsToReviewForAllChains.ts +++ b/hooks/useQuestsToReviewForAllChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; export const useQuestsToReviewForAllChains = ( address: string | undefined | null, diff --git a/hooks/useUserBadgesForAllChains.ts b/hooks/useUserBadgesForAllChains.ts index 49e62ea1..c54668e7 100644 --- a/hooks/useUserBadgesForAllChains.ts +++ b/hooks/useUserBadgesForAllChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; export const useUserBadgesForAllChains = ( address: string, diff --git a/hooks/useUserProgressForAllChains.ts b/hooks/useUserProgressForAllChains.ts index e017b9fd..a94ade8e 100644 --- a/hooks/useUserProgressForAllChains.ts +++ b/hooks/useUserProgressForAllChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; export const useUserProgressForAllChains = ( address: string, diff --git a/hooks/useUserQuestsRejectedForAllChains.ts b/hooks/useUserQuestsRejectedForAllChains.ts index 2592d156..d68ea2cb 100644 --- a/hooks/useUserQuestsRejectedForAllChains.ts +++ b/hooks/useUserQuestsRejectedForAllChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; import { useRefresh } from './useRefresh'; diff --git a/hooks/useUserRolesForAllChains.ts b/hooks/useUserRolesForAllChains.ts index 95c801f6..644a1a8e 100644 --- a/hooks/useUserRolesForAllChains.ts +++ b/hooks/useUserRolesForAllChains.ts @@ -1,7 +1,7 @@ import { graphql } from '@quest-chains/sdk'; import { useEffect, useState } from 'react'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; export const useUserRolesForAllChains = ( address: string, diff --git a/lib/mongodb/client.ts b/lib/mongodb/client.ts index 7d8e0546..78857f0d 100644 --- a/lib/mongodb/client.ts +++ b/lib/mongodb/client.ts @@ -8,11 +8,9 @@ if (!process.env.MONGODB_URI) { const MONGODB_URI = process.env.MONGODB_URI; -if (!process.env.MONGODB_DATABASE) { - throw new EnvironmentError('MONGODB_DATABASE'); -} +const IS_PRODUCTION = process.env.NEXT_PUBLIC_IS_PRODUCTION === 'true'; -const MONGODB_DATABASE = process.env.MONGODB_DATABASE; +const MONGODB_DATABASE = IS_PRODUCTION ? 'quest-chains' : 'quest-chains-dev'; declare const global: { _clientPromise: Promise; diff --git a/package.json b/package.json index 34508c6b..1ef547f4 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@emotion/react": "^11.10.6", "@emotion/styled": "^11.10.6", "@next/bundle-analyzer": "^13.2.4", - "@quest-chains/sdk": "0.2.9", + "@quest-chains/sdk": "^0.2.11", "@react-three/drei": "9.26.1", "@react-three/fiber": "8.7.1", "@walletconnect/web3-provider": "^1.8.0", diff --git a/pages/[network]/[address]/index.tsx b/pages/[network]/[address]/index.tsx index e370ff31..91704850 100644 --- a/pages/[network]/[address]/index.tsx +++ b/pages/[network]/[address]/index.tsx @@ -3,7 +3,7 @@ import { isAddress } from '@ethersproject/address'; import { graphql } from '@quest-chains/sdk'; import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'; import { useRouter } from 'next/router'; -import React, { useCallback } from 'react'; +import { useCallback } from 'react'; import { Page } from '@/components/Layout/Page'; import { LoadingState } from '@/components/LoadingState'; @@ -11,8 +11,11 @@ import { QuestChainV0Page } from '@/components/QuestChain/QuestChainV0Page'; import { QuestChainV2Page } from '@/components/QuestChain/QuestChainV2Page'; import { useLatestQuestChainData } from '@/hooks/useLatestQuestChainData'; import { useLatestQuestStatusesForChainData } from '@/hooks/useLatestQuestStatusesForChainData'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; -import { AVAILABLE_NETWORK_INFO, CHAIN_URL_MAPPINGS } from '@/web3/networks'; +import { + AVAILABLE_NETWORK_INFO, + CHAIN_URL_MAPPINGS, + SUPPORTED_NETWORKS, +} from '@/web3/networks'; const { getQuestChainAddresses, diff --git a/pages/[network]/[address]/review.tsx b/pages/[network]/[address]/review.tsx index 89010dc2..213bba14 100644 --- a/pages/[network]/[address]/review.tsx +++ b/pages/[network]/[address]/review.tsx @@ -14,9 +14,9 @@ import { QuestChainV1ReviewPage } from '@/components/Review/QuestChainV1ReviewPa import { HeadComponent } from '@/components/Seo'; import { useLatestQuestChainData } from '@/hooks/useLatestQuestChainData'; import { useLatestQuestStatusesForChainData } from '@/hooks/useLatestQuestStatusesForChainData'; -import { SUPPORTED_NETWORKS } from '@/utils/constants'; import { getQuestChainURL } from '@/utils/uriHelpers'; import { AVAILABLE_NETWORK_INFO, CHAIN_URL_MAPPINGS, useWallet } from '@/web3'; +import { SUPPORTED_NETWORKS } from '@/web3/networks'; const { getQuestChainAddresses, diff --git a/sample.env b/sample.env index 9576524c..b89e5053 100644 --- a/sample.env +++ b/sample.env @@ -1,6 +1,6 @@ -NEXT_PUBLIC_SUPPORTED_NETWORKS=0x5 -NEXT_PUBLIC_INFURA_ID=9aa3d95b3bc440fa88ea12eaa4456161 NEXT_PUBLIC_API_URL=https://api.questchains.xyz +NEXT_PUBLIC_IS_PRODUCTION=false + +NEXT_PUBLIC_GRAPH_API_KEY= MONGODB_URI= -MONGODB_DATABASE= diff --git a/utils/constants.ts b/utils/constants.ts index 8afd466b..768a3726 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -1,21 +1,3 @@ -import { graphql } from '@quest-chains/sdk'; - -import { EnvironmentError } from './errors'; - -if (!process.env.NEXT_PUBLIC_INFURA_ID) - throw new EnvironmentError('NEXT_PUBLIC_INFURA_ID'); - -export const INFURA_ID = process.env.NEXT_PUBLIC_INFURA_ID; - -if (!process.env.NEXT_PUBLIC_SUPPORTED_NETWORKS) - throw new EnvironmentError('NEXT_PUBLIC_SUPPORTED_NETWORKS'); - -export const SUPPORTED_NETWORKS = - process.env.NEXT_PUBLIC_SUPPORTED_NETWORKS.split(' ') - .filter(n => !!n && !Number.isNaN(Number(n))) - .map(n => `0x${Number(n).toString(16)}`) - .filter(n => graphql.SUPPORTED_NETWORKS.includes(n)); - export const API_URL = process.env.NEXT_PUBLIC_API_URL || 'https://api.questchains.xyz'; @@ -27,6 +9,6 @@ export const QUESTCHAINS_URL = export const PLAUSIBLE_DATA_DOMAIN = process.env.NEXT_PUBLIC_PLAUSIBLE_DATA_DOMAIN || - 'questchains.xyz,app.questchains.xyz'; + 'questchains.xyz,app.questchains.xyz,dev.questchains.xyz'; export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; diff --git a/web3/networks.ts b/web3/networks.ts index f339e9df..3bd17355 100644 --- a/web3/networks.ts +++ b/web3/networks.ts @@ -1,4 +1,5 @@ -import { INFURA_ID, SUPPORTED_NETWORKS } from '../utils/constants'; +import { graphql } from '@quest-chains/sdk'; + import ArbitrumImage from './images/arbitrum.svg'; import EthereumImage from './images/ethereum.svg'; import GnosisImage from './images/gnosis.svg'; @@ -16,6 +17,7 @@ export type NetworkInfo = { explorerLabel: string; rpc: string; image: string; + testnet: boolean; }; }; @@ -28,8 +30,9 @@ export const AVAILABLE_NETWORK_INFO: NetworkInfo = { symbol: 'ETH', explorer: 'https://etherscan.com', explorerLabel: 'EtherScan', - rpc: `https://mainnet.infura.io/v3/${INFURA_ID}`, + rpc: `https://1rpc.io/eth`, image: EthereumImage.src, + testnet: false, }, '0x89': { chainId: '0x89', @@ -41,6 +44,7 @@ export const AVAILABLE_NETWORK_INFO: NetworkInfo = { explorerLabel: 'PolygonScan', rpc: `https://polygon-rpc.com`, image: PolygonImage.src, + testnet: false, }, '0x64': { chainId: '0x64', @@ -52,6 +56,7 @@ export const AVAILABLE_NETWORK_INFO: NetworkInfo = { explorerLabel: 'GnosisScan', rpc: 'https://rpc.gnosischain.com/', image: GnosisImage.src, + testnet: false, }, '0xa': { chainId: '0xa', @@ -63,28 +68,19 @@ export const AVAILABLE_NETWORK_INFO: NetworkInfo = { explorerLabel: 'EtherScan', rpc: 'https://mainnet.optimism.io', image: OptimismImage.src, + testnet: false, }, - '0x5': { - chainId: '0x5', - name: 'Görli Testnet', - label: 'Görli', - urlName: 'goerli', + '0xaa36a7': { + chainId: '0xaa36a7', + name: 'Sepolia Testnet', + label: 'Sepolia', + urlName: 'sepolia', symbol: 'ETH', - explorer: 'https://goerli.etherscan.io', + explorer: 'https://sepolia.etherscan.io', explorerLabel: 'EtherScan', - rpc: `https://goerli.infura.io/v3/${INFURA_ID}`, + rpc: `https://1rpc.io/sepolia`, image: EthereumImage.src, - }, - '0x13881': { - chainId: '0x13881', - name: 'Mumbai Testnet', - label: 'Mumbai', - urlName: 'mumbai', - symbol: 'MATIC', - explorer: 'https://mumbai.polygonscan.com', - explorerLabel: 'PolygonScan', - rpc: 'https://rpc-mumbai.maticvigil.com', - image: PolygonImage.src, + testnet: true, }, '0xa4b1': { chainId: '0xa4b1', @@ -96,17 +92,7 @@ export const AVAILABLE_NETWORK_INFO: NetworkInfo = { explorerLabel: 'ArbiScan', rpc: 'https://arb1.arbitrum.io/rpc', image: ArbitrumImage.src, - }, - '0x66eed': { - chainId: '0x66eed', - name: 'Arbitrum Goerli', - label: 'Arbitrum Goerli', - urlName: 'arbitrum-goerli', - symbol: 'ETH', - explorer: 'https://goerli.arbiscan.io', - explorerLabel: 'ArbiScan', - rpc: 'https://goerli-rollup.arbitrum.io/rpc', - image: ArbitrumImage.src, + testnet: false, }, }; @@ -115,12 +101,10 @@ export const CHAIN_URL_MAPPINGS: { } = { polygon: '0x89', gnosis: '0x64', - goerli: '0x5', optimism: '0xa', arbitrum: '0xa4b1', - ['arbitrum-goerli']: '0x66eed', - mumbai: '0x13881', mainnet: '0x1', + sepolia: '0xaa36a7', }; const getNetworkInfo = (networks: string[] | undefined): NetworkInfo => { @@ -132,9 +116,21 @@ const getNetworkInfo = (networks: string[] | undefined): NetworkInfo => { return t; }, {}); } - return AVAILABLE_NETWORK_INFO; + return {}; }; +const IS_TESTNET = process.env.NEXT_PUBLIC_IS_PRODUCTION !== 'true'; + +export const SUPPORTED_NETWORKS = graphql.SUPPORTED_NETWORKS.filter( + n => + AVAILABLE_NETWORK_INFO[n] && + AVAILABLE_NETWORK_INFO[n].testnet === IS_TESTNET, +); + +if (SUPPORTED_NETWORKS.length === 0) { + throw new Error('No supported networks found'); +} + export const SUPPORTED_NETWORK_INFO = getNetworkInfo(SUPPORTED_NETWORKS); export const CHAIN_ID = SUPPORTED_NETWORKS[0]; diff --git a/yarn.lock b/yarn.lock index c7bfc2a6..f87722d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1739,10 +1739,10 @@ resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.6.tgz#cee20bd55e68a1720bdab363ecf0c821ded4cd45" integrity sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw== -"@quest-chains/sdk@0.2.9": - version "0.2.9" - resolved "https://registry.yarnpkg.com/@quest-chains/sdk/-/sdk-0.2.9.tgz#12f4eac0bac91966a48f8ffda273b59c2a0d1455" - integrity sha512-jwp2o+plVBVoDmj9UoNS9FXQn7Mx0SeBGbGh9W6E7c03/+A6ZE9Z7e7weFLe49lnP9DaUoLOp07/OMwXUCZEAg== +"@quest-chains/sdk@^0.2.11": + version "0.2.11" + resolved "https://registry.yarnpkg.com/@quest-chains/sdk/-/sdk-0.2.11.tgz#14fcb66b888bc47e5514201f32987992a8b9a01e" + integrity sha512-K5aQpEgj1/wNeD/otJx9Z3cC5LEJ+08L7KQoQmesDjTgFXljD9VgSwMYKBM+T1aSNj4dAtMxIS0MJcYvfHnvYw== dependencies: ajv "^8.11.0" axios "^1.1.1"