From 1f3c2d4b6fcbf71598db6f9ecf432a05821d74dc Mon Sep 17 00:00:00 2001 From: Philip Welber Date: Sat, 30 Jun 2018 20:35:09 -0400 Subject: [PATCH] fix(Partner Labels): refactor --- .../TransactionListItem/PartnerLabel/index.js | 30 +++++-------------- .../TransactionListItem/template.js | 7 ++--- .../modals/SfoxExchangeData/sift-science.js | 8 ++--- .../Transactions/Bch/Content/Pages/index.js | 4 +-- .../Bch/Content/Pages/template.success.js | 2 +- .../scenes/Transactions/Bch/Content/index.js | 4 +-- .../Transactions/Bch/Content/selectors.js | 6 ++-- .../Transactions/Bch/Content/template.js | 2 +- .../Bitcoin/Content/Pages/index.js | 4 +-- .../Bitcoin/Content/Pages/template.success.js | 2 -- .../Transactions/Bitcoin/Content/index.js | 4 +-- .../Transactions/Bitcoin/Content/selectors.js | 7 +---- .../Transactions/Bitcoin/Content/template.js | 2 +- .../Transactions/Ether/Content/Pages/index.js | 4 +-- .../Ether/Content/Pages/template.success.js | 2 +- .../Transactions/Ether/Content/index.js | 4 +-- .../Transactions/Ether/Content/selectors.js | 8 ++--- .../Transactions/Ether/Content/template.js | 2 +- .../src/redux/common/bch/selectors.js | 4 ++- .../src/redux/common/btc/selectors.js | 13 ++++---- .../src/redux/common/eth/selectors.js | 4 ++- .../src/redux/kvStore/buySell/selectors.js | 9 +++++- .../src/redux/kvStore/shapeShift/selectors.js | 15 +++++++++- .../src/transactions/bitcoin.js | 3 +- .../src/transactions/ethereum.js | 3 +- 25 files changed, 75 insertions(+), 78 deletions(-) diff --git a/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/PartnerLabel/index.js b/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/PartnerLabel/index.js index 9317a8b1090..5dda3e3b9a4 100644 --- a/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/PartnerLabel/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/PartnerLabel/index.js @@ -2,8 +2,6 @@ import React from 'react' import PropTypes from 'prop-types' import { FormattedMessage } from 'react-intl' import styled from 'styled-components' -import { contains, any } from 'ramda' - import { Banner } from 'blockchain-info-components' const LabelContainer = styled.div` @@ -14,28 +12,14 @@ const PartnerBanner = styled(Banner)` ` const PartnerLabel = props => { - const { txHash, txType, shiftTrades, buysellTrades, buysellPartner } = props - - const shiftMatch = shiftTrades.map(trade => { - if (trade.hashIn === txHash) return 'shift-deposit' - if (trade.hashOut === txHash) return 'shift-receive' - }) - const isShift = (match) => match === 'shift-deposit' || match === 'shift-receive' + const { txType, partnerLabel, buysellPartner } = props - const buysellMatch = buysellTrades && buysellTrades.map(trade => { - if (trade.tx_hash === txHash) { - if (txType === 'sent') return 'sold-via' - if (txType === 'received') return 'bought-via' - } - }) - const isBuysell = (match) => match === 'sold-via' || match === 'bought-via' - - if (any(isShift)(shiftMatch)) { + if (partnerLabel === 'shift') { return ( { - contains('shift-deposit', shiftMatch) + txType === 'sent' ? : } @@ -44,16 +28,16 @@ const PartnerLabel = props => { ) } - if (buysellTrades && any(isBuysell)(buysellMatch)) { + if (partnerLabel === 'buy-sell' && buysellPartner) { return ( - + { - contains('sold-via', buysellMatch) + txType === 'sent' ? : } - + ) } diff --git a/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/template.js b/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/template.js index 409368eb4b6..ce35ad808d7 100644 --- a/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/template.js +++ b/packages/blockchain-wallet-v4-frontend/src/components/TransactionListItem/template.js @@ -113,8 +113,7 @@ const dateHelper = (time) => { } const TransactionListItem = (props) => { - const { handleCoinToggle, transaction, handleEditDescription, coin, minConfirmations, shiftTrades, buysellTrades, buysellPartner } = props - const hasLabel = prop('length', shiftTrades) || prop('length', buysellTrades) + const { handleCoinToggle, transaction, handleEditDescription, coin, minConfirmations, buysellPartner } = props return ( @@ -130,8 +129,8 @@ const TransactionListItem = (props) => { )} { - hasLabel - ? + prop('partnerLabel', transaction) + ? : null } diff --git a/packages/blockchain-wallet-v4-frontend/src/modals/SfoxExchangeData/sift-science.js b/packages/blockchain-wallet-v4-frontend/src/modals/SfoxExchangeData/sift-science.js index a0fb3367d0e..d018c94b888 100644 --- a/packages/blockchain-wallet-v4-frontend/src/modals/SfoxExchangeData/sift-science.js +++ b/packages/blockchain-wallet-v4-frontend/src/modals/SfoxExchangeData/sift-science.js @@ -47,13 +47,9 @@ class SiftScience extends Component { const helperDomain = path(['domains', 'walletHelper'], walletOptions) const sfoxSiftScience = path(['platforms', 'web', 'sfox', 'config', 'siftScience'], walletOptions) - let url = `${helperDomain}/wallet-helper/sift-science/#/key/${sfoxSiftScience}/user/${userId.getOrElse()}` + let url = `${helperDomain}/wallet-helper/sift-science/#/key/${sfoxSiftScience}/user/${userId}` url += tradeId ? `/trade/${tradeId}` : '' - if (!userId.getOrElse(null)) { - return null - } - if (siftScienceEnabled) { return ( ({ walletOptions: path(['walletOptionsPath'], state), - userId: selectors.core.kvStore.buySell.getSfoxUser(state).getOrElse(undefined), + userId: selectors.core.kvStore.buySell.getSfoxUser(state).getOrElse(null), siftScienceEnabled: path(['sfoxSignup', 'siftScienceEnabled'], state), trades: selectors.core.data.sfox.getTrades(state).getOrElse([]) }) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/index.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/index.js index 9c76c5f76a1..24d3ec5a321 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/index.js @@ -6,10 +6,10 @@ import Success from './template.success' class Pages extends React.PureComponent { render () { - const { data, shiftTrades } = this.props + const { data } = this.props return data.cata({ - Success: (value) => , + Success: (value) => , Failure: () => this.props.onRefresh()} />, Loading: () => , NotAsked: () => diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/template.success.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/template.success.js index 2c858456c72..4c7c0b72233 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/template.success.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/Pages/template.success.js @@ -15,7 +15,7 @@ const Wrapper = styled.div` const Success = props => { return ( - {props.transactions.map((transaction, index) => )} + {props.transactions.map((transaction, index) => )} ) } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/index.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/index.js index 04db8e07778..a7e17173ba2 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/index.js @@ -22,8 +22,8 @@ class ContentContainer extends React.PureComponent { } render () { - const { empty, pages, search, shiftTrades } = this.props - return + const { empty, pages, search } = this.props + return } } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/selectors.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/selectors.js index 182150b832a..215bf00d58d 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/selectors.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/selectors.js @@ -13,8 +13,7 @@ const filterTransactions = curry((status, criteria, transactions) => { export const getData = createSelector( [ selectors.form.getFormValues('bchTransactions'), - selectors.core.common.bch.getWalletTransactions, - selectors.core.kvStore.shapeShift.getTrades + selectors.core.common.bch.getWalletTransactions ], (formValues, pages, trades) => { const empty = (page) => isEmpty(page.data) @@ -27,8 +26,7 @@ export const getData = createSelector( return { pages: filteredPages, empty: all(empty)(filteredPages), - search: search.length > 0 || status !== '', - shiftTrades: trades.getOrElse([]) + search: search.length > 0 || status !== '' } } ) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/template.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/template.js index 33bc9f4b4c9..a577d58f6b0 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/template.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bch/Content/template.js @@ -17,7 +17,7 @@ const Success = props => { {props.empty ? props.search ? : - : props.pages.map((value, index) => ) + : props.pages.map((value, index) => ) } ) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/index.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/index.js index aa3e06be307..1aa1ef0cc8c 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/index.js @@ -6,10 +6,10 @@ import Success from './template.success' class Pages extends React.PureComponent { render () { - const { data, shiftTrades, buysellTrades, buysellPartner } = this.props + const { data, buysellPartner } = this.props return data.cata({ - Success: (value) => , + Success: (value) => , Failure: () => this.props.onRefresh()} />, Loading: () => , NotAsked: () => diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/template.success.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/template.success.js index 484c74461c4..4029ca1a8d0 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/template.success.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/Pages/template.success.js @@ -20,8 +20,6 @@ const Success = props => { transaction={transaction} coin='BTC' minConfirmations={3} - shiftTrades={props.shiftTrades} - buysellTrades={props.buysellTrades} buysellPartner={props.buysellPartner} />)} diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/index.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/index.js index 96f4ea47acb..40a8d45259d 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/index.js @@ -22,9 +22,9 @@ class ContentContainer extends React.PureComponent { } render () { - const { empty, pages, search, shiftTrades, buysellTrades, buysellPartner } = this.props + const { empty, pages, search, buysellPartner } = this.props - return + return } } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/selectors.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/selectors.js index 7c3eaebf8cb..cfae6872c07 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/selectors.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/selectors.js @@ -15,12 +15,9 @@ export const getData = createSelector( [ selectors.form.getFormValues('btcTransactions'), selectors.core.common.btc.getWalletTransactions, - selectors.core.kvStore.shapeShift.getTrades, - selectors.core.kvStore.buySell.getSfoxTrades, - selectors.core.kvStore.buySell.getCoinifyTrades, selectors.core.kvStore.buySell.getMetadata ], - (formValues, pages, trades, sfoxTrades, coinifyTrades, buysellMetadata) => { + (formValues, pages, buysellMetadata) => { const empty = (page) => isEmpty(page.data) const search = propOr('', 'search', formValues) const status = propOr('', 'status', formValues) @@ -33,8 +30,6 @@ export const getData = createSelector( pages: filteredPages, empty: all(empty)(filteredPages), search: search.length > 0 || status !== '', - shiftTrades: trades.getOrElse([]), - buysellTrades: sfoxTrades.getOrElse([]).concat(coinifyTrades.getOrElse([])), buysellPartner: hasAccount(partnerData) } } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/template.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/template.js index dc64a67a92b..1dfe9484dc1 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/template.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Bitcoin/Content/template.js @@ -17,7 +17,7 @@ const Success = props => { {props.empty ? props.search ? : - : props.pages.map((value, index) => ) + : props.pages.map((value, index) => ) } ) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/index.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/index.js index 9c76c5f76a1..24d3ec5a321 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/index.js @@ -6,10 +6,10 @@ import Success from './template.success' class Pages extends React.PureComponent { render () { - const { data, shiftTrades } = this.props + const { data } = this.props return data.cata({ - Success: (value) => , + Success: (value) => , Failure: () => this.props.onRefresh()} />, Loading: () => , NotAsked: () => diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/template.success.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/template.success.js index ad838b66740..b712ede5f87 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/template.success.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/Pages/template.success.js @@ -15,7 +15,7 @@ const Wrapper = styled.div` const Success = props => { return ( - {props.transactions.map((transaction, index) => )} + {props.transactions.map((transaction, index) => )} ) } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/index.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/index.js index 45644757227..e2345a0616e 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/index.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/index.js @@ -22,8 +22,8 @@ class ContentContainer extends React.PureComponent { } render () { - const { empty, pages, search, shiftTrades } = this.props - return + const { empty, pages, search } = this.props + return } } diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/selectors.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/selectors.js index bbf765f91d0..b2844cbd592 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/selectors.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/selectors.js @@ -13,10 +13,9 @@ const filterTransactions = curry((status, criteria, transactions) => { export const getData = createSelector( [ selectors.form.getFormValues('ethTransactions'), - selectors.core.common.eth.getWalletTransactions, - selectors.core.kvStore.shapeShift.getTrades + selectors.core.common.eth.getWalletTransactions ], - (formValues, pages, trades) => { + (formValues, pages) => { const empty = (page) => isEmpty(page.data) const search = propOr('', 'search', formValues) const status = propOr('', 'status', formValues) @@ -27,8 +26,7 @@ export const getData = createSelector( return { pages: filteredPages, empty: all(empty)(filteredPages), - search: search.length > 0 || status !== '', - shiftTrades: trades.getOrElse([]) + search: search.length > 0 || status !== '' } } ) diff --git a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/template.js b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/template.js index 33bc9f4b4c9..a577d58f6b0 100644 --- a/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/template.js +++ b/packages/blockchain-wallet-v4-frontend/src/scenes/Transactions/Ether/Content/template.js @@ -17,7 +17,7 @@ const Success = props => { {props.empty ? props.search ? : - : props.pages.map((value, index) => ) + : props.pages.map((value, index) => ) } ) diff --git a/packages/blockchain-wallet-v4/src/redux/common/bch/selectors.js b/packages/blockchain-wallet-v4/src/redux/common/bch/selectors.js index 324a27206e3..b2ba6c1e743 100644 --- a/packages/blockchain-wallet-v4/src/redux/common/bch/selectors.js +++ b/packages/blockchain-wallet-v4/src/redux/common/bch/selectors.js @@ -7,6 +7,7 @@ import Remote from '../../../remote' import { getAccountsList, getBchTxNote } from '../../kvStore/bch/selectors.js' import { toCashAddr } from '../../../utils/bch' import { isValidBitcoinAddress } from '../../../utils/bitcoin' +import { getShapeshiftTxHashMatch } from '../../kvStore/shapeShift/selectors' const mTransformTx = transactions.bitcoin.transformTx @@ -114,10 +115,11 @@ export const getWalletTransactions = state => { // [Remote([tx])] == [Page] == Pages const getDescription = (hash) => getBchTxNote(state, hash).getOrElse('') const pages = getTransactions(state) + const getPartnerLabel = hash => getShapeshiftTxHashMatch(state, hash) // mTransformTx :: wallet -> blockHeight -> Tx // ProcessPage :: wallet -> blockHeight -> [Tx] -> [Tx] const ProcessTxs = (wallet, block, txList) => - map(mTransformTx.bind(undefined, wallet, block, getDescription, undefined), txList) + map(mTransformTx.bind(undefined, wallet, block, getDescription, getPartnerLabel), txList) // ProcessRemotePage :: Page -> Page const ProcessPage = lift(ProcessTxs)(walletR, blockHeightR) const txs = map(ProcessPage, pages) diff --git a/packages/blockchain-wallet-v4/src/redux/common/btc/selectors.js b/packages/blockchain-wallet-v4/src/redux/common/btc/selectors.js index d3a4679865a..f240e2ed7f8 100644 --- a/packages/blockchain-wallet-v4/src/redux/common/btc/selectors.js +++ b/packages/blockchain-wallet-v4/src/redux/common/btc/selectors.js @@ -1,13 +1,14 @@ import { Wallet, HDWallet, HDAccountList, HDAccount, TXNotes } from '../../../types' import { keys, compose, assoc, isNil, map, max, path, prop, curry, split, values, sequence, lift } from 'ramda' -import memoize from 'fast-memoize' import { getAddresses, getChangeIndex, getReceiveIndex, getHeight, getTransactions } from '../../data/bitcoin/selectors.js' -import { getAddressLabel, getMetadata } from '../../kvStore/btc/selectors' +import { getAddressLabel } from '../../kvStore/btc/selectors' +import { getBuySellTxHashMatch } from '../../kvStore/buySell/selectors' +import { getShapeshiftTxHashMatch } from '../../kvStore/shapeShift/selectors' import * as transactions from '../../../transactions' import * as walletSelectors from '../../wallet/selectors' import Remote from '../../../remote' -const mTransformTx = memoize(transactions.bitcoin.transformTx) +const mTransformTx = transactions.bitcoin.transformTx const _getAccounts = selector => state => { const balancesR = getAddresses(state) @@ -113,12 +114,14 @@ export const getWalletTransactions = state => { // [Remote([tx])] == [Page] == Pages const getDescription = (hash, to) => TXNotes.selectNote(hash, Wallet.selectTxNotes(wallet)) || getAddressLabel(to, state).getOrElse('') + const getPartnerLabel = hash => getShapeshiftTxHashMatch(state, hash) || getBuySellTxHashMatch(state, hash) + const pages = getTransactions(state) - const metadata = getMetadata(state) + // mTransformTx :: wallet -> blockHeight -> Tx // ProcessPage :: wallet -> blockHeight -> [Tx] -> [Tx] const ProcessTxs = (wallet, block, txList) => - map(mTransformTx.bind(undefined, wallet, block, getDescription, metadata), txList) + map(mTransformTx.bind(undefined, wallet, block, getDescription, getPartnerLabel), txList) // ProcessRemotePage :: Page -> Page const ProcessPage = lift(ProcessTxs)(walletR, blockHeightR) return map(ProcessPage, pages) diff --git a/packages/blockchain-wallet-v4/src/redux/common/eth/selectors.js b/packages/blockchain-wallet-v4/src/redux/common/eth/selectors.js index 7a5fb333cd9..75bf737a4fc 100644 --- a/packages/blockchain-wallet-v4/src/redux/common/eth/selectors.js +++ b/packages/blockchain-wallet-v4/src/redux/common/eth/selectors.js @@ -2,6 +2,7 @@ import { lift, map, path, prop } from 'ramda' import { getAddresses, getTransactions, getHeight } from '../../data/ethereum/selectors.js' import { getAccounts } from '../../kvStore/ethereum/selectors.js' import * as transactions from '../../../transactions' +import { getShapeshiftTxHashMatch } from '../../kvStore/shapeShift/selectors' export const getAccountBalances = (state) => { const digest = (addresses, account) => ({ @@ -30,8 +31,9 @@ export const getWalletTransactions = (state) => { const blockHeightR = getHeight(state) const addressesR = accountsR.map(map(prop('addr'))) const pages = getTransactions(state) + const getPartnerLabel = hash => getShapeshiftTxHashMatch(state, hash) const ProcessTxs = (addresses, blockHeight, txList) => { - return map(mTransformTx(addresses, blockHeight, state), txList) + return map(mTransformTx(addresses, blockHeight, state, getPartnerLabel), txList) } const ProcessPage = lift(ProcessTxs)(addressesR, blockHeightR) return map(ProcessPage, pages) diff --git a/packages/blockchain-wallet-v4/src/redux/kvStore/buySell/selectors.js b/packages/blockchain-wallet-v4/src/redux/kvStore/buySell/selectors.js index 8ece96d8776..eb39f0e6842 100644 --- a/packages/blockchain-wallet-v4/src/redux/kvStore/buySell/selectors.js +++ b/packages/blockchain-wallet-v4/src/redux/kvStore/buySell/selectors.js @@ -1,4 +1,4 @@ -import { path } from 'ramda' +import { path, concat, contains } from 'ramda' import { BUYSELL } from '../config' import { kvStorePath } from '../../paths' @@ -9,3 +9,10 @@ export const getSfoxTrades = state => getMetadata(state).map(path(['value', 'sfo export const getSfoxUser = state => getMetadata(state).map(path(['value', 'sfox', 'user'])) export const getCoinifyTrades = state => getMetadata(state).map(path(['value', 'coinify', 'trades'])) + +export const getBuySellTxHashMatch = (state, hash) => getMetadata(state).map(data => { + const allTrades = concat(getSfoxTrades(state).getOrElse([]), getCoinifyTrades(state).getOrElse([])) + const tradeHashes = allTrades.map(t => t.tx_hash) + const shouldHaveLabel = contains(hash, tradeHashes) + return shouldHaveLabel && 'buy-sell' +}).getOrElse(false) diff --git a/packages/blockchain-wallet-v4/src/redux/kvStore/shapeShift/selectors.js b/packages/blockchain-wallet-v4/src/redux/kvStore/shapeShift/selectors.js index 2bee9f5dd0b..21d9e310e4a 100644 --- a/packages/blockchain-wallet-v4/src/redux/kvStore/shapeShift/selectors.js +++ b/packages/blockchain-wallet-v4/src/redux/kvStore/shapeShift/selectors.js @@ -1,4 +1,4 @@ -import { compose, curry, filter, head, path, reverse } from 'ramda' +import { compose, curry, filter, head, path, reverse, contains } from 'ramda' import { SHAPESHIFT } from '../config' import { kvStorePath } from '../../paths' @@ -7,3 +7,16 @@ export const getUsState = state => getMetadata(state).map(path(['value', 'USASta export const getTrades = state => getMetadata(state).map(path(['value', 'trades'])).map(trades => reverse(trades)) export const getTrade = curry((address, state) => getTrades(state) .map(compose(head, filter(x => path(['quote', 'deposit'], x) === address)))) + +export const getShapeshiftTxHashMatch = (state, hash) => getMetadata(state).map(data => { + const trades = getTrades(state).getOrElse([]) + + const tradesHashIn = trades.map(t => t.hashIn) + const tradesHashOut = trades.map(t => t.hashOut) + + const hasHashInLabel = contains(hash, tradesHashIn) + const hasHashOutLabel = contains(hash, tradesHashOut) + + if (hasHashInLabel || hasHashOutLabel) return 'shift' + return null +}).getOrElse(false) diff --git a/packages/blockchain-wallet-v4/src/transactions/bitcoin.js b/packages/blockchain-wallet-v4/src/transactions/bitcoin.js index f5e572cf329..decf6e40cad 100644 --- a/packages/blockchain-wallet-v4/src/transactions/bitcoin.js +++ b/packages/blockchain-wallet-v4/src/transactions/bitcoin.js @@ -167,7 +167,7 @@ export const getTime = tx => { : date.format('MMMM D YYYY @ h:mm A') } -export const _transformTx = (wallet, currentBlockHeight, getDescription, meta, tx) => { +export const _transformTx = (wallet, currentBlockHeight, getDescription, getPartnerLabel, tx) => { const conf = currentBlockHeight - tx.block_height + 1 const confirmations = conf > 0 ? conf : 0 const type = txtype(tx.result, tx.fee) @@ -188,6 +188,7 @@ export const _transformTx = (wallet, currentBlockHeight, getDescription, meta, t amount: computeAmount(type, inputData, outputData), type: toLower(type), description: getDescription(tx.hash, toAddress), + partnerLabel: typeof getPartnerLabel === 'function' && getPartnerLabel(tx.hash), time: tx.time, timeFormatted: getTime(tx), fee: tx.fee, diff --git a/packages/blockchain-wallet-v4/src/transactions/ethereum.js b/packages/blockchain-wallet-v4/src/transactions/ethereum.js index 430ced869f9..47787df949b 100644 --- a/packages/blockchain-wallet-v4/src/transactions/ethereum.js +++ b/packages/blockchain-wallet-v4/src/transactions/ethereum.js @@ -37,7 +37,7 @@ export const getLabel = (address, state) => { return labelR.getOrElse(address) } -export const _transformTx = curry((addresses, latestBlock, state, tx) => { +export const _transformTx = curry((addresses, latestBlock, state, getPartnerLabel, tx) => { const fee = getFee(tx) const type = toLower(getType(tx, addresses)) const amount = type === 'sent' ? parseInt(tx.value) + parseInt(fee) : parseInt(tx.value) @@ -49,6 +49,7 @@ export const _transformTx = curry((addresses, latestBlock, state, tx) => { to: getLabel(tx.to, state), from: getLabel(tx.from, state), description: getEthereumTxNote(state, tx.hash).data || '', + partnerLabel: getPartnerLabel && getPartnerLabel(tx.hash), confirmations: getConfirmations(tx.blockNumber, latestBlock), timeFormatted: getTime(tx), time: tx.timeStamp