fix create and join bws errors

This commit is contained in:
Javier 2015-10-19 17:26:15 -03:00
commit 3d7132861d
7 changed files with 73 additions and 82 deletions

View file

@ -56,6 +56,7 @@ angular.module('copayApp.controllers').controller('createController',
name: form.walletName.$modelValue, name: form.walletName.$modelValue,
myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null, myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null,
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet', networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl
}; };
var setSeed = form.setSeed.$modelValue; var setSeed = form.setSeed.$modelValue;
if (setSeed) { if (setSeed) {
@ -111,15 +112,6 @@ angular.module('copayApp.controllers').controller('createController',
return; return;
} }
var opts_ = {
bws: {}
};
opts_.bws[walletId] = $scope.bwsurl;
configService.set(opts_, function(err) {
if (err) console.log(err);
go.walletHome();
});
if (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey) { if (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey) {
if (opts.n == 1) { if (opts.n == 1) {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);

View file

@ -28,10 +28,7 @@ angular.module('copayApp.controllers').controller('importController',
bws: {} bws: {}
}; };
opts.bws[walletId] = $scope.bwsurl; opts.bws[walletId] = $scope.bwsurl;
configService.set(opts, function(err) { configService.set(opts, cb);
if (err) return cb(err);
return cb(null);
});
} }
var _importBlob = function(str, opts) { var _importBlob = function(str, opts) {
@ -56,7 +53,8 @@ angular.module('copayApp.controllers').controller('importController',
$timeout(function() { $timeout(function() {
profileService.importWallet(str2, { profileService.importWallet(str2, {
compressed: null, compressed: null,
password: null password: null,
bwsurl: $scope.bwsurl
}, function(err, walletId) { }, function(err, walletId) {
self.loading = false; self.loading = false;
if (err) { if (err) {
@ -64,7 +62,6 @@ angular.module('copayApp.controllers').controller('importController',
} else { } else {
setBwsURL(walletId, function() { setBwsURL(walletId, function() {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
go.walletHome();
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
}); });
} }
@ -88,7 +85,6 @@ angular.module('copayApp.controllers').controller('importController',
setBwsURL(walletId, function() { setBwsURL(walletId, function() {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}); });
}); });
}, 100); }, 100);
@ -109,7 +105,6 @@ angular.module('copayApp.controllers').controller('importController',
setBwsURL(walletId, function() { setBwsURL(walletId, function() {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}); });
}); });
}, 100); }, 100);
@ -264,7 +259,6 @@ angular.module('copayApp.controllers').controller('importController',
setBwsURL(walletId, function() { setBwsURL(walletId, function() {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}); });
}); });
}, 100); }, 100);

View file

@ -1129,18 +1129,15 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setFocusedWallet(); self.setFocusedWallet();
self.updateTxHistory(); self.updateTxHistory();
go.walletHome(); go.walletHome();
storageService.getCleanAndScanAddresses(function(err, val) { storageService.getCleanAndScanAddresses(function(err, walletId) {
if (val) { if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan'); $log.debug('Clear last address cache and Scan ', walletId);
lodash.each(lodash.keys(profileService.walletClients), function(walletId) { addressService.expireAddress(walletId, function(err) {
addressService.expireAddress(walletId, function(err) { self.startScan(walletId);
self.startScan(walletId);
});
}); });
storageService.removeCleanAndScanAddresses(function() {}); storageService.removeCleanAndScanAddresses(function() {});
} }
}); });
}); });
$rootScope.$on('Local/SetTab', function(event, tab, reset) { $rootScope.$on('Local/SetTab', function(event, tab, reset) {

View file

@ -1,11 +1,10 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('joinController', angular.module('copayApp.controllers').controller('joinController',
function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, $modal, gettext, lodash, ledger, trezor) { function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor) {
var self = this; var self = this;
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
var defaults = configService.getDefaults();
$scope.bwsurl = defaults.bws.url; $scope.bwsurl = defaults.bws.url;
this.onQrCodeScanned = function(data) { this.onQrCodeScanned = function(data) {
@ -24,6 +23,7 @@ angular.module('copayApp.controllers').controller('joinController',
var opts = { var opts = {
secret: form.secret.$modelValue, secret: form.secret.$modelValue,
myName: form.myName.$modelValue, myName: form.myName.$modelValue,
bwsurl: $scope.bwsurl
} }
var setSeed = form.setSeed.$modelValue; var setSeed = form.setSeed.$modelValue;
@ -71,25 +71,13 @@ angular.module('copayApp.controllers').controller('joinController',
self.loading = false; self.loading = false;
self.error = err; self.error = err;
$rootScope.$apply(); $rootScope.$apply();
return return;
} }
$timeout(function() { $timeout(function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey))
var opts_ = {
bws: {}
};
opts_.bws[fc.credentials.walletId] = $scope.bwsurl;
configService.set(opts_, function(err) {
if (err) console.log(err);
});
if (fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
$rootScope.$emit('Local/WalletImported', fc.credentials.walletId); $rootScope.$emit('Local/WalletImported', fc.credentials.walletId);
} else {
go.walletHome();
}
}, 2000); }, 2000);
}); });
}, 100); }, 100);

View file

@ -35,16 +35,16 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
this.bwsurl = bws; this.bwsurl = bws;
} }
var opts = { var opts = {
bws: {} bws: {}
}; };
opts.bws[walletId] = this.bwsurl; opts.bws[walletId] = this.bwsurl;
configService.set(opts, function(err) { configService.set(opts, function(err) {
if (err) console.log(err); if (err) console.log(err);
storageService.setCleanAndScanAddresses(function() { storageService.setCleanAndScanAddresses(walletId, function() {
applicationService.restart(); applicationService.restart();
});
}); });
});
}; };
}); });

View file

@ -48,17 +48,21 @@ angular.module('copayApp.services')
}); });
}; };
root.setBaseURL = function(walletId) {
var config = configService.getSync();
var defaults = configService.getDefaults();
bwcService.setBaseUrl(config.bws[walletId] || defaults.bws.url);
bwcService.setTransports(['polling']);
}
root.setWalletClient = function(credentials) { root.setWalletClient = function(credentials) {
if (root.walletClients[credentials.walletId] && if (root.walletClients[credentials.walletId] &&
root.walletClients[credentials.walletId].started) { root.walletClients[credentials.walletId].started) {
return; return;
} }
var config = configService.getSync(); root.setBaseURL(credentials.walletId);
var defaults = configService.getDefaults();
bwcService.setBaseUrl(config.bws[credentials.walletId] || defaults.bws.url);
bwcService.setTransports(['polling']);
var client = bwcService.getClient(JSON.stringify(credentials)); var client = bwcService.getClient(JSON.stringify(credentials));
root.walletClients[credentials.walletId] = client; root.walletClients[credentials.walletId] = client;
@ -108,7 +112,7 @@ angular.module('copayApp.services')
}); });
} }
root.setWalletClients = function(walletId) { root.setWalletClients = function() {
var credentials = root.profile.credentials; var credentials = root.profile.credentials;
lodash.each(credentials, function(credentials) { lodash.each(credentials, function(credentials) {
root.setWalletClient(credentials); root.setWalletClient(credentials);
@ -165,6 +169,9 @@ angular.module('copayApp.services')
root._seedWallet = function(opts, cb) { root._seedWallet = function(opts, cb) {
opts = opts || {}; opts = opts || {};
if (opts.bwsurl)
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
var network = opts.networkName || 'livenet'; var network = opts.networkName || 'livenet';
@ -240,19 +247,36 @@ angular.module('copayApp.services')
}, function(err, secret) { }, function(err, secret) {
if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb);
root.profile.credentials.push(JSON.parse(walletClient.export())); root.storeData(walletClient, function(err) {
root.setWalletClients(); if (err) return cb(err);
return cb(null);
root.setAndStoreFocus(walletClient.credentials.walletId, function() {
storageService.storeProfile(root.profile, function(err) {
return cb(null, secret, walletClient.credentials.walletId);
});
}); });
}) })
}); });
}; };
root.joinWallet = function(opts, cb) { root.storeData = function(walletClient, cb) {
var walletId = walletClient.credentials.walletId;
var opts_ = {
bws: {}
};
opts_.bws[walletId] = bwsurl;
configService.set(opts_, function(err) {
if (err) console.log(err);
root.profile.credentials.push(JSON.parse(walletClient.export()));
root.setWalletClients();
root.setAndStoreFocus(walletId, function() {
storageService.storeProfile(root.profile, function(err) {
if (err) return cb(err);
return cb(null);
});
});
});
}
root.joinWallet = function(opts, bwsurl, cb) {
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Joining Wallet:', opts); $log.debug('Joining Wallet:', opts);
@ -278,19 +302,14 @@ angular.module('copayApp.services')
walletClient.joinWallet(opts.secret, opts.myName || 'me', {}, function(err) { walletClient.joinWallet(opts.secret, opts.myName || 'me', {}, function(err) {
if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb); if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb);
root.profile.credentials.push(JSON.parse(walletClient.export())); root.storeData(walletClient, function(err) {
root.setWalletClients(); if (err) return cb(err);
return cb(null);
root.setAndStoreFocus(walletClient.credentials.walletId, function() {
storageService.storeProfile(root.profile, function(err) {
return cb();
});
}); });
}) });
}) });
}; };
root.getClient = function(walletId) { root.getClient = function(walletId) {
return root.walletClients[walletId]; return root.walletClients[walletId];
}; };
@ -341,7 +360,11 @@ angular.module('copayApp.services')
}; };
root.importWallet = function(str, opts, cb) { root.importWallet = function(str, opts, cb) {
if (opts.bwsurl)
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
$log.debug('Importing Wallet:', opts); $log.debug('Importing Wallet:', opts);
try { try {
walletClient.import(str, { walletClient.import(str, {
@ -366,7 +389,6 @@ angular.module('copayApp.services')
}); });
}; };
root._normalizeMnemonic = function(words) { root._normalizeMnemonic = function(words) {
var isJA = words.indexOf('\u3000') > -1; var isJA = words.indexOf('\u3000') > -1;
var wordList = words.split(/[\u3000\s]+/); var wordList = words.split(/[\u3000\s]+/);
@ -409,8 +431,6 @@ angular.module('copayApp.services')
}); });
}; };
root.create = function(opts, cb) { root.create = function(opts, cb) {
$log.info('Creating profile'); $log.info('Creating profile');
configService.get(function(err) { configService.get(function(err) {

View file

@ -124,7 +124,7 @@ angular.module('copayApp.services')
}; };
root.storeFocusedWalletId = function(id, cb) { root.storeFocusedWalletId = function(id, cb) {
storage.set('focusedWalletId', id||'', cb); storage.set('focusedWalletId', id || '', cb);
}; };
root.getFocusedWalletId = function(cb) { root.getFocusedWalletId = function(cb) {
@ -151,8 +151,8 @@ angular.module('copayApp.services')
storage.get('backup-' + walletId, cb); storage.get('backup-' + walletId, cb);
}; };
root.setCleanAndScanAddresses = function(cb) { root.setCleanAndScanAddresses = function(walletId, cb) {
storage.set('CleanAndScanAddresses', Date.now(), cb); storage.set('CleanAndScanAddresses', walletId, cb);
}; };
root.getCleanAndScanAddresses = function(cb) { root.getCleanAndScanAddresses = function(cb) {