Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Watch Only): guard against bch as well
- Loading branch information
plondon
committed
Jun 1, 2018
1 parent
96581e2
commit b251318
Showing
22 changed files
with
288 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../blockchain-wallet-v4-frontend/src/layouts/Wallet/MenuTop/Balance/BchBalance/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { selectors } from 'data' | ||
|
||
export const getData = selectors.core.data.bch.getBalance | ||
export const getData = selectors.core.data.bch.getSpendableBalance |
53 changes: 53 additions & 0 deletions
53
...kchain-wallet-v4-frontend/src/layouts/Wallet/MenuTop/Balance/BchWatchOnlyBalance/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { connect } from 'react-redux' | ||
import { bindActionCreators } from 'redux' | ||
|
||
import { Remote } from 'blockchain-wallet-v4/src' | ||
import { actions } from 'data' | ||
import { getData } from './selectors' | ||
import Error from './template.error' | ||
import Loading from './template.loading' | ||
import Success from './template.success' | ||
|
||
class BchWatchOnlyBalance extends React.PureComponent { | ||
constructor (props) { | ||
super(props) | ||
this.handleRefresh = this.handleRefresh.bind(this) | ||
} | ||
|
||
componentWillMount () { | ||
if (Remote.NotAsked.is(this.props.data)) { | ||
this.props.actions.fetchUnspendableBalance(this.props.context) | ||
} | ||
} | ||
|
||
handleRefresh () { | ||
this.props.actions.fetchUnspendableBalance(this.props.context) | ||
} | ||
|
||
render () { | ||
const { data, large } = this.props | ||
|
||
return data.cata({ | ||
Success: (value) => <Success balance={value} large={large} />, | ||
Failure: (message) => <Error onRefresh={this.handleRefresh} />, | ||
Loading: () => <Loading />, | ||
NotAsked: () => <Loading /> | ||
}) | ||
} | ||
} | ||
|
||
BchWatchOnlyBalance.propTypes = { | ||
context: PropTypes.string.isRequired | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
data: getData(state) | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
actions: bindActionCreators(actions.core.data.bch, dispatch) | ||
}) | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(BchWatchOnlyBalance) |
3 changes: 3 additions & 0 deletions
3
...in-wallet-v4-frontend/src/layouts/Wallet/MenuTop/Balance/BchWatchOnlyBalance/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { selectors } from 'data' | ||
|
||
export const getData = selectors.core.data.bch.getUnspendableBalance |
22 changes: 22 additions & 0 deletions
22
...llet-v4-frontend/src/layouts/Wallet/MenuTop/Balance/BchWatchOnlyBalance/template.error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
import { FormattedMessage } from 'react-intl' | ||
import { Link } from 'blockchain-info-components' | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
box-sizing: border-box; | ||
justify-content: flex-end; | ||
padding-right: 25px; | ||
` | ||
const ErrorLink = styled(Link)` | ||
text-decoration: underline; | ||
` | ||
|
||
export default (props) => ( | ||
<Wrapper> | ||
<ErrorLink size='12px' weight={300} onClick={() => props.onRefresh()}> | ||
<FormattedMessage id='wallet.menutop.balance.refresh' defaultMessage='Refresh {curr} data' values={{curr: 'Watch Only Bitcoin Cash'}} /> | ||
</ErrorLink> | ||
</Wrapper> | ||
) |
21 changes: 21 additions & 0 deletions
21
...et-v4-frontend/src/layouts/Wallet/MenuTop/Balance/BchWatchOnlyBalance/template.loading.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react' | ||
import styled from 'styled-components' | ||
|
||
import { FlatLoader } from 'blockchain-info-components' | ||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: center; | ||
padding: 5px; | ||
box-sizing: border-box; | ||
` | ||
|
||
export default (props) => { | ||
return ( | ||
<Wrapper> | ||
<FlatLoader width='50px' height='14px' /> | ||
</Wrapper> | ||
) | ||
} |
46 changes: 46 additions & 0 deletions
46
...et-v4-frontend/src/layouts/Wallet/MenuTop/Balance/BchWatchOnlyBalance/template.success.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import styled from 'styled-components' | ||
import FiatDisplay from 'components/Display/FiatDisplay' | ||
import { LinkContainer } from 'react-router-bootstrap' | ||
import { FormattedMessage } from 'react-intl' | ||
import { Banner, Text } from 'blockchain-info-components' | ||
|
||
const Wrapper = styled.div` | ||
display: inline-flex; | ||
flex-direction: row; | ||
align-items: center; | ||
padding-left: 5px; | ||
margin-bottom: 10px; | ||
padding-right: ${props => props.large ? '15px' : '25px'}; | ||
> div:last-child { | ||
margin-left: 10px; | ||
> div { | ||
color: ${props => props.theme['gray-3']} | ||
} | ||
} | ||
` | ||
|
||
const Success = props => { | ||
const { balance } = props | ||
|
||
return ( | ||
<LinkContainer to='/bch/transactions'> | ||
<Wrapper> | ||
<Text size='10px' weight={300}>BCH</Text> | ||
<Banner inline type='informational'> | ||
<FiatDisplay coin='BCH' cursor='pointer' size='10px' weight={300}>{balance}</FiatDisplay> | ||
<Text size='10px' weight={300}> | ||
<FormattedMessage id='scenes.wallet.menutop.balance.watchonlybchbalance' defaultMessage=' Non-Spendable' /> | ||
</Text> | ||
</Banner> | ||
</Wrapper> | ||
</LinkContainer> | ||
) | ||
} | ||
|
||
Success.propTypes = { | ||
balance: PropTypes.number.isRequired | ||
} | ||
|
||
export default Success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 8 additions & 11 deletions
19
packages/blockchain-wallet-v4-frontend/src/layouts/Wallet/MenuTop/Balance/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
import { Remote } from 'blockchain-wallet-v4/src' | ||
import { selectors } from 'data' | ||
import { filter, reject, prop, lift } from 'ramda' | ||
import { lift } from 'ramda' | ||
|
||
export const getData = (state) => { | ||
const ethContextR = selectors.core.kvStore.ethereum.getContext(state) | ||
const bchContextR = Remote.of(selectors.core.kvStore.bch.getContext(state)) | ||
const btcActiveAccountsR = selectors.core.common.btc.getActiveHDAccounts(state) | ||
const btcActiveAddressesR = selectors.core.common.btc.getActiveAddresses(state) | ||
const btcContextR = Remote.of(selectors.core.wallet.getSpendableContext(state)) | ||
const bchContextR = Remote.of(selectors.core.kvStore.bch.getSpendableContext(state)) | ||
const btcUnspendableContextR = Remote.of(selectors.core.wallet.getUnspendableContext(state)) | ||
const bchUnspendableContextR = Remote.of(selectors.core.kvStore.bch.getUnspendableContext(state)) | ||
const path = state.router.location.pathname | ||
|
||
const transform = lift((btcActiveAddresses, btcActiveAccounts, ethContext, bchContext) => { | ||
const spendable = (a) => a.priv | ||
const accounts = btcActiveAccounts.map(prop('xpub')) | ||
const btcUnspendableContext = reject(spendable, btcActiveAddresses).map(prop('addr')) | ||
const btcSpendableContext = filter(spendable, btcActiveAddresses).map(prop('addr')).concat(accounts) | ||
return {btcSpendableContext, btcUnspendableContext, ethContext, bchContext, path} | ||
const transform = lift((btcContext, ethContext, bchContext, btcUnspendableContext, bchUnspendableContext) => { | ||
return {btcContext, ethContext, bchContext, btcUnspendableContext, bchUnspendableContext, path} | ||
}) | ||
return transform(btcActiveAddressesR, btcActiveAccountsR, ethContextR, bchContextR) | ||
return transform(btcContextR, ethContextR, bchContextR, btcUnspendableContextR, bchUnspendableContextR) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.