add coin to preferences/info

+ refactor duplicate
This commit is contained in:
matiu 2017-09-08 16:37:26 -03:00
commit acc1549633
13 changed files with 212 additions and 146 deletions

View file

@ -50,16 +50,6 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
});
};
$scope.openBitcoinCashWeb = function() {
var url = 'https://www.bitcoincash.org/';
var optIn = true;
var title = null;
var message = gettextCatalog.getString('Open bitcoincash.org?');
var okText = gettextCatalog.getString('Open');
var cancelText = gettextCatalog.getString('Go Back');
externalLinkService.open(url, optIn, title, message, okText, cancelText);
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
updateConfig();

View file

@ -1,97 +0,0 @@
'use strict';
angular.module('copayApp.controllers').controller('otherBalanceController',
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, bwcError ) {
var wallet;
var listeners = [];
var notifications = [];
$scope.isCordova = platformInfo.isCordova;
$scope.isAndroid = platformInfo.isAndroid;
$scope.isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
$scope.isNW = platformInfo.isNW;
$scope.$on("$ionicView.enter", function(event, data) {
updateAllWallets();
});
var updateAllWallets = function() {
var wallets = profileService.getWallets({coin:'btc', onlyComplete:true, network: 'livenet' });
// TODO ?
if (lodash.isEmpty(wallets)) return;
console.log('[otherBalance.js.24:wallets:]',wallets); //TODO
var walletsBCH = profileService.getWallets({coin:'bch', network: 'livenet' });
var xPubKeyIndex = lodash.indexBy(walletsBCH,"credentials.xPubKey");
console.log('[otherBalance.js.28:xPubKeyIndex:]',xPubKeyIndex); //TODO
wallets= lodash.filter(wallets,function(w) { return xPubKeyIndex[w.credentials.xPubKey]; });
console.log('[otherBalance.js.31:wallets:]',wallets); //TODO
// TODO Filterout already duplicated walelts
// TODO filterout balance=0 wallets
//
//
$scope.wallets = wallets;
var i = wallets.length;
var j = 0;
lodash.each(wallets, function(wallet) {
walletService.getBalance(wallet, {coin:'bch'}, function(err, status) {
if (err) {
wallet.error = (err === 'WALLET_NOT_REGISTERED') ? gettextCatalog.getString('Wallet not registered') : bwcError.msg(err);
$log.error(err);
return;
}
//
console.log('[otherBalance.js.28:status:]',status); //TODO
wallet.error = null;
wallet.status = status;
if (++j == i) {
//
}
});
});
};
$scope.duplicate = function(wallet) {
$log.debug('Duplicating wallet for BCH:' + wallet.id + ':' + wallet.name);
var opts = {};
opts.name = wallet.name + '[BCH]';
opts.m = wallet.m;
opts.n = wallet.n;
opts.myName = wallet.credentials.copayerName;
opts.networkName = wallet.network;
opts.coin = 'bch';
// TODO: finger print / decrypt
$log.warn('TODO finger print / decrypt');
opts.walletPrivKey = wallet.credentials.walletPrivKey;
walletService.getStatus(wallet, {}, function(err, status){
if (err) {
// TODO
$log.err('TODO Err');
return;
}
opts.singleAddress = status.wallet.singleAddress;
// create and store a wallet
profileService.createWallet(opts, function(err) {
$state.go('tabs.home');
});
});
}
});

View file

@ -0,0 +1,117 @@
'use strict';
angular.module('copayApp.controllers').controller('cashScanController',
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, txFormatService, bwcError, pushNotificationsService, bwcService) {
var wallet;
var errors = bwcService.getErrors();
$scope.error = null;
$scope.$on("$ionicView.enter", function(event, data) {
updateAllWallets();
});
var updateAllWallets = function() {
var wallets = profileService.getWallets({coin:'btc', onlyComplete:true, network: 'livenet' });
var kk = lodash.indexBy(wallets,"credentials.xPubKey");
// TODO ?
if (lodash.isEmpty(wallets)) return;
var walletsBCH = profileService.getWallets({coin:'bch', network: 'livenet' });
var xPubKeyIndex = lodash.indexBy(walletsBCH,"credentials.xPubKey");
// wallets= lodash.filter(wallets,function(w) { return !xPubKeyIndex[w.credentials.xPubKey]; });
$scope.wallets = wallets;
var i = wallets.length;
var j = 0;
lodash.each(wallets, function(wallet) {
walletService.getBalance(wallet, {coin:'bch'}, function(err, balance) {
if (err) {
wallet.error = (err === 'WALLET_NOT_REGISTERED') ? gettextCatalog.getString('Wallet not registered') : bwcError.msg(err);
$log.error(err);
return;
}
//
console.log('[otherBalance.js.28:balance:]',balance); //TODO
wallet.error = null;
wallet.bchBalance = txFormatService.formatAmountStr('bch', balance.availableAmount);
if (++j == i) {
//Done
$timeout(function() {
$rootScope.$apply();
}, 10);
}
});
});
};
$scope.duplicate = function(wallet) {
$scope.error = null;
$log.debug('Duplicating wallet for BCH:' + wallet.id + ':' + wallet.name);
var opts = {};
opts.name = wallet.name + '[BCH]';
opts.m = wallet.m;
opts.n = wallet.n;
opts.myName = wallet.credentials.copayerName;
opts.networkName = wallet.network;
opts.coin = 'bch';
// TODO: finger print / decrypt
$log.warn('TODO finger print / decrypt');
opts.extendedPrivateKey = wallet.credentials.xPrivKey;
function setErr(err, cb) {
$scope.error = bwcError.cb(err, gettextCatalog.getString('Could not duplicate'), function() {
return cb(err);
});
$timeout(function() {
$rootScope.$apply();
}, 10);
}
function importOrCreate(cb) {
walletService.getStatus(wallet, {}, function(err, status){
if (err) return cb(err);
opts.singleAddress = status.wallet.singleAddress;
// first try to import
profileService.importExtendedPrivateKey(opts.extendedPrivateKey, opts, function(err, client) {
if (err && !(err instanceof errors.NOT_AUTHORIZED) ) {
return setErr(err, cb);
}
if (err) {
// create and store a wallet
return profileService.createWallet(opts, function(err, client) {
if (err) return setErr(err, cb);
return cb(null, client, true);
});
}
return cb(null, client);
});
});
};
importOrCreate(function(err, client, isNew) {
if (err) return;
walletService.updateRemotePreferences(client);
pushNotificationsService.updateSubscription(client);
walletService.startScan(wallet, function() { });
$state.go('tabs.home');
});
}
});

View file

@ -1,12 +1,13 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesCashController', function($scope, $log, $timeout, appConfigService, lodash, configService, platformInfo, pushNotificationsService, emailService) {
angular.module('copayApp.controllers').controller('preferencesCashController', function($scope, $log, $timeout, appConfigService, lodash, configService, gettextCatalog, externalLinkService) {
var updateConfig = function() {
var config = configService.getSync();
$scope.appName = appConfigService.nameCase;
$scope.cashSupport = {
value: config.wallet.cashSupport.enabled
value: config.cashSupport
};
$timeout(function() {
@ -16,15 +17,25 @@ angular.module('copayApp.controllers').controller('preferencesCashController', f
$scope.cashSupportChange = function() {
var opts = {
wallet: {
cashSupport: $scope.cashSupport.value
}
cashSupport: $scope.cashSupport.value
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.openBitcoinCashWeb = function() {
var url = 'https://www.bitcoincash.org/';
var optIn = true;
var title = null;
var message = gettextCatalog.getString('Open bitcoincash.org?');
var okText = gettextCatalog.getString('Open');
var cancelText = gettextCatalog.getString('Go Back');
externalLinkService.open(url, optIn, title, message, okText, cancelText);
};
$scope.$on("$ionicView.enter", function(event, data) {
updateConfig();
});

View file

@ -26,7 +26,7 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
});
$scope.cashSupport = {
value: config.cashSupport.enabled
value: config.cashSupport
};