Skip to content

Commit

Permalink
AccountModule: Bypass connection hooks on local / unknown networks (#…
Browse files Browse the repository at this point in the history
…1474)

* Bypass connection hooks on local / unknown networks

* Add new live key to settings and detect if bypass is needed with it
  • Loading branch information
Evalir authored Jul 6, 2020
1 parent 82f4d5f commit 380fb85
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/components/AccountModule/connection-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,23 @@ export function useWalletConnectionDetails(
) {
const { walletNetworkName, hasNetworkMismatch } = useNetworkConnectionData()
const theme = useTheme()
let connectionDetails = {}
const isWalletAndClientSynced =
Math.abs(walletSyncDelay - clientSyncDelay) <= OK_PROVIDER_SYNC_DELAY
const networkSlowdown =
walletSyncDelay >= MILD_PROVIDER_SYNC_DELAY &&
clientSyncDelay >= MILD_PROVIDER_SYNC_DELAY &&
isWalletAndClientSynced

const connectionDetails = {
connectionMessage: `Connected to ${walletNetworkName}`,
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`,
connectionColor: theme.positive,
}

if (clientListening && !network.live) {
return connectionDetails
}

if (
!clientListening ||
!walletListening ||
Expand All @@ -80,7 +89,7 @@ export function useWalletConnectionDetails(
clientSyncDelay >= MAX_PROVIDER_SYNC_DELAY ||
walletSyncDelay >= MAX_PROVIDER_SYNC_DELAY
) {
connectionDetails = {
return {
connectionMessage: 'No connection',
connectionMessageLong: 'No connection',
connectionColor: theme.negative,
Expand All @@ -89,24 +98,19 @@ export function useWalletConnectionDetails(
walletSyncDelay >= OK_PROVIDER_SYNC_DELAY ||
clientSyncDelay >= OK_PROVIDER_SYNC_DELAY
) {
connectionDetails = {
return {
connectionMessage: 'Syncing issues',
connectionMessageLong: 'Syncing issues',
connectionColor: theme.warning,
}
} else if (hasNetworkMismatch) {
connectionDetails = {
return {
connectionMessage: 'Wrong network',
connectionMessageLong: 'Wrong network',
connectionColor: theme.warning,
}
} else {
connectionDetails = {
connectionMessage: `Connected to ${walletNetworkName}`,
connectionMessageLong: `Connected to Ethereum ${walletNetworkName} Network`,
connectionColor: theme.positive,
}
}

return connectionDetails
}

Expand Down Expand Up @@ -215,6 +219,16 @@ export function useSyncState(

const minimumTransactionBalance = new BN(0.005)

const syncedStatus = {
header: 'Synced',
info: currentBlock ? `: current block ${currentBlock}` : '',
status: STATUS_CONNECTION_OK,
}

if (clientListening && !network.live) {
return syncedStatus
}

if (!clientOnline || !clientListening) {
return {
header: '',
Expand Down Expand Up @@ -255,9 +269,5 @@ export function useSyncState(
}
}

return {
header: 'Synced',
info: currentBlock ? `: current block ${currentBlock}` : '',
status: STATUS_CONNECTION_OK,
}
return syncedStatus
}
6 changes: 6 additions & 0 deletions src/network-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const networkConfigs = {
name: 'Mainnet',
shortName: 'Mainnet',
type: 'main', // as returned by web3.eth.net.getNetworkType()
live: true,
},
providers: [
{ id: 'provided' },
Expand All @@ -44,6 +45,7 @@ export const networkConfigs = {
name: 'Rinkeby testnet',
shortName: 'Rinkeby',
type: 'rinkeby', // as returned by web3.eth.net.getNetworkType()
live: true,
},
// providers: ['injected', 'frame'],
providers: [
Expand All @@ -66,6 +68,7 @@ export const networkConfigs = {
name: 'Ropsten testnet',
shortName: 'Ropsten',
type: 'ropsten', // as returned by web3.eth.net.getNetworkType()
live: true,
},
providers: [{ id: 'provided' }, { id: 'frame' }],
},
Expand All @@ -84,6 +87,7 @@ export const networkConfigs = {
name: 'local testnet',
shortName: 'Local',
type: 'private',
live: false,
},
providers: [{ id: 'provided' }, { id: 'frame' }],
},
Expand All @@ -102,6 +106,7 @@ export const networkConfigs = {
name: 'xDai',
shortName: 'xdai',
type: 'private',
live: true,
},
providers: [
{ id: 'provided' },
Expand All @@ -120,6 +125,7 @@ export const networkConfigs = {
name: `Unknown network`,
shortName: 'Unknown',
type: 'unknown',
live: false,
},
providers: [{ id: 'provided' }, { id: 'frame' }],
},
Expand Down

0 comments on commit 380fb85

Please sign in to comment.