Skip to content

Commit

Permalink
Merge pull request #1481 from blockchain/fix/tx-confirmations
Browse files Browse the repository at this point in the history
Fix(Tx confirmations updating and label searches)
  • Loading branch information
plondon authored Feb 26, 2019
2 parents 39b181e + a04c61b commit c3de7aa
Show file tree
Hide file tree
Showing 20 changed files with 130 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import PropTypes from 'prop-types'
import styled from 'styled-components'
import { FormattedMessage } from 'react-intl'
import { toString } from 'ramda'
import { connect } from 'react-redux'

import { getBlockHeight } from './selectors'

import {
Icon,
Expand Down Expand Up @@ -61,12 +64,14 @@ const getMinConfirms = coin => {
}

const Confirmations = props => {
const { coin } = props
const { blockHeight, coin, txBlockHeight } = props
const conf = blockHeight - txBlockHeight + 1
const confirmations = conf > 0 ? conf : 0
const minConfirmations = getMinConfirms(coin)

return (
<Wrapper>
{props.confirmations >= minConfirmations ? (
{confirmations >= minConfirmations ? (
<Text size='14px' weight={300} color='received'>
<FormattedMessage
id='scenes.transactions.content.pages.listitem.confirmation.confirmed'
Expand All @@ -79,14 +84,14 @@ const Confirmations = props => {
id='scenes.transactions.content.pages.listitem.confirmation.unconfirmed'
defaultMessage='Pending: {count}/{total} Confirmations'
values={{
count: toString(props.confirmations),
count: toString(confirmations),
total: minConfirmations
}}
/>
</ConfirmationsText>
)}
<IconWrapper>
{props.confirmations < minConfirmations && (
{confirmations < minConfirmations && (
<TransactionTooltip
id='confirmations'
data-iscapture='true'
Expand Down Expand Up @@ -128,9 +133,15 @@ const Confirmations = props => {
</Wrapper>
)
}

Confirmations.propTypes = {
confirmations: PropTypes.number.isRequired,
hash: PropTypes.string.isRequired
blockHeight: PropTypes.number.isRequired,
hash: PropTypes.string.isRequired,
txBlockHeight: PropTypes.number.isRequired
}

export default Confirmations
const mapStateToProps = (state, ownProps) => ({
blockHeight: getBlockHeight(state, ownProps.coin)
})

export default connect(mapStateToProps)(Confirmations)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { selectors } from 'data'

export const getBlockHeight = (state, coin) => {
switch (coin) {
case 'BTC':
return selectors.core.data.bitcoin.getHeight(state).getOrElse(0)
case 'BCH':
return selectors.core.data.bch.getHeight(state).getOrElse(0)
case 'BSV':
return selectors.core.data.bsv.getHeight(state).getOrElse(0)
case 'ETH':
return selectors.core.data.ethereum.getHeight(state).getOrElse(0)
case 'XLM':
return 0
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import { actions } from 'data'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import { actions } from 'data'
import EditDescription from './template'
import { getDescription } from './selectors'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { selectors } from 'data'
import { Wallet, TXNotes } from 'blockchain-wallet-v4/src/types'

// TODO: delete all dis
export const getDescription = (state, ownProps) => {
const { coin, hash, toAddress } = ownProps
switch (coin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'

import { actions } from 'data'
import TransactionListItem from './template.js'
import TransactionListItem from './template'

class ListItemContainer extends React.PureComponent {
state = { isToggled: false }
Expand Down Expand Up @@ -43,14 +43,15 @@ class ListItemContainer extends React.PureComponent {
}

render () {
const { coin, currency, transaction, buySellPartner } = this.props
return (
<TransactionListItem
coin={this.props.coin}
currency={this.props.currency}
coin={coin}
currency={currency}
isToggled={this.state.isToggled}
handleToggle={this.handleToggle}
transaction={this.props.transaction}
buySellPartner={this.props.buySellPartner}
transaction={transaction}
buySellPartner={buySellPartner}
handleEditDescription={this.handleEditDescription}
/>
)
Expand All @@ -67,6 +68,6 @@ const mapDispatchToProps = dispatch => ({
})

export default connect(
undefined,
null,
mapDispatchToProps
)(ListItemContainer)
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ const TransactionListItem = ({
<Description
coin={coin}
hash={transaction.hash}
value={transaction.description}
toAddress={transaction.toAddress}
handleEditDescription={handleEditDescription}
/>
Expand Down Expand Up @@ -301,7 +300,7 @@ const TransactionListItem = ({
<Confirmations
coin={coin}
hash={transaction.hash}
confirmations={transaction.confirmations}
txBlockHeight={transaction.blockHeight}
/>
{transaction.type !== 'received' && (
<React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
allPass,
anyPass,
compose,
contains,
includes,
map,
filter,
path,
Expand All @@ -30,7 +30,7 @@ const filterTransactions = curry((status, criteria, transactions) => {
)
const search = curry((text, txPath, tx) =>
compose(
contains(toUpper(text || '')),
includes(toUpper(text || '')),
toUpper,
String,
path(txPath)
Expand Down
29 changes: 10 additions & 19 deletions packages/blockchain-wallet-v4/src/redux/data/bch/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Remote from '../../../remote'
import * as walletSelectors from '../../wallet/selectors'
import { MISSING_WALLET } from '../utils'
import { HDAccountList } from '../../../types'
import { getAccountsList } from '../../kvStore/bch/selectors'
import { getAccountsList, getBchTxNotes } from '../../kvStore/bch/selectors'
import { getLockboxBchAccounts } from '../../kvStore/lockbox/selectors'
import * as transactions from '../../../transactions'

Expand Down Expand Up @@ -95,35 +95,26 @@ export default ({ api }) => {
// Remote(wallet)
const wallet = yield select(walletSelectors.getWallet)
const walletR = Remote.of(wallet)
// Remote(blockHeight)
const blockHeightR = yield select(S.getLatestBlock)
// Remote(kvStoreAccountList)
const accountListR = yield select(getAccountsList)
const accountList = accountListR.getOrElse([])
// Remote(lockboxXpubs)
const lockboxAccountListR = (yield select(getLockboxBchAccounts))
const accountList = (yield select(getAccountsList)).getOrElse([])
const txNotes = (yield select(getBchTxNotes)).getOrElse({})
const lockboxAccountList = (yield select(getLockboxBchAccounts))
.map(HDAccountList.fromJS)
.getOrElse([])

// transformTx :: wallet -> blockHeight -> Tx
// ProcessPage :: wallet -> blockHeight -> [Tx] -> [Tx]
const ProcessTxs = (wallet, block, lockboxAccountList, txList) =>
// transformTx :: wallet -> Tx
// ProcessPage :: wallet -> [Tx] -> [Tx]
const ProcessTxs = (wallet, lockboxAccountList, txList, txNotes) =>
map(
transformTx.bind(
undefined,
wallet.getOrFail(MISSING_WALLET),
block.getOrElse(0),
lockboxAccountList
lockboxAccountList,
txNotes
),
txList
)
// ProcessRemotePage :: Page -> Page
const processedTxs = ProcessTxs(
walletR,
blockHeightR,
lockboxAccountListR,
txs
)
const processedTxs = ProcessTxs(walletR, lockboxAccountList, txs, txNotes)
return addFromToAccountNames(wallet, accountList, processedTxs)
}

Expand Down
27 changes: 10 additions & 17 deletions packages/blockchain-wallet-v4/src/redux/data/bsv/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { addFromToAccountNames } from '../../../utils/accounts'
import Remote from '../../../remote'
import * as walletSelectors from '../../wallet/selectors'
import * as transactions from '../../../transactions'
import { getAccountsList } from '../../kvStore/bsv/selectors'
import { getAccountsList, getBsvTxNotes } from '../../kvStore/bsv/selectors'

const transformTx = transactions.bsv.transformTx

Expand Down Expand Up @@ -91,33 +91,26 @@ export default ({ api }) => {
// Remote(wallet)
const wallet = yield select(walletSelectors.getWallet)
const walletR = Remote.of(wallet)
// Remote(blockHeight)
const blockHeightR = yield select(S.getLatestBlock)
// Remote(kvStoreAccountList)
const accountListR = yield select(getAccountsList)
const accountList = accountListR.getOrElse([])
const accountList = (yield select(getAccountsList)).getOrElse([])
const txNotes = (yield select(getBsvTxNotes)).getOrElse({})
// Remote(lockboxXpubs)
const lockboxAccountListR = []
const lockboxAccountList = []

// transformTx :: wallet -> blockHeight -> Tx
// ProcessPage :: wallet -> blockHeight -> [Tx] -> [Tx]
const ProcessTxs = (wallet, block, lockboxAccountList, txList) =>
// transformTx :: wallet -> Tx
// ProcessPage :: wallet -> [Tx] -> [Tx]
const ProcessTxs = (wallet, lockboxAccountList, txList, txNotes) =>
map(
transformTx.bind(
undefined,
wallet.getOrFail(MISSING_WALLET),
block.getOrElse(0),
lockboxAccountList
lockboxAccountList,
txNotes
),
txList
)
// ProcessRemotePage :: Page -> Page
const processedTxs = ProcessTxs(
walletR,
blockHeightR,
lockboxAccountListR,
txs
)
const processedTxs = ProcessTxs(walletR, lockboxAccountList, txs, txNotes)
return addFromToAccountNames(wallet, accountList, processedTxs)
}

Expand Down
21 changes: 11 additions & 10 deletions packages/blockchain-wallet-v4/src/redux/data/btc/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import * as selectors from '../../selectors'
import Remote from '../../../remote'
import * as walletSelectors from '../../wallet/selectors'
import { MISSING_WALLET } from '../utils'
import { HDAccountList } from '../../../types'
import { HDAccountList, Wallet } from '../../../types'
import { getLockboxBtcAccounts } from '../../kvStore/lockbox/selectors'
import { getAddressLabels } from '../../kvStore/btc/selectors'
import * as transactions from '../../../transactions'

const transformTx = transactions.btc.transformTx

const TX_PER_PAGE = 10

export default ({ api }) => {
Expand Down Expand Up @@ -123,27 +123,28 @@ export default ({ api }) => {
// Remote(wallet)
const wallet = yield select(walletSelectors.getWallet)
const walletR = Remote.of(wallet)
// Remote(blockHeight)
const blockHeightR = yield select(S.getLatestBlock)
// Remote(lockboxXpubs)
const accountListR = (yield select(getLockboxBtcAccounts))
.map(HDAccountList.fromJS)
.getOrElse([])
const addressLabels = (yield select(getAddressLabels)).getOrElse({})
const txNotes = Wallet.selectTxNotes(wallet)

// transformTx :: wallet -> blockHeight -> Tx
// ProcessPage :: wallet -> blockHeight -> [Tx] -> [Tx]
const ProcessTxs = (wallet, block, accountList, txList) =>
// transformTx :: wallet -> Tx
// ProcessPage :: wallet -> [Tx] -> [Tx]
const ProcessTxs = (wallet, accountList, txList, txNotes, addressLabels) =>
map(
transformTx.bind(
undefined,
wallet.getOrFail(MISSING_WALLET),
block.getOrElse(0),
accountList
accountList,
txNotes,
addressLabels
),
txList
)
// ProcessRemotePage :: Page -> Page
return ProcessTxs(walletR, blockHeightR, accountListR, txs)
return ProcessTxs(walletR, accountListR, txs, txNotes, addressLabels)
}

const fetchFiatAtTime = function*(action) {
Expand Down
6 changes: 2 additions & 4 deletions packages/blockchain-wallet-v4/src/redux/data/eth/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as AT from './actionTypes'
import * as S from './selectors'
import * as selectors from '../../selectors'
import * as kvStoreSelectors from '../../kvStore/eth/selectors'
import { getLockboxEthContext } from '../../kvStore/lockbox/selectors.js'
import { getLockboxEthContext } from '../../kvStore/lockbox/selectors'
import * as transactions from '../../../transactions'

const transformTx = transactions.eth.transformTx
Expand Down Expand Up @@ -124,13 +124,11 @@ export default ({ api }) => {
const __processTxs = function*(txs) {
const accountsR = yield select(kvStoreSelectors.getAccounts)
const addresses = accountsR.getOrElse([]).map(prop('addr'))
const blockHeightR = yield select(S.getHeight)
const blockHeight = blockHeightR.getOrElse(0)
const lockboxContextR = yield select(getLockboxEthContext)
const lockboxContext = lockboxContextR.getOrElse([])
const state = yield select()
const ethAddresses = concat(addresses, lockboxContext)
return map(transformTx(ethAddresses, blockHeight, state), txs)
return map(transformTx(ethAddresses, state), txs)
}

const fetchLegacyBalance = function*() {
Expand Down
11 changes: 5 additions & 6 deletions packages/blockchain-wallet-v4/src/redux/data/xlm/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as S from './selectors'
import * as selectors from '../../selectors'
import Remote from '../../../remote'
import { xlm } from '../../../transactions'
import { getAccounts } from '../../kvStore/xlm/selectors'
import { getAccounts, getXlmTxNotes } from '../../kvStore/xlm/selectors'
import { getLockboxXlmAccounts } from '../../kvStore/lockbox/selectors'

const { transformTx, decodeOperations, isLumenOperation } = xlm
Expand Down Expand Up @@ -128,17 +128,16 @@ export default ({ api, networks }) => {
}

const __processTxs = function*(txList) {
const walletAccountsR = yield select(getAccounts)
const walletAccounts = walletAccountsR.getOrElse([])
const lockboxAccountsR = yield select(getLockboxXlmAccounts)
const lockboxAccounts = lockboxAccountsR.getOrElse([])
const walletAccounts = (yield select(getAccounts)).getOrElse([])
const lockboxAccounts = (yield select(getLockboxXlmAccounts)).getOrElse([])
const txNotes = (yield select(getXlmTxNotes)).getOrElse({})
const accounts = concat(walletAccounts, lockboxAccounts)
return unnest(
map(tx => {
const operations = decodeOperations(tx)
return compose(
filter(prop('belongsToWallet')),
map(transformTx(accounts, tx)),
map(transformTx(accounts, txNotes, tx)),
filter(isLumenOperation)
)(operations)
}, txList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export const getUnspendableContext = state =>
export const getDefaultAccountIndex = state =>
getMetadata(state).map(path(['value', 'default_account_idx']))

export const getBsvTxNotes = state =>
getMetadata(state).map(path(['value', 'tx_notes']))

export const getBsvTxNote = (state, txHash) =>
getMetadata(state).map(path(['value', 'tx_notes', txHash]))

Expand Down
Loading

0 comments on commit c3de7aa

Please sign in to comment.