refactor backup flag process
This commit is contained in:
parent
9f42ae3891
commit
a9c4762ef7
9 changed files with 77 additions and 90 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue