From 9f42ae38917974d400925a2aebff2610fc7a0145 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 30 Aug 2016 15:43:17 -0300 Subject: [PATCH 1/4] warning backup needed --- public/views/tab-receive.html | 23 ++++++++--------------- src/js/controllers/tab-receive.js | 31 ++++++++++++++++--------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/public/views/tab-receive.html b/public/views/tab-receive.html index 54649635c..ebf14d19a 100644 --- a/public/views/tab-receive.html +++ b/public/views/tab-receive.html @@ -4,39 +4,32 @@ -
- +
+
{{error|translate}}
-
-
-
- -
-
-
-
No Wallet
-
+
Share address
-
+
Next Address
-
+
- ... - {{addr}} + ... + {{addr}} +
diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index c7e2b319b..0b7d04f34 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -10,38 +10,38 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi }); $scope.isCordova = platformInfo.isCordova; $scope.isNW = platformInfo.isNW; + $scope.needsBackup = false; } $scope.$on('Wallet/Changed', function(event, wallet) { - if (lodash.isEmpty(wallet)) { + if (!wallet) { $log.debug('No wallet provided'); return; } - $scope.defaultWallet = wallet; + $scope.wallet = wallet; $log.debug('Wallet changed: ' + wallet.name); - $scope.setAddress(wallet); + + walletService.needsBackup(wallet, function(needsBackup) { + if (needsBackup) $scope.needsBackup = true; + else $scope.needsBackup = false; + + $scope.setAddress(wallet); + }); }); $scope.shareAddress = function(addr) { + if ($scope.needsBackup || $scope.generatingAddress) return; if ($scope.isCordova) { window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null); } }; $scope.setAddress = function(wallet, forceNew) { - var wallet = wallet || $scope.defaultWallet; if ($scope.generatingAddress) return; - $scope.addr = null; + var wallet = wallet || $scope.wallet; $scope.error = null; - - if (wallet && !wallet.isComplete()) { - $timeout(function() { - $scope.$digest(); - }); - return; - } - + $scope.addr = null; $scope.generatingAddress = true; $timeout(function() { @@ -53,8 +53,9 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi if (addr) $scope.addr = addr; } - $scope.$digest(); + + $scope.$apply(); }); - }); + }, 1); }; }); From a9c4762ef7a14b0fa1598b495a7957c79cf31f9a Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 30 Aug 2016 17:07:49 -0300 Subject: [PATCH 2/4] refactor backup flag process --- public/views/includes/wallets.html | 3 +- public/views/tab-receive.html | 3 +- src/js/controllers/backup.js | 7 +-- src/js/controllers/create.js | 7 +-- src/js/controllers/import.js | 38 +++++++------- src/js/controllers/preferencesDeleteWords.js | 6 +-- src/js/controllers/tab-receive.js | 11 +--- src/js/services/profileService.js | 55 ++++++++++++++------ src/js/services/walletService.js | 35 +++---------- 9 files changed, 76 insertions(+), 89 deletions(-) diff --git a/public/views/includes/wallets.html b/public/views/includes/wallets.html index 978d7804e..356ce9135 100644 --- a/public/views/includes/wallets.html +++ b/public/views/includes/wallets.html @@ -1,7 +1,7 @@
-
+
{{wallet.name || wallet.id}} @@ -10,6 +10,7 @@ Incomplete +
diff --git a/public/views/tab-receive.html b/public/views/tab-receive.html index ebf14d19a..7ddd1b495 100644 --- a/public/views/tab-receive.html +++ b/public/views/tab-receive.html @@ -25,11 +25,10 @@ Next Address
-
+
... {{addr}} -
diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index 27ad27aba..c301a7344 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -136,11 +136,8 @@ angular.module('copayApp.controllers').controller('backupController', } } - $log.debug('Backup done'); - storageService.setBackupFlag(wallet.credentials.walletId, function(err) { - $log.debug('Backup stored'); - return cb(); - }); + profileService.setBackupFlag(walletClient.credentials.walletId); + return cb(); }, 1); }; diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index 1a1ec2dd2..84ea631d4 100644 --- a/src/js/controllers/create.js +++ b/src/js/controllers/create.js @@ -183,12 +183,7 @@ angular.module('copayApp.controllers').controller('createController', if (self.seedSourceId == 'set') { - $timeout(function() { - $log.debug('Backup done'); - storageService.setBackupFlag(wallet.credentials.walletId, function(err) { - $log.debug('Backup stored'); - }); - }, 1); + profileService.setBackupFlag(client.credentials.walletId); } $state.go('tabs.home') }); diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index cb24f92cc..a5f09fd26 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -109,12 +109,12 @@ angular.module('copayApp.controllers').controller('importController', $log.debug('Remote preferences saved for:' + client.credentials.walletId) }); - $rootScope.$emit('Local/WalletImported', client.credentials.walletId); - if ($stateParams.fromOnboarding) + profileService.setBackupFlag(client.credentials.walletId); + if ($stateParams.fromOnboarding) { profileService.setDisclaimerAccepted(function(err) { if (err) $log.error(err); }); - + } $state.go('tabs.home'); }); }, 100); @@ -141,12 +141,12 @@ angular.module('copayApp.controllers').controller('importController', $log.debug('Remote preferences saved for:' + client.credentials.walletId) }); - $rootScope.$emit('Local/WalletImported', client.credentials.walletId); - if ($stateParams.fromOnboarding) + profileService.setBackupFlag(client.credentials.walletId); + if ($stateParams.fromOnboarding) { profileService.setDisclaimerAccepted(function(err) { if (err) $log.error(err); }); - + } $state.go('tabs.home'); }); }, 100); @@ -166,12 +166,13 @@ angular.module('copayApp.controllers').controller('importController', $scope.$apply(); }); } - $rootScope.$emit('Local/WalletImported', walletId); - if ($stateParams.fromOnboarding) + + profileService.setBackupFlag(walletId); + if ($stateParams.fromOnboarding) { profileService.setDisclaimerAccepted(function(err) { if (err) $log.error(err); }); - + } $state.go('tabs.home'); }); }, 100); @@ -200,12 +201,12 @@ angular.module('copayApp.controllers').controller('importController', $log.debug('Remote preferences saved for:' + client.credentials.walletId) }); - $rootScope.$emit('Local/WalletImported', client.credentials.walletId); - if ($stateParams.fromOnboarding) + profileService.setBackupFlag(client.credentials.walletId); + if ($stateParams.fromOnboarding) { profileService.setDisclaimerAccepted(function(err) { if (err) $log.error(err); }); - + } $state.go('tabs.home'); }); }, 100); @@ -339,12 +340,13 @@ angular.module('copayApp.controllers').controller('importController', walletService.updateRemotePreferences(wallet, {}, function() { $log.debug('Remote preferences saved for:' + wallet.walletId) }); - $rootScope.$emit('Local/WalletImported', wallet.walletId); - if ($stateParams.fromOnboarding) + + profileService.setBackupFlag(wallet.walletId); + if ($stateParams.fromOnboarding) { profileService.setDisclaimerAccepted(function(err) { if (err) $log.error(err); }); - + } $state.go('tabs.home'); }); }, 100); @@ -421,13 +423,13 @@ angular.module('copayApp.controllers').controller('importController', walletService.updateRemotePreferences(wallet, {}, function() { $log.debug('Remote preferences saved for:' + wallet.walletId) }); - $rootScope.$emit('Local/WalletImported', wallet.walletId); - if ($stateParams.fromOnboarding) + profileService.setBackupFlag(wallet.walletId); + if ($stateParams.fromOnboarding) { profileService.setDisclaimerAccepted(function(err) { if (err) $log.error(err); }); - + } $state.go('tabs.home'); }); }, 100); diff --git a/src/js/controllers/preferencesDeleteWords.js b/src/js/controllers/preferencesDeleteWords.js index 8a5f777b3..e1fde81d3 100644 --- a/src/js/controllers/preferencesDeleteWords.js +++ b/src/js/controllers/preferencesDeleteWords.js @@ -1,14 +1,12 @@ 'use strict'; -angular.module('copayApp.controllers').controller('preferencesDeleteWordsController', function($scope, $ionicHistory, $stateParams, $ionicNavBarDelegate, gettextCatalog, confirmDialog, lodash, profileService, walletService, gettext) { +angular.module('copayApp.controllers').controller('preferencesDeleteWordsController', function($scope, $ionicHistory, $stateParams, $ionicNavBarDelegate, gettextCatalog, confirmDialog, lodash, profileService, gettext) { $ionicNavBarDelegate.title(gettextCatalog.getString('Delete recovery phrase')); var wallet = profileService.getWallet($stateParams.walletId); var msg = gettext('Are you sure you want to delete the recovery phrase?'); var successMsg = gettext('Recovery phrase deleted'); + $scope.needsBackup = wallet.needsBackup; - walletService.needsBackup(wallet, function(needsBackup) { - $scope.needsBackup = needsBackup; - }); if (lodash.isEmpty(wallet.credentials.mnemonic) && lodash.isEmpty(wallet.credentials.mnemonicEncrypted)) $scope.deleted = true; diff --git a/src/js/controllers/tab-receive.js b/src/js/controllers/tab-receive.js index 0b7d04f34..16d509897 100644 --- a/src/js/controllers/tab-receive.js +++ b/src/js/controllers/tab-receive.js @@ -10,7 +10,6 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi }); $scope.isCordova = platformInfo.isCordova; $scope.isNW = platformInfo.isNW; - $scope.needsBackup = false; } $scope.$on('Wallet/Changed', function(event, wallet) { @@ -20,17 +19,11 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi } $scope.wallet = wallet; $log.debug('Wallet changed: ' + wallet.name); - - walletService.needsBackup(wallet, function(needsBackup) { - if (needsBackup) $scope.needsBackup = true; - else $scope.needsBackup = false; - - $scope.setAddress(wallet); - }); + $scope.setAddress(wallet); }); $scope.shareAddress = function(addr) { - if ($scope.needsBackup || $scope.generatingAddress) return; + if ($scope.generatingAddress) return; if ($scope.isCordova) { window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null); } diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 3026753f9..e515f2033 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -36,9 +36,35 @@ angular.module('copayApp.services') wallet.name = config.aliasFor[wallet.id] || wallet.credentials.walletName; wallet.color = config.colorFor[wallet.id] || '#4A90E2'; - } + root.setBackupFlag = function(walletId) { + storageService.setBackupFlag(walletId, function(err) { + if (err) $log.error(err); + $log.debug('Backup stored'); + root.wallet[walletId].needsBackup = false; + }); + }; + + function _requiresBackup(wallet) { + if (wallet.isPrivKeyExternal()) return false; + if (!wallet.credentials.mnemonic) return false; + if (wallet.credentials.network == 'testnet') return false; + + return true; + }; + + function _needsBackup(wallet, cb) { + if (!_requiresBackup(wallet)) + return cb(false); + + storageService.getBackupFlag(wallet.credentials.walletId, function(err, val) { + if (err) $log.error(err); + if (val) return cb(false); + return cb(true); + }); + }; + // Adds a wallet client to profileService root.bindWalletClient = function(wallet, opts) { var opts = opts || {}; @@ -48,20 +74,20 @@ angular.module('copayApp.services') return false; } - // INIT WALLET VIEWMODEL - wallet.id = walletId; - wallet.started = true; - wallet.doNotVerifyPayPro = isChromeApp; + _needsBackup(wallet, function(val) { + // INIT WALLET VIEWMODEL + wallet.id = walletId; + wallet.started = true; + wallet.doNotVerifyPayPro = isChromeApp; + wallet.network = wallet.credentials.network; + wallet.copayerId = wallet.credentials.copayerId; + wallet.m = wallet.credentials.m; + wallet.n = wallet.credentials.n; + wallet.needsBackup = val; - - wallet.network = wallet.credentials.network; - wallet.copayerId = wallet.credentials.copayerId; - wallet.m = wallet.credentials.m; - wallet.n = wallet.credentials.n; - - root.updateWalletSettings(wallet); - - root.wallet[walletId] = wallet; + root.updateWalletSettings(wallet); + root.wallet[walletId] = wallet; + }); wallet.removeAllListeners(); wallet.on('report', function(n) { @@ -103,7 +129,6 @@ angular.module('copayApp.services') }); }); - $rootScope.$on('Local/SettingsUpdated', function(e, walletId) { if (!walletId || walletId == wallet.id) { $log.debug('Updating settings for wallet:' + wallet.id); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index f4230fc33..bdfe1a291 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -65,27 +65,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; - root.requiresBackup = function(wallet) { - if (wallet.isPrivKeyExternal()) return false; - if (!wallet.credentials.mnemonic) return false; - if (wallet.credentials.network == 'testnet') return false; - - return true; - }; - - root.needsBackup = function(wallet, cb) { - - if (!root.requiresBackup(wallet)) - return cb(false); - - storageService.getBackupFlag(wallet.credentials.walletId, function(err, val) { - if (err) $log.error(err); - if (val) return cb(false); - return cb(true); - }); - }; - - // TODO // This handles errors from BWS/index which normally // trigger from async events (like updates). @@ -815,11 +794,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim if (!wallet.isComplete()) return cb('WALLET_NOT_COMPLETE'); - root.needsBackup(wallet, function(needsBackup) { - if (needsBackup) - return cb('WALLET_NEEDS_BACKUP'); - return cb(); - }); + if (wallet.needsBackup) + return cb('WALLET_NEEDS_BACKUP'); + return cb(); }; @@ -859,7 +836,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim askPassword(wallet.name, gettext('Enter new spending password'), function(password) { if (!password) return cb('no password'); askPassword(wallet.name, gettext('Confirm you new spending password'), function(password2) { - if (!password2 || password != password2) + if (!password2 || password != password2) return cb('password mismatch'); wallet.encryptPrivateKey(password); @@ -950,7 +927,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim } root.prepare(wallet, function(err, password) { - if (err) return cb('Prepare error: ' + err); + if (err) return cb('Prepare error: ' + err); ongoingProcess.set('sendingTx', true); publishFn(wallet, txp, function(err, publishedTxp) { @@ -1040,7 +1017,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign()) return null; - root.getKeys(wallet, function(err, keys){ + root.getKeys(wallet, function(err, keys) { if (err || !keys) return cb(err); if (keys.mnemonic) { From 309e0dfc1ad3a61660fa3c68f7cdc0cde86b0ec4 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 30 Aug 2016 18:59:29 -0300 Subject: [PATCH 3/4] warning message --- public/views/tab-receive.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/views/tab-receive.html b/public/views/tab-receive.html index 7ddd1b495..6036b7127 100644 --- a/public/views/tab-receive.html +++ b/public/views/tab-receive.html @@ -6,6 +6,9 @@
+
+ Before receiving funds, you must backup your wallet. If this device is lost, it is impossible to access your funds without a backup. +
From 12b3808ade504308137560062b166bb5410bda55 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 31 Aug 2016 09:35:47 -0300 Subject: [PATCH 4/4] only needsBackup parameter in function callback --- src/js/services/profileService.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index e515f2033..7085baa34 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -41,7 +41,7 @@ angular.module('copayApp.services') root.setBackupFlag = function(walletId) { storageService.setBackupFlag(walletId, function(err) { if (err) $log.error(err); - $log.debug('Backup stored'); + $log.debug('Backup flag stored'); root.wallet[walletId].needsBackup = false; }); }; @@ -74,22 +74,24 @@ angular.module('copayApp.services') return false; } - _needsBackup(wallet, function(val) { - // INIT WALLET VIEWMODEL - wallet.id = walletId; - wallet.started = true; - wallet.doNotVerifyPayPro = isChromeApp; - wallet.network = wallet.credentials.network; - wallet.copayerId = wallet.credentials.copayerId; - wallet.m = wallet.credentials.m; - wallet.n = wallet.credentials.n; - wallet.needsBackup = val; + // INIT WALLET VIEWMODEL + wallet.id = walletId; + wallet.started = true; + wallet.doNotVerifyPayPro = isChromeApp; + wallet.network = wallet.credentials.network; + wallet.copayerId = wallet.credentials.copayerId; + wallet.m = wallet.credentials.m; + wallet.n = wallet.credentials.n; - root.updateWalletSettings(wallet); - root.wallet[walletId] = wallet; + root.updateWalletSettings(wallet); + root.wallet[walletId] = wallet; + + _needsBackup(wallet, function(val) { + wallet.needsBackup = val; }); wallet.removeAllListeners(); + wallet.on('report', function(n) { $log.info('BWC Report:' + n); });