From 2a97446ef9cdc204356cb027d4e0bde242f5ba27 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 13:52:44 -0300 Subject: [PATCH 01/13] remote ignoreMobilePause, refactor openURL --- public/views/paymentUri.html | 2 +- src/js/controllers/buyCoinbase.js | 2 - src/js/controllers/buyGlidera.js | 3 - src/js/controllers/coinbase.js | 1 - src/js/controllers/copayers.js | 3 - src/js/controllers/export.js | 3 - src/js/controllers/glideraUri.js | 2 + src/js/controllers/import.js | 8 - src/js/controllers/index.js | 518 ++++++++++--------- src/js/controllers/modals/customAmount.js | 3 - src/js/controllers/paymentUri.js | 10 +- src/js/controllers/preferencesInformation.js | 4 - src/js/controllers/sellCoinbase.js | 1 - src/js/controllers/sellGlidera.js | 2 - src/js/controllers/walletHome.js | 4 - src/js/directives/qrScanner.js | 3 - src/js/init.js | 40 +- src/js/routes.js | 49 +- src/js/services/animationService.js | 1 + src/js/services/configService.js | 4 +- src/js/services/go.js | 6 +- src/js/services/openURL.js | 69 +++ src/js/services/profileService.js | 1 - 23 files changed, 379 insertions(+), 360 deletions(-) create mode 100644 src/js/services/openURL.js diff --git a/public/views/paymentUri.html b/public/views/paymentUri.html index e0d0d337d..73c553a5a 100644 --- a/public/views/paymentUri.html +++ b/public/views/paymentUri.html @@ -5,7 +5,7 @@
-
+

Bitcoin URI is NOT valid!

diff --git a/src/js/controllers/buyCoinbase.js b/src/js/controllers/buyCoinbase.js index 7b40fc26a..e81c12fa5 100644 --- a/src/js/controllers/buyCoinbase.js +++ b/src/js/controllers/buyCoinbase.js @@ -2,8 +2,6 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', function($scope, $modal, $log, $ionicModal, $timeout, lodash, profileService, coinbaseService, bwsError, addressService) { - - window.ignoreMobilePause = true; var self = this; var fc; diff --git a/src/js/controllers/buyGlidera.js b/src/js/controllers/buyGlidera.js index ef243a9a3..793c0bb51 100644 --- a/src/js/controllers/buyGlidera.js +++ b/src/js/controllers/buyGlidera.js @@ -8,9 +8,6 @@ angular.module('copayApp.controllers').controller('buyGlideraController', this.error = null; this.success = null; this.loading = null; - - window.ignoreMobilePause = true; - var otherWallets = function(testnet) { var network = testnet ? 'testnet' : 'livenet'; return lodash.filter(profileService.getWallets(network), function(w) { diff --git a/src/js/controllers/coinbase.js b/src/js/controllers/coinbase.js index 8d972a0ee..61553b3e9 100644 --- a/src/js/controllers/coinbase.js +++ b/src/js/controllers/coinbase.js @@ -4,7 +4,6 @@ angular.module('copayApp.controllers').controller('coinbaseController', function($rootScope, $scope, $timeout, $modal, $ionicModal, profileService, configService, storageService, coinbaseService, lodash, platformInfo) { var isNW = platformInfo.isNW; - window.ignoreMobilePause = true; this.openAuthenticateWindow = function() { var oauthUrl = this.getAuthenticateUrl(); diff --git a/src/js/controllers/copayers.js b/src/js/controllers/copayers.js index b263a6e29..de9e40172 100644 --- a/src/js/controllers/copayers.js +++ b/src/js/controllers/copayers.js @@ -92,9 +92,6 @@ angular.module('copayApp.controllers').controller('copayersController', self.shareSecret = function(secret) { if (isCordova) { - if (isAndroid || isWP) { - window.ignoreMobilePause = true; - } var message = gettextCatalog.getString('Join my Copay wallet. Here is the invitation code: {{secret}} You can download Copay for your phone or desktop at https://copay.io', { secret: secret }); diff --git a/src/js/controllers/export.js b/src/js/controllers/export.js index 289fbf767..d5110de52 100644 --- a/src/js/controllers/export.js +++ b/src/js/controllers/export.js @@ -126,9 +126,6 @@ angular.module('copayApp.controllers').controller('exportController', self.sendWalletBackup = function() { var fc = profileService.focusedClient; - if (isAndroid || isWP) { - window.ignoreMobilePause = true; - } window.plugins.toast.showShortCenter(gettextCatalog.getString('Preparing backup...')); var name = (fc.credentials.walletName || fc.credentials.walletId); if (fc.alias) { diff --git a/src/js/controllers/glideraUri.js b/src/js/controllers/glideraUri.js index a42859e5d..32f13ee6d 100644 --- a/src/js/controllers/glideraUri.js +++ b/src/js/controllers/glideraUri.js @@ -3,6 +3,7 @@ angular.module('copayApp.controllers').controller('glideraUriController', function($scope, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { this.submitOauthCode = function(code) { +console.log('[glideraUri.js.5:code:]'+code); //TODO var self = this; var glideraTestnet = configService.getSync().glidera.testnet; var network = glideraTestnet ? 'testnet' : 'livenet'; @@ -31,6 +32,7 @@ angular.module('copayApp.controllers').controller('glideraUriController', }; this.checkCode = function() { +console.log('[glideraUri.js.35:$stateParams:]' + JSON.stringify($stateParams)); //TODO this.code = $stateParams.code; this.submitOauthCode(this.code); }; diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index 010520814..d44b487f1 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -15,14 +15,6 @@ angular.module('copayApp.controllers').controller('importController', $scope.account = 1; self.importErr = false; - window.ignoreMobilePause = true; - $scope.$on('$destroy', function() { - $timeout(function() { - window.ignoreMobilePause = false; - }, 100); - }); - - var updateSeedSourceSelect = function() { self.seedOptions = []; diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index cc78efba0..734105396 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1,6 +1,6 @@ '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) { +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) { var self = this; var SOFT_CONFIRMATION_LIMIT = 12; var errors = bwcService.getErrors(); @@ -289,6 +289,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r initStatusHash = _walletStatusHash(); $log.debug('Updating status until it changes. initStatusHash:' + initStatusHash) } + var get = function(cb) { if (opts.walletStatus) return cb(null, opts.walletStatus); @@ -351,6 +352,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.setPendingTxps(walletStatus.pendingTxps); // Status Shortcuts + self.lastUpdate = Date.now(); self.walletName = walletStatus.wallet.name; self.walletSecret = walletStatus.wallet.secret; self.walletStatus = walletStatus.wallet.status; @@ -1492,59 +1494,105 @@ angular.module('copayApp.controllers').controller('indexController', function($r } }); - self.debouncedUpdate = lodash.throttle(function() { - self.updateAll({ - quiet: true - }); - self.debounceUpdateHistory(); - }, 2000, { - leading: false, - trailing: true - }); + self.debouncedUpdate = function() { + var now = Date.now(); + var oneHr = 1000 * 60 * 60; - $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); + if (!self.lastUpdate || (now - self.lastUpdate) > oneHr) { + self.updateAll({ + quiet: true + triggerTxUpdate: true, }); - }); + } }); - $rootScope.$on('NewIncomingTx', function() { +$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, @@ -1552,244 +1600,200 @@ angular.module('copayApp.controllers').controller('indexController', function($r 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; +//untilItChange FALSE +lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'NewOutgoingTxByThirdParty', + 'Local/GlideraTx' +], function(eventName) { + $rootScope.$on(eventName, function(event) { self.updateAll({ walletStatus: null, - untilItChanges: untilItChanges, + untilItChanges: null, triggerTxUpdate: true, }); }); +}); - $rootScope.$on('ScanFinished', function() { - $log.debug('Scan Finished. Updating history'); - storageService.removeTxHistory(self.walletId, function() { - self.updateAll({ - walletStatus: 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.updatingStatus) { - return $timeout(f, 200); - }; - self.updatePendingTxps(); +lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy'], function(eventName) { + $rootScope.$on(eventName, function() { + var f = function() { + if (self.updatingStatus) { + return $timeout(f, 200); }; - f(); - }); + 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(); - - profileService.isDisclaimerAccepted(function(v) { - if (v) { - go.path('import'); - } - }); - }); - }); - - $rootScope.$on('Local/NewFocusedWallet', function() { +$rootScope.$on('Local/NoWallets', function(event) { + $timeout(function() { + self.hasProfile = true; + self.noFocusedWallet = true; + self.isComplete = null; + self.walletName = null; 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'); + profileService.isDisclaimerAccepted(function(v) { + if (v) { + go.path('import'); } }); }); +}); - $rootScope.$on('Local/SetTab', function(event, tab, reset) { - self.setTab(tab, reset); - }); +$rootScope.$on('Local/NewFocusedWallet', function() { + uxLanguage.update(); + self.setFocusedWallet(); + self.updateHistory(); + storageService.getCleanAndScanAddresses(function(err, walletId) { - $rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) { - - function openConfirmationPopup(txp, cb) { - - $scope.tx = txFormatService.processTx(txp); - - self.confirmationPopup = $ionicPopup.show({ - templateUrl: 'views/includes/confirm-tx.html', - scope: $scope, + if (walletId && profileService.walletClients[walletId]) { + $log.debug('Clear last address cache and Scan ', walletId); + addressService.expireAddress(walletId, function(err) { + self.startScan(walletId); }); - - $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); - }; + storageService.removeCleanAndScanAddresses(function() { + $rootScope.$emit('Local/NewFocusedWalletReady'); + }); + } else { + $rootScope.$emit('Local/NewFocusedWalletReady'); } - - openConfirmationPopup(txp, function(accept) { - self.confirmationPopup.close(); - return cb(accept); - }); }); +}); - $rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) { +$rootScope.$on('Local/SetTab', function(event, tab, reset) { + self.setTab(tab, reset); +}); - function openPasswordPopup(isSetup, cb) { - $scope.data = {}; - $scope.data.password = null; - $scope.isSetup = isSetup; - $scope.isVerification = false; - $scope.loading = false; - var pass = null; +$rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) { - self.passwordPopup = $ionicPopup.show({ - templateUrl: 'views/includes/password.html', - scope: $scope, - }); + function openConfirmationPopup(txp, cb) { - $scope.cancel = function() { - return cb('No spending password given'); - }; + $scope.tx = txFormatService.processTx(txp); - $scope.set = function() { - $scope.loading = true; - $scope.error = null; + self.confirmationPopup = $ionicPopup.show({ + templateUrl: 'views/includes/confirm-tx.html', + scope: $scope, + }); - $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); - }; + $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) + '%'; }; - openPasswordPopup(isSetup, function(err, pass) { - self.passwordPopup.close(); - return cb(err, pass); - }); + $scope.cancel = function() { + return cb(); + }; + $scope.accept = function() { + return cb(true); + }; + } + + openConfirmationPopup(txp, function(accept) { + self.confirmationPopup.close(); + return cb(accept); }); - - $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); +}); + +$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.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/modals/customAmount.js b/src/js/controllers/modals/customAmount.js index 091394bcc..48db4d9cf 100644 --- a/src/js/controllers/modals/customAmount.js +++ b/src/js/controllers/modals/customAmount.js @@ -69,9 +69,6 @@ angular.module('copayApp.controllers').controller('customAmountController', func $scope.shareAddress = function(uri) { if (platformInfo.isCordova) { - if (platformInfo.isAndroid || platformInfo.isWP) { - window.ignoreMobilePause = true; - } window.plugins.socialsharing.share(uri, null, null, null); } }; diff --git a/src/js/controllers/paymentUri.js b/src/js/controllers/paymentUri.js index 241d05a46..deaf152a0 100644 --- a/src/js/controllers/paymentUri.js +++ b/src/js/controllers/paymentUri.js @@ -1,20 +1,14 @@ 'use strict'; angular.module('copayApp.controllers').controller('paymentUriController', function($rootScope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, go) { - - window.ignoreMobilePause = true; function strip(number) { return (parseFloat(number.toPrecision(12))); }; // Build bitcoinURI with querystring - this.checkBitcoinUri = function() { + this.init = function() { var query = []; - angular.forEach($location.search(), function(value, key) { - query.push(key + "=" + value); - }); - var queryString = query ? query.join("&") : null; - this.bitcoinURI = $stateParams.data + (queryString ? '?' + queryString : ''); + this.bitcoinURI = $stateParams.url; var URI = bitcore.URI; var isUriValid = URI.isValid(this.bitcoinURI); diff --git a/src/js/controllers/preferencesInformation.js b/src/js/controllers/preferencesInformation.js index a3f148c61..8f31255b1 100644 --- a/src/js/controllers/preferencesInformation.js +++ b/src/js/controllers/preferencesInformation.js @@ -46,10 +46,6 @@ angular.module('copayApp.controllers').controller('preferencesInformation', this.sendAddrs = function() { var self = this; - if (platformInfo.isAndroid || platformInfo.isWP) { - window.ignoreMobilePause = true; - } - self.loading = true; function formatDate(ts) { diff --git a/src/js/controllers/sellCoinbase.js b/src/js/controllers/sellCoinbase.js index c94a3304b..679caf9f0 100644 --- a/src/js/controllers/sellCoinbase.js +++ b/src/js/controllers/sellCoinbase.js @@ -3,7 +3,6 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', function($rootScope, $scope, $modal, $log, $timeout, $ionicModal, lodash, profileService, coinbaseService, bwsError, configService, walletService, fingerprintService) { - window.ignoreMobilePause = true; var self = this; var fc; diff --git a/src/js/controllers/sellGlidera.js b/src/js/controllers/sellGlidera.js index 53321bb80..6804e083f 100644 --- a/src/js/controllers/sellGlidera.js +++ b/src/js/controllers/sellGlidera.js @@ -12,8 +12,6 @@ angular.module('copayApp.controllers').controller('sellGlideraController', this.loading = null; var fc; - window.ignoreMobilePause = true; - var otherWallets = function(testnet) { var network = testnet ? 'testnet' : 'livenet'; return lodash.filter(profileService.getWallets(network), function(w) { diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index c80f9a1b9..d3bb4f61d 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -8,7 +8,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var isChromeApp = platformInfo.isChromeApp; var self = this; - window.ignoreMobilePause = false; $rootScope.shouldHideMenuBar = false; $rootScope.wpInputFocused = false; var config = configService.getSync(); @@ -217,9 +216,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.shareAddress = function(addr) { if (isCordova) { - if (isAndroid || isWP) { - window.ignoreMobilePause = true; - } window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null); } }; diff --git a/src/js/directives/qrScanner.js b/src/js/directives/qrScanner.js index cb9bf0b88..a43ca9b1c 100644 --- a/src/js/directives/qrScanner.js +++ b/src/js/directives/qrScanner.js @@ -12,7 +12,6 @@ angular.module('copayApp.directives') var onSuccess = function(result) { $timeout(function() { window.plugins.spinnerDialog.hide(); - window.ignoreMobilePause = false; }, 100); if (isWP && result.cancelled) return; @@ -26,13 +25,11 @@ angular.module('copayApp.directives') var onError = function(error) { $timeout(function() { - window.ignoreMobilePause = false; window.plugins.spinnerDialog.hide(); }, 100); }; $scope.cordovaOpenScanner = function() { - window.ignoreMobilePause = true; window.plugins.spinnerDialog.show(null, gettextCatalog.getString('Preparing camera...'), true); $timeout(function() { if (isIOS) { diff --git a/src/js/init.js b/src/js/init.js index 44392c992..e8141f5c9 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -7,42 +7,32 @@ angular.element(document).ready(function() { angular.bootstrap(document, ['copayApp']); }; - var handleBitcoinURI = function(url) { - if (!url) return; - console.log('Custom URL:' + url); //TODO - var glidera = 'copay://glidera'; - var coinbase = 'copay://coinbase'; - - if (url.indexOf('bitcoin:') == 0) { - url = '#/uri-payment/' + url; - } else if (url.indexOf(glidera) != -1) { - url = '#/uri-glidera' + url.replace(glidera, ''); - } else if (url.indexOf(coinbase) != -1) { - url = '#/uri-coinbase' + url.replace(coinbase, ''); + function handleOpenURL(url) { + if ('cordova' in window) { + console.log('DEEP LINK:' + url); + cordova.fireDocumentEvent('handleopenurl', { + url: url + }); } else { - console.log('Unknown URL!') - }; - - setTimeout(function() { - window.location = url; - }, 1000); + console.log("ERROR: Cannont handle open URL in non-cordova apps") + } }; - /* Cordova specific Init */ - if (window.cordova !== undefined) { + if ('cordova' in window) { + + window.handleOpenURL = handleOpenURL; + document.addEventListener('deviceready', function() { - window.handleOpenURL = handleBitcoinURI; + + // Create a sticky event for handling the app being opened via a custom URL + cordova.addStickyDocumentEventHandler('handleopenurl'); startAngular(); }, false); } else { - try { - window.handleOpenURL = handleBitcoinURI; - } catch (e) {} - startAngular(); } diff --git a/src/js/routes.js b/src/js/routes.js index 998ac7848..d9400b67e 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -112,8 +112,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } } }) - .state('payment', { - url: '/uri-payment/:data', + .state('uripayment', { + url: '/uri-payment/:url', templateUrl: 'views/paymentUri.html', views: { 'main': { @@ -215,7 +215,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('uriglidera', { - url: '/uri-glidera?code', + url: '/uri-glidera/:code', needProfile: true, views: { 'main': { @@ -284,7 +284,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('uricoinbase', { - url: '/uri-coinbase?code', + url: '/uri-coinbase/:code', needProfile: true, views: { 'main': { @@ -520,7 +520,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $log, $timeout, $ionicPlatform, uriHandler, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) { + .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, uriHandler, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) { $ionicPlatform.ready(function() { if (platformInfo.isCordova) { @@ -539,14 +539,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }); $ionicPlatform.on('resume', function() { - if (!window.ignoreMobilePause) { - $rootScope.$emit('Local/Resume'); - } - setTimeout(function() { - var loc = window.location; - var ignoreMobilePause = loc.toString().match(/(buy|sell|buycoinbase|sellcoinbase)/) ? true : false; - window.ignoreMobilePause = ignoreMobilePause; - }, 100); + // Nothing to do + $rootScope.$emit('Local/Resume'); }); $ionicPlatform.on('backbutton', function(event) { @@ -575,10 +569,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }, 100); go.walletHome(); - - setTimeout(function() { - window.ignoreMobilePause = false; - }, 100); }); $ionicPlatform.on('menubutton', function() { @@ -614,6 +604,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { $log.debug('Route change from:', fromState.name || '-', ' to:', toState.name); + $log.debug(' toParams:' + JSON.stringify(toParams || {})); + $log.debug(' fromParams:' + JSON.stringify(fromParams || {})); if (!profileService.profile && toState.needProfile) { @@ -640,17 +632,22 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } else { if (profileService.focusedClient && !profileService.focusedClient.isComplete() && toState.walletShouldBeComplete) { - $state.transitionTo('copayers'); event.preventDefault(); + $state.transitionTo('copayers'); } } - - if (!animationService.transitionAnimated(fromState, toState)) { - event.preventDefault(); - // Time for the backpane to render - setTimeout(function() { - $state.transitionTo(toState); - }, 50); - } +// event.preventDefault(); +// $state.transitionTo(toState); +// if (!animationService.transitionAnimated(fromState, toState)) { +// +// console.log('[routes.js.649] ANIMATION!'); //TODO +// event.preventDefault(); +// // Time for the backpane to render +// return setTimeout(function() { +// +// console.log('[routes.js.654] TRANSITION'); //TODO +// $state.transitionTo(toState); +// }, 50); +// } }); }); diff --git a/src/js/services/animationService.js b/src/js/services/animationService.js index 7197194cb..6a0c8a5fb 100644 --- a/src/js/services/animationService.js +++ b/src/js/services/animationService.js @@ -60,6 +60,7 @@ angular.module('copayApp.services').factory('animationService', function(platfor }; function cleanUpLater(e, e2) { +console.log('[animationService.js.62:cleanUpLater:]'); //TODO var cleanedUp = false, timeoutID; var cleanUp = function() { diff --git a/src/js/services/configService.js b/src/js/services/configService.js index 9af77287d..9a18c9894 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -111,11 +111,11 @@ angular.module('copayApp.services').factory('configService', function(storageSer // Glidera // Disabled for testnet - configCache.glidera.testnet = false; + configCache.glidera.testnet = true; // Coinbase // Disabled for testnet - configCache.coinbase.testnet = false; + configCache.coinbase.testnet = true; $log.debug('Preferences read:', configCache) return cb(err, configCache); diff --git a/src/js/services/go.js b/src/js/services/go.js index f30a2b6b7..52f00de33 100644 --- a/src/js/services/go.js +++ b/src/js/services/go.js @@ -48,15 +48,15 @@ angular.module('copayApp.services').factory('go', function($window, $ionicSideMe }; root.addWallet = function() { - $state.go('add'); + $state.transitionTo('add'); }; root.preferences = function() { - $state.go('preferences'); + $state.transitionTo('preferences'); }; root.preferencesGlobal = function() { - $state.go('preferencesGlobal'); + $state.transitionTo('preferencesGlobal'); }; root.reload = function() { diff --git a/src/js/services/openURL.js b/src/js/services/openURL.js new file mode 100644 index 000000000..a7f219a40 --- /dev/null +++ b/src/js/services/openURL.js @@ -0,0 +1,69 @@ +'use strict'; + +angular.module('copayApp.services').factory('openURLService', function($ionicHistory, $document, $log, $state, go) { + var root = {}; + + root.registeredUriHandlers = [{ + name: 'Bitcoin BIP21 URL', + startsWith: 'bitcoin:', + transitionTo: 'uripayment', + }, { + name: 'Glidera Authentication Callback', + startsWith: 'copay://glidera', + transitionTo: 'uriglidera', + }, { + name: 'Coinbase Authentication Callback', + startsWith: 'copay://coinbase', + transitionTo: 'uricoinbase', + }]; + + + var handleOpenURL = function(args) { + $log.info('Handling Open URL: ' + JSON.stringify(args)); + + // Stop it from caching the first view as one to return when the app opens + $ionicHistory.nextViewOptions({ + historyRoot: true, + disableBack: true, + disableAnimation: true + }); + + if (url) { + window.cordova.removeDocumentEventHandler('handleopenurl'); + window.cordova.addStickyDocumentEventHandler('handleopenurl'); + document.removeEventListener('handleopenurl', root.handleOpenUrl); + } + + + var url = args.url; + + lodash.each(root.registeredUriHandlers, function(x) { + if (url.indexOf(x.startWith) == 0) { + $log.debug('openURL GOT ' + x.name + ' URL'); + return $state.transitionTo(x.transitionTo, { + url: url + }); + } + }); + $log.warn('Unknown URL! : ' + url); + }; + + var handleResume = function() { + $log.debug('Handle Resume @ openURL...'); + document.addEventListener('handleopenurl', handleOpenUrl, false); + }; + + root.init = function() { + console.log('[openURL.js.29]'); //TODO + document.addEventListener('handleopenurl', handleOpenURL, false); + document.addEventListener('resume', handleResume, false); + }; + + + root.registerHandler = function(x) { + $log.debug('Registering URL Handler: ' + x.name); + root.registeredUriHandlers.push(x); + }; + + return root; +}); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index bd537977b..1ed664bd0 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -182,7 +182,6 @@ angular.module('copayApp.services') push.on('notification', function(data) { if (!data.additionalData.foreground) { - window.ignoreMobilePause = true; $log.debug('Push notification event: ', data.message); $timeout(function() { From ecf16d61ea8c3bdc5dfafd84b7b3a86d34bfb809 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 18:28:31 -0300 Subject: [PATCH 02/13] Glidera working again. Rm ignoreMobilePause! --- public/views/uri.html | 11 +++++ src/js/controllers/glideraUri.js | 73 ++++++++++++++++--------------- src/js/controllers/index.js | 6 +-- src/js/controllers/uri.js | 12 +++++ src/js/routes.js | 32 +++++--------- src/js/services/openURL.js | 71 ++++++++++++++++++++++-------- src/js/services/profileService.js | 1 - src/js/services/uriHandler.js | 14 ------ 8 files changed, 128 insertions(+), 92 deletions(-) create mode 100644 public/views/uri.html create mode 100644 src/js/controllers/uri.js delete mode 100644 src/js/services/uriHandler.js diff --git a/public/views/uri.html b/public/views/uri.html new file mode 100644 index 000000000..e16b42d1c --- /dev/null +++ b/public/views/uri.html @@ -0,0 +1,11 @@ + +
+
+ +
+
+

+ Please wait to be redirected... +

+
+ diff --git a/src/js/controllers/glideraUri.js b/src/js/controllers/glideraUri.js index 32f13ee6d..c4bbdd5e9 100644 --- a/src/js/controllers/glideraUri.js +++ b/src/js/controllers/glideraUri.js @@ -1,40 +1,43 @@ 'use strict'; angular.module('copayApp.controllers').controller('glideraUriController', - function($scope, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { +function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { - this.submitOauthCode = function(code) { -console.log('[glideraUri.js.5:code:]'+code); //TODO - var self = this; - var glideraTestnet = configService.getSync().glidera.testnet; - var network = glideraTestnet ? 'testnet' : 'livenet'; - this.loading = true; - this.error = null; - $timeout(function() { - glideraService.getToken(code, function(err, data) { - self.loading = null; - if (err) { - self.error = err; + this.submitOauthCode = function(code) { + $log.debug('Glidera Oauth Code:' + code); + var self = this; + var glideraTestnet = configService.getSync().glidera.testnet; + var network = glideraTestnet ? 'testnet' : 'livenet'; + this.loading = true; + this.error = null; + $timeout(function() { + glideraService.getToken(code, function(err, data) { + self.loading = null; + if (err) { + self.error = err; + $timeout(function() { + $scope.$apply(); + }, 100); + } else if (data && data.access_token) { + storageService.setGlideraToken(network, data.access_token, function() { + $scope.$emit('Local/GlideraUpdated', data.access_token); $timeout(function() { - $scope.$apply(); - }, 100); - } - else if (data && data.access_token) { - storageService.setGlideraToken(network, data.access_token, function() { - $scope.$emit('Local/GlideraUpdated', data.access_token); - $timeout(function() { - go.path('glidera'); - $scope.$apply(); - }, 100); - }); - } - }); - }, 100); - }; + go.path('glidera'); + $scope.$apply(); + }, 100); + }); + } + }); + }, 100); + }; - this.checkCode = function() { -console.log('[glideraUri.js.35:$stateParams:]' + JSON.stringify($stateParams)); //TODO - this.code = $stateParams.code; - this.submitOauthCode(this.code); - }; - - }); + this.checkCode = function() { + if ($stateParams.url) { + var match = $stateParams.url.match(/code=(.+)/); + if (match && match[1]) { + this.code = match[1]; + return this.submitOauthCode(this.code); + } + } + $log.error('Bad state: ' + JSON.stringify($stateParams)); + } +}); diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 734105396..05f3e4077 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1500,11 +1500,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r if (!self.lastUpdate || (now - self.lastUpdate) > oneHr) { self.updateAll({ - quiet: true - triggerTxUpdate: true, + quiet: true, + triggerTxUpdate: true }); } - }); + }; $rootScope.$on('Local/Resume', function(event) { $log.debug('### Resume event'); diff --git a/src/js/controllers/uri.js b/src/js/controllers/uri.js new file mode 100644 index 000000000..bf6c91120 --- /dev/null +++ b/src/js/controllers/uri.js @@ -0,0 +1,12 @@ +'use strict'; +angular.module('copayApp.controllers').controller('uriController', + function($rootScope, $stateParams, $log, openURLService) { + + + /* This is only for BROWSER links, it is not excecuted on mobile devices */ + + $log.info('DEEP LINK from Browser:' + $stateParams.url); + openURLService.handleURL({ + url: $stateParams.url + }); + }); diff --git a/src/js/routes.js b/src/js/routes.js index d9400b67e..299def8a4 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -112,6 +112,15 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } } }) + .state('uri', { + url: '/uri/:url', + needProfile: true, + views: { + 'main': { + templateUrl: 'views/uri.html' + } + } + }) .state('uripayment', { url: '/uri-payment/:url', templateUrl: 'views/paymentUri.html', @@ -122,11 +131,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }, needProfile: true }) - .state('selectWalletForPayment', { - url: '/selectWalletForPayment', - controller: 'walletForPaymentController', - needProfile: true - }) .state('join', { url: '/join', needProfile: true, @@ -215,7 +219,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('uriglidera', { - url: '/uri-glidera/:code', + url: '/uri-glidera/:url', needProfile: true, views: { 'main': { @@ -284,7 +288,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('uricoinbase', { - url: '/uri-coinbase/:code', + url: '/uri-coinbase/:url', needProfile: true, views: { 'main': { @@ -504,12 +508,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }, } }) - .state('warning', { - url: '/warning', - controller: 'warningController', - templateUrl: 'views/warning.html', - needProfile: false - }) .state('add', { url: '/add', needProfile: true, @@ -520,7 +518,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, uriHandler, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) { + .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) { $ionicPlatform.ready(function() { if (platformInfo.isCordova) { @@ -539,7 +537,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }); $ionicPlatform.on('resume', function() { - // Nothing to do $rootScope.$emit('Local/Resume'); }); @@ -583,11 +580,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr uxLanguage.init(); - // Register URI handler, not for mobileApp - if (!platformInfo.isMobile) { - uriHandler.register(); - } - if (platformInfo.isNW) { var gui = require('nw.gui'); var win = gui.Window.get(); diff --git a/src/js/services/openURL.js b/src/js/services/openURL.js index a7f219a40..07cd8935d 100644 --- a/src/js/services/openURL.js +++ b/src/js/services/openURL.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('openURLService', function($ionicHistory, $document, $log, $state, go) { +angular.module('copayApp.services').factory('openURLService', function($ionicHistory, $document, $log, $state, go, platformInfo, lodash) { var root = {}; root.registeredUriHandlers = [{ @@ -9,11 +9,11 @@ angular.module('copayApp.services').factory('openURLService', function($ionicHis transitionTo: 'uripayment', }, { name: 'Glidera Authentication Callback', - startsWith: 'copay://glidera', + startsWith: 'copay:glidera', transitionTo: 'uriglidera', }, { name: 'Coinbase Authentication Callback', - startsWith: 'copay://coinbase', + startsWith: 'copay:coinbase', transitionTo: 'uricoinbase', }]; @@ -27,43 +27,76 @@ angular.module('copayApp.services').factory('openURLService', function($ionicHis disableBack: true, disableAnimation: true }); + var url = args.url; + if (!url) { + $log.error('No url provided'); + return; + }; if (url) { - window.cordova.removeDocumentEventHandler('handleopenurl'); - window.cordova.addStickyDocumentEventHandler('handleopenurl'); - document.removeEventListener('handleopenurl', root.handleOpenUrl); + if ('cordova' in window) { + window.cordova.removeDocumentEventHandler('handleopenurl'); + window.cordova.addStickyDocumentEventHandler('handleopenurl'); + } + document.removeEventListener('handleopenurl', handleOpenURL); } + document.addEventListener('handleopenurl', handleOpenURL, false); - var url = args.url; - - lodash.each(root.registeredUriHandlers, function(x) { - if (url.indexOf(x.startWith) == 0) { - $log.debug('openURL GOT ' + x.name + ' URL'); - return $state.transitionTo(x.transitionTo, { - url: url - }); - } + var x = lodash.find(root.registeredUriHandlers, function(x) { + return url.indexOf(x.startsWith) == 0 || + url.indexOf('web+' + x.startsWith) == 0 || // web protocols + url.indexOf(x.startsWith.replace(':','://')) == 0 // from mobile devices + ; }); - $log.warn('Unknown URL! : ' + url); + + if (x) { + $log.debug('openURL GOT ' + x.name + ' URL'); + return $state.transitionTo(x.transitionTo, { + url: url + }); + } else { + $log.warn('Unknown URL! : ' + url); + } }; var handleResume = function() { $log.debug('Handle Resume @ openURL...'); - document.addEventListener('handleopenurl', handleOpenUrl, false); + document.addEventListener('handleopenurl', handleOpenURL, false); }; root.init = function() { - console.log('[openURL.js.29]'); //TODO + $log.debug('Initializing openURL'); document.addEventListener('handleopenurl', handleOpenURL, false); document.addEventListener('resume', handleResume, false); - }; + if (platformInfo.isChromeApp) { + $log.debug('Registering Chrome message listener'); + chrome.runtime.onMessage.addListener( + function(request, sender, sendResponse) { + if (request.url) { + handleOpenURL(request.url); + } + }); + } else if (platformInfo.isDevel) { + + var base = window.location.origin + '/'; + var url = base + '#/uri/%s'; + + if (navigator.registerProtocolHandler) { + $log.debug('Registering Browser handlers base:' + base); + navigator.registerProtocolHandler('bitcoin', url, 'Copay Bitcoin Handler'); + navigator.registerProtocolHandler('web+copay', url, 'Copay Wallet Handler'); + } + } + }; root.registerHandler = function(x) { $log.debug('Registering URL Handler: ' + x.name); root.registeredUriHandlers.push(x); }; + root.handleURL = handleOpenURL; + return root; }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 1ed664bd0..5e69bb8c4 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -293,7 +293,6 @@ angular.module('copayApp.services') var name = opts.name || gettextCatalog.getString('Personal Wallet'); var myName = opts.myName || gettextCatalog.getString('me'); -console.log('[profileService.js.303]', opts); //TODO walletClient.createWallet(name, myName, opts.m, opts.n, { network: opts.networkName, singleAddress: opts.singleAddress, diff --git a/src/js/services/uriHandler.js b/src/js/services/uriHandler.js deleted file mode 100644 index da67ab4be..000000000 --- a/src/js/services/uriHandler.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -var UriHandler = function() {}; - -UriHandler.prototype.register = function() { - var base = window.location.origin + '/'; - var url = base + '#/uri-payment/%s'; - - if(navigator.registerProtocolHandler) { - navigator.registerProtocolHandler('bitcoin', url, 'Copay'); - } -}; - -angular.module('copayApp.services').value('uriHandler', new UriHandler()); From d42e9f6896219e8ffa2e7259c287e460103d7e93 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 18:40:29 -0300 Subject: [PATCH 03/13] fix coinbase --- src/js/controllers/coinbaseUri.js | 22 ++++++---- src/js/controllers/glideraUri.js | 68 +++++++++++++++---------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/js/controllers/coinbaseUri.js b/src/js/controllers/coinbaseUri.js index 24c48280b..2aff6d1fd 100644 --- a/src/js/controllers/coinbaseUri.js +++ b/src/js/controllers/coinbaseUri.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.controllers').controller('coinbaseUriController', - function($scope, $stateParams, $timeout, profileService, configService, coinbaseService, storageService, go) { + function($scope, $stateParams, $timeout, profileService, configService, coinbaseService, storageService, go) { this.submitOauthCode = function(code) { var self = this; @@ -14,10 +14,9 @@ angular.module('copayApp.controllers').controller('coinbaseUriController', if (err) { self.error = err; $timeout(function() { - $scope.$apply(); - }, 100); - } - else if (data && data.access_token && data.refresh_token) { + $scope.$apply(); + }, 100); + } else if (data && data.access_token && data.refresh_token) { storageService.setCoinbaseToken(network, data.access_token, function() { storageService.setCoinbaseRefreshToken(network, data.refresh_token, function() { $scope.$emit('Local/CoinbaseUpdated', data.access_token); @@ -33,8 +32,13 @@ angular.module('copayApp.controllers').controller('coinbaseUriController', }; this.checkCode = function() { - this.code = $stateParams.code; - this.submitOauthCode(this.code); - }; - + if ($stateParams.url) { + var match = $stateParams.url.match(/code=(.+)&/); + if (match && match[1]) { + this.code = match[1]; + return this.submitOauthCode(this.code); + } + } + $log.error('Bad state: ' + JSON.stringify($stateParams)); + } }); diff --git a/src/js/controllers/glideraUri.js b/src/js/controllers/glideraUri.js index c4bbdd5e9..d7c27f832 100644 --- a/src/js/controllers/glideraUri.js +++ b/src/js/controllers/glideraUri.js @@ -1,43 +1,43 @@ 'use strict'; angular.module('copayApp.controllers').controller('glideraUriController', -function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { + function($scope, $log, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) { - this.submitOauthCode = function(code) { - $log.debug('Glidera Oauth Code:' + code); - var self = this; - var glideraTestnet = configService.getSync().glidera.testnet; - var network = glideraTestnet ? 'testnet' : 'livenet'; - this.loading = true; - this.error = null; - $timeout(function() { - glideraService.getToken(code, function(err, data) { - self.loading = null; - if (err) { - self.error = err; - $timeout(function() { - $scope.$apply(); - }, 100); - } else if (data && data.access_token) { - storageService.setGlideraToken(network, data.access_token, function() { - $scope.$emit('Local/GlideraUpdated', data.access_token); + this.submitOauthCode = function(code) { + $log.debug('Glidera Oauth Code:' + code); + var self = this; + var glideraTestnet = configService.getSync().glidera.testnet; + var network = glideraTestnet ? 'testnet' : 'livenet'; + this.loading = true; + this.error = null; + $timeout(function() { + glideraService.getToken(code, function(err, data) { + self.loading = null; + if (err) { + self.error = err; $timeout(function() { - go.path('glidera'); $scope.$apply(); }, 100); - }); - } - }); - }, 100); - }; + } else if (data && data.access_token) { + storageService.setGlideraToken(network, data.access_token, function() { + $scope.$emit('Local/GlideraUpdated', data.access_token); + $timeout(function() { + go.path('glidera'); + $scope.$apply(); + }, 100); + }); + } + }); + }, 100); + }; - this.checkCode = function() { - if ($stateParams.url) { - var match = $stateParams.url.match(/code=(.+)/); - if (match && match[1]) { - this.code = match[1]; - return this.submitOauthCode(this.code); + this.checkCode = function() { + if ($stateParams.url) { + var match = $stateParams.url.match(/code=(.+)/); + if (match && match[1]) { + this.code = match[1]; + return this.submitOauthCode(this.code); + } } + $log.error('Bad state: ' + JSON.stringify($stateParams)); } - $log.error('Bad state: ' + JSON.stringify($stateParams)); - } -}); + }); From bf16391085194beb44d8f365c483d260095424a5 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 22:29:17 -0300 Subject: [PATCH 04/13] rm importLegacy --- public/views/import.html | 10 +---- public/views/importLegacy.html | 68 ------------------------------ src/js/controllers/importLegacy.js | 63 --------------------------- src/js/services/openURL.js | 11 ++++- src/js/services/profileService.js | 3 ++ 5 files changed, 14 insertions(+), 141 deletions(-) delete mode 100644 public/views/importLegacy.html delete mode 100644 src/js/controllers/importLegacy.js diff --git a/public/views/import.html b/public/views/import.html index 990f0a7a6..6ab456c69 100644 --- a/public/views/import.html +++ b/public/views/import.html @@ -21,7 +21,7 @@
File/Text Backup @@ -161,14 +161,6 @@ Import backup - -
-

Have a Backup from Copay v0.9?

- -
-
diff --git a/public/views/importLegacy.html b/public/views/importLegacy.html deleted file mode 100644 index 0c969e898..000000000 --- a/public/views/importLegacy.html +++ /dev/null @@ -1,68 +0,0 @@ -
-
- -
-
-
-
-

Importing...

-
    -
  • - {{m.message|translate}} -
-
- -
- - {{importLegacy.error|translate}} - -
- -
-
- - - - - - - - - - -
- - - -
-
-
-
diff --git a/src/js/controllers/importLegacy.js b/src/js/controllers/importLegacy.js deleted file mode 100644 index 0a1258876..000000000 --- a/src/js/controllers/importLegacy.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('importLegacyController', - function($rootScope, $scope, $log, $timeout, notification, legacyImportService, profileService, go, lodash, bitcore, gettext, gettextCatalog) { - - var self = this; - self.messages = []; - self.fromCloud = true; - self.server = "https://insight.bitpay.com:443/api/email"; - - - $rootScope.$on('Local/ImportStatusUpdate', function(event, status) { - $timeout(function() { - $log.debug(status); - - self.messages.unshift({ - message: status, - }); - - var op = 1; - lodash.each(self.messages, function(m) { - if (op < 0.1) op = 0.1; - m.opacity = op; - op = op - 0.15; - }); - }, 100); - }); - - self.scan = function(ids) { - $log.debug('### Scanning: ' + ids) - var i = 0; - lodash.each(ids, function(id) { - $rootScope.$emit('Local/WalletImported', id); - if (++i == ids.length) { - go.walletHome(); - }; - }); - }; - - - self.import = function(form) { - var username = form.username.$modelValue; - var password = form.password.$modelValue; - var serverURL = form.server.$modelValue; - var fromCloud = form.fromCloud.$modelValue; - - self.error = null; - self.importing = true; - $timeout(function() { - legacyImportService.import(username, password, serverURL, fromCloud, function(err, ids, toScanIds) { - if (err || !ids || !ids.length) { - self.importing = false; - self.error = err || gettext('Failed to import wallets'); - return; - } - - notification.success( gettextCatalog.getString('{{len}} wallets imported. Funds scanning in progress. Hold on to see updated balance', {len: ids.length})); - self.scan(toScanIds); - }); - }, 100); - }; - // TODO destroy event... - }); diff --git a/src/js/services/openURL.js b/src/js/services/openURL.js index 07cd8935d..31f0c72b8 100644 --- a/src/js/services/openURL.js +++ b/src/js/services/openURL.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('openURLService', function($ionicHistory, $document, $log, $state, go, platformInfo, lodash) { +angular.module('copayApp.services').factory('openURLService', function($rootScope, $ionicHistory, $document, $log, $state, go, platformInfo, lodash, profileService) { var root = {}; root.registeredUriHandlers = [{ @@ -21,6 +21,15 @@ angular.module('copayApp.services').factory('openURLService', function($ionicHis var handleOpenURL = function(args) { $log.info('Handling Open URL: ' + JSON.stringify(args)); + if (!profileService.isBound) { + $log.warn('Profile not bound yet. Waiting'); + + return $rootScope.$on('Local/ProfileBound', function(){ + $log.warn('Profile ready, retrying...'); + handleOpenURL(args); + }); + }; + // Stop it from caching the first view as one to return when the app opens $ionicHistory.nextViewOptions({ historyRoot: true, diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 5e69bb8c4..a3352c869 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -169,6 +169,9 @@ angular.module('copayApp.services') if (!val) { return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); } + + root.isBound = true; + $root.$emit('Local/ProfileBound'); return cb(); }); }); From e28a4fb2ada2b94f3ff2c03a66b0591a60b615d5 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 22:52:23 -0300 Subject: [PATCH 05/13] rm comments --- public/views/uri.html | 2 +- src/js/controllers/uri.js | 2 +- src/js/routes.js | 13 --- src/js/services/animationService.js | 164 ---------------------------- 4 files changed, 2 insertions(+), 179 deletions(-) delete mode 100644 src/js/services/animationService.js diff --git a/public/views/uri.html b/public/views/uri.html index e16b42d1c..212aaf41e 100644 --- a/public/views/uri.html +++ b/public/views/uri.html @@ -4,7 +4,7 @@
-

+

Please wait to be redirected...

diff --git a/src/js/controllers/uri.js b/src/js/controllers/uri.js index bf6c91120..5a54eb254 100644 --- a/src/js/controllers/uri.js +++ b/src/js/controllers/uri.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.controllers').controller('uriController', - function($rootScope, $stateParams, $log, openURLService) { + function($stateParams, $log, openURLService) { /* This is only for BROWSER links, it is not excecuted on mobile devices */ diff --git a/src/js/routes.js b/src/js/routes.js index 299def8a4..ca9048f77 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -628,18 +628,5 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $state.transitionTo('copayers'); } } -// event.preventDefault(); -// $state.transitionTo(toState); -// if (!animationService.transitionAnimated(fromState, toState)) { -// -// console.log('[routes.js.649] ANIMATION!'); //TODO -// event.preventDefault(); -// // Time for the backpane to render -// return setTimeout(function() { -// -// console.log('[routes.js.654] TRANSITION'); //TODO -// $state.transitionTo(toState); -// }, 50); -// } }); }); diff --git a/src/js/services/animationService.js b/src/js/services/animationService.js deleted file mode 100644 index 6a0c8a5fb..000000000 --- a/src/js/services/animationService.js +++ /dev/null @@ -1,164 +0,0 @@ -'use strict'; - -angular.module('copayApp.services').factory('animationService', function(platformInfo) { - var root = {}; - var cachedTransitionState, cachedBackPanel; - - var isCordova = platformInfo.isCordova; - - - // DISABLE ANIMATION ON DESKTOP - root.modalAnimated = { - slideUp: isCordova ? 'full animated slideInUp' : 'full', - slideRight: isCordova ? 'full animated slideInRight' : 'full', - slideOutDown: isCordova ? 'slideOutDown' : 'hideModal', - slideOutRight: isCordova ? 'slideOutRight' : 'hideModal', - }; - - var pageWeight = { - walletHome: 0, - copayers: -1, - cordova: -1, - payment: -1, - uriglidera: -1, - - preferences: 11, - preferencesGlobal: 11, - glidera: 11, - coinbase: 11, - preferencesColor: 12, - backup: 12, - preferencesAdvanced: 12, - buyGlidera: 12, - buyCoinbase: 12, - sellGlidera: 12, - sellCoinbase: 12, - preferencesGlidera: 12, - preferencesCoinbase: 12, - about: 12, - delete: 13, - preferencesLanguage: 12, - preferencesUnit: 12, - preferencesFee: 12, - preferencesAltCurrency: 12, - preferencesBwsUrl: 13, - preferencesHistory: 13, - preferencesAlias: 12, - preferencesEmail: 12, - export: 13, - paperWallet: 13, - logs: 13, - information: 13, - termOfUse: 13, - translators: 13, - add: 11, - buyandsell: 11, - create: 12, - join: 12, - import: 12, - importLegacy: 13 - }; - - function cleanUpLater(e, e2) { -console.log('[animationService.js.62:cleanUpLater:]'); //TODO - var cleanedUp = false, - timeoutID; - var cleanUp = function() { - if (cleanedUp) return; - cleanedUp = true; - e2.parentNode.removeChild(e2); - e2.innerHTML = ""; - e.className = ''; - cachedBackPanel = null; - cachedTransitionState = ''; - if (timeoutID) { - timeoutID = null; - window.clearTimeout(timeoutID); - } - }; - e.addEventListener("animationend", cleanUp, true); - e2.addEventListener("animationend", cleanUp, true); - e.addEventListener("webkitAnimationEnd", cleanUp, true); - e2.addEventListener("webkitAnimationEnd", cleanUp, true); - timeoutID = setTimeout(cleanUp, 500); - }; - - root.transitionAnimated = function(fromState, toState, event) { - - if (isaosp) - return true; - - // Animation in progress? - var x = document.getElementById('mainSectionDup'); - if (x && !cachedTransitionState) { - console.log('Anim in progress'); - return true; - } - - var fromName = fromState.name; - var toName = toState.name; - if (!fromName || !toName) - return true; - - var fromWeight = pageWeight[fromName]; - var toWeight = pageWeight[toName]; - - - var entering = null, - leaving = null; - - // Horizontal Slide Animation? - if (isCordova && fromWeight && toWeight) { - if (fromWeight > toWeight) { - leaving = 'CslideOutRight'; - } else { - entering = 'CslideInRight'; - } - - // Vertical Slide Animation? - } else if (isCordova && fromName && fromWeight >= 0 && toWeight >= 0) { - if (toWeight) { - entering = 'CslideInUp'; - - } else { - leaving = 'CslideOutDown'; - } - - // no Animation ? - } else { - return true; - } - - var e = document.getElementById('mainSection'); - - - var desiredTransitionState = (fromName || '-') + ':' + (toName || '-'); - - if (desiredTransitionState == cachedTransitionState) { - e.className = entering || ''; - cachedBackPanel.className = leaving || ''; - cleanUpLater(e, cachedBackPanel); - //console.log('USing animation', cachedTransitionState); - return true; - } else { - var sc; - // Keep prefDiv scroll - var contentDiv = e.getElementsByClassName('content'); - if (contentDiv && contentDiv[0]) - sc = contentDiv[0].scrollTop; - - cachedBackPanel = e.cloneNode(true); - cachedBackPanel.id = 'mainSectionDup'; - var c = document.getElementById('sectionContainer'); - c.appendChild(cachedBackPanel); - - if (sc) - cachedBackPanel.getElementsByClassName('content')[0].scrollTop = sc; - - cachedTransitionState = desiredTransitionState; - return false; - } - } - - return root; -}); From 27e925b84fde8e40028b9e9599d9ed6aa29a41cd Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 23:08:30 -0300 Subject: [PATCH 06/13] fix url handling on cold start --- src/js/routes.js | 2 +- src/js/services/openURL.js | 17 ++++++++++------- src/js/services/profileService.js | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/js/routes.js b/src/js/routes.js index ca9048f77..26386c4aa 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -518,7 +518,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) { + .run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, platformInfo, profileService, uxLanguage, go, gettextCatalog) { $ionicPlatform.ready(function() { if (platformInfo.isCordova) { diff --git a/src/js/services/openURL.js b/src/js/services/openURL.js index 31f0c72b8..c154d94a7 100644 --- a/src/js/services/openURL.js +++ b/src/js/services/openURL.js @@ -24,9 +24,12 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop if (!profileService.isBound) { $log.warn('Profile not bound yet. Waiting'); - return $rootScope.$on('Local/ProfileBound', function(){ - $log.warn('Profile ready, retrying...'); - handleOpenURL(args); + return $rootScope.$on('Local/ProfileBound', function() { + // Wait ux to settle + setTimeout(function() { + $log.warn('Profile ready, retrying...'); + handleOpenURL(args); + }, 2000); }); }; @@ -53,10 +56,10 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop document.addEventListener('handleopenurl', handleOpenURL, false); var x = lodash.find(root.registeredUriHandlers, function(x) { - return url.indexOf(x.startsWith) == 0 || - url.indexOf('web+' + x.startsWith) == 0 || // web protocols - url.indexOf(x.startsWith.replace(':','://')) == 0 // from mobile devices - ; + return url.indexOf(x.startsWith) == 0 || + url.indexOf('web+' + x.startsWith) == 0 || // web protocols + url.indexOf(x.startsWith.replace(':', '://')) == 0 // from mobile devices + ; }); if (x) { diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index a3352c869..f1844be49 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -171,7 +171,7 @@ angular.module('copayApp.services') } root.isBound = true; - $root.$emit('Local/ProfileBound'); + $rootScope.$emit('Local/ProfileBound'); return cb(); }); }); From 4b0abd77a21a5b82bdfac503d45c9cadc60459e7 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Jun 2016 23:55:28 -0300 Subject: [PATCH 07/13] refactor wallet seletors in buy/sell controllers --- public/views/buyCoinbase.html | 2 +- public/views/buyGlidera.html | 2 +- public/views/sellCoinbase.html | 2 +- public/views/sellGlidera.html | 2 +- src/js/controllers/buyCoinbase.js | 34 ++++++------------ src/js/controllers/buyGlidera.js | 32 ++++++----------- src/js/controllers/sellCoinbase.js | 56 +++++++++++------------------- src/js/controllers/sellGlidera.js | 54 +++++++++++----------------- src/js/services/profileService.js | 8 ++++- 9 files changed, 73 insertions(+), 119 deletions(-) diff --git a/public/views/buyCoinbase.html b/public/views/buyCoinbase.html index 620a90a6a..2c3ea385b 100644 --- a/public/views/buyCoinbase.html +++ b/public/views/buyCoinbase.html @@ -84,7 +84,7 @@
+ ng-click="openWalletsModal(buy.allWallets)">
+ ng-click="openWalletsModal(buy.allWallets)">
+ ng-click="openWalletsModal(sell.allWallets)">
+ ng-click="openWalletsModal(sell.allWallets)">
Date: Sun, 12 Jun 2016 00:31:12 -0300 Subject: [PATCH 08/13] replace some links to sref link --- public/views/add.html | 6 +++--- public/views/buyAndSell.html | 4 ++-- public/views/includes/sidebar.html | 17 +++++------------ src/sass/main.scss | 5 ++--- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/public/views/add.html b/public/views/add.html index 669868385..b399d9bd7 100644 --- a/public/views/add.html +++ b/public/views/add.html @@ -9,21 +9,21 @@
  • - + Create new wallet
  • - + Join shared wallet
  • - + Import wallet diff --git a/public/views/buyAndSell.html b/public/views/buyAndSell.html index f38e5772c..67ff082ef 100644 --- a/public/views/buyAndSell.html +++ b/public/views/buyAndSell.html @@ -7,12 +7,12 @@
    diff --git a/src/sass/main.scss b/src/sass/main.scss index ce0afdbf8..d59fc5468 100644 --- a/src/sass/main.scss +++ b/src/sass/main.scss @@ -1701,15 +1701,14 @@ a.missing-copayers { padding: 1rem 0.7rem; font-size: 12px; font-weight: 300; + color: #A5B2BF; + cursor: pointer !important; } .sidebar ul { margin: 0 0 30px 0; } -.sidebar a { - color: #A5B2BF; -} .modal-content ul li a { font-size: 12px; From d950df04c38b16607b01983260aabe77b02b4ce8 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 12 Jun 2016 00:35:04 -0300 Subject: [PATCH 09/13] rm isComplete in by/sell --- public/views/includes/sidebar.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/views/includes/sidebar.html b/public/views/includes/sidebar.html index b1ff70823..4b5675c00 100644 --- a/public/views/includes/sidebar.html +++ b/public/views/includes/sidebar.html @@ -26,7 +26,7 @@
    Create, join or import
  • -
  • +
  • From 3776062e16b1033c235c6c211f7ad8cb5361cc85 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Sun, 12 Jun 2016 16:42:32 -0300 Subject: [PATCH 10/13] Removes importLegacy. Enable Coinbase/Glidera for livenet. Fix undefined variable on buyCoinbase/Glidera --- src/js/controllers/buyCoinbase.js | 2 +- src/js/controllers/buyGlidera.js | 2 +- src/js/routes.js | 10 -- src/js/services/configService.js | 4 +- src/js/services/legacyImportService.js | 146 ------------------------- src/js/services/profileService.js | 17 --- 6 files changed, 4 insertions(+), 177 deletions(-) delete mode 100644 src/js/services/legacyImportService.js diff --git a/src/js/controllers/buyCoinbase.js b/src/js/controllers/buyCoinbase.js index edf5903df..4126329d6 100644 --- a/src/js/controllers/buyCoinbase.js +++ b/src/js/controllers/buyCoinbase.js @@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', this.init = function(testnet) { self.allWallets = profileService.getWallets(testnet ? 'testnet' : 'livenet', 1) - client = profileService.focusedClient; + var client = profileService.focusedClient; if (client) { $timeout(function() { self.selectedWalletId = client.credentials.walletId; diff --git a/src/js/controllers/buyGlidera.js b/src/js/controllers/buyGlidera.js index 9209ef792..207419a04 100644 --- a/src/js/controllers/buyGlidera.js +++ b/src/js/controllers/buyGlidera.js @@ -12,7 +12,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController', this.init = function(testnet) { self.allWallets = profileService.getWallets(testnet ? 'testnet' : 'livenet', 1) - client = profileService.focusedClient; + var client = profileService.focusedClient; if (client) { $timeout(function() { self.selectedWalletId = client.credentials.walletId; diff --git a/src/js/routes.js b/src/js/routes.js index 26386c4aa..0da8607e8 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -149,16 +149,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }, } }) - .state('importLegacy', { - url: '/importLegacy', - needProfile: true, - views: { - 'main': { - templateUrl: 'views/importLegacy.html', - }, - } - - }) .state('create', { url: '/create', templateUrl: 'views/create.html', diff --git a/src/js/services/configService.js b/src/js/services/configService.js index 9a18c9894..9af77287d 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -111,11 +111,11 @@ angular.module('copayApp.services').factory('configService', function(storageSer // Glidera // Disabled for testnet - configCache.glidera.testnet = true; + configCache.glidera.testnet = false; // Coinbase // Disabled for testnet - configCache.coinbase.testnet = true; + configCache.coinbase.testnet = false; $log.debug('Preferences read:', configCache) return cb(err, configCache); diff --git a/src/js/services/legacyImportService.js b/src/js/services/legacyImportService.js deleted file mode 100644 index a4103a1d4..000000000 --- a/src/js/services/legacyImportService.js +++ /dev/null @@ -1,146 +0,0 @@ -'use strict'; -angular.module('copayApp.services') - .factory('legacyImportService', function($rootScope, $log, $timeout, $http, lodash, bitcore, bwcService, sjcl, profileService, platformInfo) { - - var root = {}; - var wc = bwcService.getClient(); - - root.getKeyForEmail = function(email) { - var hash = bitcore.crypto.Hash.sha256ripemd160(new bitcore.deps.Buffer(email)).toString('hex'); - $log.debug('Storage key:' + hash); - return 'profile::' + hash; - }; - - root.getKeyForWallet = function(id) { - return 'wallet::' + id; - }; - - root._importOne = function(user, pass, walletId, get, cb) { - get(root.getKeyForWallet(walletId), function(err, blob) { - if (err) { - $log.warn('Could not fetch wallet: ' + walletId + ":" + err); - return cb('Could not fetch ' + walletId); - } - profileService.importLegacyWallet(user, pass, blob, cb); - }); - }; - - - root._doImport = function(user, pass, get, cb) { - var self = this; - get(root.getKeyForEmail(user), function(err, p) { - if (err || !p) - return cb(err || ('Could not find profile for ' + user)); - - - var ids = wc.getWalletIdsFromOldCopay(user, pass, p); - if (!ids) - return cb('Could not find wallets on the profile'); - - $rootScope.$emit('Local/ImportStatusUpdate', - 'Found ' + ids.length + ' wallets to import:' + ids.join()); - - $log.info('Importing Wallet Ids:', ids); - - var i = 0; - var okIds = []; - var toScanIds = []; - lodash.each(ids, function(walletId) { - $timeout(function() { - $rootScope.$emit('Local/ImportStatusUpdate', - 'Importing wallet ' + walletId + ' ... '); - - self._importOne(user, pass, walletId, get, function(err, id, name, existed) { - if (err) { - $rootScope.$emit('Local/ImportStatusUpdate', - 'Failed to import wallet ' + (name || walletId)); - } else { - okIds.push(walletId); - $rootScope.$emit('Local/ImportStatusUpdate', - 'Wallet ' + id + '[' + name + '] imported successfully'); - - if (!existed) { - $log.info('Wallet ' + walletId + ' was created. need to be scanned'); - toScanIds.push(id); - } - } - - if (++i == ids.length) { - return cb(null, okIds, toScanIds); - } - }); - }, 100); - }); - }); - }; - - root.import = function(user, pass, serverURL, fromCloud, cb) { - - var insightGet = function(key, cb) { - - - var kdfbinary = function(password, salt, iterations, length) { - iterations = iterations || defaultIterations; - length = length || 512; - salt = sjcl.codec.base64.toBits(salt || defaultSalt); - - var hash = sjcl.hash.sha256.hash(sjcl.hash.sha256.hash(password)); - var prff = function(key) { - return new sjcl.misc.hmac(hash, sjcl.hash.sha1); - }; - - return sjcl.misc.pbkdf2(hash, salt, iterations, length, prff); - }; - - var salt = 'jBbYTj8zTrOt6V'; - var iter = 1000; - var SEPARATOR = '|'; - - var kdfb = kdfbinary(pass + SEPARATOR + user, salt, iter); - var kdfb64 = sjcl.codec.base64.fromBits(kdfb); - - - var keyBuf = new bitcore.deps.Buffer(kdfb64); - var passphrase = bitcore.crypto.Hash.sha256sha256(keyBuf).toString('base64'); - var authHeader = new bitcore.deps.Buffer(user + ':' + passphrase).toString('base64'); - var retrieveUrl = serverURL + '/retrieve'; - var getParams = { - method: 'GET', - url: retrieveUrl + '?key=' + encodeURIComponent(key) + '&rand=' + Math.random(), - headers: { - 'Authorization': authHeader, - }, - }; - $log.debug('Insight GET', getParams); - - $http(getParams) - .success(function(data) { - data = JSON.stringify(data); - $log.info('Fetch from insight OK:' + getParams.url); - return cb(null, data); - }) - .error(function() { - $log.warn('Failed to fetch from insight'); - return cb('PNOTFOUND: Profile not found'); - }); - }; - - var localStorageGet = function(key, cb) { - if (platformInfo.isChromeApp) { - chrome.storage.local.get(key, - function(data) { - return cb(null, data[key]); - }); - } else { - var v = localStorage.getItem(key); - return cb(null, v); - } - }; - - var get = fromCloud ? insightGet : localStorageGet; - - root._doImport(user, pass, get, cb); - }; - - return root; - }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 37b92f425..769cc1d1c 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -650,23 +650,6 @@ angular.module('copayApp.services') }); }; - root.importLegacyWallet = function(username, password, blob, cb) { - var walletClient = bwcService.getClient(); - - walletClient.createWalletFromOldCopay(username, password, blob, function(err, existed) { - if (err) return cb(gettext('Error importing wallet: ') + err); - - if (root.profile.hasWallet(walletClient.credentials.walletId)) { - $log.debug('Wallet:' + walletClient.credentials.walletName + ' already imported'); - return cb(gettext('Wallet Already Imported: ') + walletClient.credentials.walletName); - }; - - root.addAndBindWalletClient(walletClient, { - isImport: true - }, cb); - }); - }; - root.updateCredentials = function(credentials, cb) { root.profile.updateWallet(credentials); storageService.storeProfileThrottled(root.profile, cb); From 487e37288930f0409a6de543d711e0799881c8e7 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 13 Jun 2016 08:37:14 -0300 Subject: [PATCH 11/13] add client check --- src/js/controllers/buyCoinbase.js | 1 - src/js/controllers/sellCoinbase.js | 5 +++++ src/js/controllers/sellGlidera.js | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/buyCoinbase.js b/src/js/controllers/buyCoinbase.js index 4126329d6..bb2a9de8f 100644 --- a/src/js/controllers/buyCoinbase.js +++ b/src/js/controllers/buyCoinbase.js @@ -3,7 +3,6 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', function($scope, $modal, $log, $ionicModal, $timeout, lodash, profileService, coinbaseService, bwsError, addressService) { var self = this; - var fc; this.init = function(testnet) { self.allWallets = profileService.getWallets(testnet ? 'testnet' : 'livenet', 1) diff --git a/src/js/controllers/sellCoinbase.js b/src/js/controllers/sellCoinbase.js index 6d6d2d809..d66a7f359 100644 --- a/src/js/controllers/sellCoinbase.js +++ b/src/js/controllers/sellCoinbase.js @@ -142,6 +142,11 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', this.createTx = function(token, account, amount) { self.error = null; + if (!client) { + self.error = 'No wallet selected'; + return; + } + var accountId = account.id; var dataSrc = { name: 'Received from Copay: ' + self.selectedWalletName diff --git a/src/js/controllers/sellGlidera.js b/src/js/controllers/sellGlidera.js index 7fbc8ef7d..31afbdb91 100644 --- a/src/js/controllers/sellGlidera.js +++ b/src/js/controllers/sellGlidera.js @@ -94,6 +94,11 @@ angular.module('copayApp.controllers').controller('sellGlideraController', var configWallet = config.wallet; var walletSettings = configWallet.settings; + if (!client) { + self.error = 'No wallet selected'; + return; + } + addressService.getAddress(client.credentials.walletId, null, function(err, refundAddress) { if (!refundAddress) { self.loading = null; From 22ed51d047d655fcae9d8929f768f5026502fe02 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 13 Jun 2016 09:50:37 -0300 Subject: [PATCH 12/13] add "verifying wallet message" --- src/js/controllers/index.js | 13 ++++++ src/js/routes.js | 1 - src/js/services/profileService.js | 75 ++++++++++++++++++++----------- 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 05f3e4077..4a735ec34 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1427,6 +1427,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.tab = 'walletHome'; }); + $rootScope.$on('Local/ValidatingWallet', function() { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + window.plugins.spinnerDialog.show(null, gettext('Validating wallet integrity...'), true); + } + }); + + $rootScope.$on('Local/ProfileBound', function() { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + } + }); + $rootScope.$on('Local/ClearHistory', function(event) { $log.debug('The wallet transaction history has been deleted'); self.txHistory = self.completeHistory = self.txHistorySearchResults = []; diff --git a/src/js/routes.js b/src/js/routes.js index 0da8607e8..a756e7f42 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -614,7 +614,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } else { if (profileService.focusedClient && !profileService.focusedClient.isComplete() && toState.walletShouldBeComplete) { - event.preventDefault(); $state.transitionTo('copayers'); } } diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 769cc1d1c..3f46cd2fe 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -123,9 +123,9 @@ angular.module('copayApp.services') // Used when reading wallets from the profile - root.bindWallet = function(credentials) { + root.bindWallet = function(credentials, cb) { if (!credentials.walletId) - throw 'bindWallet should receive credentials JSON'; + return cb('bindWallet should receive credentials JSON'); // Create the client @@ -136,16 +136,21 @@ angular.module('copayApp.services') }; var skipKeyValidation = root.profile.isChecked(platformInfo.ua, credentials.walletId); - $log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation); - var client = bwcService.getClient(JSON.stringify(credentials), { - bwsurl: getBWSURL(credentials.walletId), - skipKeyValidation: skipKeyValidation, - }); + if (!skipKeyValidation) { + $rootScope.$emit('Local/ValidatingWallet'); + } + $timeout(function() { + $log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation); + var client = bwcService.getClient(JSON.stringify(credentials), { + bwsurl: getBWSURL(credentials.walletId), + skipKeyValidation: skipKeyValidation, + }); - if (!skipKeyValidation && !client.incorrectDerivation) - root.profile.setChecked(platformInfo.ua, credentials.walletId); + if (!skipKeyValidation && !client.incorrectDerivation) + root.profile.setChecked(platformInfo.ua, credentials.walletId); - return root.bindWalletClient(client); + return cb(null, root.bindWalletClient(client)); + }, 1); }; root.bindProfile = function(profile, cb) { @@ -155,26 +160,42 @@ angular.module('copayApp.services') $log.debug('Preferences read'); if (err) return cb(err); - lodash.each(root.profile.credentials, function(credentials) { - root.bindWallet(credentials); - }); - $rootScope.$emit('Local/WalletListUpdated'); + function bindWallets(cb) { + var l = root.profile.credentials.length; + var i = 0, totalBound = 0; - storageService.getFocusedWalletId(function(err, focusedWalletId) { - if (err) return cb(err); - root._setFocus(focusedWalletId, function() { - if (usePushNotifications) - root.pushNotificationsInit(); - root.isDisclaimerAccepted(function(val) { - if (!val) { - return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); + lodash.each(root.profile.credentials, function(credentials) { + root.bindWallet(credentials, function(err, bound) { + i++; + totalBound += bound; + if (i == l) { + $log.info('Bound ' + totalBound + ' out of ' + l + ' wallets'); + if (totalBound) + $rootScope.$emit('Local/WalletListUpdated'); + return cb(); } + }); + }); + } + + bindWallets(function() { + storageService.getFocusedWalletId(function(err, focusedWalletId) { + if (err) return cb(err); + root._setFocus(focusedWalletId, function() { + if (usePushNotifications) + root.pushNotificationsInit(); root.isBound = true; $rootScope.$emit('Local/ProfileBound'); - return cb(); + + root.isDisclaimerAccepted(function(val) { + if (!val) { + return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); + } + return cb(); + }); }); - }); + }) }); }); }; @@ -348,8 +369,8 @@ angular.module('copayApp.services') // check if exist if (lodash.find(root.profile.credentials, { - 'walletId': walletData.walletId - })) { + 'walletId': walletData.walletId + })) { return cb(gettext('Cannot join the same wallet more that once')); } } catch (ex) { @@ -709,7 +730,7 @@ angular.module('copayApp.services') return (w.n == n); }); } - + return lodash.sortBy(ret, 'name'); }; From 399ab1a75f047ae3f2993f45256be4365376dbf2 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 13 Jun 2016 10:39:28 -0300 Subject: [PATCH 13/13] fix tests --- src/js/services/profileService.js | 31 +++++++++++++++++-------------- test/helpers.js | 1 - 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 3f46cd2fe..39d5d33f0 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -150,7 +150,7 @@ angular.module('copayApp.services') root.profile.setChecked(platformInfo.ua, credentials.walletId); return cb(null, root.bindWalletClient(client)); - }, 1); + }, skipKeyValidation ? 50 : 0); }; root.bindProfile = function(profile, cb) { @@ -164,6 +164,8 @@ angular.module('copayApp.services') var l = root.profile.credentials.length; var i = 0, totalBound = 0; + if (!l) return cb(); + lodash.each(root.profile.credentials, function(credentials) { root.bindWallet(credentials, function(err, bound) { i++; @@ -311,21 +313,23 @@ angular.module('copayApp.services') // Creates a wallet on BWC/BWS var doCreateWallet = function(opts, cb) { $log.debug('Creating Wallet:', opts); - seedWallet(opts, function(err, walletClient) { - if (err) return cb(err); + $timeout(function() { + seedWallet(opts, function(err, walletClient) { + if (err) return cb(err); - var name = opts.name || gettextCatalog.getString('Personal Wallet'); - var myName = opts.myName || gettextCatalog.getString('me'); + var name = opts.name || gettextCatalog.getString('Personal Wallet'); + var myName = opts.myName || gettextCatalog.getString('me'); - walletClient.createWallet(name, myName, opts.m, opts.n, { - network: opts.networkName, - singleAddress: opts.singleAddress, - walletPrivKey: opts.walletPrivKey, - }, function(err, secret) { - if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); - return cb(null, walletClient, secret); + walletClient.createWallet(name, myName, opts.m, opts.n, { + network: opts.networkName, + singleAddress: opts.singleAddress, + walletPrivKey: opts.walletPrivKey, + }, function(err, secret) { + if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); + return cb(null, walletClient, secret); + }); }); - }); + }, 5); }; // Creates the default Copay profile and its wallet @@ -634,7 +638,6 @@ angular.module('copayApp.services') var defaults = configService.getDefaults(); configService.get(function(err) { - root.createDefaultProfile(opts, function(err, p) { if (err) return cb(err); diff --git a/test/helpers.js b/test/helpers.js index b8adbfb58..001a164d3 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -221,7 +221,6 @@ mocks.init = function(fixtures, controllerName, opts, done) { done(); }); } else { - _profileService_.create({ noWallet: true }, function(err) {