diff --git a/src/bch/bch-account.js b/src/bch/bch-account.js index e4f97b3ff..3ffe0000d 100644 --- a/src/bch/bch-account.js +++ b/src/bch/bch-account.js @@ -1,5 +1,6 @@ /* eslint-disable semi */ const BchSpendable = require('./bch-spendable') +const BchShiftPayment = require('../shift/bch-payment'); const ACCOUNT_LABEL_PREFIX = 'Bitcoin Cash - ' @@ -50,6 +51,10 @@ class BchAccount extends BchSpendable { createPayment () { return super.createPayment().from(this.index, this.changeAddress) } + + createShiftPayment (wallet) { + return BchShiftPayment.fromWallet(wallet, this) + } } module.exports = BchAccount diff --git a/src/eth/eth-account.js b/src/eth/eth-account.js index 954973d33..6e4abf3ef 100644 --- a/src/eth/eth-account.js +++ b/src/eth/eth-account.js @@ -3,6 +3,7 @@ const EthTxBuilder = require('./eth-tx-builder'); const EthWalletTx = require('./eth-wallet-tx'); const API = require('../api'); const { toBigNumber, toWei, fromWei } = require('../helpers'); +const EthShiftPayment = require('../shift/eth-payment'); class EthAccount { constructor (obj) { @@ -143,6 +144,10 @@ class EthAccount { }); } + createShiftPayment (wallet) { + return EthShiftPayment.fromWallet(wallet, this); + } + static privateKeyToAddress (privateKey) { return ethUtil.toChecksumAddress(ethUtil.privateToAddress(privateKey).toString('hex')); } diff --git a/src/hd-account.js b/src/hd-account.js index afaab145b..f726bc028 100644 --- a/src/hd-account.js +++ b/src/hd-account.js @@ -8,6 +8,7 @@ var MyWallet = require('./wallet'); // This cyclic import should be avoided once var API = require('./api'); var Transaction = require('./transaction'); var constants = require('./constants'); +var BtcShiftPayment = require('./shift/btc-payment'); // HDAccount Class @@ -318,3 +319,7 @@ HDAccount.prototype.getAvailableBalance = function (feeType) { return { amount, fee: fees[feeType] }; }); }; + +HDAccount.prototype.createShiftPayment = function (wallet) { + return BtcShiftPayment.fromWallet(wallet, this); +}; diff --git a/src/shift/index.js b/src/shift/index.js index 6811e6480..53412bdd8 100644 --- a/src/shift/index.js +++ b/src/shift/index.js @@ -3,9 +3,6 @@ const { delay, asyncOnce, trace } = require('../helpers') const Api = require('./api') const Trade = require('./trade') const Quote = require('./quote') -const BtcPayment = require('./btc-payment') -const EthPayment = require('./eth-payment') -const BchPayment = require('./bch-payment') const METADATA_TYPE_SHAPE_SHIFT = 6; @@ -53,28 +50,13 @@ class ShapeShift { buildPayment (quote, fee, fromAccount) { trace('building payment') - let payment if (quote.depositAddress == null) { throw new Error('Quote is missing deposit address') } - if (fromAccount != null && fromAccount.coinCode !== quote.fromCurrency) { + if (fromAccount.coinCode !== quote.fromCurrency) { throw new Error('Sending account currency does not match quote deposit currency') } - if (quote.fromCurrency === 'btc') { - let account = fromAccount || this._wallet.hdwallet.defaultAccount - payment = BtcPayment.fromWallet(this._wallet, account) - } - if (quote.fromCurrency === 'eth') { - let account = fromAccount || this._wallet.eth.defaultAccount - payment = EthPayment.fromWallet(this._wallet, account) - } - if (quote.fromCurrency === 'bch') { - let account = fromAccount || this._wallet.bch.defaultAccount - payment = BchPayment.fromWallet(this._wallet, account) - } - if (payment == null) { - throw new Error(`Tried to build for unsupported currency ${quote.fromCurrency}`) - } + let payment = fromAccount.createShiftPayment(this._wallet) return payment.setFromQuote(quote, fee) }