Skip to content

Commit

Permalink
fix - bug in payment system, could not fetch correctly BCH unspent
Browse files Browse the repository at this point in the history
fix - shapeshift reviewed validationMessage logic
  • Loading branch information
Lyncee59 committed May 30, 2018
1 parent 32f7892 commit 1b71100
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ export default ({ api, coreSagas }) => {
const source = prop('source', form)
const target = prop('target', form)
const sourceAmount = prop('sourceAmount', form)
if (isUndefinedOrEqualsToZero(sourceAmount)) {
yield put(A.firstStepFormUnvalidated('invalid'))
return yield put(A.firstStepEnabled())
}
const effectiveBalance = yield call(calculateEffectiveBalance, source)
const pair = yield call(getShapeShiftLimits, source, target)
const minimum = getMinimum(source.coin, pair.minimum)
const maximum = getMaximum(source.coin, pair.maximum, effectiveBalance)
const sourceAmountBase = convertStandardToBase(source.coin, sourceAmount)
if (isUndefinedOrEqualsToZero(sourceAmount) || isMinimumGreaterThanMaximum(minimum, maximum)) {
yield put(A.firstStepFormUnvalidated('invalid'))
} else if (isAmountBelowMinimum(effectiveBalance, minimum)) {
if (isMinimumGreaterThanMaximum(minimum, maximum)) {
yield put(A.firstStepFormUnvalidated('insufficient'))
} else if (isAmountBelowMinimum(sourceAmountBase, minimum)) {
yield put(A.firstStepFormUnvalidated('minimum'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export const isAmountAboveMaximum = (value, maximum) => {
}

export const isUndefinedOrEqualsToZero = (value) => {
return isNil(value) || new BigNumber(value).equals(new BigNumber(0))
const amount = value || 0
return new BigNumber(amount).equals(new BigNumber(0))
}

export const isMinimumGreaterThanMaximum = (minimum, maximum) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default ({ api }) => {

// Single account index
if (isPositiveInteger(origin)) {
return fromAccount(network, appState, origin)
return fromAccount(network, appState, origin, 'BCH')
}

// From private key (watch only: compressed / uncompressed, external)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default ({ api }) => {

// Single account index
if (isPositiveInteger(origin)) {
return fromAccount(network, appState, origin)
return fromAccount(network, appState, origin, 'BTC')
}

// From private key (watch only: compressed / uncompressed, external)
Expand Down
13 changes: 8 additions & 5 deletions packages/blockchain-wallet-v4/src/redux/payment/btc/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { converge, or, assoc, drop, curry, set, always, compose } from 'ramda'
import { converge, equals, or, assoc, drop, curry, set, always, compose } from 'ramda'
import * as Coin from '../../../coinSelection/coin'
import { Wallet, HDAccount, Address } from '../../../types'
import { isPositiveInteger } from '../../../utils/checks'
Expand Down Expand Up @@ -50,12 +50,15 @@ export const fromExternal = (addrComp, addrUncomp, wifComp, wifUncomp) => ({
})

// fromAccount :: Network -> ReduxState -> Object
export const fromAccount = (network, state, index) => {
export const fromAccount = (network, state, index, coin) => {
const wallet = S.wallet.getWallet(state)
let account = Wallet.getAccount(index, wallet).get()
let changeAddress = S.data.bitcoin.getChangeIndex(account.xpub, state)
.map((index) => HDAccount.getChangeAddress(account, index, network))
.getOrFail(new Error('missing_change_address'))

let changeIndex = equals(coin, 'BTC')
? S.data.bitcoin.getChangeIndex(account.xpub, state)
: S.data.bch.getChangeIndex(account.xpub, state)
let changeAddress = changeIndex.map((index) => HDAccount.getChangeAddress(account, index, network)).getOrFail('missing_change_address')

return {
fromType: FROM.ACCOUNT,
from: [account.xpub],
Expand Down

0 comments on commit 1b71100

Please sign in to comment.