Merge branch 'master' into feature/socket-io-support

Fix conflicts:
	js/app.js
	js/controllers/signin.js
This commit is contained in:
Gustavo Cortez 2014-04-17 11:58:11 -03:00
commit 2454d930fa
9 changed files with 63 additions and 68 deletions

View File

@ -337,6 +337,7 @@
<script src="js/filters.js"></script> <script src="js/filters.js"></script>
<script src="js/services/socket.js"></script> <script src="js/services/socket.js"></script>
<script src="js/services/walletFactory.js"></script> <script src="js/services/walletFactory.js"></script>
<script src="js/services/controllerUtils.js"></script>
<script src="js/controllers/header.js"></script> <script src="js/controllers/header.js"></script>
<script src="js/controllers/home.js"></script> <script src="js/controllers/home.js"></script>

View File

@ -12,6 +12,7 @@ angular.module('copay',[
'copay.walletFactory', 'copay.walletFactory',
'copay.signin', 'copay.signin',
'copay.socket', 'copay.socket',
'copay.controllerUtils',
'copay.setup', 'copay.setup',
'copay.peer' 'copay.peer'
]); ]);
@ -22,6 +23,7 @@ angular.module('copay.transactions', []);
angular.module('copay.send', []); angular.module('copay.send', []);
angular.module('copay.backup', []); angular.module('copay.backup', []);
angular.module('copay.walletFactory', []); angular.module('copay.walletFactory', []);
angular.module('copay.controllerUtils', []);
angular.module('copay.signin', []); angular.module('copay.signin', []);
angular.module('copay.setup', []); angular.module('copay.setup', []);
angular.module('copay.peer', []); angular.module('copay.peer', []);

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copay.setup').controller('SetupController', angular.module('copay.setup').controller('SetupController',
function($scope, $rootScope, $location, walletFactory) { function($scope, $rootScope, $location, walletFactory, controllerUtils) {
$scope.loading = false; $scope.loading = false;
@ -32,16 +32,7 @@ angular.module('copay.setup').controller('SetupController',
totalCopayers: totalCopayers totalCopayers: totalCopayers
}; };
var w = walletFactory.create(opts); var w = walletFactory.create(opts);
w.on('created', function(){ controllerUtils.setupUxHandlers(w);
$location.path('peer');
$rootScope.wallet = w;
$rootScope.$digest();
});
w.on('openError', function(){
$scope.loading = false;
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
$location.path('signin');
});
w.netStart(); w.netStart();
}; };

View File

@ -1,7 +1,9 @@
'use strict'; 'use strict';
angular.module('copay.signin').controller('SigninController', angular.module('copay.signin').controller('SigninController',
function($scope, $rootScope, $location, walletFactory) { function($scope, $rootScope, $location, walletFactory, controllerUtils) {
// var peerData = Storage.get($rootScope.walletId, 'peerData'); // var peerData = Storage.get($rootScope.walletId, 'peerData');
// $rootScope.peerId = peerData ? peerData.peerId : null; // $rootScope.peerId = peerData ? peerData.peerId : null;
@ -13,32 +15,6 @@ angular.module('copay.signin').controller('SigninController',
return walletFactory.getWalletIds(); return walletFactory.getWalletIds();
}; };
var _setupUxHandlers = function(w) {
w.on('created', function() {
$location.path('peer');
$rootScope.wallet = w;
// Initial getBalance
$rootScope.wallet.getBalance(function(balance) {
$scope.$apply(function() {
$rootScope.totalBalance = balance;
});
});
$rootScope.$digest();
});
w.on('refresh', function() {
console.log('[signin.js.23] RECEIVED REFRESH'); //TODO
});
w.on('openError', function(){
$scope.loading = false;
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
$location.path('signin');
});
};
$scope.create = function() { $scope.create = function() {
$location.path('setup'); $location.path('setup');
}; };
@ -47,7 +23,7 @@ console.log('[signin.js.23] RECEIVED REFRESH'); //TODO
$scope.loading = true; $scope.loading = true;
var w = walletFactory.open(walletId); var w = walletFactory.open(walletId);
_setupUxHandlers(w); controllerUtils.setupUxHandlers(w);
w.netStart(); w.netStart();
}; };
@ -56,7 +32,7 @@ console.log('[signin.js.42:join:]'); //TODO
$scope.loading = true; $scope.loading = true;
walletFactory.connectTo(cid, function(w) { walletFactory.connectTo(cid, function(w) {
console.log('[signin.js.50]'); //TODO console.log('[signin.js.50]'); //TODO
_setupUxHandlers(w); controllerUtils.setupUxHandlers(w);
w.netStart(); w.netStart();
}); });
}; };

View File

@ -22,7 +22,7 @@ function Wallet(opts) {
self[k] = opts[k]; self[k] = opts[k];
}); });
console.log('creating '+opts.requiredCopayers+' of '+opts.totalCopayers+' wallet'); this.log('creating '+opts.requiredCopayers+' of '+opts.totalCopayers+' wallet');
this.id = opts.id || Wallet.getRandomId(); this.id = opts.id || Wallet.getRandomId();
this.verbose = opts.verbose; this.verbose = opts.verbose;
@ -33,7 +33,7 @@ function Wallet(opts) {
Wallet.parent=EventEmitter; Wallet.parent=EventEmitter;
Wallet.prototype.log = function(){ Wallet.prototype.log = function(){
// if (!this.verbose) return; if (!this.verbose) return;
console.log(arguments); console.log(arguments);
}; };
@ -99,7 +99,7 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
if (this.id !== data.walletId) if (this.id !== data.walletId)
throw new Error('wrong message received: Bad wallet ID'); throw new Error('wrong message received: Bad wallet ID');
console.log('[Wallet.js.98]' , data.type); //TODO this.log('[Wallet.js.98]' , data.type); //TODO
switch(data.type) { switch(data.type) {
case 'publicKeyRing': case 'publicKeyRing':
@ -120,6 +120,7 @@ Wallet.prototype._handleNetworkChange = function(newPeer) {
this.sendWalletId(newPeer); this.sendWalletId(newPeer);
this.sendPublicKeyRing(newPeer); this.sendPublicKeyRing(newPeer);
this.sendTxProposals(newPeer); this.sendTxProposals(newPeer);
this.emit('refresh');
}; };
Wallet.prototype.netStart = function() { Wallet.prototype.netStart = function() {
@ -135,7 +136,7 @@ Wallet.prototype.netStart = function() {
}; };
Wallet.prototype.store = function() { Wallet.prototype.store = function() {
console.log('[Wallet.js.135:store:]'); //TODO this.log('[Wallet.js.135:store:]'); //TODO
this.storage.set(this.id,'opts', { this.storage.set(this.id,'opts', {
id: this.id, id: this.id,
spendUnconfirmed: this.spendUnconfirmed, spendUnconfirmed: this.spendUnconfirmed,
@ -146,7 +147,7 @@ console.log('[Wallet.js.135:store:]'); //TODO
this.storage.set(this.id,'txProposals', this.txProposals.toObj()); this.storage.set(this.id,'txProposals', this.txProposals.toObj());
this.storage.set(this.id,'privateKey', this.privateKey.toObj()); this.storage.set(this.id,'privateKey', this.privateKey.toObj());
console.log('[Wallet.js.146] EMIT REFRESH'); //TODO this.log('[Wallet.js.146] EMIT REFRESH'); //TODO
this.emit('refresh'); this.emit('refresh');
}; };
@ -229,13 +230,13 @@ Wallet.prototype.sign = function(ntxid) {
if (ret.signaturesAdded) { if (ret.signaturesAdded) {
txp.signedBy[this.privateKey.id] = Date.now(); txp.signedBy[this.privateKey.id] = Date.now();
console.log('[Wallet.js.230:ret:]',ret); //TODO this.log('[Wallet.js.230:ret:]',ret); //TODO
if (ret.isFullySigned) { if (ret.isFullySigned) {
console.log('[Wallet.js.231] BROADCASTING TX!!!'); //TODO this.log('[Wallet.js.231] BROADCASTING TX!!!'); //TODO
var tx = txp.builder.build(); var tx = txp.builder.build();
var txHex = tx.serialize().toString('hex'); var txHex = tx.serialize().toString('hex');
this.blockchain.sendRawTransaction(txHex, function(txid) { this.blockchain.sendRawTransaction(txHex, function(txid) {
console.log('[Wallet.js.235:txid:]',txid); //TODO this.log('[Wallet.js.235:txid:]',txid); //TODO
if (txid) { if (txid) {
this.store(); this.store();
} }

View File

@ -148,7 +148,10 @@ WalletFactory.prototype.openRemote = function(peedId) {
opts.storage = this.storage; opts.storage = this.storage;
opts.network = this.network; opts.network = this.network;
opts.blockchain = this.blockchain; opts.blockchain = this.blockchain;
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
opts.spendUnconfirmed = typeof opts.spendUnconfirmed === undefined
?this.walletDefaults.spendUnconfirmed : opts.spendUnconfirmed;
opts.requiredCopayers = requiredCopayers; opts.requiredCopayers = requiredCopayers;
opts.totalCopayers = totalCopayers; opts.totalCopayers = totalCopayers;
var w = new Wallet(opts); var w = new Wallet(opts);

View File

@ -61,14 +61,9 @@ Network._arrayRemove = function(el, array) {
return array; return array;
}; };
// DEBUG
Network.prototype._showConnectedPeers = function() {
// console.log("### CONNECTED PEERS", this.connectedPeers);
};
Network.prototype._onClose = function(peerId) { Network.prototype._onClose = function(peerId) {
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers); this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
this._notify(); this._notifyNetworkChange();
}; };
Network.prototype._connectToPeers = function(peerIds) { Network.prototype._connectToPeers = function(peerIds) {
@ -97,7 +92,7 @@ Network.prototype._onData = function(data, isInbound) {
switch(obj.data.type) { switch(obj.data.type) {
case 'peerList': case 'peerList':
this._connectToPeers(obj.data.peers); this._connectToPeers(obj.data.peers);
this._notify(); this._notifyNetworkChange();
break; break;
case 'disconnect': case 'disconnect':
this._onClose(obj.sender); this._onClose(obj.sender);
@ -144,7 +139,7 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
dataConn.peer, isInbound); dataConn.peer, isInbound);
self._addPeer(dataConn.peer, isInbound); self._addPeer(dataConn.peer, isInbound);
self._notify( isInbound ? dataConn.peer : null); self._notifyNetworkChange( isInbound ? dataConn.peer : null);
this.emit('open'); this.emit('open');
} }
}); });
@ -166,8 +161,8 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
}); });
}; };
Network.prototype._notify = function(newPeer) { Network.prototype._notifyNetworkChange = function(newPeer) {
this._showConnectedPeers(); console.log('[WebRTC.js.164:_notifyNetworkChange:]', newPeer); //TODO
this.emit('networkChange', newPeer); this.emit('networkChange', newPeer);
}; };
@ -178,7 +173,7 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
p.on('open', function(peerId) { p.on('open', function(peerId) {
self.peerId = peerId; self.peerId = peerId;
self.connectedPeers = [peerId]; self.connectedPeers = [peerId];
self._notify(); self._notifyNetworkChange();
return openCallback(peerId); return openCallback(peerId);
}); });
@ -263,7 +258,6 @@ Network.prototype.connectTo = function(peerId) {
console.log('### STARTING TO CONNECT TO:' + peerId ); console.log('### STARTING TO CONNECT TO:' + peerId );
var dataConn = this.peer.connect(peerId, { var dataConn = this.peer.connect(peerId, {
// label: 'wallet',
serialization: 'none', serialization: 'none',
reliable: true, reliable: true,
metadata: { message: 'hi copayer!' } metadata: { message: 'hi copayer!' }

View File

@ -0,0 +1,25 @@
'use strict';
angular.module('copay.controllerUtils').factory('controllerUtils', function ($rootScope, $location) {
var root = {};
root.setupUxHandlers = function(w) {
w.on('created', function() {
$location.path('peer');
$rootScope.wallet = w;
$rootScope.$digest();
});
w.on('refresh', function() {
console.log('[controllerUtils.js] RECEIVED REFRESH'); //TODO
$rootScope.$digest();
});
w.on('openError', function(){
$scope.loading = false;
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
$location.path('signin');
});
};
return root;
});

View File

@ -56,7 +56,7 @@ describe('PublicKeyRing model', function() {
w2.registeredCopayers().should.equal(0); w2.registeredCopayers().should.equal(0);
w2.isComplete().should.equal(false); w2.isComplete().should.equal(false);
w2.getAddress.bind(false).should.throw(); (function() {w2.getAddress(0, false);}).should.throw();
}); });
it('should add and check when adding shared pub keys', function () { it('should add and check when adding shared pub keys', function () {
@ -65,9 +65,10 @@ describe('PublicKeyRing model', function() {
var copayers = k.copayers; var copayers = k.copayers;
w.isComplete().should.equal(true); w.isComplete().should.equal(true);
w.addCopayer.bind().should.throw(); w.addCopayer.should.throw();
for(var i =0; i<5; i++) for(var i =0; i<5; i++) {
w.addCopayer.bind(copayers[i]).should.throw(); (function() {w.addCopayer(copayers[i])}).should.throw();
}
}); });
it('show be able to tostore and read', function () { it('show be able to tostore and read', function () {
@ -85,9 +86,10 @@ describe('PublicKeyRing model', function() {
var w2 = PublicKeyRing.fromObj(data); var w2 = PublicKeyRing.fromObj(data);
w2.walletId.should.equal(w.walletId); w2.walletId.should.equal(w.walletId);
w2.isComplete().should.equal(true); w2.isComplete().should.equal(true);
w2.addCopayer.bind().should.throw(); w2.addCopayer.should.throw();
for(var i =0; i<5; i++) for(var i =0; i<5; i++) {
w2.addCopayer.bind(copayers[i]).should.throw(); (function() {w.addCopayer(copayers[i])}).should.throw();
}
w2.changeAddressIndex.should.equal(3); w2.changeAddressIndex.should.equal(3);
w2.addressIndex.should.equal(5); w2.addressIndex.should.equal(5);