Skip to content

Commit

Permalink
refactoring and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
schnogz committed May 30, 2018
1 parent c179397 commit 451efec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
@@ -1,5 +1,5 @@
import { call, put, select } from 'redux-saga/effects'
import { findIndex, forEach, propEq } from 'ramda'
import { filter, findIndex, forEach, propEq } from 'ramda'

import * as A from './actions'
import * as actions from '../../actions'
Expand Down Expand Up @@ -29,26 +29,20 @@ export default ({ api }) => {
yield put(A.fetchUsedAddressesLoading(walletIndex))
const wallet = yield select(selectors.core.wallet.getWallet)
const account = Types.Wallet.selectHDAccounts(wallet).get(walletIndex)
// get current receive index
// get current receive index of wallet
const receiveIndex = yield select(selectors.core.data.bitcoin.getReceiveIndex(account.xpub))
// derive old addresses
// derive previous addresses
const derivedAddrs = yield call(deriveAddresses, account, receiveIndex)
// fetch blockchain data for each address
const derivedAddrsFull = yield call(api.fetchBlockchainData, derivedAddrs)
// fetch label indexes and derive addresses
// fetch label indexes and derive those addresses
const labels = Types.HDAccount.selectAddressLabels(account).reverse().toArray()
const labeledAddrs = labels.map(l => {
return {
address: Types.HDAccount.getReceiveAddress(account, l.index, settings.NETWORK_BITCOIN),
index: l.index,
label: l.label
}
return { address: Types.HDAccount.getReceiveAddress(account, l.index, settings.NETWORK_BITCOIN), index: l.index, label: l.label }
})

// filter only addresses with tx's
const usedAddresses = derivedAddrsFull.addresses.filter(a => {
return a.n_tx > 0
})
const usedAddresses = filter(a => a.n_tx > 0, derivedAddrsFull.addresses)

// match labels with addresses
if (labeledAddrs.length) {
Expand Down
Expand Up @@ -17,8 +17,8 @@ class UsedAddressesTableContainer extends React.PureComponent {
usedAddresses.cata({
Success: (value) => <UsedAddressesTable usedAddresses={value} />,
Failure: (message) => <div>{message}</div>,
Loading: () => <div>LOADING</div>,
NotAsked: () => <div>LOADING</div>
Loading: () => <div/>,
NotAsked: () => <div/>
})
)
}
Expand Down
Expand Up @@ -29,6 +29,8 @@ class UsedAddressesContainer extends React.PureComponent {
}

const mapStateToProps = (state, ownProps) => {
// since usedAddresses state tree is stored based on walletIndexes, the default states will not exist
// on first attempt to access
if (!path(['state', 'components', 'usedAddresses', ownProps.walletIndex])) {
state.components.usedAddresses[ownProps.walletIndex] = {
visible: false,
Expand Down

0 comments on commit 451efec

Please sign in to comment.