delete focused wallet

This commit is contained in:
Gabriel Bazán 2016-08-19 13:09:27 -03:00
commit 6e4a1e7ff2
28 changed files with 184 additions and 194 deletions

View file

@ -1,30 +1,28 @@
'use strict';
angular.module('copayApp.controllers').controller('backupController',
function($rootScope, $scope, $timeout, $log, $state, lodash, fingerprintService, platformInfo, configService, profileService, gettext, bwcService, walletService, ongoingProcess) {
function($rootScope, $scope, $timeout, $log, $state, $stateParams, lodash, fingerprintService, platformInfo, configService, profileService, gettext, bwcService, walletService, ongoingProcess) {
var fc = profileService.focusedClient;
var prevState;
var wallet = profileService.getWallet($stateParams.walletId);
$scope.customWords = [];
$scope.walletName = fc.credentials.walletName;
$scope.credentialsEncrypted = fc.isPrivKeyEncrypted;
$scope.walletName = wallet.credentials.walletName;
$scope.credentialsEncrypted = wallet.isPrivKeyEncrypted;
$scope.init = function(state) {
prevState = state || 'walletHome';
$scope.init = function() {
$scope.step = 1;
$scope.deleted = isDeletedSeed();
if ($scope.deleted) return;
fingerprintService.check(fc, function(err) {
fingerprintService.check(wallet, function(err) {
if (err) {
go.path(prevState);
$state.transitionTo('preferences');
return;
}
handleEncryptedWallet(fc, function(err) {
handleEncryptedWallet(wallet, function(err) {
if (err) {
$log.warn('Error decrypting credentials:', $scope.error);
go.path(prevState);
$state.transitionTo('preferences');
return;
}
$scope.credentialsEncrypted = false;
@ -45,11 +43,11 @@ angular.module('copayApp.controllers').controller('backupController',
};
$scope.initFlow = function() {
var words = fc.getMnemonic();
$scope.xPrivKey = fc.credentials.xPrivKey;
var words = wallet.getMnemonic();
$scope.xPrivKey = wallet.credentials.xPrivKey;
$scope.mnemonicWords = words.split(/[\u3000\s]+/);
$scope.shuffledMnemonicWords = shuffledWords($scope.mnemonicWords);
$scope.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
$scope.mnemonicHasPassphrase = wallet.mnemonicHasPassphrase();
$scope.useIdeograms = words.indexOf("\u3000") >= 0;
$scope.passphrase = '';
$scope.customWords = [];
@ -63,17 +61,13 @@ angular.module('copayApp.controllers').controller('backupController',
};
function isDeletedSeed() {
if (lodash.isEmpty(fc.credentials.mnemonic) && lodash.isEmpty(fc.credentials.mnemonicEncrypted))
if (lodash.isEmpty(wallet.credentials.mnemonic) && lodash.isEmpty(wallet.credentials.mnemonicEncrypted))
return true;
return false;
};
$scope.goBack = function() {
$state.go('wallet.preferences');
};
$scope.$on('$destroy', function() {
walletService.lock(fc);
walletService.lock(wallet);
});
$scope.goToStep = function(n) {
@ -147,9 +141,9 @@ angular.module('copayApp.controllers').controller('backupController',
try {
walletClient.seedFromMnemonic(customSentence, {
network: fc.credentials.network,
network: wallet.credentials.network,
passphrase: passphrase,
account: fc.credentials.account
account: wallet.credentials.account
});
} catch (err) {
return cb(err);

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('copayersController',
function($scope, $rootScope, $timeout, $log, $ionicModal, profileService, go, notification, platformInfo, gettext, gettextCatalog, $stateParams, $state) {
function($scope, $rootScope, $timeout, $log, $ionicModal, $stateParams, profileService, go, notification, platformInfo, gettext, gettextCatalog, $state) {
var self = this;
$scope.isCordova = platformInfo.isCordova;
var isWP = platformInfo.isWP;
@ -30,9 +30,9 @@ angular.module('copayApp.controllers').controller('copayersController',
};
var doDeleteWallet = function() {
var fc = profileService.focusedClient;
var walletName = fc.credentials.walletName;
profileService.deleteWalletClient(fc, function(err) {
var wallet = profileService.getWallet($stateParams.walletId);
var walletName = wallet.credentials.walletName;
profileService.deleteWalletClient(wallet, function(err) {
if (err) {
self.error = err.message || err;
$timeout(function() {
@ -53,7 +53,7 @@ angular.module('copayApp.controllers').controller('copayersController',
};
$scope.deleteWallet = function() {
var fc = profileService.focusedClient;
var wallet = profileService.focusedClient;
if ($scope.isCordova) {
navigator.notification.confirm(
delete_msg,
@ -86,18 +86,18 @@ angular.module('copayApp.controllers').controller('copayersController',
};
if (!$stateParams.walletId) {
$log.debug('No wallet provided...back to home');
return $state.transitionTo('tabs.home')
}
if (!$stateParams.walletId) {
$log.debug('No wallet provided...back to home');
return $state.transitionTo('tabs.home')
}
var wallet = profileService.getWallet($stateParams.walletId);
var secret;
try {
secret = wallet.status.wallet.secret;
} catch (e) {};
var wallet = profileService.getWallet($stateParams.walletId);
var secret;
try {
secret = wallet.status.wallet.secret;
} catch (e) {};
$scope.wallet = wallet;
$scope.secret = secret;
});
$scope.wallet = wallet;
$scope.secret = secret;
});

View file

@ -75,7 +75,7 @@ angular.module('copayApp.controllers').controller('exportController',
};
$scope.getAddressbook = function(cb) {
storageService.getAddressbook(fc.credentials.network, function(err, addressBook) {
storageService.getAddressbook(wallet.credentials.network, function(err, addressBook) {
if (err) return cb(err);
var localAddressBook = [];

View file

@ -1,17 +1,17 @@
'use strict';
angular.module('copayApp.controllers').controller('txDetailsController', function($rootScope, $log, $scope, $filter, $ionicPopup, gettextCatalog, profileService, configService, lodash, txFormatService) {
angular.module('copayApp.controllers').controller('txDetailsController', function($rootScope, $log, $scope, $filter, $stateParams, $ionicPopup, gettextCatalog, profileService, configService, lodash, txFormatService) {
var self = $scope.self;
var fc = profileService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
$scope.alternativeIsoCode = walletSettings.alternativeIsoCode;
$scope.color = fc.backgroundColor;
$scope.copayerId = fc.credentials.copayerId;
$scope.isShared = fc.credentials.n > 1;
$scope.color = wallet.color;
$scope.copayerId = wallet.credentials.copayerId;
$scope.isShared = wallet.credentials.n > 1;
$scope.btx.amountStr = txFormatService.formatAmount($scope.btx.amount, true) + ' ' + walletSettings.unitName;
$scope.btx.feeStr = txFormatService.formatAmount($scope.btx.fees, true) + ' ' + walletSettings.unitName;
@ -40,7 +40,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
args.body = $scope.data.comment;
};
fc.editTxNote(args, function(err) {
wallet.editTxNote(args, function(err) {
if (err) {
$log.debug('Could not save tx comment');
return;
@ -50,7 +50,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
if (args.body) {
$scope.btx.note = {};
$scope.btx.note.body = $scope.data.comment;
$scope.btx.note.editedByName = fc.credentials.copayerName;
$scope.btx.note.editedByName = wallet.credentials.copayerName;
$scope.btx.note.editedOn = Math.floor(Date.now() / 1000);
}
$scope.btx.searcheableString = null;
@ -62,7 +62,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
$scope.getAlternativeAmount = function() {
var satToBtc = 1 / 100000000;
fc.getFiatRate({
wallet.getFiatRate({
code: $scope.alternativeIsoCode,
ts: $scope.btx.time * 1000
}, function(err, res) {
@ -81,7 +81,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
};
$scope.getShortNetworkName = function() {
var n = fc.credentials.network;
var n = wallet.credentials.network;
return n.substring(0, 4);
};

View file

@ -1,7 +1,7 @@
angular.module('copayApp.controllers').controller('paperWalletController',
function($scope, $timeout, $log, $ionicModal, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess, txFormatService) {
function($scope, $timeout, $log, $ionicModal, $stateParams, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess, txFormatService) {
var fc = profileService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
var rawTx;
$scope.onQrCodeScanned = function(data) {
@ -18,11 +18,11 @@ angular.module('copayApp.controllers').controller('paperWalletController',
function _scanFunds(cb) {
function getPrivateKey(scannedKey, isPkEncrypted, passphrase, cb) {
if (!isPkEncrypted) return cb(null, scannedKey);
fc.decryptBIP38PrivateKey(scannedKey, passphrase, null, cb);
wallet.decryptBIP38PrivateKey(scannedKey, passphrase, null, cb);
};
function getBalance(privateKey, cb) {
fc.getBalanceFromPrivateKey(privateKey, cb);
wallet.getBalanceFromPrivateKey(privateKey, cb);
};
function checkPrivateKey(privateKey) {
@ -70,13 +70,13 @@ angular.module('copayApp.controllers').controller('paperWalletController',
};
function _sweepWallet(cb) {
addressService.getAddress(fc.credentials.walletId, true, function(err, destinationAddress) {
addressService.getAddress(wallet.credentials.walletId, true, function(err, destinationAddress) {
if (err) return cb(err);
fc.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, tx) {
wallet.buildTxFromPrivateKey($scope.privateKey, destinationAddress, null, function(err, tx) {
if (err) return cb(err);
fc.broadcastRawTx({
wallet.broadcastRawTx({
rawTx: tx.serialize(),
network: 'livenet'
}, function(err, txid) {
@ -113,7 +113,7 @@ angular.module('copayApp.controllers').controller('paperWalletController',
$scope.openStatusModal = function(type, txp, cb) {
$scope.type = type;
$scope.tx = txFormatService.processTx(txp);
$scope.color = fc.backgroundColor;
$scope.color = wallet.backgroundColor;
$scope.cb = cb;
$ionicModal.fromTemplateUrl('views/modals/tx-status.html', {

View file

@ -11,7 +11,6 @@ angular.module('copayApp.controllers').controller('preferencesController',
$scope.externalSource = null;
if (wallet) {
walletService.getStatus(wallet, {}, function(err, status) {});
var config = configService.getSync();
config.aliasFor = config.aliasFor || {};
$scope.alias = config.aliasFor[walletId] || wallet.credentials.walletName;

View file

@ -1,12 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
function($scope, $log, configService, applicationService, profileService, storageService) {
function($scope, $log, $stateParams, configService, applicationService, profileService, storageService) {
$scope.error = null;
$scope.success = null;
var fc = profileService.focusedClient;
var walletId = fc.credentials.walletId;
var wallet = profileService.getWallet($stateParams.walletId);
var walletId = wallet.credentials.walletId;
var defaults = configService.getDefaults();
var config = configService.getSync();

View file

@ -1,9 +1,10 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesHistory',
function($scope, $log, $timeout, storageService, go, profileService, lodash) {
var fc = profileService.focusedClient;
var c = fc.credentials;
function($scope, $log, $stateParams, $timeout, storageService, go, profileService, lodash) {
var wallet = profileService.getWallet($stateParams.walletId);
var c = wallet.credentials;
$scope.csvReady = false;
$scope.csvHistory = function(cb) {
@ -125,7 +126,7 @@ angular.module('copayApp.controllers').controller('preferencesHistory',
$scope.$emit('Local/ClearHistory');
$timeout(function() {
go.walletHome();
go.choosedWallet(c.walletId);
}, 100);
});
};

View file

@ -13,8 +13,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
$scope.openSearchModal = function() {
var fc = profileService.focusedClient;
$scope.color = fc.backgroundColor;
var wallet = profileService.getWallet($stateParams.walletId);
$scope.color = wallet.color;
$scope.self = self;
$ionicModal.fromTemplateUrl('views/modals/search.html', {

View file

@ -190,17 +190,17 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
templateUrl: 'views/copayers.html'
})
// OLD
// .state('walletHome', {
// url: '/old',
// needProfile: true,
// views: {
// 'main': {
// templateUrl: 'views/walletHome.html',
// },
// }
// })
.state('tabs', {
// OLD
// .state('walletHome', {
// url: '/old',
// needProfile: true,
// views: {
// 'main': {
// templateUrl: 'views/walletHome.html',
// },
// }
// })
.state('tabs', {
url: '/tabs',
cache: false,
needProfile: true,
@ -280,7 +280,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
},
})
.state('unsupported', {
.state('unsupported', {
url: '/unsupported',
needProfile: false,
views: {
@ -697,7 +697,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} else {
profileService.storeProfileIfDirty();
$log.debug('Profile loaded ... Starting UX.');
$state.transitionTo('tabs.home');
// $state.transitionTo('tabs.home');
}
});

View file

@ -1,11 +1,11 @@
'use strict';
angular.module('copayApp.services').factory('addressbookService', function(storageService, profileService, lodash) {
angular.module('copayApp.services').factory('addressbookService', function($stateParams, storageService, profileService, lodash) {
var root = {};
root.getLabel = function(addr, cb) {
var fc = profileService.focusedClient;
storageService.getAddressbook(fc.credentials.network, function(err, ab) {
var wallet = profileService.getWallet($stateParams.walletId);
storageService.getAddressbook(wallet.credentials.network, function(err, ab) {
if (!ab) return cb();
if (ab[addr]) return cb(ab[addr]);
else return cb();
@ -23,19 +23,19 @@ angular.module('copayApp.services').factory('addressbookService', function(stora
if (ab2) ab2 = JSON.parse(ab2);
ab2 = ab2 || {};
return cb(err, lodash.defaults(ab2,ab));
return cb(err, lodash.defaults(ab2, ab));
});
});
};
root.add = function(entry, cb) {
var fc = profileService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
root.list(function(err, ab) {
if (err) return cb(err);
if (!ab) ab = {};
if (ab[entry.address]) return cb('Entry already exist');
ab[entry.address] = entry.label;
storageService.setAddressbook(fc.credentials.network, JSON.stringify(ab), function(err, ab) {
storageService.setAddressbook(wallet.credentials.network, JSON.stringify(ab), function(err, ab) {
if (err) return cb('Error adding new entry');
root.list(function(err, ab) {
return cb(err, ab);
@ -43,26 +43,26 @@ angular.module('copayApp.services').factory('addressbookService', function(stora
});
});
};
root.remove = function(addr, cb) {
var fc = profileService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
root.list(function(err, ab) {
if (err) return cb(err);
if (!ab) return;
if (!ab[addr]) return cb('Entry does not exist');
delete ab[addr];
storageService.setAddressbook(fc.credentials.network, JSON.stringify(ab), function(err) {
storageService.setAddressbook(wallet.credentials.network, JSON.stringify(ab), function(err) {
if (err) return cb('Error deleting entry');
root.list(function(err, ab) {
return cb(err, ab);
});
});
});
});
};
root.removeAll = function() {
var fc = profileService.focusedClient;
storageService.removeAddressbook(fc.credentials.network, function(err) {
var wallet = profileService.getWallet($stateParams.walletId);
storageService.removeAddressbook(wallet.credentials.network, function(err) {
if (err) return cb('Error deleting addressbook');
return cb();
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services')
.factory('backupService', function backupServiceFactory($log, $timeout, profileService, sjcl) {
.factory('backupService', function backupServiceFactory($log, $timeout, $stateParams, profileService, sjcl) {
var root = {};
@ -57,10 +57,10 @@ angular.module('copayApp.services')
if (!password) {
return null;
}
var fc = profileService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
try {
opts = opts || {};
var b = fc.export(opts);
var b = wallet.export(opts);
if (opts.addressBook) b = root.addMetadata(b, opts);
var e = sjcl.encrypt(password, b, {
@ -74,11 +74,11 @@ angular.module('copayApp.services')
};
root.walletDownload = function(password, opts, cb) {
var fc = profileService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
var ew = root.walletExport(password, opts);
if (!ew) return cb('Could not create backup');
var walletName = (fc.alias || '') + (fc.alias ? '-' : '') + fc.credentials.walletName;
var walletName = (wallet.alias || '') + (wallet.alias ? '-' : '') + wallet.credentials.walletName;
if (opts.noSign) walletName = walletName + '-noSign'
var filename = walletName + '-Copaybackup.aes.json';
_download(ew, filename, cb)

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('feeService', function($log, bwcService, walletService, configService, gettext, lodash, txFormatService) {
angular.module('copayApp.services').factory('feeService', function($log, $stateParams, bwcService, walletService, configService, gettext, lodash, txFormatService) {
var root = {};
// Constant fee options to translate
@ -16,12 +16,12 @@ angular.module('copayApp.services').factory('feeService', function($log, bwcServ
};
root.getCurrentFeeValue = function(cb) {
console.log('[feeService.js.18:getCurrentFeeValue:] TODO TODO TODO'); //TODO
console.log('[feeService.js.18:getCurrentFeeValue:] TODO TODO TODO'); //TODO
// TODO TODO TODO
var fc = walletService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
var feeLevel = root.getCurrentFeeLevel();
fc.getFeeLevels(fc.credentials.network, function(err, levels) {
wallet.getFeeLevels(wallet.credentials.network, function(err, levels) {
if (err)
return cb({
message: 'Could not get dynamic fee'

View file

@ -5,7 +5,7 @@ angular.module('copayApp.services').factory('txStatus', function(lodash, profile
var isCordova = platformInfo.isCordova;
root.notify = function(txp) {
var fc = profileService.focusedClient;
var wallet = profileService.getWallet($stateParams.walletId);
var status = txp.status;
var type;
var INMEDIATE_SECS = 10;
@ -16,7 +16,7 @@ angular.module('copayApp.services').factory('txStatus', function(lodash, profile
var n = txp.actions.length;
var action = lodash.find(txp.actions, {
copayerId: fc.credentials.copayerId
copayerId: wallet.credentials.copayerId
});
if (!action) {