Skip to content

Commit

Permalink
support latest sdk & sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed May 2, 2024
1 parent cb15629 commit 0590673
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 97 deletions.
20 changes: 8 additions & 12 deletions components/QuestChain/QuestChainV2Page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
IconButton,
Image,
Input,
Link as ChakraLink,
Modal,
ModalBody,
ModalCloseButton,
Expand Down Expand Up @@ -1054,18 +1053,15 @@ export const QuestChainV2Page: React.FC<QuestChainV2PageProps> = ({
href={`/${
AVAILABLE_NETWORK_INFO[questChain.chainId].urlName
}/[address]/review`}
passHref
>
<ChakraLink display="block" _hover={{}}>
<SubmitButton
fontSize={14}
fontWeight="bold"
height={10}
px={6}
>
Review Submissions
</SubmitButton>
</ChakraLink>
<SubmitButton
fontSize={14}
fontWeight="bold"
height={10}
px={6}
>
Review Submissions
</SubmitButton>
</NextLink>
</Flex>
)}
Expand Down
9 changes: 4 additions & 5 deletions components/UserDisplay.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -57,6 +57,7 @@ export const UserDisplay: React.FC<{
size={size}
height={8}
px={2}
borderRadius="full"
_hover={noLink ? {} : undefined}
>
<HStack position="relative" color={color}>
Expand All @@ -71,10 +72,8 @@ export const UserDisplay: React.FC<{
return noLink ? (
inner
) : (
<NextLink as={`/profile/${name}`} href="/profile/[name]" passHref>
<Link _hover={{}} borderRadius="full">
{inner}
</Link>
<NextLink as={`/profile/${name}`} href="/profile/[name]">
{inner}
</NextLink>
);
};
2 changes: 1 addition & 1 deletion hooks/useFeaturedQuestChains.ts
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand Down
2 changes: 1 addition & 1 deletion hooks/useFilteredQuestChains.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion hooks/useLatestCreatedQuestChainsDataForAllChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
2 changes: 1 addition & 1 deletion hooks/useNFTsToMintForAllChains.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion hooks/useQuestChainSearchForAllChains.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hooks/useQuestsToReviewForAllChains.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hooks/useUserBadgesForAllChains.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hooks/useUserProgressForAllChains.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hooks/useUserQuestsRejectedForAllChains.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion hooks/useUserRolesForAllChains.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 2 additions & 4 deletions lib/mongodb/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Db>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 6 additions & 3 deletions pages/[network]/[address]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ 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';
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,
Expand Down
2 changes: 1 addition & 1 deletion pages/[network]/[address]/review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions sample.env
Original file line number Diff line number Diff line change
@@ -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=
20 changes: 1 addition & 19 deletions utils/constants.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';
66 changes: 31 additions & 35 deletions web3/networks.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,6 +17,7 @@ export type NetworkInfo = {
explorerLabel: string;
rpc: string;
image: string;
testnet: boolean;
};
};

Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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,
},
};

Expand All @@ -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 => {
Expand All @@ -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];
Loading

0 comments on commit 0590673

Please sign in to comment.