replace ongoingprocess

This commit is contained in:
Matias Alejo Garcia 2016-06-13 11:44:58 -03:00
commit c294097c1d
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
5 changed files with 279 additions and 359 deletions

View file

@ -16,35 +16,6 @@
</div> </div>
</div> </div>
<div class="onGoingProcess" ng-show="index.isOffline">
<div class="onGoingProcess-content" ng-style="{'background-color':'#222'}">
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
<span translate>Reconnecting to Wallet Service...</span>
</div>
</div>
<div class="onGoingProcess" ng-show="index.anyOnGoingProcess && !index.isOffline">
<div class="onGoingProcess-content" ng-style="{'background-color':index.backgroundColor}">
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
<span translate ng-show="
index.onGoingProcessName == 'openingWallet'
|| index.onGoingProcessName == 'updatingStatus'
|| index.onGoingProcessName == 'updatingBalance'
|| index.onGoingProcessName == 'updatingPendingTxps'
"> Updating Wallet... </span>
<span translate ng-show="index.onGoingProcessName == 'scanning'">Scanning Wallet funds...</span>
<span translate ng-show="index.onGoingProcessName == 'recreating'">Recreating Wallet...</span>
<span translate ng-show="index.onGoingProcessName == 'generatingCSV'">Generating .csv file...</span>
</div>
</div>
<div class="onGoingProcess" ng-show="home.onGoingProcess && !index.anyOnGoingProces && !index.isOffline">
<div class="onGoingProcess-content" ng-style="{'background-color':index.backgroundColor}">
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
{{home.onGoingProcess}}...
</div>
</div>
<div class="oh" ng-show="!index.noFocusedWallet"> <div class="oh" ng-show="!index.noFocusedWallet">
<!-- <!--
@ -63,7 +34,7 @@
</ion-refresher> </ion-refresher>
<div class="oh pr"> <div class="oh pr">
<div ng-style="{'background-color':index.backgroundColor}" class="amount"> <div ng-style="{'background-color':index.backgroundColor}" class="amount">
<div ng-if="!index.anyOnGoingProcess && !index.notAuthorized"> <div ng-if="!index.notAuthorized">
<div class="m15t" ng-show="index.updateError" ng-click='index.updateAll({triggerTxUpdate: true})'> <div class="m15t" ng-show="index.updateError" ng-click='index.updateAll({triggerTxUpdate: true})'>
<span class="size-12 db m10b">{{index.updateError|translate}}</span> <span class="size-12 db m10b">{{index.updateError|translate}}</span>
<button class="outline white tiny round" translate>Tap to retry</button> <button class="outline white tiny round" translate>Tap to retry</button>
@ -89,12 +60,6 @@
</div> </div>
</div> </div>
</div> </div>
<div ng-if="index.anyOnGoingProcess">
<div class="size-36">
<strong>...</strong>
</div>
</div>
</div> <!-- amount --> </div> <!-- amount -->
<div class="wallet-info"> <div class="wallet-info">
@ -114,7 +79,7 @@
</span> </span>
</div> </div>
</div> </div>
<div class="oh pr m20t" ng-show="index.notAuthorized && !index.anyOnGoingProcess"> <div class="oh pr m20t" ng-show="index.notAuthorized">
<div class="text-center text-warning"> <div class="text-center text-warning">
<i class="fi-alert"></i> <i class="fi-alert"></i>
<span translate> <span translate>
@ -335,7 +300,7 @@
<div class="large-12 columns"> <div class="large-12 columns">
<div class="line-t size-10 text-gray m10b p10t" ng-show="!index.isSingleAddress"> <div class="line-t size-10 text-gray m10b p10t" ng-show="!index.isSingleAddress">
<span translate> Share this wallet address to receive payments. To protect your privacy, new addresses are generated automatically once you use them.</span> <span translate> Share this wallet address to receive payments. To protect your privacy, new addresses are generated automatically once you use them.</span>
<a ng-show="!home.blockUx && !home.generatingAddress" ng-click="home.setAddress(true)" translate>Generate new address</a> <a ng-show="!home.generatingAddress" ng-click="home.setAddress(true)" translate>Generate new address</a>
</div> </div>
<div class="line-t size-10 text-gray m10b p10t" ng-show="index.isSingleAddress"> <div class="line-t size-10 text-gray m10b p10t" ng-show="index.isSingleAddress">
<span translate> Share this wallet address to receive payments</span>. <span translate> Share this wallet address to receive payments</span>.
@ -357,10 +322,10 @@
<h4 class="title m0"> <h4 class="title m0">
<available-balance ng-show="!index.shouldHideBalance"></available-balance> <available-balance ng-show="!index.shouldHideBalance"></available-balance>
<span <span
ng-show="home.lockedCurrentFeePerKb || home.blockUx || home.lockAmount" ng-show="home.lockedCurrentFeePerKb || home.lockAmount"
class="text-gray" translate>Send Max</span> class="text-gray" translate>Send Max</span>
<a <a
ng-show="index.availableBalanceSat > 0 && !home.lockedCurrentFeePerKb && !home.blockUx && !home.lockAmount" ng-show="index.availableBalanceSat > 0 && !home.lockedCurrentFeePerKb && !home.lockAmount"
ng-click="home.sendMax(index.availableBalanceSat)" ng-click="home.sendMax(index.availableBalanceSat)"
translate>Send Max translate>Send Max
</a> </a>
@ -380,7 +345,7 @@
</div> </div>
<div class="row m20t"> <div class="row m20t">
<div class="large-12 large-centered columns"> <div class="large-12 large-centered columns">
<form name="sendForm" ng-disabled="home.blockUx || home.onGoingProcess" novalidate> <form name="sendForm" novalidate>
<div ng-hide="home._paypro || home.hideAddress"> <div ng-hide="home._paypro || home.hideAddress">
<div class="row collapse"> <div class="row collapse">
@ -399,7 +364,7 @@
</div> </div>
<div class="input"> <div class="input">
<input ng-show="sendForm.address.$invalid" class="m0" type="text" id="address" name="address" ng-disabled="home.blockUx || home.lockAddress" ng-attr-placeholder="{{'Bitcoin address'|translate}}" ng-model="_address" valid-address required ng-focus="home.formFocus('address')" ng-blur="home.formFocus(false)"> <input ng-show="sendForm.address.$invalid" class="m0" type="text" id="address" name="address" ng-disabled=" home.lockAddress" ng-attr-placeholder="{{'Bitcoin address'|translate}}" ng-model="_address" valid-address required ng-focus="home.formFocus('address')" ng-blur="home.formFocus(false)">
<div class="addressbook-input" ng-show="!sendForm.address.$invalid && _address"> <div class="addressbook-input" ng-show="!sendForm.address.$invalid && _address">
{{index.addressbook[_address] || _address}} {{index.addressbook[_address] || _address}}
</div> </div>
@ -441,7 +406,7 @@
<span translate>Amount</span> <span translate>Amount</span>
</label> </label>
<div class="input"> <div class="input">
<input type="number" id="amount" ng-disabled="home.blockUx || home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}" ng-minlength="0.00000001" ng-maxlength="10000000000" ng-model="_amount" valid-amount required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)"> <input type="number" id="amount" ng-disabled=" home.lockAmount" name="amount" ng-attr-placeholder="{{'Amount in'|translate}} {{home.unitName}}" ng-minlength="0.00000001" ng-maxlength="10000000000" ng-model="_amount" valid-amount required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)">
<input type="number" id="alternative" name="alternative" ng-model="_alternative" style="display:none"> <input type="number" id="alternative" name="alternative" ng-model="_alternative" style="display:none">
<a class="postfix button" ng-style="{'background-color':index.backgroundColor}" ng-click="home.showAlternative()">{{home.unitName}}</a> <a class="postfix button" ng-style="{'background-color':index.backgroundColor}" ng-click="home.showAlternative()">{{home.unitName}}</a>
</div> </div>
@ -450,7 +415,7 @@
<label for="alternative"><span translate>Amount</span> [{{ home.alternativeIsoCode }}] <label for="alternative"><span translate>Amount</span> [{{ home.alternativeIsoCode }}]
</label> </label>
<div class="input"> <div class="input">
<input type="number" id="alternative" ng-disabled="home.blockUx || !home.isRateAvailable || home.lockAmount" name="alternative" ng-attr-placeholder="{{'Amount in'|translate}} {{ home.alternativeName }}" ng-model="_alternative" required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)"> <input type="number" id="alternative" ng-disabled="!home.isRateAvailable || home.lockAmount" name="alternative" ng-attr-placeholder="{{'Amount in'|translate}} {{ home.alternativeName }}" ng-model="_alternative" required autocomplete="off" ng-focus="home.formFocus('amount')" ng-blur="home.formFocus(false)">
<input type="number" id="amount" name="amount" ng-model="_amount" style="display:none"> <input type="number" id="amount" name="amount" ng-model="_amount" style="display:none">
<a class="postfix button black" ng-click="home.hideAlternative()"> {{ home.alternativeIsoCode }}</a> <a class="postfix button black" ng-click="home.hideAlternative()"> {{ home.alternativeIsoCode }}</a>
</div> </div>
@ -464,19 +429,19 @@
<small translate class="has-error" ng-show="sendForm.comment.$invalid && !sendForm.comment.$pristine">too long!</small> <small translate class="has-error" ng-show="sendForm.comment.$invalid && !sendForm.comment.$pristine">too long!</small>
</label> </label>
<div class="input"> <div class="input">
<textarea id="comment" ng-disabled="home.blockUx" name="comment" <textarea id="comment" name="comment"
ng-maxlength="500" ng-model="_comment" ng-focus="home.formFocus('msg')" ng-maxlength="500" ng-model="_comment" ng-focus="home.formFocus('msg')"
ng-blur="home.formFocus(false)"></textarea> ng-blur="home.formFocus(false)"></textarea>
</div> </div>
</div> </div>
</div> </div>
<div class="row" ng-show="!home.onGoingProcess"> <div class="row">
<div class="large-6 medium-6 small-6 columns" ng-show="!home.blockUx && (home._paypro || home.lockAddress || home.lockAmount)"> <div class="large-6 medium-6 small-6 columns" ng-show="(home._paypro || home.lockAddress || home.lockAmount)">
<a ng-click="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a> <a ng-click="home.resetForm(sendForm)" class="button expand outline dark-gray round" translate>Cancel</a>
</div> </div>
<div class="columns" ng-class="{'small-6 medium-6 large-6':(home._paypro || home.lockAddress || home.lockAmount)}"> <div class="columns" ng-class="{'small-6 medium-6 large-6':(home._paypro || home.lockAddress || home.lockAmount)}">
<button class="button black round expand" ng-disabled="sendForm.$invalid || home.blockUx || index.isOffline || home.paymentExpired" <button class="button black round expand" ng-disabled="sendForm.$invalid || home.paymentExpired"
ng-style="{'background-color':index.backgroundColor}" ng-click="home.submitForm()" translate> ng-style="{'background-color':index.backgroundColor}" ng-click="home.submitForm()" translate>
Send Send
</button> </button>

View file

@ -1,10 +1,12 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('disclaimerController', angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go, storageService) { function($scope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go, storageService, gettext, platformInfo, ongoingProcess) {
var self = this; var self = this;
self.tries = 0; self.tries = 0;
self.creatingProfile = true; var isCordova = platformInfo.isCordova;
ongoingProcess.set('creatingWallet', true);
var create = function(opts) { var create = function(opts) {
opts = opts || {}; opts = opts || {};
@ -30,7 +32,7 @@ angular.module('copayApp.controllers').controller('disclaimerController',
}; };
$scope.error = ""; $scope.error = "";
self.creatingProfile = false; ongoingProcess.set('creatingWallet', false);
}); });
}; };
@ -43,7 +45,7 @@ angular.module('copayApp.controllers').controller('disclaimerController',
create(opts); create(opts);
} else { } else {
$log.info('There is already a profile'); $log.info('There is already a profile');
self.creatingProfile = false; ongoingProcess.set('creatingWallet', false);
profileService.bindProfile(profile, function(err) { profileService.bindProfile(profile, function(err) {
if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) { if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.'); $log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.');

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService) { angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService, ongoingProcess) {
var self = this; var self = this;
var SOFT_CONFIRMATION_LIMIT = 12; var SOFT_CONFIRMATION_LIMIT = 12;
var errors = bwcService.getErrors(); var errors = bwcService.getErrors();
@ -14,7 +14,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
ret.isChromeApp = isChromeApp; ret.isChromeApp = isChromeApp;
ret.isSafari = platformInfo.isSafari; ret.isSafari = platformInfo.isSafari;
ret.isWindowsPhoneApp = platformInfo.isWP; ret.isWindowsPhoneApp = platformInfo.isWP;
ret.onGoingProcess = {};
ret.historyShowLimit = 10; ret.historyShowLimit = 10;
ret.historyShowMoreLimit = 10; ret.historyShowMoreLimit = 10;
ret.isSearching = false; ret.isSearching = false;
@ -81,24 +80,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
storageService.setHideBalanceFlag(self.walletId, self.shouldHideBalance, function() {}); storageService.setHideBalanceFlag(self.walletId, self.shouldHideBalance, function() {});
} }
self.setOngoingProcess = function(processName, isOn) {
$log.debug('onGoingProcess', processName, isOn);
self[processName] = isOn;
self.onGoingProcess[processName] = isOn;
var name;
self.anyOnGoingProcess = lodash.any(self.onGoingProcess, function(isOn, processName) {
if (isOn)
name = name || processName;
return isOn;
});
// The first one
self.onGoingProcessName = name;
$timeout(function() {
$rootScope.$apply();
});
};
self.cleanInstance = function() { self.cleanInstance = function() {
$log.debug('Cleaning Index Instance'); $log.debug('Cleaning Index Instance');
lodash.each(self, function(v, k) { lodash.each(self, function(v, k) {
@ -125,16 +106,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (!fc) return; if (!fc) return;
ongoingProcess.clear();
self.cleanInstance(); self.cleanInstance();
self.loadingWallet = true; self.loadingWallet = true;
self.setSpendUnconfirmed(); self.setSpendUnconfirmed();
$timeout(function() { $timeout(function() {
$rootScope.$apply(); $rootScope.$apply();
self.hasProfile = true; self.hasProfile = true;
self.isSingleAddress = false; self.isSingleAddress = false;
self.noFocusedWallet = false; self.noFocusedWallet = false;
self.onGoingProcess = {};
// Credentials Shortcuts // Credentials Shortcuts
self.m = fc.credentials.m; self.m = fc.credentials.m;
@ -303,7 +285,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
} else { } else {
self.isSingleAddress = !!ret.wallet.singleAddress; self.isSingleAddress = !!ret.wallet.singleAddress;
if (!opts.quiet) if (!opts.quiet)
self.setOngoingProcess('scanning', ret.wallet.scanStatus == 'running'); ongoingProcess.set('scanning', ret.wallet.scanStatus == 'running');
} }
return cb(err, ret); return cb(err, ret);
}); });
@ -320,7 +302,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$timeout(function() { $timeout(function() {
if (!opts.quiet) if (!opts.quiet)
self.setOngoingProcess('updatingStatus', true); ongoingProcess.set('updatingStatus', true);
$log.debug('Updating Status:', fc.credentials.walletName, tries); $log.debug('Updating Status:', fc.credentials.walletName, tries);
get(function(err, walletStatus) { get(function(err, walletStatus) {
@ -340,8 +322,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (walletId != profileService.focusedClient.credentials.walletId) if (walletId != profileService.focusedClient.credentials.walletId)
return; return;
if (!opts.quiet) ongoingProcess.set('updatingStatus', false);
self.setOngoingProcess('updatingStatus', false);
if (err) { if (err) {
@ -389,10 +370,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateBalance = function() { self.updateBalance = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
$timeout(function() { $timeout(function() {
self.setOngoingProcess('updatingBalance', true); ongoingProcess.set('updatingBalance', true);
$log.debug('Updating Balance'); $log.debug('Updating Balance');
fc.getBalance(function(err, balance) { fc.getBalance(function(err, balance) {
self.setOngoingProcess('updatingBalance', false); ongoingProcess.set('updatingBalance', false);
if (err) { if (err) {
self.handleError(err); self.handleError(err);
return; return;
@ -406,10 +387,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updatePendingTxps = function() { self.updatePendingTxps = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
$timeout(function() { $timeout(function() {
self.setOngoingProcess('updatingPendingTxps', true); ongoingProcess.set('updatingPendingTxps', true);
$log.debug('Updating PendingTxps'); $log.debug('Updating PendingTxps');
fc.getTxProposals({}, function(err, txps) { fc.getTxProposals({}, function(err, txps) {
self.setOngoingProcess('updatingPendingTxps', false); ongoingProcess.set('updatingPendingTxps', false);
if (err) { if (err) {
self.handleError(err); self.handleError(err);
} else { } else {
@ -445,10 +426,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
$timeout(function() { $timeout(function() {
$rootScope.$apply(); $rootScope.$apply();
self.setOngoingProcess('openingWallet', true); ongoingProcess.set('openingWallet', true);
self.updateError = false; self.updateError = false;
fc.openWallet(function(err, walletStatus) { fc.openWallet(function(err, walletStatus) {
self.setOngoingProcess('openingWallet', false); ongoingProcess.set('openingWallet', false);
if (err) { if (err) {
self.updateError = true; self.updateError = true;
self.handleError(err); self.handleError(err);
@ -997,10 +978,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.recreate = function(cb) { self.recreate = function(cb) {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
self.setOngoingProcess('recreating', true); ongoingProcess.set('recreating', true);
fc.recreateWallet(function(err) { fc.recreateWallet(function(err) {
self.notAuthorized = false; self.notAuthorized = false;
self.setOngoingProcess('recreating', false); ongoingProcess.set('recreating', false);
if (err) { if (err) {
self.handleError(err); self.handleError(err);
@ -1034,13 +1015,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (!c.isComplete()) return; if (!c.isComplete()) return;
if (self.walletId == walletId) if (self.walletId == walletId)
self.setOngoingProcess('scanning', true); ongoingProcess.set('scanning', true);
c.startScan({ c.startScan({
includeCopayerBranches: true, includeCopayerBranches: true,
}, function(err) { }, function(err) {
if (err && self.walletId == walletId) { if (err && self.walletId == walletId) {
self.setOngoingProcess('scanning', false); ongoingProcess.set('scanning', false);
self.handleError(err); self.handleError(err);
$rootScope.$apply(); $rootScope.$apply();
} }
@ -1428,16 +1409,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
$rootScope.$on('Local/ValidatingWallet', function() { $rootScope.$on('Local/ValidatingWallet', function() {
if (isCordova) { ongoingProcess.set('validatingWallet', true);
window.plugins.spinnerDialog.hide();
window.plugins.spinnerDialog.show(null, gettext('Validating wallet integrity...'), true);
}
}); });
$rootScope.$on('Local/ProfileBound', function() { $rootScope.$on('Local/ProfileBound', function() {
if (isCordova) { ongoingProcess.set('validatingWallet', false);
window.plugins.spinnerDialog.hide();
}
}); });
$rootScope.$on('Local/ClearHistory', function(event) { $rootScope.$on('Local/ClearHistory', function(event) {
@ -1519,93 +1495,49 @@ angular.module('copayApp.controllers').controller('indexController', function($r
} }
}; };
$rootScope.$on('Local/Resume', function(event) { $rootScope.$on('Local/Resume', function(event) {
$log.debug('### Resume event'); $log.debug('### Resume event');
profileService.isDisclaimerAccepted(function(v) { profileService.isDisclaimerAccepted(function(v) {
if (!v) { if (!v) {
$log.debug('Disclaimer not accepted, resume to home'); $log.debug('Disclaimer not accepted, resume to home');
go.path('disclaimer'); go.path('disclaimer');
} }
});
self.debouncedUpdate();
}); });
self.debouncedUpdate();
});
$rootScope.$on('Local/BackupDone', function(event, walletId) { $rootScope.$on('Local/BackupDone', function(event, walletId) {
self.needsBackup = false; self.needsBackup = false;
$log.debug('Backup done'); $log.debug('Backup done');
storageService.setBackupFlag(walletId || self.walletId, function(err) { storageService.setBackupFlag(walletId || self.walletId, function(err) {
$log.debug('Backup stored'); $log.debug('Backup stored');
});
});
$rootScope.$on('Local/DeviceError', function(event, err) {
self.showErrorPopup(err, function() {
if (isCordova && navigator && navigator.app) {
navigator.app.exitApp();
}
});
});
$rootScope.$on('Local/WalletImported', function(event, walletId) {
self.needsBackup = false;
storageService.setBackupFlag(walletId, function() {
$log.debug('Backup done stored');
addressService.expireAddress(walletId, function(err) {
$timeout(function() {
self.txHistory = self.completeHistory = self.txHistorySearchResults = [];
storageService.removeTxHistory(walletId, function() {
self.startScan(walletId);
});
}, 500);
}); });
}); });
});
$rootScope.$on('NewIncomingTx', function() { $rootScope.$on('Local/DeviceError', function(event, err) {
self.newTx = true; self.showErrorPopup(err, function() {
self.updateAll({ if (isCordova && navigator && navigator.app) {
walletStatus: null, navigator.app.exitApp();
untilItChanges: true, }
triggerTxUpdate: true, });
}); });
});
$rootScope.$on('Local/WalletImported', function(event, walletId) {
$rootScope.$on('NewBlock', function() { self.needsBackup = false;
if (self.glideraEnabled) { storageService.setBackupFlag(walletId, function() {
$timeout(function() { $log.debug('Backup done stored');
self.updateGlidera(); addressService.expireAddress(walletId, function(err) {
$timeout(function() {
self.txHistory = self.completeHistory = self.txHistorySearchResults = [];
storageService.removeTxHistory(walletId, function() {
self.startScan(walletId);
});
}, 500);
});
}); });
} });
if (self.coinbaseEnabled) {
$timeout(function() {
self.updateCoinbase();
});
}
if (self.pendingAmount) {
self.updateAll({
walletStatus: null,
untilItChanges: null,
triggerTxUpdate: true,
});
} else if (self.hasUnsafeConfirmed) {
$log.debug('Wallet has transactions with few confirmations. Updating.')
if (self.network == 'testnet') {
self.throttledUpdateHistory();
} else {
self.debounceUpdateHistory();
}
}
});
$rootScope.$on('BalanceUpdated', function(e, n) { $rootScope.$on('NewIncomingTx', function() {
self.setBalance(n.data);
});
//untilItChange TRUE
lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName) {
$rootScope.$on(eventName, function(event) {
self.newTx = true; self.newTx = true;
self.updateAll({ self.updateAll({
walletStatus: null, walletStatus: null,
@ -1613,200 +1545,245 @@ lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName)
triggerTxUpdate: true, triggerTxUpdate: true,
}); });
}); });
});
//untilItChange FALSE
lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty', $rootScope.$on('NewBlock', function() {
'Local/GlideraTx' if (self.glideraEnabled) {
], function(eventName) { $timeout(function() {
$rootScope.$on(eventName, function(event) { self.updateGlidera();
});
}
if (self.coinbaseEnabled) {
$timeout(function() {
self.updateCoinbase();
});
}
if (self.pendingAmount) {
self.updateAll({
walletStatus: null,
untilItChanges: null,
triggerTxUpdate: true,
});
} else if (self.hasUnsafeConfirmed) {
$log.debug('Wallet has transactions with few confirmations. Updating.')
if (self.network == 'testnet') {
self.throttledUpdateHistory();
} else {
self.debounceUpdateHistory();
}
}
});
$rootScope.$on('BalanceUpdated', function(e, n) {
self.setBalance(n.data);
});
//untilItChange TRUE
lodash.each(['NewOutgoingTx', 'NewOutgoingTxByThirdParty'], function(eventName) {
$rootScope.$on(eventName, function(event) {
self.newTx = true;
self.updateAll({
walletStatus: null,
untilItChanges: true,
triggerTxUpdate: true,
});
});
});
//untilItChange FALSE
lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty',
'Local/GlideraTx'
], function(eventName) {
$rootScope.$on(eventName, function(event) {
self.updateAll({
walletStatus: null,
untilItChanges: null,
triggerTxUpdate: true,
});
});
});
//untilItChange Maybe
$rootScope.$on('Local/TxProposalAction', function(event, untilItChanges) {
self.newTx = untilItChanges;
self.updateAll({ self.updateAll({
walletStatus: null, walletStatus: null,
untilItChanges: null, untilItChanges: untilItChanges,
triggerTxUpdate: true, triggerTxUpdate: true,
}); });
}); });
});
$rootScope.$on('ScanFinished', function() {
//untilItChange Maybe $log.debug('Scan Finished. Updating history');
$rootScope.$on('Local/TxProposalAction', function(event, untilItChanges) { storageService.removeTxHistory(self.walletId, function() {
self.newTx = untilItChanges; self.updateAll({
self.updateAll({ walletStatus: null,
walletStatus: null, triggerTxUpdate: true,
untilItChanges: untilItChanges, });
triggerTxUpdate: true,
});
});
$rootScope.$on('ScanFinished', function() {
$log.debug('Scan Finished. Updating history');
storageService.removeTxHistory(self.walletId, function() {
self.updateAll({
walletStatus: null,
triggerTxUpdate: true,
}); });
}); });
});
lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy'], function(eventName) { lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy'], function(eventName) {
$rootScope.$on(eventName, function() { $rootScope.$on(eventName, function() {
var f = function() { var f = function() {
if (self.updatingStatus) { if (self.updatingStatus) {
return $timeout(f, 200); return $timeout(f, 200);
};
self.updatePendingTxps();
}; };
self.updatePendingTxps(); f();
}; });
f();
}); });
});
$rootScope.$on('Local/NoWallets', function(event) { $rootScope.$on('Local/NoWallets', function(event) {
$timeout(function() { $timeout(function() {
self.hasProfile = true; self.hasProfile = true;
self.noFocusedWallet = true; self.noFocusedWallet = true;
self.isComplete = null; self.isComplete = null;
self.walletName = null; self.walletName = null;
uxLanguage.update();
profileService.isDisclaimerAccepted(function(v) {
if (v) {
go.path('import');
}
});
});
});
$rootScope.$on('Local/NewFocusedWallet', function() {
uxLanguage.update(); uxLanguage.update();
self.setFocusedWallet();
self.updateHistory();
storageService.getCleanAndScanAddresses(function(err, walletId) {
profileService.isDisclaimerAccepted(function(v) { if (walletId && profileService.walletClients[walletId]) {
if (v) { $log.debug('Clear last address cache and Scan ', walletId);
go.path('import'); addressService.expireAddress(walletId, function(err) {
self.startScan(walletId);
});
storageService.removeCleanAndScanAddresses(function() {
$rootScope.$emit('Local/NewFocusedWalletReady');
});
} else {
$rootScope.$emit('Local/NewFocusedWalletReady');
} }
}); });
}); });
});
$rootScope.$on('Local/NewFocusedWallet', function() { $rootScope.$on('Local/SetTab', function(event, tab, reset) {
uxLanguage.update(); self.setTab(tab, reset);
self.setFocusedWallet(); });
self.updateHistory();
storageService.getCleanAndScanAddresses(function(err, walletId) {
if (walletId && profileService.walletClients[walletId]) { $rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) {
$log.debug('Clear last address cache and Scan ', walletId);
addressService.expireAddress(walletId, function(err) { function openConfirmationPopup(txp, cb) {
self.startScan(walletId);
$scope.tx = txFormatService.processTx(txp);
self.confirmationPopup = $ionicPopup.show({
templateUrl: 'views/includes/confirm-tx.html',
scope: $scope,
}); });
storageService.removeCleanAndScanAddresses(function() {
$rootScope.$emit('Local/NewFocusedWalletReady'); $scope.processFee = function(amount, fee) {
}); var walletSettings = configService.getSync().wallet.settings;
} else { var feeAlternativeIsoCode = walletSettings.alternativeIsoCode;
$rootScope.$emit('Local/NewFocusedWalletReady');
$scope.feeLevel = feeService.feeOpts[feeService.getCurrentFeeLevel()];
$scope.feeAlternativeStr = parseFloat((rateService.toFiat(fee, feeAlternativeIsoCode)).toFixed(2), 10) + ' ' + feeAlternativeIsoCode;
$scope.feeRateStr = (fee / (amount + fee) * 100).toFixed(2) + '%';
};
$scope.cancel = function() {
return cb();
};
$scope.accept = function() {
return cb(true);
};
} }
openConfirmationPopup(txp, function(accept) {
self.confirmationPopup.close();
return cb(accept);
});
}); });
});
$rootScope.$on('Local/SetTab', function(event, tab, reset) { $rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
self.setTab(tab, reset);
});
$rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) { function openPasswordPopup(isSetup, cb) {
$scope.data = {};
$scope.data.password = null;
$scope.isSetup = isSetup;
$scope.isVerification = false;
$scope.loading = false;
var pass = null;
function openConfirmationPopup(txp, cb) { self.passwordPopup = $ionicPopup.show({
templateUrl: 'views/includes/password.html',
scope: $scope,
});
$scope.tx = txFormatService.processTx(txp); $scope.cancel = function() {
return cb('No spending password given');
};
self.confirmationPopup = $ionicPopup.show({ $scope.set = function() {
templateUrl: 'views/includes/confirm-tx.html', $scope.loading = true;
scope: $scope, $scope.error = null;
$timeout(function() {
if (isSetup && !$scope.isVerification) {
$scope.loading = false;
$scope.isVerification = true;
pass = $scope.data.password;
$scope.data.password = null;
return;
}
if (isSetup && pass != $scope.data.password) {
$scope.loading = false;
$scope.error = gettext('Spending Passwords do not match');
$scope.isVerification = false;
$scope.data.password = null;
pass = null;
return;
}
return cb(null, $scope.data.password);
}, 100);
};
};
openPasswordPopup(isSetup, function(err, pass) {
self.passwordPopup.close();
return cb(err, pass);
}); });
$scope.processFee = function(amount, fee) {
var walletSettings = configService.getSync().wallet.settings;
var feeAlternativeIsoCode = walletSettings.alternativeIsoCode;
$scope.feeLevel = feeService.feeOpts[feeService.getCurrentFeeLevel()];
$scope.feeAlternativeStr = parseFloat((rateService.toFiat(fee, feeAlternativeIsoCode)).toFixed(2), 10) + ' ' + feeAlternativeIsoCode;
$scope.feeRateStr = (fee / (amount + fee) * 100).toFixed(2) + '%';
};
$scope.cancel = function() {
return cb();
};
$scope.accept = function() {
return cb(true);
};
}
openConfirmationPopup(txp, function(accept) {
self.confirmationPopup.close();
return cb(accept);
}); });
});
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) { $rootScope.$on('Local/EmailUpdated', function(event, email) {
self.preferences.email = email;
});
function openPasswordPopup(isSetup, cb) { lodash.each(['NewCopayer', 'CopayerUpdated'], function(eventName) {
$scope.data = {}; $rootScope.$on(eventName, function() {
$scope.data.password = null; // Re try to open wallet (will triggers)
$scope.isSetup = isSetup; self.setFocusedWallet();
$scope.isVerification = false;
$scope.loading = false;
var pass = null;
self.passwordPopup = $ionicPopup.show({
templateUrl: 'views/includes/password.html',
scope: $scope,
}); });
$scope.cancel = function() {
return cb('No spending password given');
};
$scope.set = function() {
$scope.loading = true;
$scope.error = null;
$timeout(function() {
if (isSetup && !$scope.isVerification) {
$scope.loading = false;
$scope.isVerification = true;
pass = $scope.data.password;
$scope.data.password = null;
return;
}
if (isSetup && pass != $scope.data.password) {
$scope.loading = false;
$scope.error = gettext('Spending Passwords do not match');
$scope.isVerification = false;
$scope.data.password = null;
pass = null;
return;
}
return cb(null, $scope.data.password);
}, 100);
};
};
openPasswordPopup(isSetup, function(err, pass) {
self.passwordPopup.close();
return cb(err, pass);
}); });
}); $rootScope.$on('Local/NewEncryptionSetting', function() {
var fc = profileService.focusedClient;
$rootScope.$on('Local/EmailUpdated', function(event, email) { self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
self.preferences.email = email; $timeout(function() {
}); $rootScope.$apply();
});
lodash.each(['NewCopayer', 'CopayerUpdated'], function(eventName) {
$rootScope.$on(eventName, function() {
// Re try to open wallet (will triggers)
self.setFocusedWallet();
}); });
});
$rootScope.$on('Local/NewEncryptionSetting', function() {
var fc = profileService.focusedClient;
self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
$timeout(function() {
$rootScope.$apply();
});
});
/* Start setup */ /* Start setup */
lodash.assign(self, vanillaScope); openURLService.init(); lodash.assign(self, vanillaScope);
openURLService.init();
}); });

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, $ionicModal, notification, txStatus, profileService, lodash, configService, rateService, storageService, bitcore, gettext, gettextCatalog, platformInfo, addressService, ledger, bwsError, confirmDialog, txFormatService, addressbookService, go, feeService, walletService, fingerprintService, nodeWebkit) { angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, $ionicModal, notification, txStatus, profileService, lodash, configService, rateService, storageService, bitcore, gettext, gettextCatalog, platformInfo, addressService, ledger, bwsError, confirmDialog, txFormatService, addressbookService, go, feeService, walletService, fingerprintService, nodeWebkit, ongoingProcess) {
var isCordova = platformInfo.isCordova; var isCordova = platformInfo.isCordova;
var isWP = platformInfo.isWP; var isWP = platformInfo.isWP;
@ -93,10 +93,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}; };
}); });
var disableOngoingProcessListener = $rootScope.$on('Addon/OngoingProcess', function(e, name) {
self.setOngoingProcess(name);
});
$scope.$on('$destroy', function() { $scope.$on('$destroy', function() {
disableAddrListener(); disableAddrListener();
disableScannerListener(); disableScannerListener();
@ -104,7 +100,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
disableTabListener(); disableTabListener();
disableFocusListener(); disableFocusListener();
disableResumeListener(); disableResumeListener();
disableOngoingProcessListener();
$rootScope.shouldHideMenuBar = false; $rootScope.shouldHideMenuBar = false;
}); });
@ -398,26 +393,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}, 1); }, 1);
}; };
// subscription
this.setOngoingProcess = function(name) {
var self = this;
self.blockUx = !!name;
if (isCordova) {
if (name) {
window.plugins.spinnerDialog.hide();
window.plugins.spinnerDialog.show(null, name + '...', true);
} else {
window.plugins.spinnerDialog.hide();
}
} else {
self.onGoingProcess = name;
$timeout(function() {
$rootScope.$apply();
});
};
};
this.submitForm = function() { this.submitForm = function() {
if (!$scope._amount || !$scope._address) return; if (!$scope._amount || !$scope._address) return;
var client = profileService.focusedClient; var client = profileService.focusedClient;
@ -473,9 +448,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
txp.excludeUnconfirmedUtxos = configWallet.spendUnconfirmed ? false : true; txp.excludeUnconfirmedUtxos = configWallet.spendUnconfirmed ? false : true;
txp.feeLevel = walletSettings.feeLevel || 'normal'; txp.feeLevel = walletSettings.feeLevel || 'normal';
self.setOngoingProcess(gettextCatalog.getString('Creating transaction')); ongoingProcess.set('creatingTx', true);
walletService.createTx(client, txp, function(err, createdTxp) { walletService.createTx(client, txp, function(err, createdTxp) {
self.setOngoingProcess(); ongoingProcess.set('creatingTx', false);
if (err) { if (err) {
return self.setSendError(err); return self.setSendError(err);
} }
@ -511,16 +486,16 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
return self.setSendError(err); return self.setSendError(err);
} }
self.setOngoingProcess(gettextCatalog.getString('Sending transaction')); ongoingProcess.set('sendingTx', true);
walletService.publishTx(client, txp, function(err, publishedTxp) { walletService.publishTx(client, txp, function(err, publishedTxp) {
if (err) { if (err) {
self.setOngoingProcess(); ongoingProcess.set('sendingTx', false);
return self.setSendError(err); return self.setSendError(err);
} }
self.setOngoingProcess(gettextCatalog.getString('Signing transaction')); ongoingProcess.set('signingTx', true);
walletService.signTx(client, publishedTxp, function(err, signedTxp) { walletService.signTx(client, publishedTxp, function(err, signedTxp) {
self.setOngoingProcess(); ongoingProcess.set('signingTx', false);
walletService.lock(client); walletService.lock(client);
if (err) { if (err) {
$scope.$emit('Local/TxProposalAction'); $scope.$emit('Local/TxProposalAction');
@ -531,9 +506,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
} }
if (signedTxp.status == 'accepted') { if (signedTxp.status == 'accepted') {
self.setOngoingProcess(gettextCatalog.getString('Broadcasting transaction')); ongoingProcess.set('broadcastingTx', true);
walletService.broadcastTx(client, signedTxp, function(err, broadcastedTxp) { walletService.broadcastTx(client, signedTxp, function(err, broadcastedTxp) {
self.setOngoingProcess(); ongoingProcess.set('broadcastingTx', false);
if (err) { if (err) {
return self.setSendError(err); return self.setSendError(err);
} }
@ -652,14 +627,14 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var satToUnit = 1 / this.unitToSatoshi; var satToUnit = 1 / this.unitToSatoshi;
var self = this; var self = this;
/// Get information of payment if using Payment Protocol /// Get information of payment if using Payment Protocol
self.setOngoingProcess(gettextCatalog.getString('Fetching Payment Information')); ongoingProcess.set('fetchingPayPro', true);
$log.debug('Fetch PayPro Request...', uri); $log.debug('Fetch PayPro Request...', uri);
$timeout(function() { $timeout(function() {
fc.fetchPayPro({ fc.fetchPayPro({
payProUrl: uri, payProUrl: uri,
}, function(err, paypro) { }, function(err, paypro) {
self.setOngoingProcess(); ongoingProcess.set('fetchingPayPro', false);
if (err) { if (err) {
$log.warn('Could not fetch payment request:', err); $log.warn('Could not fetch payment request:', err);
@ -836,11 +811,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var self = this; var self = this;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
this.error = null; this.error = null;
this.setOngoingProcess(gettextCatalog.getString('Calculating fee')); ongoingProcess.set('calculatingFee', true);
feeService.getCurrentFeeValue(function(err, feePerKb) { feeService.getCurrentFeeValue(function(err, feePerKb) {
ongoingProcess.set('calculatingFee', false);
if (err || !lodash.isNumber(feePerKb)) { if (err || !lodash.isNumber(feePerKb)) {
self.setOngoingProcess();
self.error = gettext('Could not get fee value'); self.error = gettext('Could not get fee value');
return; return;
} }
@ -850,10 +825,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
opts.returnInputs = true; opts.returnInputs = true;
var config = configService.getSync(); var config = configService.getSync();
opts.excludeUnconfirmedUtxos = !config.wallet.spendUnconfirmed; opts.excludeUnconfirmedUtxos = !config.wallet.spendUnconfirmed;
self.setOngoingProcess(gettextCatalog.getString('Retrieving inputs information')); ongoingProcess.set('retrivingInputs', true);
fc.getSendMaxInfo(opts, function(err, resp) { fc.getSendMaxInfo(opts, function(err, resp) {
self.setOngoingProcess(); ongoingProcess.set('retrivingInputs', false);
if (err) { if (err) {
self.error = err; self.error = err;
$scope.$apply(); $scope.$apply();

View file

@ -329,7 +329,7 @@ angular.module('copayApp.services')
return cb(null, walletClient, secret); return cb(null, walletClient, secret);
}); });
}); });
}, 5); }, 50);
}; };
// Creates the default Copay profile and its wallet // Creates the default Copay profile and its wallet