refactor duplicate

This commit is contained in:
matiu 2017-09-09 21:14:27 -03:00
commit 7349e8237a
8 changed files with 149 additions and 52 deletions

View file

@ -45,7 +45,8 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti
'cancelingGiftCard': 'Canceling Gift Card...',
'creatingGiftCard': 'Creating Gift Card...',
'buyingGiftCard': 'Buying Gift Card...',
'topup': gettext('Top up in progress...')
'topup': gettext('Top up in progress...'),
'duplicatingWallet': gettext('Duplicating wallet...'),
};
root.clear = function() {

View file

@ -386,7 +386,6 @@ angular.module('copayApp.services')
}
}
}
return cb(null, walletClient);
};
// Creates a wallet on BWC/BWS

View file

@ -259,6 +259,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
function cacheStatus(status) {
if (status.wallet && status.wallet.scanStatus == 'running') return;
wallet.cachedStatus = status ||  {};
var cache = wallet.cachedStatus;
cache.statusUpdatedOn = Date.now();
@ -931,15 +933,17 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
// Approx utxo amount, from which the uxto is economically redeemable
root.getLowAmount = function(wallet, feeLevels, nbOutputs) {
var minFee = root.getMinFee(wallet,feeLevels, nbOutputs);
return parseInt( minFee / LOW_AMOUNT_RATIO);
var minFee = root.getMinFee(wallet, feeLevels, nbOutputs);
return parseInt(minFee / LOW_AMOUNT_RATIO);
};
root.getLowUtxos = function(wallet, levels, cb) {
wallet.getUtxos({coin: wallet.coin}, function(err, resp) {
wallet.getUtxos({
coin: wallet.coin
}, function(err, resp) {
if (err || !resp || !resp.length) return cb();
var minFee = root.getMinFee(wallet, levels, resp.length);
@ -955,7 +959,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
var totalLow = lodash.sum(lowUtxos, 'satoshis');
return cb(err, {
allUtxos: resp || [],
allUtxos: resp || [],
lowUtxos: lowUtxos || [],
warning: minFee / balance > TOTAL_LOW_WARNING_RATIO,
minFee: minFee,
@ -1237,5 +1241,33 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
else return 'bitcoin';
}
root.copyCopayers = function(wallet, newWallet, cb) {
var c = wallet.credentials;
var walletPrivKey = bitcore.PrivateKey.fromString(c.walletPrivKey);
var copayer = 1,
i = 0,
l = c.publicKeyRing.length;
var mainErr = null;
lodash.each(c.publicKeyRing, function(item) {
var name = item.copayerName || ('copayer ' + copayer++);
newWallet._doJoinWallet(newWallet.credentials.walletId, walletPrivKey, item.xPubKey, item.requestPubKey, name, {
coin: newWallet.credentials.coin,
}, function(err) {
//Ignore error is copayer already in wallet
if (err && !(err instanceof errors.COPAYER_IN_WALLET)) {
mainErr = err;
}
if (++i == l) {
return cb(mainErr);
}
});
});
};
return root;
});