Added loaded and avaialble provider selector. Updated Header component

This commit is contained in:
apanizo 2018-09-06 10:55:31 +02:00
parent d0ab6f4581
commit 00caa6e951
3 changed files with 33 additions and 42 deletions

View File

@ -15,13 +15,30 @@ type Props = {
fetchProvider: Function,
userAddress: string,
network: string,
connected: boolean,
loaded: boolean,
available: boolean,
}
type State = {
hasError: boolean,
}
const getProviderInfoBased = (hasError, loaded, available, provider, network, userAddress) => {
if (hasError || !loaded) {
return <ProviderDisconnected />
}
return <ProviderInfo provider={provider} network={network} userAddress={userAddress} connected={available} />
}
const getProviderDetailsBased = (hasError, loaded, available, provider, network, userAddress) => {
if (hasError || !loaded) {
return <ConnectDetails />
}
return <ProviderDetails provider={provider} network={network} userAddress={userAddress} connected={available} />
}
class Header extends React.PureComponent<Props, State> {
state = {
hasError: false,
@ -37,46 +54,14 @@ class Header extends React.PureComponent<Props, State> {
logComponentStack(error, info)
}
getProviderInfoBased = (hasError, disconnected) => {
if (hasError) {
// return
}
if (disconnected) {
return <ProviderDisconnected />
}
const {
provider, network, userAddress, connected,
} = this.props
return <ProviderInfo provider={provider} network={network} userAddress={userAddress} connected={connected} />
}
getProviderDetailsBased = (hasError, disconnected) => {
if (hasError) {
// return
}
if (disconnected) {
return <ConnectDetails />
}
const {
provider, network, userAddress, connected,
} = this.props
return <ProviderDetails provider={provider} network={network} userAddress={userAddress} connected={connected} />
}
render() {
const { connected } = this.props
const { hasError } = this.state
const providerDisconnected = !hasError && !connected
const {
loaded, available, provider, network, userAddress,
} = this.props
const info = this.getProviderInfoBased(hasError, providerDisconnected)
const details = this.getProviderDetailsBased(hasError, providerDisconnected)
const info = getProviderInfoBased(hasError, loaded, available, provider, network, userAddress)
const details = getProviderDetailsBased(hasError, loaded, available, provider, network, userAddress)
return <Layout providerInfo={info} providerDetails={details} />
}

View File

@ -1,10 +1,11 @@
// @flow
import { createStructuredSelector } from 'reselect'
import { providerNameSelector, userAccountSelector, networkSelector, connectedSelector } from '~/logic/wallets/store/selectors'
import { providerNameSelector, userAccountSelector, networkSelector, availableSelector, loadedSelector } from '~/logic/wallets/store/selectors'
export default createStructuredSelector({
provider: providerNameSelector,
userAddress: userAccountSelector,
network: networkSelector,
connected: connectedSelector,
loaded: loadedSelector,
available: availableSelector,
})

View File

@ -36,7 +36,12 @@ export const networkSelector = createSelector(
},
)
export const connectedSelector = createSelector(
export const loadedSelector = createSelector(
providerSelector,
(provider: Provider) => provider.get('loaded') && provider.get('available'),
(provider: Provider) => provider.get('loaded'),
)
export const availableSelector = createSelector(
providerSelector,
(provider: Provider) => provider.get('available'),
)