handle network reconnection

This commit is contained in:
Matias Alejo Garcia 2015-04-13 14:58:07 -03:00
commit 9efa2dfe24
16 changed files with 125 additions and 66 deletions

View file

@ -28,9 +28,9 @@
<div ng-include="'views/includes/sidebar.html'" ng-if="index.hasProfile"></div> <div ng-include="'views/includes/sidebar.html'" ng-if="index.hasProfile"></div>
<div notifications="right top"></div> <div notifications="right top"></div>
<div ng-include="'views/includes/offline.html'" ng-if="index.hasProfile && index.isOffLine"></div> <div ng-include="'views/includes/offline.html'" ng-if="index.isOffline"></div>
<div ng-include="'views/includes/clientError.html'"
ng-if="index.hasProfile && !index.isOffLine && index.clientError"></div> <div ng-include="'views/includes/clientError.html'" ng-if="index.clientError"></div>
<div ng-include="'views/includes/password.html'" ng-if="index.askPassword" <div ng-include="'views/includes/password.html'" ng-if="index.askPassword"
></div> ></div>

View file

@ -1,5 +1,5 @@
<div ng-controller="copayersController as copayers" ng-init="copayers.init()" <div ng-controller="copayersController as copayers" ng-init="copayers.init()"
ng-if="!index.isOffLine && !index.clientError"> ng-if="!index.clientError">
<div ng-show="!index.notAuthorized"> <div ng-show="!index.notAuthorized">
<div class="row m10t text-center"> <div class="row m10t text-center">

View file

@ -5,16 +5,11 @@
<img src="img/logo-negative-beta.svg" alt="Copay" width="100"> <img src="img/logo-negative-beta.svg" alt="Copay" width="100">
<div ng-include="'views/includes/version.html'"></div> <div ng-include="'views/includes/version.html'"></div>
</div> </div>
<div ng-if="index.isOffLine" class="row"> <div class="text-center size-12 text-warning" ng-show="cp.error">
<div class="large-12 columns"> {{(cp.error)|translate}}. Retrying...
<h1 class="text-center text-warning" translate>Warning</h1>
<div class="panel">
<p translate>You dont have an internet connection active. Copay needs connection to create a wallet</p>
</div>
</div>
</div> </div>
<!-- <div ng&#45;if="!index.isOffLine &#38;&#38; !cp.creatingProfile" ng&#45;include="'views/includes/pin.html'" ng&#45;init="confirmPin=true"></div> -->
<div class="m20tp text-white text-center animated infinite flash" ng-if="!index.isOffLine && cp.creatingProfile"> <div class="m20tp text-white text-center animated infinite flash" ng-if="cp.creatingProfile">
<span translate>Creating wallet...</span> <span translate>Creating wallet...</span>
</div> </div>
</div> </div>

View file

@ -3,7 +3,15 @@
<div class="large-12 columns"> <div class="large-12 columns">
<div class="oh text-center"> <div class="oh text-center">
<span ng-if="index.updatingTxHistory" class="text-gray" translate>Getting transactions...</span> <span ng-if="index.updatingTxHistory" class="text-gray" translate>Getting transactions...</span>
<span ng-if="!index.updatingTxHistory">No transactions yet</span>
<div class="box-notification" ng-show="index.txHistoryError">
<div class="box-icon error">
<i class="fi-x size-24"></i>
</div>
<span class="text-warning size-14" translate> Could not fetch transaction history
</span>
</div>
<span ng-if="!index.updatingTxHistory && !index.txHistoryError">No transactions yet</span>
</div> </div>
</div> </div>
</div> </div>

View file

@ -4,8 +4,8 @@
<i class="fi-alert"></i> <i class="fi-alert"></i>
</div> </div>
<div class="dr-notification-content"> <div class="dr-notification-content">
<h3 class="dr-notification-title">{{'No internet connection'|translate}}</h3> <h3 class="dr-notification-title">{{'Could not connect to Wallet Service'|translate}}</h3>
<div class="dr-notification-text ellipsis">{{'Copay needs connection to run basic functions'|translate}}</div> <div class="dr-notification-text ellipsis">{{'Trying to reconnnect...'|translate}}</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -15,7 +15,7 @@
<div class="size-12">{{item.m}} of {{item.n}}</div> <div class="size-12">{{item.m}} of {{item.n}}</div>
</a> </a>
</li> </li>
<li ng-if="!index.isOffLine"> <li>
<a ng-click="$root.go('add')"> <a ng-click="$root.go('add')">
<i class="icon-arrow-right3 size-18 right m10t"></i> <i class="icon-arrow-right3 size-18 right m10t"></i>
<i class="fi-plus size-24 db left m10r"></i> <i class="fi-plus size-24 db left m10r"></i>

View file

@ -34,6 +34,15 @@
</div> </div>
</div> </div>
<div ng-show="!receive.generatingAddress"> <div ng-show="!receive.generatingAddress">
<div class="box-notification" ng-show="receive.error ">
<div class="box-icon error">
<i class="fi-x size-24"></i>
</div>
<span class="text-warning size-14">
{{receive.error|translate}}
</span>
</div>
<div class="row" ng-show="receive.addr"> <div class="row" ng-show="receive.addr">
<!-- Address--> <!-- Address-->
<div class="large-12 columns"> <div class="large-12 columns">
@ -56,7 +65,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row m20t" ng-show="receive.addr && !index.isOffLine && !index.clientError"> <div class="row m20t" ng-show="receive.addr">
<div class="large-12 columns"> <div class="large-12 columns">
<a class="button black expand radius" ng-click="receive.newAddress()" <a class="button black expand radius" ng-click="receive.newAddress()"
ng-style="{'background-color':index.backgroundColor}" translate> ng-style="{'background-color':index.backgroundColor}" translate>

View file

@ -1,4 +1,4 @@
<div class="send" ng-controller="sendController as send" ng-init="send.init()" ng-show="!index.isOffLine"> <div class="send" ng-controller="sendController as send" ng-init="send.init()">
<div ng-show="index.lockedBalance"> <div ng-show="index.lockedBalance">
<h4 class="title m0"> <h4 class="title m0">
<div class="left"> <div class="left">
@ -152,6 +152,4 @@
</div> </div>
<!-- end of row --> <!-- end of row -->
</div> </div>
<div ng-if="index.isOffLine" class="m20tp text-center" translate>Checking your internet connection...</div>
<div class="extra-margin-bottom"></div> <div class="extra-margin-bottom"></div>

View file

@ -1,6 +1,7 @@
<div class="home-wallet" ng-controller="walletHomeController as home" ng-init="home.init()"> <div class="home-wallet" ng-controller="walletHomeController as home" ng-init="home.init()">
<div class="row" ng-show="!index.noFocusedWallet"> <div class="row" ng-show="!index.noFocusedWallet">
<div class="amount" ng-style="{'background-color':index.backgroundColor}"> <div class="amount" ng-style="{'background-color':index.backgroundColor}">
<div class="size-36"> <div class="size-36">
<strong> <strong>
<span ng-show="!index.hideBalance"> <span ng-show="!index.hideBalance">
@ -39,6 +40,15 @@
</div> </div>
</div> </div>
<div ng-show="index.updateError">
<div class="text-center text-warning m10t">
<i class="fi-alert"></i>
<span translate>
Could not update Wallet
</span>
</div>
</div>
</div>
<div ng-show="index.notAuthorized"> <div ng-show="index.notAuthorized">
<div class="text-center text-warning"> <div class="text-center text-warning">

View file

@ -476,8 +476,10 @@ a.pin-button:active {
.dr-notification-wrapper.offline { .dr-notification-wrapper.offline {
position: absolute; position: absolute;
top: 45px; top: 0px;
z-index: 11; z-index: 2000;
opacity: 1.0 !important;
background-color: #2C3E50;
} }
.dr-notification-wrapper.client-error { .dr-notification-wrapper.client-error {

View file

@ -69,8 +69,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var get = function(cb) { var get = function(cb) {
if (walletStatus) if (walletStatus)
return cb(null, walletStatus); return cb(null, walletStatus);
else else {
return fc.getStatus(cb); self.updateError = false;
return fc.getStatus(function(err, ret) {
if (err) self.updateError = true;
return cb(err, ret);
});
}
}; };
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
@ -144,6 +149,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$timeout(function() { $timeout(function() {
self.setOngoingProcess('updatingTxHistory', true); self.setOngoingProcess('updatingTxHistory', true);
$log.debug('Updating Transaction History'); $log.debug('Updating Transaction History');
self.txHistoryError = false;
fc.getTxHistory({ fc.getTxHistory({
skip: self.skipHistory, skip: self.skipHistory,
limit: self.limitHistory + 1 limit: self.limitHistory + 1
@ -152,8 +158,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (err) { if (err) {
$log.debug('TxHistory ERROR:', err); $log.debug('TxHistory ERROR:', err);
$scope.$emit('Local/ClientError', err); $scope.$emit('Local/ClientError', err);
} self.txHistoryError = true;
else { } else {
$log.debug('Wallet Transaction History:', txs); $log.debug('Wallet Transaction History:', txs);
self.skipHistory = self.skipHistory + self.limitHistory; self.skipHistory = self.skipHistory + self.limitHistory;
self.setTxHistory(txs); self.setTxHistory(txs);
@ -390,14 +396,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r
go.walletHome(); go.walletHome();
}); });
$rootScope.$on('Local/OnLine', function(event) { lodash.each(['Local/Online', 'Local/Resume'], function(eventName) {
self.isOffLine = false; $rootScope.$on(eventName, function(event) {
self.updateAll(); $log.debug('### Online event');
self.updateTxHistory(); self.isOffline = false;
self.updateAll();
self.updateTxHistory();
});
}); });
$rootScope.$on('Local/OffLine', function(event) { $rootScope.$on('Local/Offline', function(event) {
self.isOffLine = true; $log.debug('========== Offline event');
self.isOffline = true;
$rootScope.$apply();
}); });
$rootScope.$on('Local/BackupDone', function(event) { $rootScope.$on('Local/BackupDone', function(event) {
@ -424,6 +435,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (err.code && err.code === 'NOTAUTHORIZED') { if (err.code && err.code === 'NOTAUTHORIZED') {
// Show not error, just redirect to home (where the recreate option is shown) // Show not error, just redirect to home (where the recreate option is shown)
go.walletHome(); go.walletHome();
} else if (err && err.cors == 'rejected') {
$log.debug('CORS error:', err);
} else { } else {
self.clientError = err; self.clientError = err;
} }
@ -506,7 +519,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) { $rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
self.askPassword = { self.askPassword = {
isSetup: isSetup, isSetup: isSetup,
callback: function (err, pass) { callback: function(err, pass) {
self.askPassword = null; self.askPassword = null;
return cb(err, pass); return cb(err, pass);
}, },

View file

@ -16,15 +16,17 @@ angular.module('copayApp.controllers').controller('receiveController',
this.newAddress = function() { this.newAddress = function() {
self.generatingAddress = true; self.generatingAddress = true;
self.error = null;
fc.createAddress(function(err, addr) { fc.createAddress(function(err, addr) {
self.generatingAddress = false;
if (err) { if (err) {
$log.debug('Creating address ERROR:', err); $log.debug('Creating address ERROR:', err);
$scope.$emit('Local/ClientError', err); $scope.$emit('Local/ClientError', err);
self.error='Could not generate address';
} else { } else {
self.addr = addr.address; self.addr = addr.address;
storageService.storeLastAddress(fc.credentials.walletId, addr.address, function() {}); storageService.storeLastAddress(fc.credentials.walletId, addr.address, function() {});
} }
self.generatingAddress = false;
$scope.$digest(); $scope.$digest();
}); });
}; };

View file

@ -23,13 +23,24 @@ angular.element(document).ready(function() {
window.location = '#/'; window.location = '#/';
} }
}, false); }, false);
document.addEventListener('resume', function() { document.addEventListener('resume', function() {
window.location = '#/cordova/resume';
setTimeout(function() { setTimeout(function() {
window.ignoreMobilePause = false; window.ignoreMobilePause = false;
}, 100); }, 100);
}, false); }, false);
// We are not emitting here, since when the BWS socket reconnects,
// update will be triggered
// document.addEventListener('offline', function() {
// window.location = '#/cordova/offline';
// }, false);
//
// document.addEventListener("online", function() {
// window.location = '#/cordoba/online';
// }, false);
document.addEventListener('backbutton', function() { document.addEventListener('backbutton', function() {
window.location = '#/walletHome'; window.location = '#/walletHome';
}, false); }, false);
@ -38,13 +49,7 @@ angular.element(document).ready(function() {
window.location = '#/preferences'; window.location = '#/preferences';
}, false); }, false);
document.addEventListener('offline', function() {
window.location = '#/network/offline';
}, false);
document.addEventListener("online", function() {
window.location = '#/network/online';
}, false);
setTimeout(function() { setTimeout(function() {
navigator.splashscreen.hide(); navigator.splashscreen.hide();

View file

@ -322,8 +322,8 @@ angular
} }
} }
}) })
.state('preferencesAltCurrency', { .state('preferencesAltCurrency', {
url: '/preferencesAltCurrency', url: '/preferencesAltCurrency',
templateUrl: 'views/preferencesAltCurrency.html', templateUrl: 'views/preferencesAltCurrency.html',
walletShouldBeComplete: true, walletShouldBeComplete: true,
@ -409,33 +409,36 @@ angular
}) })
.state('add', { .state('add', {
url: '/add', url: '/add',
needProfile: true, needProfile: true,
views: { views: {
'main': { 'main': {
templateUrl: 'views/add.html' templateUrl: 'views/add.html'
}, },
'topbar': { 'topbar': {
templateUrl: 'views/includes/topbar.html', templateUrl: 'views/includes/topbar.html',
controller: function($scope) { controller: function($scope) {
$scope.titleSection = 'Add wallet'; $scope.titleSection = 'Add wallet';
$scope.goBackToState = 'walletHome'; $scope.goBackToState = 'walletHome';
}
} }
} }
} })
}) .state('cordova', {
.state('network', { url: '/cordova/:status',
url: '/network/:status',
views: { views: {
'main': { 'main': {
controller: function($scope, $stateParams, go) { controller: function($scope, $stateParams, go) {
switch ($stateParams.status) { switch ($stateParams.status) {
case 'online': case 'resume':
$scope.$emit('Local/OnLine'); $scope.$emit('Local/Resume');
break;
case 'offline':
$scope.$emit('Local/OffLine');
break; break;
// case 'online':
// // $scope.$emit('Local/Online');
// break;
// case 'offline':
// // $scope.$emit('Local/Offline');
// break;
}; };
go.walletHome(); go.walletHome();
} }
@ -491,8 +494,7 @@ angular
if (pageWeight[fromState.name] > pageWeight[toState.name]) { if (pageWeight[fromState.name] > pageWeight[toState.name]) {
$rootScope.$emit('Animation/SwipeRight'); $rootScope.$emit('Animation/SwipeRight');
} } else if (pageWeight[fromState.name] < pageWeight[toState.name]) {
else if (pageWeight[fromState.name] < pageWeight[toState.name]) {
$rootScope.$emit('Animation/SwipeLeft'); $rootScope.$emit('Animation/SwipeLeft');
} }

View file

@ -13,6 +13,7 @@ angular.module('copayApp.services').factory('configService', function(localStora
// Bitcore wallet service URL // Bitcore wallet service URL
bws: { bws: {
url: 'http://162.242.245.33:3004/bws/api', url: 'http://162.242.245.33:3004/bws/api',
// url: 'http://localhost:3001/bws/api',
}, },
// insight // insight

View file

@ -60,6 +60,20 @@ angular.module('copayApp.services')
root.walletClients[credentials.walletId] = client; root.walletClients[credentials.walletId] = client;
client.removeAllListeners(); client.removeAllListeners();
client.on('reconnect', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$rootScope.$emit('Local/Online');
}
});
client.on('reconnecting', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$rootScope.$emit('Local/Offline');
}
});
client.on('notification', function(n) { client.on('notification', function(n) {
$log.debug('BWC Notification:', n); $log.debug('BWC Notification:', n);
notificationService.newBWCNotification(n, notificationService.newBWCNotification(n,