From aba2e3425573867b476453de4c91e9b0d1396828 Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Mon, 25 Mar 2024 14:28:27 +0900 Subject: [PATCH] update config (#110) * update config * u * u --- .../DApp/src/components/ConnectionNetwork.tsx | 6 ++- .../src/components/card/CardCommunity.tsx | 4 +- packages/DApp/src/components/top/TopBar.tsx | 2 +- .../src/componentsMobile/ConnectMobile.tsx | 2 +- packages/DApp/src/config.ts | 54 +++++++++++++++---- packages/DApp/src/constants/contracts.ts | 34 ------------ packages/DApp/src/constants/peers.ts | 29 +++++----- packages/DApp/src/hooks/useAccount.ts | 2 +- packages/DApp/src/hooks/useAvailableAmount.ts | 7 ++- packages/DApp/src/hooks/useContracts.ts | 4 +- packages/DApp/src/main.tsx | 5 +- 11 files changed, 77 insertions(+), 72 deletions(-) delete mode 100644 packages/DApp/src/constants/contracts.ts diff --git a/packages/DApp/src/components/ConnectionNetwork.tsx b/packages/DApp/src/components/ConnectionNetwork.tsx index 8321891..af8d708 100644 --- a/packages/DApp/src/components/ConnectionNetwork.tsx +++ b/packages/DApp/src/components/ConnectionNetwork.tsx @@ -19,7 +19,9 @@ export function ConnectionNetwork({ buttonText, autoWidth = false }: ConnectionN - switchNetwork(config.daapConfig.readOnlyChainId!)}>Switch Network + switchNetwork(config.usedappConfig.readOnlyChainId!)}> + Switch Network + ) } @@ -54,7 +56,7 @@ export const ConnectButton = styled(ProposeButton)<{ autoWidth: boolean }>` ` width: auto; padding: 10px 27px; - + @media (max-width: 600px) { padding: 7px 27px; margin-top: -9px; diff --git a/packages/DApp/src/components/card/CardCommunity.tsx b/packages/DApp/src/components/card/CardCommunity.tsx index ec9acde..4f241da 100644 --- a/packages/DApp/src/components/card/CardCommunity.tsx +++ b/packages/DApp/src/components/card/CardCommunity.tsx @@ -10,8 +10,8 @@ import { RemoveModal } from './RemoveModal' import { CardHeading } from '../Card' import { useEthers, getExplorerAddressLink, ChainId } from '@usedapp/core' import { useHistory } from 'react-router' -import { contracts } from '../../constants/contracts' import { useAccount } from '../../hooks/useAccount' +import { config } from '../../config' interface CardCommunityProps { community: CommunityDetail @@ -118,7 +118,7 @@ export const CardCommunity = ({ Visit community diff --git a/packages/DApp/src/components/top/TopBar.tsx b/packages/DApp/src/components/top/TopBar.tsx index 79d14e1..4ad90b6 100644 --- a/packages/DApp/src/components/top/TopBar.tsx +++ b/packages/DApp/src/components/top/TopBar.tsx @@ -70,7 +70,7 @@ export function TopBar() { switchNetwork(config.daapConfig.readOnlyChainId!)} + onClick={() => switchNetwork(config.usedappConfig.readOnlyChainId!)} > Switch network diff --git a/packages/DApp/src/componentsMobile/ConnectMobile.tsx b/packages/DApp/src/componentsMobile/ConnectMobile.tsx index 2dd1302..035a2a8 100644 --- a/packages/DApp/src/componentsMobile/ConnectMobile.tsx +++ b/packages/DApp/src/componentsMobile/ConnectMobile.tsx @@ -39,7 +39,7 @@ export const ConnectMobile = () => { ⚠️ Unsupported network switchNetwork(config.daapConfig.readOnlyChainId!)} + onClick={() => switchNetwork(config.usedappConfig.readOnlyChainId!)} > Switch network diff --git a/packages/DApp/src/config.ts b/packages/DApp/src/config.ts index 5eb71ac..0549f3e 100644 --- a/packages/DApp/src/config.ts +++ b/packages/DApp/src/config.ts @@ -1,9 +1,10 @@ // import { v4 as uuidv4 } from 'uuid' import { Chain, ChainId, Optimism, OptimismGoerli, Config as DAppConfig, Localhost, Hardhat } from '@usedapp/core' +import { peers } from './constants/peers' const version = '0.0.6' -export const OptimismSepolia: Chain = { +const OptimismSepolia: Chain = { chainId: 11155420, chainName: 'OptimismSepolia', isTestChain: true, @@ -23,11 +24,12 @@ export const OptimismSepolia: Chain = { export interface Config { wakuConfig: { - environment: 'test' | 'production' + peers: string[] wakuTopic: string wakuFeatureTopic: string } - daapConfig: DAppConfig + usedappConfig: DAppConfig + contracts: Record> votesLimit: number } @@ -40,11 +42,11 @@ const configs: Record = { */ development: { wakuConfig: { - environment: 'test', + peers: peers.development, wakuTopic: `/communitiesCuration/localhost/${version}/directory/proto/`, wakuFeatureTopic: `/communitiesCuration/localhost/${version}/featured/proto/`, }, - daapConfig: { + usedappConfig: { readOnlyChainId: ChainId.Hardhat, readOnlyUrls: { [ChainId.Hardhat]: 'http://127.0.0.1:8545', @@ -61,6 +63,15 @@ const configs: Record = { }, }, votesLimit: 2, + contracts: { + [ChainId.Hardhat]: { + votingContract: process.env.VOTING_CONTRACT ?? '0x0000000000000000000000000000000000000000', + directoryContract: process.env.DIRECTORY_CONTRACT ?? '0x0000000000000000000000000000000000000000', + tokenContract: process.env.TOKEN_CONTRACT ?? '0x0000000000000000000000000000000000000000', + multicallContract: process.env.MULTICALL_CONTRACT ?? '0x0000000000000000000000000000000000000000', + featuredVotingContract: process.env.FEATURED_VOTING_CONTRACT ?? '0x0000000000000000000000000000000000000000', + }, + }, }, /** * Preview. @@ -69,11 +80,11 @@ const configs: Record = { */ preview: { wakuConfig: { - environment: 'test', + peers: peers.preview, wakuTopic: `/communitiesCuration/preview/${version}/directory/proto/`, wakuFeatureTopic: `/communitiesCuration/preview/${version}/featured/proto/`, }, - daapConfig: { + usedappConfig: { readOnlyChainId: OptimismSepolia.chainId, readOnlyUrls: { [OptimismSepolia.chainId]: `https://optimism-sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`, @@ -86,17 +97,33 @@ const configs: Record = { }, }, votesLimit: 2, + contracts: { + [OptimismSepolia.chainId]: { + votingContract: '0x7Ff554af5b6624db2135E4364F416d1D397f43e6', + featuredVotingContract: '0x336DFD512164Fe8CFA809BdE94B13E76e42edD6B', + directoryContract: '0x6B94e21FAB8Af38E8d89dd4A0480C04e9a5c53Ab', + tokenContract: '0x0B5DAd18B8791ddb24252B433ec4f21f9e6e5Ed0', + multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11', + }, + [ChainId.OptimismGoerli]: { + votingContract: '0x744Fd6e98dad09Fb8CCF530B5aBd32B56D64943b', + featuredVotingContract: '0x898331B756EE1f29302DeF227a4471e960c50612', + directoryContract: '0xB3Ef5B0825D5f665bE14394eea41E684CE96A4c5', + tokenContract: '0xcAD273fA2bb77875333439FDf4417D995159c3E1', + multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11', + }, + }, }, /** * Production. */ production: { wakuConfig: { - environment: 'production', + peers: peers.production, wakuTopic: `/communitiesCuration/${version}/directory/proto/`, wakuFeatureTopic: `/communitiesCuration/${version}/featured/proto/`, }, - daapConfig: { + usedappConfig: { readOnlyChainId: ChainId.Optimism, readOnlyUrls: { [ChainId.Optimism]: `https://optimism-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`, @@ -108,6 +135,15 @@ const configs: Record = { }, }, votesLimit: 400, + contracts: { + [ChainId.Optimism]: { + votingContract: '0x321Ba646d994200257Ce4bfe18F66C9283ad1407', + featuredVotingContract: '0x2EA9700E7F27E09F254f2DaEc5E05015b2b961d0', + directoryContract: '0xA8d270048a086F5807A8dc0a9ae0e96280C41e3A', + tokenContract: '0x650AF3C15AF43dcB218406d30784416D64Cfb6B2', + multicallContract: '0xeAa6877139d436Dc6d1f75F3aF15B74662617B2C', + }, + }, }, } diff --git a/packages/DApp/src/constants/contracts.ts b/packages/DApp/src/constants/contracts.ts deleted file mode 100644 index da35951..0000000 --- a/packages/DApp/src/constants/contracts.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { ChainId } from '@usedapp/core' -import { OptimismSepolia } from '../config' - -// todo?: move to config.ts -export const contracts = { - [ChainId.Optimism]: { - votingContract: '0x321Ba646d994200257Ce4bfe18F66C9283ad1407', - featuredVotingContract: '0x2EA9700E7F27E09F254f2DaEc5E05015b2b961d0', - directoryContract: '0xA8d270048a086F5807A8dc0a9ae0e96280C41e3A', - tokenContract: '0x650AF3C15AF43dcB218406d30784416D64Cfb6B2', - multicallContract: '0xeAa6877139d436Dc6d1f75F3aF15B74662617B2C', - }, - [ChainId.OptimismGoerli]: { - votingContract: '0x744Fd6e98dad09Fb8CCF530B5aBd32B56D64943b', - featuredVotingContract: '0x898331B756EE1f29302DeF227a4471e960c50612', - directoryContract: '0xB3Ef5B0825D5f665bE14394eea41E684CE96A4c5', - tokenContract: '0xcAD273fA2bb77875333439FDf4417D995159c3E1', - multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11', - }, - [OptimismSepolia.chainId]: { - votingContract: '0x7Ff554af5b6624db2135E4364F416d1D397f43e6', - featuredVotingContract: '0x336DFD512164Fe8CFA809BdE94B13E76e42edD6B', - directoryContract: '0x6B94e21FAB8Af38E8d89dd4A0480C04e9a5c53Ab', - tokenContract: '0x0B5DAd18B8791ddb24252B433ec4f21f9e6e5Ed0', - multicallContract: '0xcA11bde05977b3631167028862bE2a173976CA11', - }, - [ChainId.Hardhat]: { - votingContract: process.env.VOTING_CONTRACT ?? '0x0000000000000000000000000000000000000000', - directoryContract: process.env.DIRECTORY_CONTRACT ?? '0x0000000000000000000000000000000000000000', - tokenContract: process.env.TOKEN_CONTRACT ?? '0x0000000000000000000000000000000000000000', - multicallContract: process.env.MULTICALL_CONTRACT ?? '0x0000000000000000000000000000000000000000', - featuredVotingContract: process.env.FEATURED_VOTING_CONTRACT ?? '0x0000000000000000000000000000000000000000', - }, -} diff --git a/packages/DApp/src/constants/peers.ts b/packages/DApp/src/constants/peers.ts index 8965151..4b5bcb0 100644 --- a/packages/DApp/src/constants/peers.ts +++ b/packages/DApp/src/constants/peers.ts @@ -2,18 +2,21 @@ * source: @see https://fleets.status.im */ -export const peers = { - production: [], - test: [ - '/dns4/boot-01.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmAR24Mbb6VuzoyUiGx42UenDkshENVDj4qnmmbabLvo31', - '/dns4/boot-01.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm8mUZ18tBWPXDQsaF7PbCKYA35z7WB2xNZH2EVq1qS8LJ', - '/dns4/boot-01.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmGwcE8v7gmJNEWFtZtojYpPMTHy2jBLL6xRk33qgDxFWX', +const production = [ + '/dns4/boot-01.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmAR24Mbb6VuzoyUiGx42UenDkshENVDj4qnmmbabLvo31', + '/dns4/boot-01.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm8mUZ18tBWPXDQsaF7PbCKYA35z7WB2xNZH2EVq1qS8LJ', + '/dns4/boot-01.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmGwcE8v7gmJNEWFtZtojYpPMTHy2jBLL6xRk33qgDxFWX', + '/dns4/store-01.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmAUdrQ3uwzuE4Gy4D56hX6uLKEeerJAnhKEHZ3DxF1EfT', + '/dns4/store-02.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9aDJPkhGxc2SFcEACTFdZ91Q5TJjp76qZEhq9iF59x7R', + '/dns4/store-01.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ', + '/dns4/store-02.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJnVR7ZzFaYvciPVafUXuYGLHPzSUigqAmeNw9nJUVGeM', + '/dns4/store-01.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm2M7xs7cLPc3jamawkEqbr7cUJX11uvY7LxQ6WFUdUKUT', + '/dns4/store-02.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P', +] - '/dns4/store-01.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmAUdrQ3uwzuE4Gy4D56hX6uLKEeerJAnhKEHZ3DxF1EfT', - '/dns4/store-02.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9aDJPkhGxc2SFcEACTFdZ91Q5TJjp76qZEhq9iF59x7R', - '/dns4/store-01.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ', - '/dns4/store-02.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJnVR7ZzFaYvciPVafUXuYGLHPzSUigqAmeNw9nJUVGeM', - '/dns4/store-01.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm2M7xs7cLPc3jamawkEqbr7cUJX11uvY7LxQ6WFUdUKUT', - '/dns4/store-02.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P', - ], +// todo?: https://github.com/status-im/infra-shards/issues/29#issuecomment-1992729489 `shards.staging`; await integration in desktop and mobile +export const peers = { + development: production, + preview: production, + production, } diff --git a/packages/DApp/src/hooks/useAccount.ts b/packages/DApp/src/hooks/useAccount.ts index 2ee5dd7..227b912 100644 --- a/packages/DApp/src/hooks/useAccount.ts +++ b/packages/DApp/src/hooks/useAccount.ts @@ -27,7 +27,7 @@ export function useAccount() { useEffect(() => { if (activateError?.name === 'ChainIdError') { - switchNetwork(config.daapConfig.readOnlyChainId!) + switchNetwork(config.usedappConfig.readOnlyChainId!) } }, [activateError]) diff --git a/packages/DApp/src/hooks/useAvailableAmount.ts b/packages/DApp/src/hooks/useAvailableAmount.ts index 3a06095..085870a 100644 --- a/packages/DApp/src/hooks/useAvailableAmount.ts +++ b/packages/DApp/src/hooks/useAvailableAmount.ts @@ -1,12 +1,11 @@ -import { useEthers, useTokenBalance } from '@usedapp/core' -import { contracts } from '../constants/contracts' +import { ChainId, useEthers, useTokenBalance } from '@usedapp/core' import { BigNumber } from 'ethers' import { useEffect, useState } from 'react' +import { config } from '../config' export function useAvailableAmount() { const { account, chainId } = useEthers() - // @ts-expect-error fixme: https://github.com/status-im/community-dapp/pull/94#discussion_r1378964354 undefined or unsupported network - const tokenBalance = useTokenBalance(contracts[chainId as keyof typeof contracts | undefined].tokenContract, account) + const tokenBalance = useTokenBalance(config.contracts[chainId as ChainId]?.tokenContract, account) const [availableAmount, setAvailableAmount] = useState(0) diff --git a/packages/DApp/src/hooks/useContracts.ts b/packages/DApp/src/hooks/useContracts.ts index 0f3b991..1d19a70 100644 --- a/packages/DApp/src/hooks/useContracts.ts +++ b/packages/DApp/src/hooks/useContracts.ts @@ -1,9 +1,9 @@ import { useEthers } from '@usedapp/core' -import { contracts } from '../constants/contracts' import { Contract } from 'ethers' import { Interface } from '@ethersproject/abi' import { VotingContract, Directory, FeaturedVotingContract } from '@status-community-dapp/contracts/abi' import { useEffect, useState } from 'react' +import { config } from '../config' export function useContracts() { const { chainId } = useEthers() @@ -22,7 +22,7 @@ export function useContracts() { useEffect(() => { if (chainId) { - const chainConfig = contracts[chainId] + const chainConfig = config.contracts[chainId] if (chainConfig) { setVotingContract(new Contract(chainConfig.votingContract, new Interface(VotingContract.abi))) setDirectoryContract(new Contract(chainConfig.directoryContract, new Interface(Directory.abi))) diff --git a/packages/DApp/src/main.tsx b/packages/DApp/src/main.tsx index 30ad526..19227e8 100644 --- a/packages/DApp/src/main.tsx +++ b/packages/DApp/src/main.tsx @@ -8,12 +8,11 @@ import { DAppProvider } from '@usedapp/core' import { WakuProvider } from './providers/waku/provider' import { CommunitiesProvider } from './providers/communities/provider' import { config } from './config' -import { peers } from './constants/peers' render( - - + +