Added loaded and avaialble provider selector. Updated Header component
This commit is contained in:
parent
d0ab6f4581
commit
00caa6e951
|
@ -15,13 +15,30 @@ type Props = {
|
||||||
fetchProvider: Function,
|
fetchProvider: Function,
|
||||||
userAddress: string,
|
userAddress: string,
|
||||||
network: string,
|
network: string,
|
||||||
connected: boolean,
|
loaded: boolean,
|
||||||
|
available: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
hasError: boolean,
|
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> {
|
class Header extends React.PureComponent<Props, State> {
|
||||||
state = {
|
state = {
|
||||||
hasError: false,
|
hasError: false,
|
||||||
|
@ -37,46 +54,14 @@ class Header extends React.PureComponent<Props, State> {
|
||||||
logComponentStack(error, info)
|
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() {
|
render() {
|
||||||
const { connected } = this.props
|
|
||||||
|
|
||||||
const { hasError } = this.state
|
const { hasError } = this.state
|
||||||
const providerDisconnected = !hasError && !connected
|
const {
|
||||||
|
loaded, available, provider, network, userAddress,
|
||||||
|
} = this.props
|
||||||
|
|
||||||
const info = this.getProviderInfoBased(hasError, providerDisconnected)
|
const info = getProviderInfoBased(hasError, loaded, available, provider, network, userAddress)
|
||||||
const details = this.getProviderDetailsBased(hasError, providerDisconnected)
|
const details = getProviderDetailsBased(hasError, loaded, available, provider, network, userAddress)
|
||||||
|
|
||||||
return <Layout providerInfo={info} providerDetails={details} />
|
return <Layout providerInfo={info} providerDetails={details} />
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { createStructuredSelector } from 'reselect'
|
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({
|
export default createStructuredSelector({
|
||||||
provider: providerNameSelector,
|
provider: providerNameSelector,
|
||||||
userAddress: userAccountSelector,
|
userAddress: userAccountSelector,
|
||||||
network: networkSelector,
|
network: networkSelector,
|
||||||
connected: connectedSelector,
|
loaded: loadedSelector,
|
||||||
|
available: availableSelector,
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,7 +36,12 @@ export const networkSelector = createSelector(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
export const connectedSelector = createSelector(
|
export const loadedSelector = createSelector(
|
||||||
providerSelector,
|
providerSelector,
|
||||||
(provider: Provider) => provider.get('loaded') && provider.get('available'),
|
(provider: Provider) => provider.get('loaded'),
|
||||||
|
)
|
||||||
|
|
||||||
|
export const availableSelector = createSelector(
|
||||||
|
providerSelector,
|
||||||
|
(provider: Provider) => provider.get('available'),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue