make my code work with the latest interface changes
...to Wallet and WalletFactory
This commit is contained in:
parent
5f8deb7d0b
commit
96a6203bb0
7 changed files with 37 additions and 42 deletions
23
API.js
23
API.js
|
|
@ -10,26 +10,13 @@ API.prototype._init = function(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
self.opts = opts;
|
self.opts = opts;
|
||||||
|
|
||||||
var Wallet = require('soop').load('./js/models/core/Wallet', {
|
var WalletFactory = require('soop').load('./js/models/core/WalletFactory', {
|
||||||
Storage: opts.Storage || require('./test/mocks/FakeStorage'),
|
Storage: opts.Storage || require('./test/mocks/FakeStorage'),
|
||||||
Network: opts.Network || require('./js/models/network/Base'),
|
Network: opts.Network || require('./js/models/network/Base'),
|
||||||
Blockchain: opts.Blockchain || require('./js/models/blockchain/Insight')
|
Blockchain: opts.Blockchain || require('./js/models/blockchain/Insight')
|
||||||
});
|
});
|
||||||
|
|
||||||
var config = {
|
|
||||||
wallet: {
|
|
||||||
requiredCopayers: opts.requiredCopayers || 3,
|
|
||||||
totalCopayers: opts.totalCopayers || 5,
|
|
||||||
},
|
|
||||||
storage: {
|
|
||||||
filename: 'copaywallet.json'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var walletConfig = opts.walletConfig || config;
|
this.walletFactory = new WalletFactory(opts);
|
||||||
var walletOpts = opts.walletOpts || {};
|
|
||||||
|
|
||||||
self.wallet = self.opts.wallet || Wallet.factory.create(walletConfig, walletOpts);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
API._coerceArgTypes = function(args, argTypes) {
|
API._coerceArgTypes = function(args, argTypes) {
|
||||||
|
|
@ -182,13 +169,13 @@ API.prototype.getCommands = decorate('getCommands', [
|
||||||
['callback', 'function']
|
['callback', 'function']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
API.prototype._cmd_getPublicKeyRingId = function(callback) {
|
API.prototype._cmd_getWalletIds = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return callback(null, self.wallet.publicKeyRing.walletId);
|
return callback(null, self.walletFactory.getWalletIds());
|
||||||
};
|
};
|
||||||
|
|
||||||
API.prototype.getPublicKeyRingId = decorate('getPublicKeyRingId', [
|
API.prototype.getWalletIds = decorate('getWalletIds', [
|
||||||
['callback', 'function']
|
['callback', 'function']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,6 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
opts.totalCopayers = totalCopayers;
|
opts.totalCopayers = totalCopayers;
|
||||||
var w = new Wallet(opts);
|
var w = new Wallet(opts);
|
||||||
w.store();
|
w.store();
|
||||||
this.addWalletId(w.id);
|
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -156,28 +155,11 @@ WalletFactory.prototype.openRemote = function(peedId) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.getWalletIds = function() {
|
WalletFactory.prototype.getWalletIds = function() {
|
||||||
var ids = this.storage.getGlobal('walletIds');
|
return this.storage.getWalletIds();
|
||||||
return ids || [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletFactory.prototype._delWalletId = function(walletId) {
|
|
||||||
var ids = this.getWalletIds();
|
|
||||||
var index = ids.indexOf(walletId);
|
|
||||||
if (index === -1) return;
|
|
||||||
ids.splice(index, 1); // removes walletId
|
|
||||||
this.storage.setGlobal('walletIds', ids);
|
|
||||||
};
|
|
||||||
|
|
||||||
WalletFactory.prototype.remove = function(walletId) {
|
WalletFactory.prototype.remove = function(walletId) {
|
||||||
WalletFactory._delWalletId(walletId);
|
// TODO remove wallet contents
|
||||||
// TODO remove wallet contents, not only the id (Wallet.remove?)
|
|
||||||
};
|
|
||||||
|
|
||||||
WalletFactory.prototype.addWalletId = function(walletId) {
|
|
||||||
var ids = this.getWalletIds();
|
|
||||||
if (ids.indexOf(walletId) !== -1) return;
|
|
||||||
ids.push(walletId);
|
|
||||||
this.storage.setGlobal('walletIds', ids);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ Storage.prototype.set = function(walletId,v) {
|
||||||
Storage.prototype.remove = function(walletId, k) {
|
Storage.prototype.remove = function(walletId, k) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Storage.prototype.getWalletIds = function() {
|
||||||
|
};
|
||||||
|
|
||||||
// remove all values
|
// remove all values
|
||||||
Storage.prototype.clearAll = function() {
|
Storage.prototype.clearAll = function() {
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,10 @@ Storage.prototype.remove = function(walletId, k, callback) {
|
||||||
this.removeGlobal(this._key(walletId, k), callback);
|
this.removeGlobal(this._key(walletId, k), callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Storage.prototype.getWalletIds = function() {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
// remove all values
|
// remove all values
|
||||||
Storage.prototype.clearAll = function(callback) {
|
Storage.prototype.clearAll = function(callback) {
|
||||||
this.data = {};
|
this.data = {};
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,21 @@ Storage.prototype.remove = function(walletId, k) {
|
||||||
this.removeGlobal(this._key(walletId,k));
|
this.removeGlobal(this._key(walletId,k));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Storage.prototype.getWalletIds = function() {
|
||||||
|
var walletIds = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < localStorage.length; i++) {
|
||||||
|
var key = localStorage.key(i);
|
||||||
|
var split = key.split('::');
|
||||||
|
if (split.length == 2) {
|
||||||
|
var walletId = split[0];
|
||||||
|
walletIds.push(walletId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return walletIds;
|
||||||
|
};
|
||||||
|
|
||||||
// remove all values
|
// remove all values
|
||||||
Storage.prototype.clearAll = function() {
|
Storage.prototype.clearAll = function() {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,8 @@ FakeStorage.prototype.clear = function() {
|
||||||
delete this['storage'];
|
delete this['storage'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FakeStorage.prototype.getWalletIds = function() {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = require('soop')(FakeStorage);
|
module.exports = require('soop')(FakeStorage);
|
||||||
|
|
|
||||||
|
|
@ -110,11 +110,11 @@ describe('API', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getPublicKeyRingId', function() {
|
describe('#getWalletIds', function() {
|
||||||
it('should get a public key ring ID', function(done) {
|
it('should get the wallet ids', function(done) {
|
||||||
var api = new API({Storage: Storage});
|
var api = new API({Storage: Storage});
|
||||||
api.getPublicKeyRingId(function(err, result) {
|
api.getWalletIds(function(err, result) {
|
||||||
result.length.should.be.greaterThan(5);
|
result.length.should.be.greaterThan(-1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue