From a8cf875defb809bc70e129e01bfe1b327212b958 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 19 Aug 2016 13:07:18 -0300 Subject: [PATCH] rm go --- {src/js/services => old}/go.js | 0 {public/views/includes => old}/menu-item.html | 0 {public/views/includes => old}/sidebar.html | 0 {src/js/controllers => old}/topbar.js | 0 public/views/backup.html | 2 +- public/views/preferencesInformation.html | 4 +- src/js/controllers/backup.js | 8 +- src/js/controllers/copayers.js | 4 +- src/js/controllers/create.js | 5 +- src/js/controllers/disclaimer.js | 6 +- src/js/controllers/export.js | 4 +- src/js/controllers/import.js | 14 +- src/js/controllers/index.js | 1334 ----------------- src/js/controllers/join.js | 4 +- src/js/controllers/paperWallet.js | 4 +- src/js/controllers/paymentUri.js | 4 +- src/js/controllers/preferencesDelete.js | 4 +- src/js/controllers/preferencesHistory.js | 4 +- src/js/controllers/preferencesInformation.js | 11 +- src/js/routes.js | 8 +- src/js/services/applicationService.js | 4 +- src/js/services/walletService.js | 21 +- 22 files changed, 53 insertions(+), 1392 deletions(-) rename {src/js/services => old}/go.js (100%) rename {public/views/includes => old}/menu-item.html (100%) rename {public/views/includes => old}/sidebar.html (100%) rename {src/js/controllers => old}/topbar.js (100%) delete mode 100644 src/js/controllers/index.js diff --git a/src/js/services/go.js b/old/go.js similarity index 100% rename from src/js/services/go.js rename to old/go.js diff --git a/public/views/includes/menu-item.html b/old/menu-item.html similarity index 100% rename from public/views/includes/menu-item.html rename to old/menu-item.html diff --git a/public/views/includes/sidebar.html b/old/sidebar.html similarity index 100% rename from public/views/includes/sidebar.html rename to old/sidebar.html diff --git a/src/js/controllers/topbar.js b/old/topbar.js similarity index 100% rename from src/js/controllers/topbar.js rename to old/topbar.js diff --git a/public/views/backup.html b/public/views/backup.html index 18cf83201..70eeb47d0 100644 --- a/public/views/backup.html +++ b/public/views/backup.html @@ -163,7 +163,7 @@ diff --git a/public/views/preferencesInformation.html b/public/views/preferencesInformation.html index 93258fe91..a513ca25f 100644 --- a/public/views/preferencesInformation.html +++ b/public/views/preferencesInformation.html @@ -104,10 +104,10 @@
Only Main (not change) addresses are shown. The addresses on this list were not verified locally at this time.
- - diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index 916e78ae7..581fc7a0c 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -4,27 +4,25 @@ angular.module('copayApp.controllers').controller('backupController', function($rootScope, $scope, $timeout, $log, $state, lodash, fingerprintService, platformInfo, configService, profileService, gettext, bwcService, walletService, ongoingProcess) { var fc = profileService.focusedClient; - var prevState; $scope.customWords = []; $scope.walletName = fc.credentials.walletName; $scope.credentialsEncrypted = fc.isPrivKeyEncrypted; - $scope.init = function(state) { - prevState = state || 'walletHome'; + $scope.init = function() { $scope.step = 1; $scope.deleted = isDeletedSeed(); if ($scope.deleted) return; fingerprintService.check(fc, function(err) { if (err) { - go.path(prevState); + $state.go('tabs.home') return; } handleEncryptedWallet(fc, function(err) { if (err) { $log.warn('Error decrypting credentials:', $scope.error); - go.path(prevState); + $state.go('tabs.home') return; } $scope.credentialsEncrypted = false; diff --git a/src/js/controllers/copayers.js b/src/js/controllers/copayers.js index 1fe16585e..2e7c871d8 100644 --- a/src/js/controllers/copayers.js +++ b/src/js/controllers/copayers.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('copayersController', - function($scope, $rootScope, $timeout, $log, $ionicModal, profileService, go, notification, platformInfo, gettext, gettextCatalog, $stateParams, $state) { + function($scope, $rootScope, $timeout, $log, $ionicModal, profileService, $state, notification, platformInfo, gettext, gettextCatalog, $stateParams, $state) { var self = this; $scope.isCordova = platformInfo.isCordova; var isWP = platformInfo.isWP; @@ -39,7 +39,7 @@ angular.module('copayApp.controllers').controller('copayersController', $scope.$digest(); }); } else { - go.walletHome(); + $state.go('tabs.home'); $timeout(function() { notification.success( gettextCatalog.getString('Success'), diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index 300fa5019..edf5085b8 100644 --- a/src/js/controllers/create.js +++ b/src/js/controllers/create.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('createController', - function($scope, $rootScope, $timeout, $log, lodash, go, profileService, configService, gettext, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess, walletService) { + function($scope, $rootScope, $timeout, $log, lodash, $state, profileService, configService, gettext, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess, walletService) { var isChromeApp = platformInfo.isChromeApp; var isCordova = platformInfo.isCordova; @@ -187,8 +187,7 @@ angular.module('copayApp.controllers').controller('createController', $rootScope.$emit('Local/BackupDone'); }, 1); } - - go.walletHome(); + $state.go('tabs.home') }); }, 100); } diff --git a/src/js/controllers/disclaimer.js b/src/js/controllers/disclaimer.js index a5ecd37f1..9ce990011 100644 --- a/src/js/controllers/disclaimer.js +++ b/src/js/controllers/disclaimer.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('disclaimerController', - function($scope, $rootScope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go, storageService, gettext, platformInfo, ongoingProcess) { + function($scope, $rootScope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, $state, storageService, gettext, platformInfo, ongoingProcess) { var tries = 0; var isCordova = platformInfo.isCordova; @@ -49,7 +49,7 @@ angular.module('copayApp.controllers').controller('disclaimerController', if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) { $log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.'); $ionicSideMenuDelegate.canDragContent(true); - go.walletHome(); + $state.go('tabs.home'); } }); } @@ -62,7 +62,7 @@ angular.module('copayApp.controllers').controller('disclaimerController', else { $ionicSideMenuDelegate.canDragContent(true); $rootScope.$emit('disclaimerAccepted'); - go.walletHome(); + $state.go('tabs.home'); } }); }; diff --git a/src/js/controllers/export.js b/src/js/controllers/export.js index dbde2ff61..14237528b 100644 --- a/src/js/controllers/export.js +++ b/src/js/controllers/export.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('exportController', - function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, storageService, profileService, platformInfo, notification, go, gettext, gettextCatalog, $state, $stateParams) { + function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, storageService, profileService, platformInfo, notification, gettext, gettextCatalog, $state, $stateParams) { var prevState; var isWP = platformInfo.isWP; var isAndroid = platformInfo.isAndroid; @@ -69,7 +69,7 @@ angular.module('copayApp.controllers').controller('exportController', return; } notification.success(gettext('Success'), gettext('Encrypted export file saved')); - go.walletHome(); + $state.go('tabs.home'); }); }); }; diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index 4c9ccb479..4dcfad174 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('importController', - function($scope, $rootScope, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, ledger, trezor, derivationPathHelper, platformInfo, bwcService, ongoingProcess, walletService) { + function($scope, $rootScope, $timeout, $log, profileService, configService, notification, sjcl, gettext, ledger, trezor, derivationPathHelper, platformInfo, bwcService, ongoingProcess, walletService) { var isChromeApp = platformInfo.isChromeApp; var isDevel = platformInfo.isDevel; @@ -111,7 +111,7 @@ angular.module('copayApp.controllers').controller('importController', $rootScope.$emit('Local/WalletImported', client.credentials.walletId); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); - go.walletHome(); + $state.go('tabs.home'); }); }, 100); }; @@ -139,7 +139,7 @@ angular.module('copayApp.controllers').controller('importController', $rootScope.$emit('Local/WalletImported', client.credentials.walletId); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); - go.walletHome(); + $state.go('tabs.home'); }); }, 100); }; @@ -160,7 +160,7 @@ angular.module('copayApp.controllers').controller('importController', } $rootScope.$emit('Local/WalletImported', walletId); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); - go.walletHome(); + $state.go('tabs.home'); }); }, 100); }; @@ -190,7 +190,7 @@ angular.module('copayApp.controllers').controller('importController', $rootScope.$emit('Local/WalletImported', client.credentials.walletId); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); - go.walletHome(); + $state.go('tabs.home'); }); }, 100); }; @@ -325,7 +325,7 @@ angular.module('copayApp.controllers').controller('importController', }); $rootScope.$emit('Local/WalletImported', wallet.walletId); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); - go.walletHome(); + $state.go('tabs.home'); }); }, 100); }; @@ -403,7 +403,7 @@ angular.module('copayApp.controllers').controller('importController', }); $rootScope.$emit('Local/WalletImported', wallet.walletId); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); - go.walletHome(); + $state.go('tabs.home'); }); }, 100); }; diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js deleted file mode 100644 index 825a7fac1..000000000 --- a/src/js/controllers/index.js +++ /dev/null @@ -1,1334 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, $ionicSideMenuDelegate, $httpBackend, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwcError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService, ongoingProcess) { - - var self = this; - var SOFT_CONFIRMATION_LIMIT = 12; - var errors = bwcService.getErrors(); - var historyUpdateInProgress = {}; - var isChromeApp = platformInfo.isChromeApp; - var isCordova = platformInfo.isCordova; - var isNW = platformInfo.isNW; - - var ret = {}; - ret.isCordova = isCordova; - ret.isChromeApp = isChromeApp; - ret.isSafari = platformInfo.isSafari; - ret.isWindowsPhoneApp = platformInfo.isWP; - ret.historyShowLimit = 10; - ret.historyShowMoreLimit = 10; - ret.isSearching = false; - ret.prevState = 'walletHome'; - ret.physicalScreenWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width); - - ret.appConfig = window.appConfig; - - // Only for testing - //storageService.checkQuota(); - - ret.menu = [{ - 'title': gettext('Receive'), - 'icon': { - false: 'icon-receive', - true: 'icon-receive-active' - }, - 'link': 'receive' - }, { - 'title': gettext('Activity'), - 'icon': { - false: 'icon-activity', - true: 'icon-activity-active' - }, - 'link': 'walletHome' - }, { - 'title': gettext('Send'), - 'icon': { - false: 'icon-send', - true: 'icon-send-active' - }, - 'link': 'send' - }]; - - ret.addonViews = addonManager.addonViews(); - ret.txTemplateUrl = addonManager.txTemplateUrl() || 'views/includes/transaction.html'; - - ret.tab = 'walletHome'; - var vanillaScope = ret; - - if (isNW) { - latestReleaseService.checkLatestRelease(function(err, newRelease) { - if (err) { - $log.warn(err); - return; - } - - if (newRelease) - $scope.newRelease = gettext('There is a new version of Copay. Please update'); - }); - } - - function strip(number) { - return (parseFloat(number.toPrecision(12))); - }; - - self.goHome = function() { - go.walletHome(); - }; - - self.allowRefresher = function() { - if ($ionicSideMenuDelegate.getOpenRatio() != 0) self.allowPullToRefresh = false; - } - - self.hideBalance = function() { - storageService.getHideBalanceFlag(self.walletId, function(err, shouldHideBalance) { - if (err) self.shouldHideBalance = false; - else self.shouldHideBalance = (shouldHideBalance == 'true') ? true : false; - }); - } - - self.onHold = function() { - self.shouldHideBalance = !self.shouldHideBalance; - storageService.setHideBalanceFlag(self.walletId, self.shouldHideBalance.toString(), function() {}); - } - - self.setWalletPreferencesTitle = function() { - return gettext("Wallet Preferences"); - } - - self.cleanInstance = function() { - $log.debug('Cleaning Index Instance'); - lodash.each(self, function(v, k) { - if (lodash.isFunction(v)) return; - // This are to prevent flicker in mobile: - if (k == 'hasProfile') return; - if (k == 'tab') return; - if (k == 'noFocusedWallet') return; - if (k == 'backgroundColor') return; - if (k == 'physicalScreenWidth') return; - if (k == 'loadingWallet') { - self.loadingWallet = true; - return; - } - if (!lodash.isUndefined(vanillaScope[k])) { - self[k] = vanillaScope[k]; - return; - } - - delete self[k]; - }); - }; - - self.setFocusedWallet = function() { - var fc = profileService.focusedClient; - if (!fc) return; - - self.cleanInstance(); - self.loadingWallet = true; - self.setSpendUnconfirmed(); - - $timeout(function() { - $rootScope.$apply(); - - self.hasProfile = true; - self.isSingleAddress = false; - self.noFocusedWallet = false; - self.updating = false; - - // Credentials Shortcuts - self.m = fc.credentials.m; - self.n = fc.credentials.n; - self.network = fc.credentials.network; - self.copayerId = fc.credentials.copayerId; - self.copayerName = fc.credentials.copayerName; - self.requiresMultipleSignatures = fc.credentials.m > 1; - self.isShared = fc.credentials.n > 1; - self.walletName = fc.credentials.walletName; - self.walletId = fc.credentials.walletId; - self.isComplete = fc.isComplete(); - self.canSign = fc.canSign(); - self.isPrivKeyExternal = fc.isPrivKeyExternal(); - self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted(); - self.externalSource = fc.getPrivKeyExternalSourceName(); - self.account = fc.credentials.account; - self.incorrectDerivation = fc.keyDerivationOk === false; - - if (self.externalSource == 'trezor') - self.account++; - - self.txps = []; - self.copayers = []; - self.updateColor(); - self.updateAlias(); - self.setAddressbook(); - - self.initGlidera(); - self.initCoinbase(); - - self.hideBalance(); - - self.setCustomBWSFlag(); - - if (!self.isComplete) { - $log.debug('Wallet not complete BEFORE update... redirecting'); - go.path('copayers'); - } else { - if (go.is('copayers')) { - $log.debug('Wallet Complete BEFORE update... redirect to home'); - go.walletHome(); - } - } - - profileService.needsBackup(fc, function(needsBackup) { - self.needsBackup = needsBackup; - self.openWallet(function() { - if (!self.isComplete) { - $log.debug('Wallet not complete after update... redirecting'); - go.path('copayers'); - } else { - if (go.is('copayers')) { - $log.debug('Wallet Complete after update... redirect to home'); - go.walletHome(); - } - } - }); - }); - }); - }; - - self.setCustomBWSFlag = function() { - var defaults = configService.getDefaults(); - var config = configService.getSync(); - - self.usingCustomBWS = config.bwsFor && config.bwsFor[self.walletId] && (config.bwsFor[self.walletId] != defaults.bws.url); - }; - - - self.setTab = function(tab, reset, tries, switchState) { - tries = tries || 0; - - // check if the whole menu item passed - if (typeof tab == 'object') { - if (tab.open) { - if (tab.link) { - self.tab = tab.link; - } - tab.open(); - return; - } else { - return self.setTab(tab.link, reset, tries, switchState); - } - } - if (self.tab === tab && !reset) - return; - - if (!document.getElementById('menu-' + tab) && ++tries < 5) { - return $timeout(function() { - self.setTab(tab, reset, tries, switchState); - }, 300); - } - - if (!self.tab || !go.is('walletHome')) - self.tab = 'walletHome'; - - var changeTab = function() { - if (document.getElementById(self.tab)) { - document.getElementById(self.tab).className = 'tab-out tab-view ' + self.tab; - var old = document.getElementById('menu-' + self.tab); - if (old) { - old.className = ''; - } - } - - if (document.getElementById(tab)) { - document.getElementById(tab).className = 'tab-in tab-view ' + tab; - var newe = document.getElementById('menu-' + tab); - if (newe) { - newe.className = 'active'; - } - } - - self.tab = tab; - $rootScope.$emit('Local/TabChanged', tab); - }; - - if (switchState && !go.is('walletHome')) { - go.path('walletHome', function() { - changeTab(); - }); - return; - } - - changeTab(); - }; - - - self.setSpendUnconfirmed = function(spendUnconfirmed) { - self.spendUnconfirmed = spendUnconfirmed || configService.getSync().wallet.spendUnconfirmed; - }; - - self.updateBalance = function() { - var fc = profileService.focusedClient; - $timeout(function() { - ongoingProcess.set('updatingBalance', true); - $log.debug('Updating Balance'); - fc.getBalance(function(err, balance) { - ongoingProcess.set('updatingBalance', false); - if (err) { - self.handleError(err); - return; - } - $log.debug('Wallet Balance:', balance); - self.setBalance(balance); - }); - }); - }; - - self.updatePendingTxps = function() { - var fc = profileService.focusedClient; - $timeout(function() { - self.updating = true; - $log.debug('Updating PendingTxps'); - fc.getTxProposals({}, function(err, txps) { - self.updating = false; - if (err) { - self.handleError(err); - } else { - $log.debug('Wallet PendingTxps:', txps); - self.setPendingTxps(txps); - } - $rootScope.$apply(); - }); - }); - }; - - // This handles errors from BWS/index which normally - // trigger from async events (like updates). - // Debounce function avoids multiple popups - var _handleError = function(err) { - $log.warn('Client ERROR: ', err); - if (err instanceof errors.NOT_AUTHORIZED) { - self.notAuthorized = true; - go.walletHome(); - } else if (err instanceof errors.NOT_FOUND) { - self.showErrorPopup(gettext('Could not access Wallet Service: Not found')); - } else { - var msg = "" - $scope.$emit('Local/ClientError', (err.error ? err.error : err)); - var msg = bwcError.msg(err, gettext('Error at Wallet Service')); - self.showErrorPopup(msg); - } - }; - - self.handleError = lodash.debounce(_handleError, 1000); - - self.openWallet = function(cb) { - var fc = profileService.focusedClient; - $timeout(function() { - $rootScope.$apply(); - self.updating = true; - self.updateError = false; - fc.openWallet(function(err, walletStatus) { - self.updating = false; - if (err) { - self.updateError = true; - self.handleError(err); - return; - } - $log.debug('Wallet Opened'); - - self.updateAll(lodash.isObject(walletStatus) ? { - walletStatus: walletStatus, - cb: cb, - } : { - cb: cb - }); - $rootScope.$apply(); - }); - }); - }; - - self.setPendingTxps = function(txps) { - self.pendingTxProposalsCountForUs = 0; - var now = Math.floor(Date.now() / 1000); - - /* Uncomment to test multiple outputs */ - /* - var txp = { - message: 'test multi-output', - fee: 1000, - createdOn: new Date() / 1000, - outputs: [] - }; - function addOutput(n) { - txp.outputs.push({ - amount: 600, - toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK', - message: 'output #' + (Number(n) + 1) - }); - }; - lodash.times(150, addOutput); - txps.push(txp); - */ - - lodash.each(txps, function(tx) { - - tx = txFormatService.processTx(tx); - - // no future transactions... - if (tx.createdOn > now) - tx.createdOn = now; - - var action = lodash.find(tx.actions, { - copayerId: self.copayerId - }); - - if (!action && tx.status == 'pending') { - tx.pendingForUs = true; - } - - if (action && action.type == 'accept') { - tx.statusForUs = 'accepted'; - } else if (action && action.type == 'reject') { - tx.statusForUs = 'rejected'; - } else { - tx.statusForUs = 'pending'; - } - - if (!tx.deleteLockTime) - tx.canBeRemoved = true; - - if (tx.creatorId != self.copayerId) { - self.pendingTxProposalsCountForUs = self.pendingTxProposalsCountForUs + 1; - } - addonManager.formatPendingTxp(tx); - }); - self.txps = txps; - }; - - var SAFE_CONFIRMATIONS = 6; - - self.processNewTxs = function(txs) { - var config = configService.getSync().wallet.settings; - var now = Math.floor(Date.now() / 1000); - var txHistoryUnique = {}; - var ret = []; - self.hasUnsafeConfirmed = false; - - lodash.each(txs, function(tx) { - tx = txFormatService.processTx(tx); - - // no future transactions... - if (tx.time > now) - tx.time = now; - - if (tx.confirmations >= SAFE_CONFIRMATIONS) { - tx.safeConfirmed = SAFE_CONFIRMATIONS + '+'; - } else { - tx.safeConfirmed = false; - self.hasUnsafeConfirmed = true; - } - - if (tx.note) { - delete tx.note.encryptedEditedByName; - delete tx.note.encryptedBody; - } - - if (!txHistoryUnique[tx.txid]) { - ret.push(tx); - txHistoryUnique[tx.txid] = true; - } else { - $log.debug('Ignoring duplicate TX in history: ' + tx.txid) - } - }); - - return ret; - }; - - self.updateAlias = function() { - var config = configService.getSync(); - config.aliasFor = config.aliasFor || {}; - self.alias = config.aliasFor[self.walletId]; - var fc = profileService.focusedClient; - fc.alias = self.alias; - }; - - self.updateColor = function() { - var config = configService.getSync(); - config.colorFor = config.colorFor || {}; - self.backgroundColor = config.colorFor[self.walletId] || '#4A90E2'; - var fc = profileService.focusedClient; - fc.backgroundColor = self.backgroundColor; - if (isCordova && StatusBar.isVisible) { - StatusBar.backgroundColorByHexString(fc.backgroundColor); - } - }; - - self.setBalance = function(balance) { - if (!balance) return; - var config = configService.getSync().wallet.settings; - var COIN = 1e8; - - - // Address with Balance - self.balanceByAddress = balance.byAddress; - - // Spend unconfirmed funds - if (self.spendUnconfirmed) { - self.totalBalanceSat = balance.totalAmount; - self.lockedBalanceSat = balance.lockedAmount; - self.availableBalanceSat = balance.availableAmount; - self.totalBytesToSendMax = balance.totalBytesToSendMax; - self.pendingAmount = null; - } else { - self.totalBalanceSat = balance.totalConfirmedAmount; - self.lockedBalanceSat = balance.lockedConfirmedAmount; - self.availableBalanceSat = balance.availableConfirmedAmount; - self.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax; - self.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount; - } - - // Selected unit - self.unitToSatoshi = config.unitToSatoshi; - self.satToUnit = 1 / self.unitToSatoshi; - self.unitName = config.unitName; - - //STR - self.totalBalanceStr = profileService.formatAmount(self.totalBalanceSat) + ' ' + self.unitName; - self.lockedBalanceStr = profileService.formatAmount(self.lockedBalanceSat) + ' ' + self.unitName; - self.availableBalanceStr = profileService.formatAmount(self.availableBalanceSat) + ' ' + self.unitName; - - if (self.pendingAmount) { - self.pendingAmountStr = profileService.formatAmount(self.pendingAmount) + ' ' + self.unitName; - } else { - self.pendingAmountStr = null; - } - - self.alternativeName = config.alternativeName; - self.alternativeIsoCode = config.alternativeIsoCode; - - // Check address - addressService.isUsed(self.walletId, balance.byAddress, function(err, used) { - if (used) { - $log.debug('Address used. Creating new'); - $rootScope.$emit('Local/AddressIsUsed'); - } - }); - - rateService.whenAvailable(function() { - - var totalBalanceAlternative = rateService.toFiat(self.totalBalanceSat, self.alternativeIsoCode); - var lockedBalanceAlternative = rateService.toFiat(self.lockedBalanceSat, self.alternativeIsoCode); - var alternativeConversionRate = rateService.toFiat(100000000, self.alternativeIsoCode); - - self.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative); - self.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative); - self.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate); - - self.alternativeBalanceAvailable = true; - - self.isRateAvailable = true; - $rootScope.$apply(); - }); - - if (!rateService.isAvailable()) { - $rootScope.$apply(); - } - }; - - - self.showMore = function() { - $timeout(function() { - if (self.isSearching) { - self.txHistorySearchResults = self.result.slice(0, self.nextTxHistory); - $log.debug('Total txs: ', self.txHistorySearchResults.length + '/' + self.result.length); - if (self.txHistorySearchResults.length >= self.result.length) - self.historyShowMore = false; - } else { - self.txHistory = self.completeHistory.slice(0, self.nextTxHistory); - $log.debug('Total txs: ', self.txHistory.length + '/' + self.completeHistory.length); - if (self.txHistory.length >= self.completeHistory.length) - self.historyShowMore = false; - } - self.nextTxHistory += self.historyShowMoreLimit; - $scope.$broadcast('scroll.infiniteScrollComplete'); - }, 100); - }; - - - - - self.toggleLeftMenu = function() { - profileService.isDisclaimerAccepted(function(val) { - if (val) go.toggleLeftMenu(); - else - $log.debug('Disclaimer not accepted, cannot open menu'); - }); - }; - - self.initGlidera = function(accessToken) { - self.glideraEnabled = configService.getSync().glidera.enabled; - self.glideraTestnet = configService.getSync().glidera.testnet; - var network = self.glideraTestnet ? 'testnet' : 'livenet'; - - self.glideraToken = null; - self.glideraError = null; - self.glideraPermissions = null; - self.glideraEmail = null; - self.glideraPersonalInfo = null; - self.glideraTxs = null; - self.glideraStatus = null; - - if (!self.glideraEnabled) return; - - glideraService.setCredentials(network); - - var getToken = function(cb) { - if (accessToken) { - cb(null, accessToken); - } else { - storageService.getGlideraToken(network, cb); - } - }; - - getToken(function(err, accessToken) { - if (err || !accessToken) return; - else { - glideraService.getAccessTokenPermissions(accessToken, function(err, p) { - if (err) { - self.glideraError = err; - } else { - self.glideraToken = accessToken; - self.glideraPermissions = p; - self.updateGlidera({ - fullUpdate: true - }); - } - }); - } - }); - }; - - self.updateGlidera = function(opts) { - if (!self.glideraToken || !self.glideraPermissions) return; - var accessToken = self.glideraToken; - var permissions = self.glideraPermissions; - - opts = opts || {}; - - glideraService.getStatus(accessToken, function(err, data) { - self.glideraStatus = data; - }); - - glideraService.getLimits(accessToken, function(err, limits) { - self.glideraLimits = limits; - }); - - if (permissions.transaction_history) { - glideraService.getTransactions(accessToken, function(err, data) { - self.glideraTxs = data; - }); - } - - if (permissions.view_email_address && opts.fullUpdate) { - glideraService.getEmail(accessToken, function(err, data) { - self.glideraEmail = data.email; - }); - } - if (permissions.personal_info && opts.fullUpdate) { - glideraService.getPersonalInfo(accessToken, function(err, data) { - self.glideraPersonalInfo = data; - }); - } - - }; - - self.initCoinbase = function(accessToken) { - self.coinbaseEnabled = configService.getSync().coinbase.enabled; - self.coinbaseTestnet = configService.getSync().coinbase.testnet; - var network = self.coinbaseTestnet ? 'testnet' : 'livenet'; - - self.coinbaseToken = null; - self.coinbaseError = null; - self.coinbasePermissions = null; - self.coinbaseEmail = null; - self.coinbasePersonalInfo = null; - self.coinbaseTxs = null; - self.coinbaseStatus = null; - - if (!self.coinbaseEnabled) return; - - coinbaseService.setCredentials(network); - - var getToken = function(cb) { - if (accessToken) { - cb(null, accessToken); - } else { - storageService.getCoinbaseToken(network, cb); - } - }; - - getToken(function(err, accessToken) { - if (err || !accessToken) return; - else { - coinbaseService.getAccounts(accessToken, function(err, a) { - if (err) { - self.coinbaseError = err; - if (err.errors[0] && err.errors[0].id == 'expired_token') { - self.refreshCoinbaseToken(); - } - } else { - self.coinbaseToken = accessToken; - lodash.each(a.data, function(account) { - if (account.primary && account.type == 'wallet') { - self.coinbaseAccount = account; - self.updateCoinbase(); - } - }); - } - }); - } - }); - }; - - self.updateCoinbase = lodash.debounce(function(opts) { - if (!self.coinbaseToken || !self.coinbaseAccount) return; - var accessToken = self.coinbaseToken; - var accountId = self.coinbaseAccount.id; - - opts = opts || {}; - - if (opts.updateAccount) { - coinbaseService.getAccount(accessToken, accountId, function(err, a) { - if (err) { - self.coinbaseError = err; - if (err.errors[0] && err.errors[0].id == 'expired_token') { - self.refreshCoinbaseToken(); - } - return; - } - self.coinbaseAccount = a.data; - }); - } - - coinbaseService.getCurrentUser(accessToken, function(err, u) { - if (err) { - self.coinbaseError = err; - if (err.errors[0] && err.errors[0].id == 'expired_token') { - self.refreshCoinbaseToken(); - } - return; - } - self.coinbaseUser = u.data; - }); - - coinbaseService.getPendingTransactions(function(err, txs) { - self.coinbasePendingTransactions = lodash.isEmpty(txs) ? null : txs; - lodash.forEach(txs, function(dataFromStorage, txId) { - if ((dataFromStorage.type == 'sell' && dataFromStorage.status == 'completed') || - (dataFromStorage.type == 'buy' && dataFromStorage.status == 'completed') || - dataFromStorage.status == 'error' || - (dataFromStorage.type == 'send' && dataFromStorage.status == 'completed')) return; - coinbaseService.getTransaction(accessToken, accountId, txId, function(err, tx) { - if (err) { - if (err.errors[0] && err.errors[0].id == 'expired_token') { - self.refreshCoinbaseToken(); - return; - } - coinbaseService.savePendingTransaction(dataFromStorage, { - status: 'error', - error: err - }, function(err) { - if (err) $log.debug(err); - }); - return; - } - _updateCoinbasePendingTransactions(dataFromStorage, tx.data); - self.coinbasePendingTransactions[txId] = dataFromStorage; - if (tx.data.type == 'send' && tx.data.status == 'completed' && tx.data.from) { - coinbaseService.sellPrice(accessToken, dataFromStorage.sell_price_currency, function(err, s) { - if (err) { - if (err.errors[0] && err.errors[0].id == 'expired_token') { - self.refreshCoinbaseToken(); - return; - } - coinbaseService.savePendingTransaction(dataFromStorage, { - status: 'error', - error: err - }, function(err) { - if (err) $log.debug(err); - }); - return; - } - var newSellPrice = s.data.amount; - var variance = Math.abs((newSellPrice - dataFromStorage.sell_price_amount) / dataFromStorage.sell_price_amount * 100); - if (variance < dataFromStorage.price_sensitivity.value) { - self.sellPending(tx.data); - } else { - var error = { - errors: [{ - message: 'Price falls over the selected percentage' - }] - }; - coinbaseService.savePendingTransaction(dataFromStorage, { - status: 'error', - error: error - }, function(err) { - if (err) $log.debug(err); - }); - } - }); - } else if (tx.data.type == 'buy' && tx.data.status == 'completed' && tx.data.buy) { - self.sendToCopay(dataFromStorage); - } else { - coinbaseService.savePendingTransaction(dataFromStorage, {}, function(err) { - if (err) $log.debug(err); - }); - } - }); - }); - }); - - }, 1000); - - var _updateCoinbasePendingTransactions = function(obj /*, …*/ ) { - for (var i = 1; i < arguments.length; i++) { - for (var prop in arguments[i]) { - var val = arguments[i][prop]; - if (typeof val == "object") - _updateCoinbasePendingTransactions(obj[prop], val); - else - obj[prop] = val ? val : obj[prop]; - } - } - return obj; - }; - - self.refreshCoinbaseToken = function() { - var network = self.coinbaseTestnet ? 'testnet' : 'livenet'; - storageService.getCoinbaseRefreshToken(network, function(err, refreshToken) { - if (!refreshToken) return; - coinbaseService.refreshToken(refreshToken, function(err, data) { - if (err) { - self.coinbaseError = err; - } else if (data && data.access_token && data.refresh_token) { - storageService.setCoinbaseToken(network, data.access_token, function() { - storageService.setCoinbaseRefreshToken(network, data.refresh_token, function() { - $timeout(function() { - self.initCoinbase(data.access_token); - }, 100); - }); - }); - } - }); - }); - }; - - self.sendToCopay = function(tx) { - if (!tx) return; - var data = { - to: tx.toAddr, - amount: tx.amount.amount, - currency: tx.amount.currency, - description: 'To Copay Wallet' - }; - coinbaseService.sendTo(self.coinbaseToken, self.coinbaseAccount.id, data, function(err, res) { - if (err) { - if (err.errors[0] && err.errors[0].id == 'expired_token') { - self.refreshCoinbaseToken(); - return; - } - coinbaseService.savePendingTransaction(tx, { - status: 'error', - error: err - }, function(err) { - if (err) $log.debug(err); - }); - } else { - if (!res.data.id) { - coinbaseService.savePendingTransaction(tx, { - status: 'error', - error: err - }, function(err) { - if (err) $log.debug(err); - }); - return; - } - coinbaseService.getTransaction(self.coinbaseToken, self.coinbaseAccount.id, res.data.id, function(err, sendTx) { - coinbaseService.savePendingTransaction(tx, { - remove: true - }, function(err) { - coinbaseService.savePendingTransaction(sendTx.data, {}, function(err) { - $timeout(function() { - self.updateCoinbase({ - updateAccount: true - }); - }, 1000); - }); - }); - }); - } - }); - }; - - self.sellPending = function(tx) { - if (!tx) return; - var data = tx.amount; - data['commit'] = true; - coinbaseService.sellRequest(self.coinbaseToken, self.coinbaseAccount.id, data, function(err, res) { - if (err) { - if (err.errors[0] && err.errors[0].id == 'expired_token') { - self.refreshCoinbaseToken(); - return; - } - coinbaseService.savePendingTransaction(tx, { - status: 'error', - error: err - }, function(err) { - if (err) $log.debug(err); - }); - } else { - if (!res.data.transaction) { - coinbaseService.savePendingTransaction(tx, { - status: 'error', - error: err - }, function(err) { - if (err) $log.debug(err); - }); - return; - } - coinbaseService.savePendingTransaction(tx, { - remove: true - }, function(err) { - coinbaseService.getTransaction(self.coinbaseToken, self.coinbaseAccount.id, res.data.transaction.id, function(err, updatedTx) { - coinbaseService.savePendingTransaction(updatedTx.data, {}, function(err) { - if (err) $log.debug(err); - $timeout(function() { - self.updateCoinbase({ - updateAccount: true - }); - }, 1000); - }); - }); - }); - } - }); - }; - - self.isInFocus = function(walletId) { - var fc = profileService.focusedClient; - return fc && fc.credentials.walletId == walletId; - }; - - self.setAddressbook = function(ab) { - if (ab) { - self.addressbook = ab; - return; - } - - addressbookService.list(function(err, ab) { - if (err) { - $log.error('Error getting the addressbook'); - return; - } - self.addressbook = ab; - }); - }; - - $rootScope.$on('$stateChangeSuccess', function(ev, to, toParams, from, fromParams) { - self.prevState = from.name || 'walletHome'; - self.tab = 'walletHome'; - }); - - $rootScope.$on('Local/ValidatingWalletEnded', function(ev, walletId, isOK) { - - if (self.isInFocus(walletId)) { - // NOTE: If the user changed the wallet, the flag is already turn off. - self.incorrectDerivation = isOK === false; - } - }); - - $rootScope.$on('Local/ClearHistory', function(event) { - $log.debug('The wallet transaction history has been deleted'); - self.txHistory = self.completeHistory = self.txHistorySearchResults = []; - self.debounceUpdateHistory(); - }); - - $rootScope.$on('Local/AddressbookUpdated', function(event, ab) { - self.setAddressbook(ab); - }); - - // UX event handlers - $rootScope.$on('Local/ColorUpdated', function(event) { - self.updateColor(); - $timeout(function() { - $rootScope.$apply(); - }); - }); - - $rootScope.$on('Local/AliasUpdated', function(event) { - self.updateAlias(); - $timeout(function() { - $rootScope.$apply(); - }); - }); - - $rootScope.$on('Local/SpendUnconfirmedUpdated', function(event, spendUnconfirmed) { - self.setSpendUnconfirmed(spendUnconfirmed); - self.updateAll(); - }); - - $rootScope.$on('Local/GlideraUpdated', function(event, accessToken) { - self.initGlidera(accessToken); - }); - - $rootScope.$on('Local/CoinbaseUpdated', function(event, accessToken) { - self.initCoinbase(accessToken); - }); - - $rootScope.$on('Local/GlideraTx', function(event, accessToken, permissions) { - self.updateGlidera(); - }); - - $rootScope.$on('Local/CoinbaseTx', function(event) { - self.updateCoinbase({ - updateAccount: true - }); - }); - - $rootScope.$on('Local/GlideraError', function(event) { - self.debouncedUpdate(); - }); - - $rootScope.$on('Local/UnitSettingUpdated', function(event) { - self.updateAll({ - triggerTxUpdate: true, - }); - }); - - $rootScope.$on('Local/WalletCompleted', function(event, walletId) { - if (self.isInFocus(walletId)) { - // reset main wallet variables - self.setFocusedWallet(); - go.walletHome(); - } - }); - - self.debouncedUpdate = function() { - var now = Date.now(); - var oneHr = 1000 * 60 * 60; - - if (!self.lastUpdate || (now - self.lastUpdate) > oneHr) { - self.updateAll({ - quiet: true, - triggerTxUpdate: true - }); - } - }; - - $rootScope.$on('Local/Resume', function(event) { - $log.debug('### Resume event'); - profileService.isDisclaimerAccepted(function(v) { - if (!v) { - $log.debug('Disclaimer not accepted, resume to home'); - go.path('disclaimer'); - } - }); - self.debouncedUpdate(); - }); - - $rootScope.$on('Local/BackupDone', function(event, walletId) { - self.needsBackup = false; - $log.debug('Backup done'); - storageService.setBackupFlag(walletId || self.walletId, function(err) { - $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() { - self.newTx = true; - self.updateAll({ - walletStatus: null, - untilItChanges: true, - triggerTxUpdate: true, - }); - }); - - - $rootScope.$on('NewBlock', function() { - if (self.glideraEnabled) { - $timeout(function() { - 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({ - walletStatus: null, - 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) { - $rootScope.$on(eventName, function() { - var f = function() { - if (self.updating) { - return $timeout(f, 200); - }; - self.updatePendingTxps(); - }; - f(); - }); - }); - - $rootScope.$on('Local/NoWallets', function(event) { - $timeout(function() { - self.hasProfile = true; - self.noFocusedWallet = true; - self.isComplete = null; - self.walletName = null; - uxLanguage.update(); - }); - }); - - $rootScope.$on('Local/NewFocusedWallet', function() { - console.log('[index.js.1200:NewFocusedWallet:] TODO'); //TODO - - return; - - - uxLanguage.update(); - self.setFocusedWallet(); - self.updateHistory(); - storageService.getCleanAndScanAddresses(function(err, walletId) { - - if (walletId && profileService.walletClients[walletId]) { - $log.debug('Clear last address cache and Scan ', walletId); - addressService.expireAddress(walletId, function(err) { - self.startScan(walletId); - }); - storageService.removeCleanAndScanAddresses(function() { - $rootScope.$emit('Local/NewFocusedWalletReady'); - }); - } else { - $rootScope.$emit('Local/NewFocusedWalletReady'); - } - }); - }); - - $rootScope.$on('Local/SetTab', function(event, tab, reset) { - self.setTab(tab, reset); - }); - - $rootScope.$on('disclaimerAccepted', function(event) { - $scope.isDisclaimerAccepted = true; - }); - - $rootScope.$on('Local/WindowResize', function() { - self.physicalScreenWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width); - }); - - $rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) { - - function openConfirmationPopup(txp, cb) { - - var config = configService.getSync(); - - $scope.color = config.colorFor[txp.walletId] || '#4A90E2'; - $scope.tx = txFormatService.processTx(txp); - - self.confirmationPopup = $ionicPopup.show({ - templateUrl: 'views/includes/confirm-tx.html', - scope: $scope, - }); - - $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) { - - function openPasswordPopup(isSetup, cb) { - $scope.data = {}; - $scope.data.password = null; - $scope.isSetup = isSetup; - $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.keyPress = function(event) { - if (!$scope.data.password || $scope.loading) return; - if (event.keyCode == 13) $scope.set(); - } - - $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/EmailUpdated', function(event, email) { - self.preferences.email = email; - }); - - 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 */ - lodash.assign(self, vanillaScope); - openURLService.init(); -}); diff --git a/src/js/controllers/join.js b/src/js/controllers/join.js index 0ab5a91a8..45535318e 100644 --- a/src/js/controllers/join.js +++ b/src/js/controllers/join.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('joinController', - function($scope, $rootScope, $timeout, go, notification, profileService, configService, storageService, applicationService, gettext, lodash, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess, walletService, $log) { + function($scope, $rootScope, $timeout, $state, notification, profileService, configService, storageService, applicationService, gettext, lodash, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess, walletService, $log) { var isChromeApp = platformInfo.isChromeApp; var isDevel = platformInfo.isDevel; @@ -140,7 +140,7 @@ angular.module('copayApp.controllers').controller('joinController', $log.debug('Remote preferences saved for:' + client.credentials.walletId) }); - go.walletHome(); + $state.go('tabs.home'); }); }, 100); }; diff --git a/src/js/controllers/paperWallet.js b/src/js/controllers/paperWallet.js index 69554c2dd..3ebf0462b 100644 --- a/src/js/controllers/paperWallet.js +++ b/src/js/controllers/paperWallet.js @@ -1,5 +1,5 @@ angular.module('copayApp.controllers').controller('paperWalletController', - function($scope, $timeout, $log, $ionicModal, configService, profileService, go, addressService, txStatus, bitcore, ongoingProcess, txFormatService) { + function($scope, $timeout, $log, $ionicModal, configService, profileService, $state, addressService, txStatus, bitcore, ongoingProcess, txFormatService) { var fc = profileService.focusedClient; var rawTx; @@ -102,7 +102,7 @@ angular.module('copayApp.controllers').controller('paperWalletController', } else { var type = txStatus.notify(txp); $scope.openStatusModal(type, txp, function() { - go.walletHome(); + $state.go('tabs.home'); }); } $scope.$apply(); diff --git a/src/js/controllers/paymentUri.js b/src/js/controllers/paymentUri.js index bfd6f9f13..79628814c 100644 --- a/src/js/controllers/paymentUri.js +++ b/src/js/controllers/paymentUri.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.controllers').controller('paymentUriController', - function($rootScope, $scope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, go) { + function($rootScope, $scope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, $state) { function strip(number) { return (parseFloat(number.toPrecision(12))); }; @@ -47,7 +47,7 @@ angular.module('copayApp.controllers').controller('paymentUriController', this.selectWallet = function(wid) { var self = this; profileService.setAndStoreFocus(wid, function() {}); - go.walletHome(); + $state.go('tabs.home'); $timeout(function() { $rootScope.$emit('paymentUri', self.bitcoinURI); }, 1000); diff --git a/src/js/controllers/preferencesDelete.js b/src/js/controllers/preferencesDelete.js index 133789e76..9ac144c57 100644 --- a/src/js/controllers/preferencesDelete.js +++ b/src/js/controllers/preferencesDelete.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('preferencesDeleteWalletController', - function($scope, $rootScope, $filter, $timeout, $log, $ionicModal, storageService, notification, profileService, platformInfo, go, gettext, gettextCatalog, applicationService, ongoingProcess) { + function($scope, $rootScope, $filter, $timeout, $log, $ionicModal, storageService, notification, profileService, platformInfo, $state, gettext, gettextCatalog, applicationService, ongoingProcess) { var isCordova = platformInfo.isCordova; $scope.isCordova = isCordova; $scope.error = null; @@ -38,7 +38,7 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro if (err) { $scope.error = err.message || err; } else { - go.walletHome(); + $state.go('tabs.home'); notification.success(gettextCatalog.getString('Success'), gettextCatalog.getString('The wallet "{{walletName}}" was deleted', { walletName: walletName })); diff --git a/src/js/controllers/preferencesHistory.js b/src/js/controllers/preferencesHistory.js index 1f988971d..493638c59 100644 --- a/src/js/controllers/preferencesHistory.js +++ b/src/js/controllers/preferencesHistory.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('preferencesHistory', - function($scope, $log, $timeout, storageService, go, profileService, lodash) { + function($scope, $log, $timeout, storageService, $state, profileService, lodash) { var fc = profileService.focusedClient; var c = fc.credentials; $scope.csvReady = false; @@ -125,7 +125,7 @@ angular.module('copayApp.controllers').controller('preferencesHistory', $scope.$emit('Local/ClearHistory'); $timeout(function() { - go.walletHome(); + $state.go('tabs.home'); }, 100); }); }; diff --git a/src/js/controllers/preferencesInformation.js b/src/js/controllers/preferencesInformation.js index 2b6a157e4..2275edafe 100644 --- a/src/js/controllers/preferencesInformation.js +++ b/src/js/controllers/preferencesInformation.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('preferencesInformation', - function($scope, $log, $timeout, platformInfo, gettextCatalog, lodash, profileService, configService, go, $stateParams) { + function($scope, $log, $timeout, platformInfo, gettextCatalog, lodash, profileService, configService, $stateParams, walletService, $state) { var base = 'xpub'; var wallet = profileService.getWallet($stateParams.walletId); var walletId = wallet.id; @@ -104,7 +104,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation', opts.colorFor[walletId] = color; configService.set(opts, function(err) { - go.walletHome(); + $state.go('tabs.home'); if (err) $log.warn(err); $scope.$emit('Local/ColorUpdated'); }); @@ -121,4 +121,11 @@ angular.module('copayApp.controllers').controller('preferencesInformation', } }; + $scope.scan = function() { + walletService.startScan(wallet); + $state.go('tabs.home'); + }; + + + }); diff --git a/src/js/routes.js b/src/js/routes.js index 0d0087391..be03b6e20 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -578,7 +578,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, lodash, platformInfo, profileService, uxLanguage, go, gettextCatalog) { + .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, lodash, platformInfo, profileService, uxLanguage, gettextCatalog) { if (platformInfo.isCordova) { if (screen.width < 768) { @@ -664,11 +664,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr else secondBackButtonPress = true; - $timeout(function() { - $rootScope.$emit('Local/SetTab', 'walletHome', true); - }, 100); - - go.walletHome(); + $state.go('tabs.home'); }); $ionicPlatform.on('menubutton', function() { diff --git a/src/js/services/applicationService.js b/src/js/services/applicationService.js index 0b82bcaf7..fd4b724af 100644 --- a/src/js/services/applicationService.js +++ b/src/js/services/applicationService.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.services') - .factory('applicationService', function($rootScope, $timeout, platformInfo, go) { + .factory('applicationService', function($rootScope, $timeout, platformInfo, $state) { var root = {}; var isChromeApp = platformInfo.isChromeApp; @@ -19,7 +19,7 @@ angular.module('copayApp.services') if (isChromeApp) { chrome.runtime.reload(); } else if (isNW) { - go.walletHome(); + $state.go('tabs.home'); $timeout(function() { var win = require('nw.gui').Window.get(); win.reload(3); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index a8be2b6c7..11013427c 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -1,10 +1,6 @@ 'use strict'; -// DO NOT INCLUDE STORAGE HERE \/ \/ -angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txStatus, txFormatService, $ionicModal) { - // DO NOT INCLUDE STORAGE HERE ^^ - // - // +angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txStatus, txFormatService, $ionicModal, $state) { // `wallet` is a decorated version of client. var root = {}; @@ -104,7 +100,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim console.log('[walletService.js.93] TODO NOT AUTH'); //TODO // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO wallet.notAuthorized = true; - go.walletHome(); + $state.go('tabs.home'); } else if (err instanceof errors.NOT_FOUND) { root.showErrorPopup(gettext('Could not access Wallet Service: Not found')); } else { @@ -665,6 +661,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim alertPopup.then(cb); }; + // walletHome root.recreate = function(wallet, cb) { ongoingProcess.set('recreating', true); wallet.recreateWallet(function(err) { @@ -672,7 +669,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim ongoingProcess.set('recreating', false); if (err) { - wallet.handleError(err); + handleError(err); return; } @@ -693,12 +690,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim includeCopayerBranches: true, }, function(err) { - // TODO - // if (err && wallet.walletId == walletId) { - // wallet.updating = false; - // wallet.handleError(err); - // $rootScope.$apply(); - // } + if (err && wallet.walletId == walletId) { + wallet.updating = false; + handleError(err); + } }); };