Merge pull request #3392 from cmgustavo/fix/bip-44-gaps

Adds limit to create addresses
This commit is contained in:
Matias Alejo Garcia 2015-11-11 10:06:34 -03:00
commit 143a998716
3 changed files with 15 additions and 3 deletions

View File

@ -25,3 +25,4 @@
"trezor-connect": "~1.0.1"
}
}

View File

@ -1,7 +1,7 @@
'use strict';
'use strict';
angular.module('copayApp.services')
.factory('addressService', function(storageService, profileService, $log, $timeout, lodash, bwsError, gettext) {
.factory('addressService', function(storageService, profileService, $log, $timeout, lodash, bwsError, gettextCatalog) {
var root = {};
@ -28,13 +28,21 @@ angular.module('copayApp.services')
client.createAddress(function(err, addr) {
if (err) {
var prefix = gettextCatalog.getString('Could not create address');
if (err.error && err.error.match(/locked/gi)) {
$log.debug(err.error);
return $timeout(function() {
root._createAddress(walletId, cb);
}, 5000);
} else if (err.code && err.code == 'MAIN_ADDRESS_GAP_REACHED') {
$log.warn(err.message);
prefix = null;
client.getMainAddresses({reverse: true, limit : 1}, function(err, addr) {
if (err) return cb(err);
return cb(null, addr[0].address);
});
}
return bwsError.cb(err, gettext('Could not create address'), cb);
return bwsError.cb(err, prefix, cb);
}
return cb(null, addr.address);
});

View File

@ -93,6 +93,9 @@ angular.module('copayApp.services')
case 'INVALID_BACKUP':
body = gettextCatalog.getString('Wallet seed is invalid');
break;
case 'MAIN_ADDRESS_GAP_REACHED':
body = gettextCatalog.getString('Empty addresses limit reached. New addresses cannot be generated.');
break;
case 'ERROR':
body = (err.message || err.error);
@ -109,7 +112,7 @@ angular.module('copayApp.services')
body = gettextCatalog.getString(err);
}
var msg = prefix + ( body ? ': ' + body : '');
var msg = prefix + ( body ? (prefix ? ': ' : '') + body : '');
return msg;
};