fix async getName calls
This commit is contained in:
parent
e48e6e3fd5
commit
4b56e06472
3 changed files with 48 additions and 14 deletions
|
|
@ -53,8 +53,8 @@ var defaultConfig = {
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
|
|
||||||
plugins: {
|
plugins: {
|
||||||
LocalStorage: true,
|
//LocalStorage: true,
|
||||||
//GoogleDrive: true,
|
GoogleDrive: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
GoogleDrive: {
|
GoogleDrive: {
|
||||||
|
|
|
||||||
|
|
@ -224,18 +224,21 @@ Storage.prototype.getWallets = function(cb) {
|
||||||
return cb([]);
|
return cb([]);
|
||||||
|
|
||||||
for (var ii in ids) {
|
for (var ii in ids) {
|
||||||
var id = ids[ii];
|
// Create a closure for async calls.
|
||||||
self.getName(id, function(name) {
|
(function() {
|
||||||
wallets.push({
|
var id = ids[ii];
|
||||||
id: id,
|
self.getName(id, function(name) {
|
||||||
name: name,
|
wallets.push({
|
||||||
|
id: id,
|
||||||
|
name: name,
|
||||||
|
});
|
||||||
|
if (++i == l) {
|
||||||
|
self.wListCache.data = wallets;
|
||||||
|
self.wListCache.ts = Date.now() + CACHE_DURATION;
|
||||||
|
return cb(wallets);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (++i == l) {
|
})();
|
||||||
self.wListCache.data = wallets;
|
|
||||||
self.wListCache.ts = Date.now() + CACHE_DURATION;
|
|
||||||
return cb(wallets);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
|
var sinon = require('sinon');
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
var is_browser = typeof process == 'undefined' || typeof process.versions === 'undefined';
|
var is_browser = typeof process == 'undefined' || typeof process.versions === 'undefined';
|
||||||
var copay = copay || require('../copay');
|
var copay = copay || require('../copay');
|
||||||
|
|
@ -153,6 +154,7 @@ describe('Storage model', function() {
|
||||||
s.set('1', "hola", 'juan', function() {
|
s.set('1', "hola", 'juan', function() {
|
||||||
s.set('2', "hola", 'juan', function() {
|
s.set('2', "hola", 'juan', function() {
|
||||||
s.setName(1, 'hola', function() {
|
s.setName(1, 'hola', function() {
|
||||||
|
|
||||||
s.getWallets(function(ws) {
|
s.getWallets(function(ws) {
|
||||||
ws[0].should.deep.equal({
|
ws[0].should.deep.equal({
|
||||||
id: '1',
|
id: '1',
|
||||||
|
|
@ -168,7 +170,36 @@ describe('Storage model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}); describe('#deleteWallet', function() {
|
it('should retreive wallets from storage (with delay)', function(done) {
|
||||||
|
s.set('1', "hola", 'juan', function() {
|
||||||
|
s.set('2', "hola", 'juan', function() {
|
||||||
|
s.setName(1, 'hola', function() {
|
||||||
|
|
||||||
|
var orig = s.getName.bind(s);
|
||||||
|
s.getName = function(wid, cb) {
|
||||||
|
setTimeout(function() {
|
||||||
|
orig(wid, cb);
|
||||||
|
},1);
|
||||||
|
};
|
||||||
|
|
||||||
|
s.getWallets(function(ws) {
|
||||||
|
ws[0].should.deep.equal({
|
||||||
|
id: '1',
|
||||||
|
name: 'hola',
|
||||||
|
});
|
||||||
|
ws[1].should.deep.equal({
|
||||||
|
id: '2',
|
||||||
|
name: undefined
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#deleteWallet', function() {
|
||||||
it('should fail to delete a unexisting wallet', function(done) {
|
it('should fail to delete a unexisting wallet', function(done) {
|
||||||
s.set('1', "hola", 'juan', function() {
|
s.set('1', "hola", 'juan', function() {
|
||||||
s.set('2', "hola", 'juan', function() {
|
s.set('2', "hola", 'juan', function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue