Skip to content
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

AccountModule: Bypass connection hooks on local / unknown networks #1474

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Evalir marked this conversation as resolved.
Show resolved Hide resolved

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