'use strict'; angular.module('copayApp.services').factory('ongoingProcess', function($log, $timeout, $filter, lodash, $ionicLoading, gettext, platformInfo) { var root = {}; var isCordova = platformInfo.isCordova; var isWP = platformInfo.isWP; var ongoingProcess = {}; var processNames = { 'broadcastingTx': gettext('Broadcasting transaction'), 'calculatingFee': gettext('Calculating fee'), 'connectingCoinbase': gettext('Connecting to Coinbase...'), 'connectingGlidera': gettext('Connecting to Glidera...'), 'connectingledger': gettext('Waiting for Ledger...'), 'connectingtrezor': gettext('Waiting for Trezor...'), 'creatingTx': gettext('Creating transaction'), 'creatingWallet': gettext('Creating Wallet...'), 'deletingWallet': gettext('Deleting Wallet...'), 'extractingWalletInfo': gettext('Extracting Wallet Information...'), 'fetchingPayPro': gettext('Fetching Payment Information'), 'generatingCSV': gettext('Generating .csv file...'), 'gettingFeeLevels': gettext('Getting fee levels...'), 'importingWallet': gettext('Importing Wallet...'), 'joiningWallet': gettext('Joining Wallet...'), 'recreating': gettext('Recreating Wallet...'), 'rejectTx': gettext('Rejecting payment proposal'), 'removeTx': gettext('Deleting payment proposal'), 'retrievingInputs': gettext('Retrieving inputs information'), 'scanning': gettext('Scanning Wallet funds...'), 'sendingTx': gettext('Sending transaction'), 'signingTx': gettext('Signing transaction'), 'sweepingWallet': gettext('Sweeping Wallet...'), 'validatingWords': gettext('Validating recovery phrase...'), 'loadingTxInfo': gettext('Loading transaction info...'), 'sendingFeedback': gettext('Sending feedback...'), 'generatingNewAddress': gettext('Generating new address...'), 'sendingByEmail': gettext('Preparing addresses...'), 'sending2faCode': gettext('Sending 2FA code...'), 'buyingBitcoin': gettext('Buying Bitcoin...'), 'sellingBitcoin': gettext('Selling Bitcoin...'), 'fetchingBitPayAccount': gettext('Fetching BitPay Account...'), 'updatingGiftCards': 'Updating Gift Cards...', 'updatingGiftCard': 'Updating Gift Card...', 'cancelingGiftCard': 'Canceling Gift Card...', 'creatingGiftCard': 'Creating Gift Card...', 'buyingGiftCard': 'Buying Gift Card...', 'topup': 'Top up in progress...' }; root.clear = function() { ongoingProcess = {}; if (isCordova && !isWP) { window.plugins.spinnerDialog.hide(); } else { $ionicLoading.hide(); } }; root.get = function(processName) { return ongoingProcess[processName]; }; root.set = function(processName, isOn, customHandler) { $log.debug('ongoingProcess', processName, isOn); root[processName] = isOn; ongoingProcess[processName] = isOn; var name; root.any = lodash.any(ongoingProcess, function(isOn, processName) { if (isOn) name = name || processName; return isOn; }); // The first one root.onGoingProcessName = name; var showName = $filter('translate')(processNames[name] || name); if (customHandler) { customHandler(processName, showName, isOn); } else if (root.onGoingProcessName) { if (isCordova && !isWP) { window.plugins.spinnerDialog.show(null, showName, root.clear); } else { var tmpl; if (isWP) tmpl = '
' + showName + '
'; else tmpl = '
' + showName + '
'; $ionicLoading.show({ template: tmpl }); } } else { if (isCordova && !isWP) { window.plugins.spinnerDialog.hide(); } else { $ionicLoading.hide(); } } }; return root; });