Skip to content

Commit

Permalink
fix(imported addrs): request screen balance
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Jun 3, 2021
1 parent 37a15d9 commit 0e6a593
Showing 1 changed file with 11 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import { ExtractSuccess } from 'blockchain-wallet-v4/src/remote/types'
import { createDeepEqualSelector } from 'blockchain-wallet-v4/src/utils'
import { CoinType } from 'core/types'
import { CoinAccountSelectorType } from 'data/coins/types'
import {
generateInterestAccount,
generateTradingAccount
} from 'data/coins/utils'
import { generateInterestAccount, generateTradingAccount } from 'data/coins/utils'

import { getInterestBalance, getTradingBalance } from '../'
import { getInterestBalance, getTradingBalance } from '..'

// retrieves introduction text for coin on its transaction page
export const getTransactionPageHeaderText = () => (
Expand All @@ -34,14 +31,7 @@ export const getAccounts = createDeepEqualSelector(
(state, { coin }) => getInterestBalance(coin, state), // custodial accounts
(state, ownProps): CoinAccountSelectorType & { coin: CoinType } => ownProps // selector config
],
(
btcAccounts,
btcDataR,
importedAddressesR,
sbBalanceR,
interestBalanceR,
ownProps
) => {
(btcAccounts, btcDataR, importedAddressesR, sbBalanceR, interestBalanceR, ownProps) => {
const transform = (
btcData,
importedAddresses,
Expand All @@ -54,25 +44,19 @@ export const getAccounts = createDeepEqualSelector(
if (ownProps?.nonCustodialAccounts) {
// each account has a derivations object with legacy xpub and segwit xpub
// need to extract each xpub for balance
const xpubArray = acc =>
prop('derivations', acc).map(derr => prop('xpub', derr))
const xpubBalance = acc =>
xpubArray(acc).map(xpub =>
prop<string, any>('final_balance', prop(xpub, btcData))
)
const xpubArray = (acc) => prop('derivations', acc).map((derr) => prop('xpub', derr))
const xpubBalance = (acc) =>
xpubArray(acc).map((xpub) => prop<string, any>('final_balance', prop(xpub, btcData)))
accounts = accounts.concat(
btcAccounts
.map(acc => ({
.map((acc) => ({
accountIndex: prop('index', acc),
address: prop('index', acc),
archived: prop('archived', acc),
// TODO: SEGWIT remove w/ DEPRECATED_V3
balance: acc.derivations
? xpubBalance(acc).reduce(add, 0)
: prop<string, any>(
'final_balance',
prop(prop('xpub', acc), btcData)
),
: prop<string, any>('final_balance', prop(prop('xpub', acc), btcData)),
baseCoin: coin,
coin,
label: prop('label', acc) || prop('xpub', acc),
Expand All @@ -85,9 +69,9 @@ export const getAccounts = createDeepEqualSelector(
// add imported addresses if requested
if (ownProps?.importedAddresses) {

This comment has been minimized.

Copy link
@gard67

gard67 Jun 5, 2021

11G5YNWhhcm3FmMz9wZeAQjw2yukW5dWJyo

accounts = accounts.concat(
importedAddresses.map(importedAcc => ({
importedAddresses.map((importedAcc) => ({
address: importedAcc.addr,
balance: importedAcc.final_balance,
balance: importedAcc.info.final_balance,
baseCoin: coin,
coin,
label: importedAcc.label || importedAcc.addr,
Expand All @@ -114,11 +98,6 @@ export const getAccounts = createDeepEqualSelector(
return accounts
}

return lift(transform)(
btcDataR,
importedAddressesR,
sbBalanceR,
interestBalanceR
)
return lift(transform)(btcDataR, importedAddressesR, sbBalanceR, interestBalanceR)
}
)

0 comments on commit 0e6a593

Please sign in to comment.