mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #77 from matiu/bug/fix-uxrefresh
fix uxrefresh with new #setup - awesome!!
This commit is contained in:
commit
73d5266a89
|
@ -335,6 +335,7 @@
|
|||
<script src="js/directives.js"></script>
|
||||
<script src="js/filters.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/home.js"></script>
|
||||
|
|
|
@ -11,6 +11,7 @@ angular.module('copay',[
|
|||
'copay.backup',
|
||||
'copay.walletFactory',
|
||||
'copay.signin',
|
||||
'copay.controllerUtils',
|
||||
'copay.setup',
|
||||
'copay.peer'
|
||||
]);
|
||||
|
@ -21,6 +22,7 @@ angular.module('copay.transactions', []);
|
|||
angular.module('copay.send', []);
|
||||
angular.module('copay.backup', []);
|
||||
angular.module('copay.walletFactory', []);
|
||||
angular.module('copay.controllerUtils', []);
|
||||
angular.module('copay.signin', []);
|
||||
angular.module('copay.setup', []);
|
||||
angular.module('copay.peer', []);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.setup').controller('SetupController',
|
||||
function($scope, $rootScope, $location, walletFactory) {
|
||||
function($scope, $rootScope, $location, walletFactory, controllerUtils) {
|
||||
|
||||
$scope.loading = false;
|
||||
|
||||
|
@ -32,16 +32,7 @@ angular.module('copay.setup').controller('SetupController',
|
|||
totalCopayers: totalCopayers
|
||||
};
|
||||
var w = walletFactory.create(opts);
|
||||
w.on('created', function(){
|
||||
$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');
|
||||
});
|
||||
controllerUtils.setupUxHandlers(w);
|
||||
w.netStart();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
|
||||
angular.module('copay.signin').controller('SigninController',
|
||||
function($scope, $rootScope, $location, walletFactory) {
|
||||
function($scope, $rootScope, $location, walletFactory, controllerUtils) {
|
||||
|
||||
// var peerData = Storage.get($rootScope.walletId, 'peerData');
|
||||
// $rootScope.peerId = peerData ? peerData.peerId : null;
|
||||
|
@ -13,25 +15,6 @@ angular.module('copay.signin').controller('SigninController',
|
|||
return walletFactory.getWalletIds();
|
||||
};
|
||||
|
||||
var _setupUxHandlers = function(w) {
|
||||
w.on('created', function() {
|
||||
$location.path('peer');
|
||||
$rootScope.wallet = w;
|
||||
$rootScope.$digest();
|
||||
});
|
||||
w.on('refresh', function() {
|
||||
|
||||
console.log('[signin.js.23] RECEIVED REFRESH'); //TODO
|
||||
$rootScope.$digest();
|
||||
});
|
||||
|
||||
w.on('openError', function(){
|
||||
$scope.loading = false;
|
||||
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
|
||||
$location.path('signin');
|
||||
});
|
||||
};
|
||||
|
||||
$scope.create = function() {
|
||||
$location.path('setup');
|
||||
};
|
||||
|
@ -40,7 +23,7 @@ console.log('[signin.js.23] RECEIVED REFRESH'); //TODO
|
|||
$scope.loading = true;
|
||||
|
||||
var w = walletFactory.open(walletId);
|
||||
_setupUxHandlers(w);
|
||||
controllerUtils.setupUxHandlers(w);
|
||||
w.netStart();
|
||||
};
|
||||
|
||||
|
@ -49,7 +32,7 @@ console.log('[signin.js.42:join:]'); //TODO
|
|||
$scope.loading = true;
|
||||
walletFactory.connectTo(cid, function(w) {
|
||||
console.log('[signin.js.50]'); //TODO
|
||||
_setupUxHandlers(w);
|
||||
controllerUtils.setupUxHandlers(w);
|
||||
w.netStart();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -120,6 +120,7 @@ Wallet.prototype._handleNetworkChange = function(newPeer) {
|
|||
this.sendWalletId(newPeer);
|
||||
this.sendPublicKeyRing(newPeer);
|
||||
this.sendTxProposals(newPeer);
|
||||
this.emit('refresh');
|
||||
};
|
||||
|
||||
Wallet.prototype.netStart = function() {
|
||||
|
|
|
@ -148,7 +148,10 @@ WalletFactory.prototype.openRemote = function(peedId) {
|
|||
opts.storage = this.storage;
|
||||
opts.network = this.network;
|
||||
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.totalCopayers = totalCopayers;
|
||||
var w = new Wallet(opts);
|
||||
|
|
|
@ -61,14 +61,9 @@ Network._arrayRemove = function(el, array) {
|
|||
return array;
|
||||
};
|
||||
|
||||
// DEBUG
|
||||
Network.prototype._showConnectedPeers = function() {
|
||||
// console.log("### CONNECTED PEERS", this.connectedPeers);
|
||||
};
|
||||
|
||||
Network.prototype._onClose = function(peerId) {
|
||||
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
|
||||
this._notify();
|
||||
this._notifyNetworkChange();
|
||||
};
|
||||
|
||||
Network.prototype._connectToPeers = function(peerIds) {
|
||||
|
@ -97,7 +92,7 @@ Network.prototype._onData = function(data, isInbound) {
|
|||
switch(obj.data.type) {
|
||||
case 'peerList':
|
||||
this._connectToPeers(obj.data.peers);
|
||||
this._notify();
|
||||
this._notifyNetworkChange();
|
||||
break;
|
||||
case 'disconnect':
|
||||
this._onClose(obj.sender);
|
||||
|
@ -144,7 +139,7 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
|||
dataConn.peer, isInbound);
|
||||
|
||||
self._addPeer(dataConn.peer, isInbound);
|
||||
self._notify( isInbound ? dataConn.peer : null);
|
||||
self._notifyNetworkChange( isInbound ? dataConn.peer : null);
|
||||
this.emit('open');
|
||||
}
|
||||
});
|
||||
|
@ -166,8 +161,8 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
|||
});
|
||||
};
|
||||
|
||||
Network.prototype._notify = function(newPeer) {
|
||||
this._showConnectedPeers();
|
||||
Network.prototype._notifyNetworkChange = function(newPeer) {
|
||||
console.log('[WebRTC.js.164:_notifyNetworkChange:]', newPeer); //TODO
|
||||
this.emit('networkChange', newPeer);
|
||||
};
|
||||
|
||||
|
@ -178,7 +173,7 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
|||
p.on('open', function(peerId) {
|
||||
self.peerId = peerId;
|
||||
self.connectedPeers = [peerId];
|
||||
self._notify();
|
||||
self._notifyNetworkChange();
|
||||
return openCallback(peerId);
|
||||
});
|
||||
|
||||
|
@ -263,7 +258,6 @@ Network.prototype.connectTo = function(peerId) {
|
|||
console.log('### STARTING TO CONNECT TO:' + peerId );
|
||||
|
||||
var dataConn = this.peer.connect(peerId, {
|
||||
// label: 'wallet',
|
||||
serialization: 'none',
|
||||
reliable: true,
|
||||
metadata: { message: 'hi copayer!' }
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
Loading…
Reference in New Issue