Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Commit

Permalink
fix(Send): refresh txs 3 seconds after send in case socket fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Feb 18, 2016
1 parent 3910eb8 commit 4680edf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
14 changes: 13 additions & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@ angular.module('walletApp', modules)
.config(($uibModalProvider, uiSelectConfig) => {
uiSelectConfig.theme = 'bootstrap';
})
.run(($rootScope, $uibModal, $state) => {
.run(($rootScope, $uibModal, $state, MyWallet, $q, currency) => {

$rootScope.$safeApply = (scope=$rootScope, before) => {
before = before;
if (!scope.$$phase && !$rootScope.$$phase) scope.$apply(before);
};

$rootScope.refresh = () => {

$rootScope.refreshing = true;
let amt = MyWallet.wallet.txList.transactions().length;
$q.all([MyWallet.wallet.getHistory(), currency.fetchExchangeRate(), MyWallet.wallet.txList.fetchTxs(amt, true)])
.catch(() => console.log('error refreshing'))
.finally(() => {
$rootScope.$broadcast('refresh');
$timeout(() => $rootScope.refreshing = false, 500);
});
}

$rootScope.$on('showNotification', (_, notification) => {
$uibModal.open({
templateUrl: 'partials/modal-notification.jade',
Expand Down
8 changes: 7 additions & 1 deletion assets/js/controllers/claimModal.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular
.module('walletApp')
.controller("ClaimModalCtrl", ClaimModalCtrl);

function ClaimModalCtrl($scope, Wallet, $translate, $uibModalInstance, claim) {
function ClaimModalCtrl($scope, Wallet, $translate, $uibModalInstance, claim, $rootScope, $timeout) {
$scope.accounts = Wallet.accounts;
$scope.fields = {
to: null
Expand All @@ -20,6 +20,12 @@ function ClaimModalCtrl($scope, Wallet, $translate, $uibModalInstance, claim) {
const success = () => {
$scope.redeeming = false;
$uibModalInstance.dismiss("");
$timeout(() => {
// In case the web socket fails:
$rootScope.refresh();
}, 3000);

$rootScope.$safeApply()
};
const error = (e) => {
console.log(e);
Expand Down
16 changes: 1 addition & 15 deletions assets/js/controllers/navigation.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,11 @@ angular
.module('walletApp')
.controller("NavigationCtrl", NavigationCtrl);

function NavigationCtrl($rootScope, $scope, Wallet, currency, SecurityCenter, $translate, $cookies, $state, filterFilter, $interval, $timeout, $q, MyWallet) {
function NavigationCtrl($rootScope, $scope, Wallet, currency, SecurityCenter, $translate, $cookies, $state, filterFilter, $interval, $timeout) {
$scope.status = Wallet.status;
$scope.security = SecurityCenter.security;
$scope.settings = Wallet.settings;

let wallet = {};
wallet.my = MyWallet.wallet;

$scope.refresh = () => {
$scope.refreshing = true;
let amt = wallet.my.txList.transactions().length;
$q.all([Wallet.my.wallet.getHistory(), currency.fetchExchangeRate(), wallet.my.txList.fetchTxs(amt, true)])
.catch(() => console.log('error refreshing'))
.finally(() => {
$rootScope.$broadcast('refresh');
$timeout(() => $scope.refreshing = false, 500);
});
}

$scope.logout = () => {
if (!Wallet.isSynchronizedWithServer()) {
if (confirm("There are changes still being saved. Are you sure you wish to logout?")) {
Expand Down
4 changes: 4 additions & 0 deletions assets/js/controllers/send.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ function SendCtrl($scope, $log, Wallet, Alerts, currency, $uibModalInstance, $ti
};

const transactionSucceeded = (tx) => {
$timeout(() => {
// In case the web socket fails:
$rootScope.refresh();
}, 3000);
$scope.sending = false;
$uibModalInstance.close("");
Wallet.beep();
Expand Down
6 changes: 5 additions & 1 deletion assets/js/controllers/settings/addressImport.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular
.module('walletApp')
.controller("AddressImportCtrl", AddressImportCtrl);

function AddressImportCtrl($scope, $log, Wallet, Alerts, $uibModalInstance, $translate, $state, $timeout, address) {
function AddressImportCtrl($scope, $log, Wallet, Alerts, $uibModalInstance, $translate, $state, $timeout, address, $rootScope) {
$scope.settings = Wallet.settings;
$scope.accounts = Wallet.accounts;
$scope.alerts = Alerts.alerts;
Expand Down Expand Up @@ -101,6 +101,10 @@ function AddressImportCtrl($scope, $log, Wallet, Alerts, $uibModalInstance, $tra
msg: translations.BITCOIN_SENT
});
});
$timeout(() => {
// In case the web socket fails:
$rootScope.refresh();
}, 3000);
};

const error = (error) => {
Expand Down

0 comments on commit 4680edf

Please sign in to comment.