Skip to content

Commit

Permalink
feat(Watch Only): dont include watch only in main balance
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed May 31, 2018
1 parent 9057dbc commit 93da3bd
Show file tree
Hide file tree
Showing 26 changed files with 81 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const getData = (state, ownProps) => {
default:
return sequence(Remote.of,
[
selectors.core.common.bitcoin.getActiveAccountsBalances(state).map(excluded).map(toDropdown),
excludeImported ? Remote.of([]) : selectors.core.common.bitcoin.getAddressesBalances(state).map(toDropdown)
selectors.core.common.btc.getActiveAccountsBalances(state).map(excluded).map(toDropdown),
excludeImported ? Remote.of([]) : selectors.core.common.btc.getAddressesBalances(state).map(toDropdown)
]).map(([b1, b2]) => ({ data: concat(b1, b2) }))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default ({ coreSagas }) => {
yield put(A.sendBtcPaymentUpdated(Remote.Loading))
let payment = coreSagas.payment.btc.create(({network: settings.NETWORK_BITCOIN}))
payment = yield payment.init()
const accountsR = yield select(selectors.core.common.bitcoin.getAccountsBalances)
const accountsR = yield select(selectors.core.common.btc.getAccountsBalances)
const defaultIndex = yield select(selectors.core.wallet.getDefaultAccountIndex)
const defaultAccountR = accountsR.map(nth(defaultIndex))
const defaultFeePerByte = path(['fees', feeType || 'regular'], payment.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const selectReceiveAddress = function * (source) {
return bchReceiveAddress.getOrElse('')
}
if (equals('BTC', coin) && is(Number, address)) {
const btcReceiveAddress = selectors.core.common.bitcoin.getNextAvailableReceiveAddress(settings.NETWORK_BITCOIN, address, appState)
const btcReceiveAddress = selectors.core.common.btc.getNextAvailableReceiveAddress(settings.NETWORK_BITCOIN, address, appState)
if (isEmpty(btcReceiveAddress.getOrElse(''))) throw new Error('Could not generate return bitcoin receive address')
return btcReceiveAddress.getOrElse('')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class BtcBalance extends React.PureComponent {

componentWillMount () {
if (Remote.NotAsked.is(this.props.data)) {
this.props.actions.fetchData(this.props.context)
this.props.actions.fetchSpendableBalance(this.props.context)
}
}

handleRefresh () {
this.props.actions.fetchData(this.props.context)
this.props.actions.fetchSpendableBalance(this.props.context)
}

render () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { selectors } from 'data'

export const getData = selectors.core.data.bitcoin.getBalance
export const getData = selectors.core.data.bitcoin.getSpendableBalance
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Exchange } from 'blockchain-wallet-v4/src'
import * as Currency from 'blockchain-wallet-v4/src/exchange/currency'

export const getData = (state) => {
const btcBalanceR = selectors.core.data.bitcoin.getBalance(state)
const btcBalanceR = selectors.core.data.bitcoin.getSpendableBalance(state)
const ethBalanceR = selectors.core.data.ethereum.getBalance(state)
const bchBalanceR = selectors.core.data.bch.getBalance(state)
const btcBalance = btcBalanceR.getOrElse(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Balance extends React.PureComponent {
render () {
const { data } = this.props
return data.cata({
Success: (value) => <Success btcContext={value.btcContext} ethContext={value.ethContext} bchContext={value.bchContext} path={value.path} />,
Success: (value) => <Success btcContext={value.btcSpendableContext} btcWatchOnlyContext={value.btcWatchOnlyContext} ethContext={value.ethContext} bchContext={value.bchContext} path={value.path} />,
Failure: (message) => <Error>{message}</Error>,
Loading: () => <Loading />,
NotAsked: () => <Loading />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Remote } from 'blockchain-wallet-v4/src'
import { selectors } from 'data'
import { lift } from 'ramda'
import { filter, reject, prop, 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 btcContextR = Remote.of(selectors.core.wallet.getWalletContext(state))

const btcActiveAccountsR = selectors.core.common.btc.getActiveHDAccounts(state)
const btcActiveAddressesR = selectors.core.common.btc.getActiveAddresses(state)
const path = state.router.location.pathname
const transform = lift((btcContext, ethContext, bchContext) => ({btcContext, ethContext, bchContext, path}))
return transform(btcContextR, ethContextR, bchContextR)

const transform = lift((btcActiveAddresses, btcActiveAccounts, ethContext, bchContext) => {
const spendable = (a) => a.priv
const accounts = btcActiveAccounts.map(prop('xpub'))
const btcWatchOnlyContext = reject(spendable, btcActiveAddresses).map(prop('addr'))
const btcSpendableContext = filter(spendable, btcActiveAddresses).map(prop('addr')).concat(accounts)
return {btcSpendableContext, btcWatchOnlyContext, ethContext, bchContext, path}
})
return transform(btcActiveAddressesR, btcActiveAccountsR, ethContextR, bchContextR)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const extractAccountIdx = (value) =>
: Remote.NotAsked

export const getData = state => {
const getReceive = index => selectors.core.common.bitcoin.getNextAvailableReceiveAddress(settings.NETWORK_BITCOIN, index, state)
const getReceiveIdx = index => selectors.core.common.bitcoin.getNextAvailableReceiveIndex(settings.NETWORK_BITCOIN, index, state)
const getReceive = index => selectors.core.common.btc.getNextAvailableReceiveAddress(settings.NETWORK_BITCOIN, index, state)
const getReceiveIdx = index => selectors.core.common.btc.getNextAvailableReceiveIndex(settings.NETWORK_BITCOIN, index, state)
const message = formValueSelector('requestBitcoin')(state, 'message')
const amount = formValueSelector('requestBitcoin')(state, 'amount')
const coin = formValueSelector('requestBitcoin')(state, 'coin')
Expand All @@ -42,7 +42,7 @@ export const getData = state => {

export const getInitialValues = state => {
const toDropdown = map(x => ({ text: x.label, value: x }))
const balancesR = selectors.core.common.bitcoin.getAccountsBalances(state).map(toDropdown)
const balancesR = selectors.core.common.btc.getAccountsBalances(state).map(toDropdown)
const xpub = selectors.core.wallet.getDefaultAccountXpub(state)
const defaultElementR = balancesR.map(x => prop('value', head(filter(y => equals(y.value.xpub, xpub), x))))
return defaultElementR.map(to => ({to, coin: 'BTC'}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const getData = state => {
const toToggled = selectors.components.sendBtc.getToToggled(state)
const feePerByteToggled = selectors.components.sendBtc.getFeePerByteToggled(state)
const paymentR = selectors.components.sendBtc.getPayment(state)
const btcAccountsLength = length(selectors.core.common.bitcoin.getActiveHDAccounts(state).getOrElse([]))
const btcAddressesLength = length(selectors.core.common.bitcoin.getActiveAddresses(state).getOrElse([]))
const btcAccountsLength = length(selectors.core.common.btc.getActiveHDAccounts(state).getOrElse([]))
const btcAddressesLength = length(selectors.core.common.btc.getActiveAddresses(state).getOrElse([]))
const enableToggle = btcAccountsLength + btcAddressesLength > 1

const transform = payment => {
Expand Down Expand Up @@ -47,4 +47,4 @@ export const getData = state => {
return paymentR.map(transform)
}

export const getBtcData = selectors.core.common.bitcoin.getHDAccounts
export const getBtcData = selectors.core.common.btc.getHDAccounts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const getData = (state) => {
const profile = selectors.core.data.sfox.getProfile(state)
const accounts = selectors.core.data.sfox.getAccounts(state)
const verificationStatus = selectors.core.data.sfox.getVerificationStatus(state).data
const nextAddress = selectors.core.common.bitcoin.getNextAvailableReceiveAddress(settings.NETWORK_BITCOIN, 0, state)
const nextAddress = selectors.core.common.btc.getNextAvailableReceiveAddress(settings.NETWORK_BITCOIN, 0, state)
return lift((profile, accounts, nextAddress) => ({ profile, accounts, verificationStatus, nextAddress }))(profile, accounts, nextAddress)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getLogs = createDeepEqualSelector(
)

export const getBtcTransactions = createDeepEqualSelector(
[selectors.core.common.bitcoin.getWalletTransactions, getNumber],
[selectors.core.common.btc.getWalletTransactions, getNumber],
(transactions, number) => Remote.Success.is(transactions[0]) && !isNil(transactions[0]) ? transactions[0].map(compose(take(number), map(transform('BTC')))) : Remote.of([])
)

Expand All @@ -35,7 +35,7 @@ export const getBchTransactions = createDeepEqualSelector(
)

export const getEthTransactions = createDeepEqualSelector(
[selectors.core.common.ethereum.getWalletTransactions, getNumber],
[selectors.core.common.eth.getWalletTransactions, getNumber],
(transactions, number) => Remote.Success.is(transactions[0]) && !isNil(transactions[0]) ? transactions[0].map(compose(take(number), map(transform('ETH')))) : Remote.of([])
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getData = (state) => {
const bchRates = selectors.core.data.bch.getRates(state)
const settings = selectors.core.settings.getSettings(state)

const btcAccountsLength = length(selectors.core.common.bitcoin.getActiveHDAccounts(state).getOrElse([]))
const btcAccountsLength = length(selectors.core.common.btc.getActiveHDAccounts(state).getOrElse([]))
const bchAccountsLength = length(selectors.core.kvStore.bch.getAccounts(state).getOrElse([]))

const transform = (btcRates, ethRates, bchRates, settings) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ImportedAddressesContainer extends React.Component {
}

const mapStateToProps = (state) => ({
activeAddresses: selectors.core.common.bitcoin.getActiveAddresses(state),
activeAddresses: selectors.core.common.btc.getActiveAddresses(state),
search: formValueSelector('settingsAddresses')(state, 'search')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export const getData = state => {
xpub: x.xpub
}))

return selectors.core.common.bitcoin.getHDAccounts(state).map(wallets)
return selectors.core.common.btc.getHDAccounts(state).map(wallets)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const filterTransactions = curry((status, criteria, transactions) => {
export const getData = createSelector(
[
selectors.form.getFormValues('btcTransactions'),
selectors.core.common.bitcoin.getWalletTransactions
selectors.core.common.btc.getWalletTransactions
],
(formValues, pages) => {
const empty = (page) => isEmpty(page.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const filterTransactions = curry((status, criteria, transactions) => {
export const getData = createSelector(
[
selectors.form.getFormValues('ethTransactions'),
selectors.core.common.ethereum.getWalletTransactions
selectors.core.common.eth.getWalletTransactions
],
(formValues, pages) => {
const empty = (page) => isEmpty(page.data)
Expand Down
8 changes: 4 additions & 4 deletions packages/blockchain-wallet-v4/src/redux/common/selectors.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as bitcoin from './bitcoin/selectors.js'
import * as ethereum from './ethereum/selectors.js'
import * as btc from './btc/selectors.js'
import * as eth from './eth/selectors.js'
import * as bch from './bch/selectors.js'

export {
bitcoin,
ethereum,
btc,
eth,
bch
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ export const FETCH_BITCOIN_TRANSACTION_HISTORY = '@CORE.FETCH_BITCOIN_TRANSACTIO
export const FETCH_BITCOIN_TRANSACTION_HISTORY_LOADING = '@CORE.FETCH_BITCOIN_TRANSACTION_HISTORY_LOADING'
export const FETCH_BITCOIN_TRANSACTION_HISTORY_SUCCESS = '@CORE.FETCH_BITCOIN_TRANSACTION_HISTORY_SUCCESS'
export const FETCH_BITCOIN_TRANSACTION_HISTORY_FAILURE = '@CORE.FETCH_BITCOIN_TRANSACTION_HISTORY_FAILURE'

// FETCH_BITCOIN_TRANSACTION_HISTORY
export const FETCH_BITCOIN_SPENDABLE_BALANCE = '@CORE.FETCH_BITCOIN_SPENDABLE_BALANCE'
export const FETCH_BITCOIN_SPENDABLE_BALANCE_LOADING = '@CORE.FETCH_BITCOIN_SPENDABLE_BALANCE_LOADING'
export const FETCH_BITCOIN_SPENDABLE_BALANCE_SUCCESS = '@CORE.FETCH_BITCOIN_SPENDABLE_BALANCE_SUCCESS'
export const FETCH_BITCOIN_SPENDABLE_BALANCE_FAILURE = '@CORE.FETCH_BITCOIN_SPENDABLE_BALANCE_FAILURE'
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ export const fetchTransactionHistory = (address, start, end) => ({ type: AT.FETC
export const fetchTransactionHistoryLoading = () => ({ type: AT.FETCH_BITCOIN_TRANSACTION_HISTORY_LOADING })
export const fetchTransactionHistorySuccess = (data) => ({ type: AT.FETCH_BITCOIN_TRANSACTION_HISTORY_SUCCESS, payload: data })
export const fetchTransactionHistoryFailure = (error) => ({ type: AT.FETCH_BITCOIN_TRANSACTION_HISTORY_FAILURE, payload: error })

// FETCH_BITCOIN_SPENDABLE_BALANCE
export const fetchSpendableBalance = (context) => ({ type: AT.FETCH_BITCOIN_SPENDABLE_BALANCE, payload: { context } })
export const fetchSpendableBalanceLoading = () => ({ type: AT.FETCH_BITCOIN_SPENDABLE_BALANCE_LOADING })
export const fetchSpendableBalanceSuccess = (data) => ({ type: AT.FETCH_BITCOIN_SPENDABLE_BALANCE_SUCCESS, payload: data })
export const fetchSpendableBalanceFailure = (error) => ({ type: AT.FETCH_BITCOIN_SPENDABLE_BALANCE_FAILURE, payload: error })
12 changes: 12 additions & 0 deletions packages/blockchain-wallet-v4/src/redux/data/bitcoin/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const INITIAL_STATE = {
rates: Remote.NotAsked,
transactions: [],
transactions_fiat: {},
spendable_balance: Remote.NotAsked,
transaction_history: Remote.NotAsked
}

Expand Down Expand Up @@ -99,6 +100,17 @@ const bitcoinReducer = (state = INITIAL_STATE, action) => {
case AT.FETCH_BITCOIN_TRANSACTION_HISTORY_FAILURE: {
return assoc('transaction_history', Remote.Failure(payload), state)
}
case AT.FETCH_BITCOIN_SPENDABLE_BALANCE_LOADING: {
return assoc('spendable_balance', Remote.Loading, state)
}
case AT.FETCH_BITCOIN_SPENDABLE_BALANCE_SUCCESS: {
const { wallet } = payload
const balance = wallet.final_balance
return assoc('spendable_balance', Remote.Success(balance), state)
}
case AT.FETCH_BITCOIN_SPENDABLE_BALANCE_FAILURE: {
return assoc('spendable_balance', Remote.Failure(payload), state)
}
default:
return state
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default ({ api }) => {
yield takeEvery(AT.FETCH_BITCOIN_FIAT_AT_TIME, dataBtcSagas.fetchFiatAtTime)
yield takeLatest(AT.FETCH_BITCOIN_RATES, dataBtcSagas.fetchRates)
yield fork(dataBtcSagas.watchTransactions)
yield takeLatest(AT.FETCH_BITCOIN_SPENDABLE_BALANCE, dataBtcSagas.fetchSpendableBalance)
yield takeLatest(AT.FETCH_BITCOIN_TRANSACTION_HISTORY, dataBtcSagas.fetchTransactionHistory)
}
}
18 changes: 15 additions & 3 deletions packages/blockchain-wallet-v4/src/redux/data/bitcoin/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ export default ({ api }) => {
}
}

const fetchSpendableBalance = function * (action) {
try {
const { context } = action.payload
yield put(A.fetchSpendableBalanceLoading())
const data = yield call(api.fetchBlockchainData, context)
yield put(A.fetchSpendableBalanceSuccess(data))
} catch (e) {
yield put(A.fetchSpendableBalanceFailure(e))
}
}

const multiaddrSaga = function * (data) {
const btcData = {
addresses: indexBy(prop('address'), prop('addresses', data)),
Expand All @@ -117,10 +128,11 @@ export default ({ api }) => {
return {
fetchData,
fetchFee,
fetchFiatAtTime,
fetchRates,
fetchUnspent,
fetchFiatAtTime,
watchTransactions,
fetchTransactionHistory,
fetchUnspent
fetchSpendableBalance,
fetchTransactionHistory
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const getTransactionHistory = path([dataPath, 'bitcoin', 'transaction_his

export const getCoins = path([dataPath, 'bitcoin', 'payment', 'coins'])

export const getSpendableBalance = path([dataPath, 'bitcoin', 'spendable_balance'])

// Specific
export const getChangeIndex = curry((xpub, state) => getAddresses(state).map(path([xpub, 'change_index'])))

Expand Down

0 comments on commit 93da3bd

Please sign in to comment.