fix create and join bws errors

This commit is contained in:
Javier 2015-10-19 17:26:15 -03:00
parent 808c7f74a5
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,
myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null,
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl
};
var setSeed = form.setSeed.$modelValue;
if (setSeed) {
@ -111,15 +112,6 @@ angular.module('copayApp.controllers').controller('createController',
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.n == 1) {
$rootScope.$emit('Local/WalletImported', walletId);

View File

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

View File

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

View File

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

View File

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

View File

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