implements delete wallet, in backuptab
This commit is contained in:
parent
46feadf57c
commit
2c60fd91c0
7 changed files with 219 additions and 79 deletions
|
|
@ -39,9 +39,9 @@ angular.module('copayApp.controllers').controller('BackupController',
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.deleteWallet = function() {
|
$scope.deleteWallet = function() {
|
||||||
var w=$rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.disconnect();
|
w.disconnect();
|
||||||
walletFactory.remove(w.id, function() {
|
walletFactory.delete(w.id, function() {
|
||||||
controllerUtils.logout();
|
controllerUtils.logout();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -177,10 +177,10 @@ WalletFactory.prototype.getWallets = function() {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.remove = function(walletId, cb) {
|
WalletFactory.prototype.delete = function(walletId, cb) {
|
||||||
var s = this.storage;
|
var s = this.storage;
|
||||||
this.log('## DELETING WALLET ID:'+ walletId); //TODO
|
this.log('## DELETING WALLET ID:' + walletId); //TODO
|
||||||
s.get(walletId, 'opts');
|
s.deleteWallet(walletId);
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,6 @@ Storage.prototype.getWalletIds = function() {
|
||||||
|
|
||||||
Storage.prototype.getWallets = function() {
|
Storage.prototype.getWallets = function() {
|
||||||
var wallets = [];
|
var wallets = [];
|
||||||
var uniq = {};
|
|
||||||
var ids = this.getWalletIds();
|
var ids = this.getWalletIds();
|
||||||
|
|
||||||
for (var i in ids) {
|
for (var i in ids) {
|
||||||
|
|
@ -148,23 +147,19 @@ Storage.prototype.getWallets = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Storage.prototype.deleteWallet = function(walletId) {
|
Storage.prototype.deleteWallet = function(walletId) {
|
||||||
var walletIds = [];
|
var toDelete = {};
|
||||||
var uniq = {};
|
toDelete['nameFor::' + walletId] = 1;
|
||||||
|
|
||||||
for (var i = 0; i < localStorage.length; i++) {
|
for (var i = 0; i < localStorage.length; i++) {
|
||||||
var key = localStorage.key(i);
|
var key = localStorage.key(i);
|
||||||
var split = key.split('::');
|
var split = key.split('::');
|
||||||
if (split.length == 2) {
|
if (split.length == 2 && split[0] === walletId) {
|
||||||
var walletId = split[0];
|
toDelete[key] = 1;
|
||||||
|
|
||||||
if (walletId === 'nameFor') continue;
|
|
||||||
|
|
||||||
if (typeof uniq[walletId] === 'undefined') {
|
|
||||||
walletIds.push(walletId);
|
|
||||||
uniq[walletId] = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (var i in toDelete) {
|
||||||
|
this.removeGlobal(i);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,98 @@
|
||||||
|
var FakeStorage = function() {
|
||||||
var FakeStorage = function(){
|
|
||||||
this.storage = {};
|
this.storage = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeStorage.prototype._setPassphrase = function (password) {
|
FakeStorage.prototype._setPassphrase = function(password) {
|
||||||
this.storage.passphrase = password;
|
this.storage.passphrase = password;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeStorage.prototype.setGlobal = function (id, payload) {
|
FakeStorage.prototype.setGlobal = function(id, payload) {
|
||||||
this.storage[id] = payload;
|
this.storage[id] = payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeStorage.prototype.getGlobal = function(id) {
|
FakeStorage.prototype.getGlobal = function(id) {
|
||||||
return this.storage[id];
|
return this.storage[id];
|
||||||
}
|
};
|
||||||
|
|
||||||
FakeStorage.prototype.set = function (wid, id, payload) {
|
|
||||||
this.storage[wid + '-' + id] = payload;
|
FakeStorage.prototype.removeGlobal = function(id) {
|
||||||
|
delete this.storage[id];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
FakeStorage.prototype.set = function(wid, id, payload) {
|
||||||
|
this.storage[wid + '::' + id] = payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeStorage.prototype.get = function(wid, id) {
|
FakeStorage.prototype.get = function(wid, id) {
|
||||||
return this.storage[wid + '-' +id];
|
return this.storage[wid + '::' + id];
|
||||||
}
|
};
|
||||||
|
|
||||||
FakeStorage.prototype.clear = function() {
|
FakeStorage.prototype.clear = function() {
|
||||||
delete this['storage'];
|
delete this['storage'];
|
||||||
}
|
};
|
||||||
|
|
||||||
|
FakeStorage.prototype.getWalletIds = function() {
|
||||||
|
var walletIds = [];
|
||||||
|
var uniq = {};
|
||||||
|
|
||||||
|
for (var ii in this.storage) {
|
||||||
|
var split = ii.split('::');
|
||||||
|
if (split.length == 2) {
|
||||||
|
var walletId = split[0];
|
||||||
|
if (walletId !== 'nameFor' && typeof uniq[walletId] === 'undefined') {
|
||||||
|
walletIds.push(walletId);
|
||||||
|
uniq[walletId] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return walletIds;
|
||||||
|
};
|
||||||
|
|
||||||
|
FakeStorage.prototype.deleteWallet = function(walletId) {
|
||||||
|
var toDelete = {};
|
||||||
|
toDelete['nameFor::' + walletId] = 1;
|
||||||
|
|
||||||
|
for (var key in this.storage) {
|
||||||
|
var split = key.split('::');
|
||||||
|
if (split.length == 2 && split[0] === walletId) {
|
||||||
|
toDelete[key] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i in toDelete) {
|
||||||
|
this.removeGlobal(i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
FakeStorage.prototype.getName = function(walletId) {
|
||||||
|
return this.getGlobal('nameFor::' + walletId);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
FakeStorage.prototype.setName = function(walletId, name) {
|
||||||
|
this.setGlobal('nameFor::' + walletId, name);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
FakeStorage.prototype.getWallets = function() {
|
FakeStorage.prototype.getWallets = function() {
|
||||||
return [];
|
var wallets = [];
|
||||||
|
var ids = this.getWalletIds();
|
||||||
|
|
||||||
|
for (var i in ids) {
|
||||||
|
wallets.push({
|
||||||
|
id: ids[i],
|
||||||
|
name: this.getName(ids[i]),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return wallets;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeStorage.prototype.setFromObj = function(walletId, obj) {
|
FakeStorage.prototype.setFromObj = function(walletId, obj) {
|
||||||
for (var i in obj) {
|
for (var k in obj) {
|
||||||
this.storage[walletId + '-' + i] = obj[i];
|
this.set(walletId, k, obj[k]);
|
||||||
};
|
}
|
||||||
|
this.setName(walletId, obj.opts.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = require('soop')(FakeStorage);
|
module.exports = require('soop')(FakeStorage);
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,22 @@
|
||||||
|
var FakeWallet = function() {
|
||||||
var FakeWallet = function(){
|
this.id = 'testID';
|
||||||
this.balance=10000;
|
this.balance = 10000;
|
||||||
this.safeBalance=1000;
|
this.safeBalance = 1000;
|
||||||
this.balanceByAddr={'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000};
|
this.balanceByAddr = {
|
||||||
|
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr){
|
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr) {
|
||||||
this.balance=balance;
|
this.balance = balance;
|
||||||
this.safeBalance = safeBalance;
|
this.safeBalance = safeBalance;
|
||||||
this.balanceByAddr = balanceByAddr;
|
this.balanceByAddr = balanceByAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeWallet.prototype.getAddressesInfo=function(){
|
FakeWallet.prototype.getAddressesInfo = function() {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
|
|
||||||
for(var ii in this.balanceByAddr){
|
for (var ii in this.balanceByAddr) {
|
||||||
ret.push({
|
ret.push({
|
||||||
address: ii,
|
address: ii,
|
||||||
isChange: false,
|
isChange: false,
|
||||||
|
|
@ -24,10 +26,22 @@ FakeWallet.prototype.getAddressesInfo=function(){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FakeWallet.prototype.getBalance=function(cb){
|
FakeWallet.prototype.getBalance = function(cb) {
|
||||||
return cb(null, this.balance, this.balanceByAddr, this.safeBalance);
|
return cb(null, this.balance, this.balanceByAddr, this.safeBalance);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FakeWallet.prototype.setEnc = function(enc) {
|
||||||
|
this.enc = enc;
|
||||||
|
};
|
||||||
|
|
||||||
|
FakeWallet.prototype.toEncryptedObj = function() {
|
||||||
|
return this.enc;
|
||||||
|
};
|
||||||
|
|
||||||
|
FakeWallet.prototype.disconnect = function() {
|
||||||
|
this.disconnectCalled = 1;
|
||||||
|
};
|
||||||
|
|
||||||
// This mock is meant for karma, module.exports is not necesary.
|
// This mock is meant for karma, module.exports is not necesary.
|
||||||
try {
|
try {
|
||||||
module.exports = require('soop')(FakeWallet);
|
module.exports = require('soop')(FakeWallet);
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ describe('WalletFactory model', function() {
|
||||||
"wallet": {
|
"wallet": {
|
||||||
"requiredCopayers": 2,
|
"requiredCopayers": 2,
|
||||||
"totalCopayers": 3,
|
"totalCopayers": 3,
|
||||||
"reconnectDelay":100,
|
"reconnectDelay": 100,
|
||||||
"spendUnconfirmed": 1,
|
"spendUnconfirmed": 1,
|
||||||
"verbose": 0
|
"verbose": 0
|
||||||
},
|
},
|
||||||
|
|
@ -122,4 +122,28 @@ describe('WalletFactory model', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to get current wallets', function() {
|
||||||
|
var wf = new WalletFactory(config, '0.0.1');
|
||||||
|
var w = wf.create({
|
||||||
|
name: 'test wallet'
|
||||||
|
});
|
||||||
|
var ws = wf.getWallets();
|
||||||
|
ws.length.should.equal(1);
|
||||||
|
ws[0].name.should.equal('test wallet');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be able to delete wallet', function(done) {
|
||||||
|
var wf = new WalletFactory(config, '0.0.1');
|
||||||
|
var w = wf.create({
|
||||||
|
name: 'test wallet'
|
||||||
|
});
|
||||||
|
var ws = wf.getWallets();
|
||||||
|
ws.length.should.equal(1);
|
||||||
|
wf.delete(ws[0].id, function() {
|
||||||
|
ws = wf.getWallets();
|
||||||
|
ws.length.should.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
//
|
//
|
||||||
// test/unit/controllers/controllersSpec.js
|
// test/unit/controllers/controllersSpec.js
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// Replace saveAs plugin
|
||||||
|
saveAsLastCall = null;
|
||||||
|
saveAs = function(o) {
|
||||||
|
saveAsLastCall = o;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
describe("Unit: Controllers", function() {
|
describe("Unit: Controllers", function() {
|
||||||
|
|
||||||
var scope;
|
var scope;
|
||||||
|
|
@ -9,6 +17,48 @@ describe("Unit: Controllers", function() {
|
||||||
beforeEach(module('copayApp.services'));
|
beforeEach(module('copayApp.services'));
|
||||||
beforeEach(module('copayApp.controllers'));
|
beforeEach(module('copayApp.controllers'));
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
requiredCopayers: 3,
|
||||||
|
totalCopayers: 5,
|
||||||
|
spendUnconfirmed: 1,
|
||||||
|
reconnectDelay: 100,
|
||||||
|
networkName: 'testnet',
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
describe.only('Backup Controller', function() {
|
||||||
|
var ctrl;
|
||||||
|
beforeEach(inject(function($controller, $rootScope) {
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
|
||||||
|
$rootScope.wallet = new FakeWallet(config);
|
||||||
|
ctrl = $controller('BackupController', {
|
||||||
|
$scope: scope,
|
||||||
|
$modal: {},
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should have a Backup controller', function() {
|
||||||
|
expect(scope.title).equal('Backup');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(' Backup controller #download', function() {
|
||||||
|
scope.wallet.setEnc('1234567');
|
||||||
|
expect(saveAsLastCall).equal(null);
|
||||||
|
scope.download();
|
||||||
|
expect(saveAsLastCall.size).equal(7);
|
||||||
|
expect(saveAsLastCall.type).equal('text/plain;charset=utf-8');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it(' Backup controller #delete', function() {
|
||||||
|
expect(scope.wallet).not.equal(undefined);
|
||||||
|
scope.deleteWallet();
|
||||||
|
expect(scope.wallet).equal(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Address Controller', function() {
|
describe('Address Controller', function() {
|
||||||
var addressCtrl;
|
var addressCtrl;
|
||||||
beforeEach(inject(function($controller, $rootScope) {
|
beforeEach(inject(function($controller, $rootScope) {
|
||||||
|
|
@ -55,15 +105,15 @@ describe("Unit: Controllers", function() {
|
||||||
beforeEach(inject(function($controller, $injector) {
|
beforeEach(inject(function($controller, $injector) {
|
||||||
$httpBackend = $injector.get('$httpBackend');
|
$httpBackend = $injector.get('$httpBackend');
|
||||||
$httpBackend.when('GET', GH)
|
$httpBackend.when('GET', GH)
|
||||||
.respond( [{
|
.respond([{
|
||||||
name: "v100.1.6",
|
name: "v100.1.6",
|
||||||
zipball_url: "https://api.github.com/repos/bitpay/copay/zipball/v0.0.6",
|
zipball_url: "https://api.github.com/repos/bitpay/copay/zipball/v0.0.6",
|
||||||
tarball_url: "https://api.github.com/repos/bitpay/copay/tarball/v0.0.6",
|
tarball_url: "https://api.github.com/repos/bitpay/copay/tarball/v0.0.6",
|
||||||
commit: {
|
commit: {
|
||||||
sha: "ead7352bf2eca705de58d8b2f46650691f2bc2c7",
|
sha: "ead7352bf2eca705de58d8b2f46650691f2bc2c7",
|
||||||
url: "https://api.github.com/repos/bitpay/copay/commits/ead7352bf2eca705de58d8b2f46650691f2bc2c7"
|
url: "https://api.github.com/repos/bitpay/copay/commits/ead7352bf2eca705de58d8b2f46650691f2bc2c7"
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var rootScope;
|
var rootScope;
|
||||||
|
|
@ -86,32 +136,31 @@ describe("Unit: Controllers", function() {
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should hit github for version', function() {
|
it('should hit github for version', function() {
|
||||||
$httpBackend.expectGET(GH);
|
$httpBackend.expectGET(GH);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check version ', function() {
|
it('should check version ', function() {
|
||||||
$httpBackend.expectGET(GH);
|
$httpBackend.expectGET(GH);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
expect(scope.updateVersion.class).equal('error');
|
expect(scope.updateVersion.class).equal('error');
|
||||||
expect(scope.updateVersion.version).equal('v100.1.6');
|
expect(scope.updateVersion.version).equal('v100.1.6');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check blockChainStatus', function() {
|
it('should check blockChainStatus', function() {
|
||||||
$httpBackend.expectGET(GH);
|
$httpBackend.expectGET(GH);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
rootScope.insightError=1;
|
rootScope.insightError = 1;
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
expect(rootScope.insightError).equal(1);
|
expect(rootScope.insightError).equal(1);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
expect(rootScope.insightError).equal(1);
|
expect(rootScope.insightError).equal(1);
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue