-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration: refactor network configuration, migrate to chainId, remove unnecessary connectivity polling #1485
Changes from all commits
a4f33cd
5d24e1f
584456c
5468dba
c456ea8
4f20948
d507385
851e9b6
9c19599
47e9d2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ import React from 'react' | |
import PropTypes from 'prop-types' | ||
import { Spring, animated } from 'react-spring' | ||
import { useTheme } from '@aragon/ui' | ||
import { EthereumAddressType, ClientThemeType } from './prop-types' | ||
import { useWallet } from './wallet' | ||
import { network, web3Providers } from './environment' | ||
import initWrapper from './aragonjs-wrapper' | ||
import { web3Providers } from './environment' | ||
import { useClientTheme } from './client-theme' | ||
import { useRouting } from './routing' | ||
import initWrapper, { pollConnectivity } from './aragonjs-wrapper' | ||
import { Onboarding } from './onboarding' | ||
import { getWeb3 } from './web3-utils' | ||
import { EthereumAddressType, ClientThemeType } from './prop-types' | ||
import { log } from './utils' | ||
import { useWallet } from './wallet' | ||
import { getWeb3 } from './web3-utils' | ||
import { ActivityProvider } from './contexts/ActivityContext' | ||
import { FavoriteDaosProvider } from './contexts/FavoriteDaosContext' | ||
import { PermissionsProvider } from './contexts/PermissionsContext' | ||
|
@@ -45,18 +45,6 @@ const INITIAL_DAO_STATE = { | |
repos: [], | ||
} | ||
|
||
const SELECTOR_NETWORKS = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This felt like an odd place to configure the available networks during onboarding, so I've moved it out into the |
||
['main', 'Ethereum Mainnet', 'https://mainnet.aragon.org/'], | ||
['rinkeby', 'Ethereum Testnet (Rinkeby)', 'https://rinkeby.aragon.org/'], | ||
] | ||
if (network.type === 'ropsten') { | ||
SELECTOR_NETWORKS.push([ | ||
'ropsten', | ||
'Ethereum Testnet (Ropsten)', | ||
'https://aragon.ropsten.aragonpm.com/', | ||
]) | ||
} | ||
|
||
class App extends React.Component { | ||
static propTypes = { | ||
clientTheme: ClientThemeType.isRequired, | ||
|
@@ -67,23 +55,14 @@ class App extends React.Component { | |
|
||
state = { | ||
...INITIAL_DAO_STATE, | ||
connected: false, | ||
fatalError: null, | ||
identityIntent: null, | ||
selectorNetworks: SELECTOR_NETWORKS, | ||
transactionBag: null, | ||
signatureBag: null, | ||
web3: getWeb3(web3Providers.default), | ||
wrapper: null, | ||
} | ||
|
||
componentDidMount() { | ||
// Only the default, because the app can work without the wallet | ||
pollConnectivity([web3Providers.default], connected => { | ||
this.setState({ connected }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I could tell, this Good riddance—this was spiking our API requests to ETH nodes! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 |
||
}) | ||
} | ||
|
||
componentDidUpdate(prevProps, prevState) { | ||
const { clientTheme, routing, walletAccount } = this.props | ||
const { wrapper } = this.state | ||
|
@@ -300,7 +279,6 @@ class App extends React.Component { | |
permissions, | ||
permissionsLoading, | ||
repos, | ||
selectorNetworks, | ||
transactionBag, | ||
signatureBag, | ||
web3, | ||
|
@@ -361,7 +339,7 @@ class App extends React.Component { | |
/> | ||
<FavoriteDaosProvider> | ||
<ActivityProvider | ||
daoDomain={daoAddress.domain} | ||
daoAddress={daoAddress.address} | ||
web3={web3} | ||
> | ||
<PermissionsProvider | ||
|
@@ -389,10 +367,7 @@ class App extends React.Component { | |
</div> | ||
</PermissionsProvider> | ||
|
||
<Onboarding | ||
selectorNetworks={selectorNetworks} | ||
web3={web3} | ||
/> | ||
<Onboarding web3={web3} /> | ||
|
||
<GlobalPreferences | ||
apps={appsWithIdentifiers} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,10 @@ import { | |
useTheme, | ||
} from '@aragon/ui' | ||
import LocalIdentityBadge from '../../components/IdentityBadge/LocalIdentityBadge' | ||
import appIds from '../../known-app-ids' | ||
import CHAIN_IDS from '../../chain-ids' | ||
import { network } from '../../environment' | ||
import { getProviderString } from '../../ethereum-providers' | ||
import { sanitizeNetworkType } from '../../network-config' | ||
import appIds from '../../known-app-ids' | ||
import { AppType, DaoAddressType } from '../../prop-types' | ||
import { useRouting, ARAGONID_ENS_DOMAIN } from '../../routing' | ||
import airdrop, { testTokensEnabled } from '../../testnet/airdrop' | ||
|
@@ -104,14 +104,13 @@ const Organization = React.memo(function Organization({ | |
const hasFinanceApp = apps.some(app => app.appId === appIds.Finance) | ||
const checksummedDaoAddr = | ||
daoAddress.address && toChecksumAddress(daoAddress.address) | ||
const enableTransactions = | ||
wallet.connected && wallet.networkType === network.type | ||
const isMainnet = network.type === 'main' | ||
const enableTransactions = wallet.connected | ||
const isMainnet = network.chainId === CHAIN_IDS.ETHEREUM | ||
const shortAddresses = layoutName !== 'large' | ||
|
||
const organizationText = checksummedDaoAddr ? ( | ||
<span> | ||
This organization is deployed on the Ethereum {network.name}.{' '} | ||
This organization is deployed on the {network.name} network.{' '} | ||
{canUpgradeOrg ? ( | ||
<span> | ||
<Link onClick={onShowOrgVersionDetails}> | ||
|
@@ -281,8 +280,8 @@ const Organization = React.memo(function Organization({ | |
) : ( | ||
<span> | ||
Unfortunately, importing into Tenderly is not available on | ||
the {sanitizeNetworkType(network.type)} network. Please | ||
use Aragon on Ethereum mainnet instead. | ||
the {network.name} network. Please use Aragon on the | ||
Ethereum main network instead. | ||
</span> | ||
)} | ||
</p> | ||
|
@@ -291,7 +290,7 @@ const Organization = React.memo(function Organization({ | |
)} | ||
</React.Fragment> | ||
)} | ||
{hasFinanceApp && testTokensEnabled(network.type) && ( | ||
{hasFinanceApp && testTokensEnabled() && ( | ||
<Box heading="Request test tokens"> | ||
<p | ||
css={` | ||
|
@@ -335,11 +334,7 @@ const Organization = React.memo(function Organization({ | |
</Info> | ||
) : ( | ||
<Info mode="warning"> | ||
{`Please ${ | ||
wallet.networkType !== network.type | ||
? `select the ${sanitizeNetworkType(network.type)} network` | ||
: 'unlock your account' | ||
} in ${getProviderString( | ||
{`Please unlock your account in ${getProviderString( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the Account module, I've simplified places where we check the connect account's network vs. the expected network as the user currently can never have their account enabled on a different network. |
||
'your Ethereum wallet', | ||
wallet.providerInfo.id | ||
)}.`} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const CHAIN_IDS = { | ||
ETHEREUM: 1, | ||
ROPSTEN: 3, | ||
RINKEBY: 4, | ||
KOVAN: 42, | ||
GOERLI: 5, | ||
XDAI: 100, | ||
} | ||
|
||
// Error on invalid accesses to CHAIN_IDS | ||
const PROTECTED_CHAIN_IDS = new Proxy(CHAIN_IDS, { | ||
get(target, property) { | ||
if (property in target) { | ||
return target[property] | ||
} else { | ||
throw new Error(`Chain ID '${property}' not supported`) | ||
} | ||
}, | ||
}) | ||
Comment on lines
+11
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
|
||
export default PROTECTED_CHAIN_IDS |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' | ||
import { useWallet } from '../../wallet' | ||
import { useLocalIdentity } from '../../hooks' | ||
import { | ||
useNetworkConnectionData, | ||
useSyncInfo, | ||
useWalletConnectionDetails, | ||
} from './connection-hooks' | ||
import { useSyncInfo, useWalletConnectionDetails } from './connection-hooks' | ||
import AccountModulePopover from './AccountModulePopover' | ||
import ButtonConnect from './ButtonConnect' | ||
import ButtonAccount from './ButtonAccount' | ||
|
@@ -58,10 +54,10 @@ function AccountModule() { | |
clientSyncDelay, | ||
connectionColor, | ||
connectionMessage, | ||
hasNetworkMismatch, | ||
label, | ||
walletConnectionStatus, | ||
walletListening, | ||
walletOnline, | ||
walletSyncDelay, | ||
} = useConnectionInfo() | ||
|
||
|
@@ -132,7 +128,6 @@ function AccountModule() { | |
<ButtonAccount | ||
connectionColor={connectionColor} | ||
connectionMessage={connectionMessage} | ||
hasNetworkMismatch={hasNetworkMismatch} | ||
label={label} | ||
onClick={toggle} | ||
/> | ||
|
@@ -189,7 +184,7 @@ function AccountModule() { | |
providerInfo={providerInfo} | ||
walletConnectionStatus={walletConnectionStatus} | ||
walletListening={walletListening} | ||
walletOnline={walletListening} | ||
walletOnline={walletOnline} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, but I think this should be a fix 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops! Haha I can definitely tell you this is a fix. 😆 |
||
walletSyncDelay={walletSyncDelay} | ||
/> | ||
) | ||
|
@@ -213,7 +208,7 @@ function useConnectionInfo() { | |
isOnline: walletOnline, | ||
connectionStatus: walletConnectionStatus, | ||
syncDelay: walletSyncDelay, | ||
} = useSyncInfo('wallet') | ||
} = useSyncInfo(wallet.web3) | ||
|
||
const { | ||
isListening: clientListening, | ||
|
@@ -222,16 +217,13 @@ function useConnectionInfo() { | |
syncDelay: clientSyncDelay, | ||
} = useSyncInfo() | ||
|
||
const { walletNetworkName, hasNetworkMismatch } = useNetworkConnectionData() | ||
|
||
const { connectionMessage, connectionColor } = useWalletConnectionDetails( | ||
clientListening, | ||
walletListening, | ||
clientOnline, | ||
walletOnline, | ||
clientSyncDelay, | ||
walletSyncDelay, | ||
walletNetworkName | ||
walletSyncDelay | ||
) | ||
|
||
return { | ||
|
@@ -241,11 +233,9 @@ function useConnectionInfo() { | |
clientSyncDelay, | ||
connectionColor, | ||
connectionMessage, | ||
hasNetworkMismatch, | ||
label, | ||
walletConnectionStatus, | ||
walletListening, | ||
walletNetworkName, | ||
walletOnline, | ||
walletSyncDelay, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started renaming our internal references to "main" or "mainnet" to "Ethereum", as "mainnet" is not descriptive enough (e.g. xDai has a mainnet, Aragon Chain will have a mainnet).