From 8229d51fdd4590ce932ae57d7bfbd23e57602a11 Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Wed, 8 Aug 2018 16:35:49 +0200 Subject: [PATCH 01/26] sendflow service --- src/js/services/sendFlowService.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/js/services/sendFlowService.js diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js new file mode 100644 index 000000000..d5c4df109 --- /dev/null +++ b/src/js/services/sendFlowService.js @@ -0,0 +1,24 @@ +'use strict'; + +angular.module('copayApp.services').factory('sendFlowService', function ($log) { + var vm = this; + + vm.amount = false; + vm.fromWalletId = false; + vm.thirdParty = false; + vm.sendMax = false; + vm.toAddress = false; + vm.toWalletId = false; + + vm.initialize = function() { + $log.debug("Reinitialize Send Flow variables"); + vm.amount = false; + vm.fromWalletId = false; + vm.thirdParty = false; + vm.sendMax = false; + vm.toAddress = false; + vm.toWalletId = false; + }; + + return vm; +}); \ No newline at end of file From f7ecdb2f2fee02c47b38c4c54fbadee711a9b9fa Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Wed, 8 Aug 2018 17:10:47 +0200 Subject: [PATCH 02/26] sendflow service integrated into flow --- src/js/controllers/amount.js | 69 ++++++++++--------- src/js/controllers/review.controller.js | 30 ++++---- src/js/controllers/tab-send.js | 2 +- src/js/controllers/walletDetails.js | 7 +- .../controllers/walletSelectorController.js | 12 ++-- src/js/services/incomingData.js | 6 +- src/js/services/sendFlowService.js | 7 ++ 7 files changed, 73 insertions(+), 60 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 8438260bc..68d4e869b 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -2,7 +2,7 @@ angular.module('copayApp.controllers').controller('amountController', amountController); -function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) { +function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) { var vm = this; vm.allowSend = false; @@ -69,12 +69,12 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, initCurrencies(); - passthroughParams = data.stateParams; + passthroughParams = sendFlowService; - vm.fromWalletId = data.stateParams.fromWalletId; - vm.toWalletId = data.stateParams.toWalletId; - vm.minAmount = parseFloat(data.stateParams.minAmount); - vm.maxAmount = parseFloat(data.stateParams.maxAmount); + vm.fromWalletId = passthroughParams.fromWalletId; + vm.toWalletId = passthroughParams.toWalletId; + vm.minAmount = parseFloat(passthroughParams.minAmount); + vm.maxAmount = parseFloat(passthroughParams.maxAmount); if (passthroughParams.thirdParty) { vm.thirdParty = JSON.parse(passthroughParams.thirdParty); // Parse stringified JSON-object @@ -96,7 +96,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } } - vm.isRequestingSpecificAmount = !data.stateParams.fromWalletId; + vm.isRequestingSpecificAmount = !passthroughParams.fromWalletId; var config = configService.getSync().wallet.settings; @@ -177,8 +177,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, // currency have preference var fiatName; - if (data.stateParams.currency) { - fiatCode = data.stateParams.currency; + if (passthroughParams.currency) { + fiatCode = passthroughParams.currency; altUnitIndex = unitIndex unitIndex = availableUnits.length; } else { @@ -205,8 +205,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, var fromWallet = profileService.getWallet(passthroughParams.fromWalletId); updateAvailableFundsFromWallet(fromWallet); } - }; - }; + } + } function goBack() { if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') { @@ -227,18 +227,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, $timeout(function() { $scope.$apply(); }); - }; + } function processClipboard() { if (!isNW) return; var value = nodeWebkitService.readFromClipboard(); if (value && evaluate(value) > 0) paste(evaluate(value)); - }; + } function sendMax() { useSendMax = true; finish(); - }; + } function updateUnitUI() { vm.unit = availableUnits[unitIndex].shortName; @@ -246,7 +246,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, processAmount(); $log.debug('Update unit coin @amount unit:' + vm.unit + " alternativeUnit:" + vm.alternativeUnit); - }; + } function changeUnit() { @@ -267,7 +267,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, updateAvailableFundsStringIfNeeded(); updateUnitUI(); - }; + } function pushDigit(digit) { if (vm.amount && digit != '.') { @@ -291,7 +291,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, vm.amount = (vm.amount + digit).replace('..', '.'); processAmount(); - }; + } function pushOperator(operator) { if (!vm.amount || vm.amount.length == 0) return; @@ -303,18 +303,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } else { return val.slice(0, -1) + operator; } - }; - }; + } + } function isOperator(val) { var regex = /[\/\-\+\x\*]/; return regex.test(val); - }; + } function isExpression(val) { var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/; return regex.test(val); - }; + } function removeDigit() { vm.amount = (vm.amount).toString().slice(0, -1); @@ -339,7 +339,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, function close() { altCurrencyModal.remove(); altCurrencyModal = null; - }; + } function processAmount() { var formatedValue = format(vm.amount); @@ -409,22 +409,22 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } else { vm.errorMessage = ''; } - }; + } function processResult(val) { if (availableUnits[unitIndex].isFiat) return $filter('formatFiatAmount')(val); else return txFormatService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true); - }; + } function fromFiat(val) { return parseFloat((rateService.fromFiat(val, fiatCode, availableUnits[altUnitIndex].id) * satToUnit).toFixed(unitDecimals)); - }; + } function toFiat(val) { if (!rateService.getRate(fiatCode)) return; return parseFloat((rateService.toFiat(val * unitToSatoshi, fiatCode, availableUnits[unitIndex].id)).toFixed(2)); - }; + } function evaluate(val) { var result; @@ -435,7 +435,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } if (!lodash.isFinite(result)) return 0; return result; - }; + } function format(val) { if (!val) return; @@ -445,7 +445,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, if (isOperator(lodash.last(val))) result = result.slice(0, -1); return result.replace('x', '*'); - }; + } function finish() { var unit = availableUnits[unitIndex]; @@ -467,16 +467,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, }; if (vm.thirdParty) { - confirmData['thirdParty'] = JSON.stringify(this.thirdParty); + confirmData['thirdParty'] = this.thirdParty; } + sendFlowService.map(confirmData); + if (!confirmData.fromWalletId) { $state.transitionTo('tabs.paymentRequest.confirm', confirmData); } else { $state.transitionTo('tabs.send.review', confirmData); $scope.useSendMax = null; } - }; + } // Currency @@ -495,7 +497,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, {isoCode: 'CNY', order: 7}, {isoCode: 'KRW', order: 8}, {isoCode: 'HKD', order: 9}, - ] + ]; function initCurrencies() { var unusedCurrencyList = [{ @@ -558,7 +560,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, $timeout(function() { $scope.$apply(); }); - }; + } function save(newAltCurrency) { var opts = { @@ -584,7 +586,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, updateUnitUI(); close(); }); - }; + } function updateAvailableFundsStringIfNeeded() { if (passthroughParams.fromWalletId && availableSatoshis !== null) { @@ -639,5 +641,4 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, vm.availableFunds = availableFundsInCrypto; } } - } diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index f565448ee..858e115c1 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -4,7 +4,7 @@ angular .module('copayApp.controllers') .controller('reviewController', reviewController); -function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) { +function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, sendFlowService, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) { var vm = this; vm.buttonText = ''; @@ -51,7 +51,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit // Functions vm.onSuccessConfirm = onSuccessConfirm; - + var sendFlowData; var config = null; var countDown = null; var defaults = {}; @@ -75,17 +75,18 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit function onBeforeEnter(event, data) { defaults = configService.getDefaults(); - originWalletId = data.stateParams.fromWalletId; - satoshis = parseInt(data.stateParams.amount, 10); - toAddress = data.stateParams.toAddress; - destinationWalletId = data.stateParams.toWalletId; + sendFlowData = sendFlowService; + originWalletId = sendFlowData.fromWalletId; + satoshis = parseInt(sendFlowData.amount, 10); + toAddress = sendFlowData.toAddress; + destinationWalletId = sendFlowData.toWalletId; vm.originWallet = profileService.getWallet(originWalletId); vm.origin.currency = vm.originWallet.coin.toUpperCase(); coin = vm.originWallet.coin; - if (data.stateParams.thirdParty) { - vm.thirdParty = JSON.parse(data.stateParams.thirdParty); // Parse stringified JSON-object + if (sendFlowData.thirdParty) { + // vm.thirdParty = JSON.parse(sendFlowData.thirdParty); // Parse stringified JSON-object if (vm.thirdParty) { handleThirdPartyInitIfBip70(); handleThirdPartyInitIfShapeshift(); @@ -105,7 +106,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit updateSendAmounts(); getOriginWalletBalance(vm.originWallet); handleDestinationAsAddress(toAddress, coin); - handleDestinationAsWallet(data.stateParams.toWalletId); + handleDestinationAsWallet(sendFlowData.toWalletId); createVanityTransaction(data); }); } @@ -221,10 +222,10 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit // Grab stateParams tx = { - amount: parseInt(data.stateParams.amount), - sendMax: data.stateParams.sendMax === 'true' ? true : false, - fromWalletId: data.stateParams.fromWalletId, - toAddress: data.stateParams.toAddress, + amount: parseInt(sendFlowData.amount), + sendMax: sendFlowData.sendMax === 'true' ? true : false, + fromWalletId: sendFlowData.fromWalletId, + toAddress: sendFlowData.toAddress, paypro: txPayproData, feeLevel: configFeeLevel, @@ -241,7 +242,6 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit }; - if (data.stateParams.requiredFeeRate) { vm.usingMerchantFee = true; tx.feeRate = parseInt(data.stateParams.requiredFeeRate); @@ -251,7 +251,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit tx.feeLevel = 'normal'; } - var B = data.stateParams.coin === 'bch' ? bitcoreCash : bitcore; + var B = tx.coin === 'bch' ? bitcoreCash : bitcore; var networkName; try { if (vm.destination.kind === 'wallet') { // This is a wallet-to-wallet transfer diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 465941c35..0c0c1bfe1 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) { +angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, sendFlowService, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) { var clipboardHasAddress = false; var clipboardHasContent = false; var originalList; diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index d3308ff1e..9eef7a5c9 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService) { +angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, sendFlowService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService) { var HISTORY_SHOW_LIMIT = 10; var currentTxHistoryPage = 0; @@ -471,9 +471,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); } $scope.goToSend = function() { - $state.go('tabs.home', { - walletId: $scope.wallet.id - }).then(function () { + sendFlowService.fromWalletId = $scope.wallet.id; + $state.go('tabs.home').then(function () { $ionicHistory.clearHistory(); $state.go('tabs.send'); }); diff --git a/src/js/controllers/walletSelectorController.js b/src/js/controllers/walletSelectorController.js index a4ff3ab3e..a26e07d8f 100644 --- a/src/js/controllers/walletSelectorController.js +++ b/src/js/controllers/walletSelectorController.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, configService, gettextCatalog, profileService, txFormatService) { +angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, sendFlowService, configService, gettextCatalog, profileService, txFormatService) { var fromWalletId = ''; var priceDisplayAsFiat = false; @@ -26,10 +26,14 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu // nop } - $scope.params = $state.params; + $scope.params = sendFlowService; $scope.coin = false; // Wallets to show (for destination screen or contacts) - $scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination - fromWalletId = data.stateParams && data.stateParams.fromWalletId; + $scope.type = $scope.params['fromWalletId'] ? 'destination' : 'origin'; // origin || destination + fromWalletId = $scope.params['fromWalletId']; + + if ($scope.type === 'destination' && $scope.params.toAddress) { + $state.transitionTo(getNextStep()); + } if ($scope.params.coin) { $scope.coin = $scope.params.coin; // Contacts have a coin embedded diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index 946144dce..91de99cf3 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) { +angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) { var root = {}; @@ -105,9 +105,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat params.thirdParty = []; params.thirdParty.id = serviceId; params.thirdParty.data = serviceData; - params.thirdParty = JSON.stringify(params.thirdParty); + sendFlowService.map(params); $state.transitionTo('tabs.send.amount', params); } else { + sendFlowService.map(params); $state.transitionTo('tabs.send.origin', params); } }, 100); @@ -458,6 +459,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat 'notify': $state.current.name == 'tabs.send' ? false : true }).then(function() { $timeout(function() { + sendFlowService.map(stateParams); $state.transitionTo('tabs.send.origin', stateParams); }); }); diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js index d5c4df109..09e55e7ec 100644 --- a/src/js/services/sendFlowService.js +++ b/src/js/services/sendFlowService.js @@ -20,5 +20,12 @@ angular.module('copayApp.services').factory('sendFlowService', function ($log) { vm.toWalletId = false; }; + vm.map = function(params) { + Object.keys(params).map(function(key, index) { + vm[key] = params[key]; + }); + console.log(vm); + }; + return vm; }); \ No newline at end of file From 220610271558cff7fe347da994eedc0319108fdc Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Wed, 8 Aug 2018 17:27:15 +0200 Subject: [PATCH 03/26] sendflow service integrated into flow --- .../controllers/walletSelectorController.js | 1 + src/js/services/sendFlowService.js | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/walletSelectorController.js b/src/js/controllers/walletSelectorController.js index a26e07d8f..69430dbb9 100644 --- a/src/js/controllers/walletSelectorController.js +++ b/src/js/controllers/walletSelectorController.js @@ -191,6 +191,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu }; $scope.goBack = function() { + sendFlowService.previousState(); $ionicHistory.goBack(); } diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js index 09e55e7ec..58b457b3a 100644 --- a/src/js/services/sendFlowService.js +++ b/src/js/services/sendFlowService.js @@ -4,13 +4,15 @@ angular.module('copayApp.services').factory('sendFlowService', function ($log) { var vm = this; vm.amount = false; + vm.fromWalletId = false; + vm.previousStates = []; vm.thirdParty = false; vm.sendMax = false; vm.toAddress = false; vm.toWalletId = false; - vm.initialize = function() { + vm.clear = function() { $log.debug("Reinitialize Send Flow variables"); vm.amount = false; vm.fromWalletId = false; @@ -18,13 +20,28 @@ angular.module('copayApp.services').factory('sendFlowService', function ($log) { vm.sendMax = false; vm.toAddress = false; vm.toWalletId = false; + vm.previousStates = []; }; vm.map = function(params) { + + var tempState = {}; + Object.keys(vm).map(function(key, index) { + if (typeof vm[key] !== 'function' && key !== 'previousStates') { + tempState[key] = vm[key]; + } + }); + vm.previousStates.push(tempState); + Object.keys(params).map(function(key, index) { vm[key] = params[key]; }); - console.log(vm); + }; + + vm.previousState = function() { + if (vm.previousStates.length) { + vm.map(vm.previousStates.pop()); + } }; return vm; From 02e8e0fbf026f44f5e999eaabb867ae835fa231f Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Wed, 8 Aug 2018 17:29:28 +0200 Subject: [PATCH 04/26] clear send flow on home and wallet details --- src/js/controllers/tab-home.js | 4 +++- src/js/controllers/walletDetails.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 07b01b974..7671d524a 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { + function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, sendFlowService, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { var wallet; var listeners = []; var notifications = []; @@ -31,6 +31,8 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); $scope.$on("$ionicView.beforeEnter", function(event, data) { + sendFlowService.clear(); + if (!$scope.homeTip) { storageService.getHomeTipAccepted(function(error, value) { $scope.homeTip = (value == 'accepted') ? false : true; diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 9eef7a5c9..5200c5987 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -374,6 +374,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun }); $scope.$on("$ionicView.beforeEnter", function(event, data) { + sendFlowService.clear(); configService.whenAvailable(function (config) { $scope.selectedPriceDisplay = config.wallet.settings.priceDisplay; From 58d99231ae449d140e01a6b5cd5722fc973c570a Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 10:46:07 +1200 Subject: [PATCH 05/26] Handle undefined currency. --- src/js/directives/formattedAmount.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/directives/formattedAmount.js b/src/js/directives/formattedAmount.js index 6269954fb..5bd307de3 100644 --- a/src/js/directives/formattedAmount.js +++ b/src/js/directives/formattedAmount.js @@ -69,6 +69,7 @@ angular.module('bitcoincom.directives') if (currencySplit.length === 2) { $scope.currency = currencySplit[1]; } + $scope.currency = $scope.currency || ''; var parsed = parseFloat($scope.value); From dff0d51ef3699df1d5ccaa5299637510b63c0ab6 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 11:10:26 +1200 Subject: [PATCH 06/26] Refactored sendFlowService and cleared its state before entering the send tab. --- src/js/controllers/addressbookView.js | 3 +- src/js/controllers/amount.js | 1 + src/js/controllers/shapeshift.js | 3 +- src/js/controllers/tab-home.js | 8 +- src/js/controllers/tab-send.js | 7 ++ src/js/controllers/tabsController.js | 9 ++- src/js/controllers/walletDetails.js | 10 ++- src/js/services/sendFlowService.js | 106 +++++++++++++++++--------- www/views/tab-home.html | 2 +- www/views/tab-send.html | 21 ++++- www/views/tabs.html | 2 +- 11 files changed, 124 insertions(+), 48 deletions(-) diff --git a/src/js/controllers/addressbookView.js b/src/js/controllers/addressbookView.js index aab6fb5b4..5f6881d10 100644 --- a/src/js/controllers/addressbookView.js +++ b/src/js/controllers/addressbookView.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService, bitcoinCashJsService) { +angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, sendFlowService, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService, bitcoinCashJsService) { var config = configService.getSync(); var defaults = configService.getDefaults(); @@ -22,6 +22,7 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f $scope.sendTo = function() { $ionicHistory.removeBackView(); + sendFlowService.clear(); $state.go('tabs.send'); $timeout(function() { var to = ''; diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 68d4e869b..8ff214d87 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -209,6 +209,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } function goBack() { + sendFlowService.previousState(); if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') { $state.go('tabs.send').then(function() { $ionicHistory.clearHistory(); diff --git a/src/js/controllers/shapeshift.js b/src/js/controllers/shapeshift.js index 4bf3db764..fcb43026d 100644 --- a/src/js/controllers/shapeshift.js +++ b/src/js/controllers/shapeshift.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, $state, $timeout, $ionicHistory, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) { +angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, sendFlowService, $state, $timeout, $ionicHistory, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) { var walletsBtc = []; var walletsBch = []; @@ -67,6 +67,7 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi thirdParty: JSON.stringify({id: 'shapeshift'}) }; + sendFlowService.clear(); $state.go('tabs.home').then(function() { $ionicHistory.clearHistory(); $state.go('tabs.send').then(function() { diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 7671d524a..3d63ae41f 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, sendFlowService, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { + function($rootScope, sendFlowService, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { var wallet; var listeners = []; var notifications = []; @@ -31,7 +31,6 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); $scope.$on("$ionicView.beforeEnter", function(event, data) { - sendFlowService.clear(); if (!$scope.homeTip) { storageService.getHomeTipAccepted(function(error, value) { @@ -119,6 +118,11 @@ angular.module('copayApp.controllers').controller('tabHomeController', return timeService.withinPastDay(time); }; + $scope.startFreshSend = function() { + sendFlowService.clear(); + $state.go('tabs.send'); + } + $scope.openExternalLink = function() { var url = 'https://github.com/Bitcoin-com/Wallet/releases/latest'; var optIn = true; diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 0c0c1bfe1..33befb8f2 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -187,6 +187,13 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }; + $scope.startWalletToWalletTransfer = function() { + console.log('startWalletToWalletTransfer()'); + $state.transitionTo('tabs.send.wallet-to-wallet', { + fromWalletId: sendFlowService.fromWalletId + }); + } + // This could probably be enhanced refactoring the routes abstract states $scope.createWallet = function() { $state.go('tabs.home').then(function() { diff --git a/src/js/controllers/tabsController.js b/src/js/controllers/tabsController.js index a186879e3..b3de6c70f 100644 --- a/src/js/controllers/tabsController.js +++ b/src/js/controllers/tabsController.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService) { +angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService, sendFlowService) { $scope.onScan = function(data) { if (!incomingData.redir(data)) { @@ -15,6 +15,11 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro }; }; + $scope.startFreshSend = function() { + sendFlowService.clear(); + $state.go('tabs.send'); + }; + $scope.importInit = function() { $scope.fromOnboarding = $stateParams.fromOnboarding; $timeout(function() { @@ -23,7 +28,7 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro }; $scope.chooseScanner = function() { - + sendFlowService.clear(); var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP; if (!isWindowsPhoneApp) { diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 5200c5987..b159f7bc4 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -471,13 +471,20 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun function rgbToHex(r, g, b) { return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); } + $scope.goToSend = function() { - sendFlowService.fromWalletId = $scope.wallet.id; + sendFlowService.startSend({ + fromWalletId: $scope.wallet.id + }); + + // Go home first so that the Home tab works properly $state.go('tabs.home').then(function () { $ionicHistory.clearHistory(); $state.go('tabs.send'); }); + }; + $scope.goToReceive = function() { $state.go('tabs.home', { walletId: $scope.wallet.id @@ -488,6 +495,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun }); }); }; + $scope.goToBuy = function() { $state.go('tabs.home', { walletId: $scope.wallet.id diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js index 58b457b3a..1af112ed2 100644 --- a/src/js/services/sendFlowService.js +++ b/src/js/services/sendFlowService.js @@ -1,48 +1,78 @@ 'use strict'; -angular.module('copayApp.services').factory('sendFlowService', function ($log) { - var vm = this; +(function(){ - vm.amount = false; +angular + .module('copayApp.services') + .factory('sendFlowService', sendFlowService); + + function sendFlowService($log) { - vm.fromWalletId = false; - vm.previousStates = []; - vm.thirdParty = false; - vm.sendMax = false; - vm.toAddress = false; - vm.toWalletId = false; + var service = { + amount: '', + fromWalletId: '', + sendMax: false, + thirdParty: null, + toAddress: '', + toWalletId: '', + previousStates: [], - vm.clear = function() { - $log.debug("Reinitialize Send Flow variables"); - vm.amount = false; - vm.fromWalletId = false; - vm.thirdParty = false; - vm.sendMax = false; - vm.toAddress = false; - vm.toWalletId = false; - vm.previousStates = []; - }; + // Functions + clear: clear, + map: map, + previousState: previousState, + startSend: startSend + }; - vm.map = function(params) { + return service; - var tempState = {}; - Object.keys(vm).map(function(key, index) { - if (typeof vm[key] !== 'function' && key !== 'previousStates') { - tempState[key] = vm[key]; - } - }); - vm.previousStates.push(tempState); - - Object.keys(params).map(function(key, index) { - vm[key] = params[key]; - }); - }; - - vm.previousState = function() { - if (vm.previousStates.length) { - vm.map(vm.previousStates.pop()); + function clear() { + $log.debug("Reinitialize Send Flow variables with clear()"); + service.amount = ''; + service.fromWalletId = ''; + service.sendMax = false; + service.thirdParty = null; + service.toAddress = ''; + service.toWalletId = ''; + service.previousStates = []; } + + /** + * Clears all previous state + * @param {} params + */ + function startSend(params) { + console.log('startSend()'); + clear(); + Object.keys(params).forEach(function forNewParam(key) { + service[key] = params[key]; + }); + } + + function map(params) { + + var currentState = {}; + Object.keys(service).forEach(function forCurrentParam(key) { + if (typeof service[key] !== 'function' && key !== 'previousStates') { + currentState[key] = service[key]; + } + }); + service.previousStates.push(currentState); + + // Do we want to inherit the previous state here, or clear first before adding new params? + + Object.keys(params).forEach(function forNewParam(key) { + service[key] = params[key]; + }); + }; + + function previousState() { + if (service.previousStates.length) { + map(service.previousStates.pop()); + } else { + clear(); + } + }; }; - return vm; -}); \ No newline at end of file +})(); \ No newline at end of file diff --git a/www/views/tab-home.html b/www/views/tab-home.html index 618f2e128..8ef922918 100644 --- a/www/views/tab-home.html +++ b/www/views/tab-home.html @@ -34,7 +34,7 @@ Buy Bitcoin
+ ng-click="startFreshSend()"> Send
diff --git a/www/views/tab-send.html b/www/views/tab-send.html index 20198c7f0..3378b53ed 100644 --- a/www/views/tab-send.html +++ b/www/views/tab-send.html @@ -4,6 +4,25 @@
+ +
+
+
From:
+
+
+ +
+
+

{{fromWallet.name}}

+ + +
+
+
+
+
@@ -22,7 +41,7 @@
- diff --git a/www/views/tabs.html b/www/views/tabs.html index 3c2683a13..39d0acf73 100644 --- a/www/views/tabs.html +++ b/www/views/tabs.html @@ -11,7 +11,7 @@ - + From be2bc4cddb5b774c49baa14c51d89c2ad013c6b5 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 11:11:10 +1200 Subject: [PATCH 07/26] Showing From wallet in send tab. --- src/js/controllers/tab-send.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 33befb8f2..caa03e92b 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -208,6 +208,13 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }; $scope.$on("$ionicView.beforeEnter", function(event, data) { + console.log('tab-send.beforeEnter sendFlowService.fromWalletId:', sendFlowService.fromWalletId); + var fromWalletId = sendFlowService.fromWalletId; + if (fromWalletId) { + $scope.fromWallet = profileService.getWallet(fromWalletId); + } else { + $scope.fromWallet = null; + } $scope.isIOS = platformInfo.isIOS && platformInfo.isCordova; $scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false; From 1d025cbf35f9bf7fa8eb36e5bd708dea5a1f149f Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 11:42:25 +1200 Subject: [PATCH 08/26] Fixes for Android 4.4 --- src/js/directives/formattedAmount.js | 6 +++--- src/js/services/clipboardService.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/directives/formattedAmount.js b/src/js/directives/formattedAmount.js index 5bd307de3..d3e2e6347 100644 --- a/src/js/directives/formattedAmount.js +++ b/src/js/directives/formattedAmount.js @@ -32,10 +32,10 @@ angular.module('bitcoincom.directives') '3': ['BHD', 'IQD', 'JOD', 'KWD', 'OMR', 'TND'], '8': ['BCH', 'BTC'] }; - var localizeNumbers = function(x, minimumFractionDigits = 0, useGrouping = true) { + var localizeNumbers = function(x, minimumFractionDigits) { return parseFloat(x).toLocaleString(uxLanguage.getCurrentLanguage(), { minimumFractionDigits: minimumFractionDigits, - useGrouping: useGrouping + useGrouping: true }); }; @@ -80,7 +80,7 @@ angular.module('bitcoincom.directives') if (isNaN(parsed)) { buildAmount('-', '', ''); } else { - valueFormatted = localizeNumbers(Math.round(parsed)); + valueFormatted = localizeNumbers(Math.round(parsed), 0); buildAmount(valueFormatted, '', ''); } break; diff --git a/src/js/services/clipboardService.js b/src/js/services/clipboardService.js index 075cb749a..77ad3d018 100644 --- a/src/js/services/clipboardService.js +++ b/src/js/services/clipboardService.js @@ -13,7 +13,7 @@ angular.module('copayApp.services').factory('clipboardService', function ($http, nodeWebkitService.writeToClipboard(data); } else if (navigator && navigator.clipboard) { $log.debug("Use navigator clipboard.") - navigator.clipboard.writeText(data).catch(err => { + navigator.clipboard.writeText(data).catch(function onClipboardError(err) { $log.debug("Clipboard writing is not supported in your browser.."); }); } else if (clipboard.supported) { From 408d46e4d342eab340ea0033d16d2d43492a71b7 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 11:43:20 +1200 Subject: [PATCH 09/26] Hid the from wallet in the send screen for now, because it requires other layout changes to fit everything in, especially on small screens. --- src/js/controllers/tab-send.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index caa03e92b..33befb8f2 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -208,13 +208,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }; $scope.$on("$ionicView.beforeEnter", function(event, data) { - console.log('tab-send.beforeEnter sendFlowService.fromWalletId:', sendFlowService.fromWalletId); - var fromWalletId = sendFlowService.fromWalletId; - if (fromWalletId) { - $scope.fromWallet = profileService.getWallet(fromWalletId); - } else { - $scope.fromWallet = null; - } $scope.isIOS = platformInfo.isIOS && platformInfo.isCordova; $scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false; From be0c18244e8be335a62f15788e661eb0fa27b0d3 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 12:12:29 +1200 Subject: [PATCH 10/26] Review Transaction screen now displaying BCH addresses in cashaddr format. --- src/js/controllers/review.controller.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index 858e115c1..886da26b8 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -403,16 +403,20 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit // Check if the recipient is a contact addressbookService.get(originCoin + address, function(err, contact) { if (!err && contact) { - handleDestinationAsContact(contact); + handleDestinationAsAddressOfContact(contact); } else { - vm.destination.address = address; + if (originCoin === 'bch') { + vm.destination.address = bitcoinCashJsService.readAddress(address).cashaddr; + } else { + vm.destination.address = address; + } vm.destination.kind = 'address'; } }); } - function handleDestinationAsContact(contact) { + function handleDestinationAsAddressOfContact(contact) { vm.destination.kind = 'contact'; vm.destination.name = contact.name; vm.destination.email = contact.email; From bf9b467bfe9324f493c0b90d6942ba459d5c5f66 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 13:01:48 +1200 Subject: [PATCH 11/26] Renamed sendFlowService functions to be more consistent. --- src/js/controllers/amount.js | 5 +- src/js/controllers/tab-send.js | 3 ++ .../controllers/walletSelectorController.js | 10 ++-- src/js/services/incomingData.js | 6 +-- src/js/services/sendFlowService.js | 48 ++++++++++++------- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 8ff214d87..6f513663c 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -66,6 +66,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } function onBeforeEnter(event, data) { + console.log('amount onBeforeEnter sendflow ', sendFlowService.getState()); initCurrencies(); @@ -209,7 +210,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } function goBack() { - sendFlowService.previousState(); + sendFlowService.popState(); if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') { $state.go('tabs.send').then(function() { $ionicHistory.clearHistory(); @@ -471,7 +472,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, confirmData['thirdParty'] = this.thirdParty; } - sendFlowService.map(confirmData); + sendFlowService.pushState(confirmData); if (!confirmData.fromWalletId) { $state.transitionTo('tabs.paymentRequest.confirm', confirmData); diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 33befb8f2..3f2c1a250 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -189,6 +189,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $scope.startWalletToWalletTransfer = function() { console.log('startWalletToWalletTransfer()'); + var params = sendFlowService.getState(); + sendFlowService.pushState(params); $state.transitionTo('tabs.send.wallet-to-wallet', { fromWalletId: sendFlowService.fromWalletId }); @@ -208,6 +210,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }; $scope.$on("$ionicView.beforeEnter", function(event, data) { + console.log('tab-send onBeforeEnter sendflow ', sendFlowService.getState()); $scope.isIOS = platformInfo.isIOS && platformInfo.isCordova; $scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false; diff --git a/src/js/controllers/walletSelectorController.js b/src/js/controllers/walletSelectorController.js index 69430dbb9..1c23bb24b 100644 --- a/src/js/controllers/walletSelectorController.js +++ b/src/js/controllers/walletSelectorController.js @@ -8,6 +8,8 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu var unitsFromSatoshis = 0; $scope.$on("$ionicView.beforeEnter", function(event, data) { + console.log('walletSelector onBeforeEnter sendflow', sendFlowService.getState()); + var config = configService.getSync().wallet.settings; priceDisplayAsFiat = config.priceDisplay === 'fiat'; unitDecimals = config.unitDecimals; @@ -182,16 +184,18 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu $scope.useWallet = function(wallet) { + var params = sendFlowService.getState(); if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from - $scope.params['fromWalletId'] = wallet.id; + params.fromWalletId = wallet.id; } else { // we're on the destination screen, set wallet to send to - $scope.params['toWalletId'] = wallet.id; + params.toWalletId = wallet.id; } + sendFlowService.pushState(params); $state.transitionTo(getNextStep(), $scope.params); }; $scope.goBack = function() { - sendFlowService.previousState(); + sendFlowService.popState(); $ionicHistory.goBack(); } diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index 91de99cf3..934f53cc7 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -105,10 +105,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat params.thirdParty = []; params.thirdParty.id = serviceId; params.thirdParty.data = serviceData; - sendFlowService.map(params); + sendFlowService.pushState(params); $state.transitionTo('tabs.send.amount', params); } else { - sendFlowService.map(params); + sendFlowService.pushState(params); $state.transitionTo('tabs.send.origin', params); } }, 100); @@ -459,7 +459,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat 'notify': $state.current.name == 'tabs.send' ? false : true }).then(function() { $timeout(function() { - sendFlowService.map(stateParams); + sendFlowService.pushState(stateParams); // Need to do more here $state.transitionTo('tabs.send.origin', stateParams); }); }); diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js index 1af112ed2..9daf0f4db 100644 --- a/src/js/services/sendFlowService.js +++ b/src/js/services/sendFlowService.js @@ -19,15 +19,17 @@ angular // Functions clear: clear, + getState: getState, map: map, - previousState: previousState, + popState: popState, + pushState: pushState, startSend: startSend }; return service; function clear() { - $log.debug("Reinitialize Send Flow variables with clear()"); + console.log("sendFlow clear()"); service.amount = ''; service.fromWalletId = ''; service.sendMax = false; @@ -38,41 +40,51 @@ angular } /** - * Clears all previous state - * @param {} params + * Handy for debugging */ - function startSend(params) { - console.log('startSend()'); - clear(); - Object.keys(params).forEach(function forNewParam(key) { - service[key] = params[key]; - }); - } - - function map(params) { - + function getState() { var currentState = {}; Object.keys(service).forEach(function forCurrentParam(key) { if (typeof service[key] !== 'function' && key !== 'previousStates') { currentState[key] = service[key]; } }); - service.previousStates.push(currentState); + return currentState; + } - // Do we want to inherit the previous state here, or clear first before adding new params? + /** + * Clears all previous state + */ + function startSend(params) { + console.log('startSend()'); + clear(); + map(params); + } + function map(params) { Object.keys(params).forEach(function forNewParam(key) { service[key] = params[key]; }); }; - function previousState() { + function popState() { + console.log('sendFlow pop'); if (service.previousStates.length) { - map(service.previousStates.pop()); + var params = service.previousStates.pop(); + clear(); + map(params); } else { clear(); } }; + + function pushState(params) { + console.log('sendFlow push'); + var currentParams = getState(); + service.previousStates.push(currentParams); + clear(); + map(params); + }; }; })(); \ No newline at end of file From b426209efb2f7a49e4338fd845edbfd593731a6c Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 13:06:50 +1200 Subject: [PATCH 12/26] Fix for clearing current state only. --- src/js/services/sendFlowService.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js index 9daf0f4db..29686b15b 100644 --- a/src/js/services/sendFlowService.js +++ b/src/js/services/sendFlowService.js @@ -30,13 +30,18 @@ angular function clear() { console.log("sendFlow clear()"); + clearCurrent(); + service.previousStates = []; + } + + function clearCurrent() { + console.log("sendFlow clearCurrent()"); service.amount = ''; service.fromWalletId = ''; service.sendMax = false; service.thirdParty = null; service.toAddress = ''; service.toWalletId = ''; - service.previousStates = []; } /** @@ -71,7 +76,7 @@ angular console.log('sendFlow pop'); if (service.previousStates.length) { var params = service.previousStates.pop(); - clear(); + clearCurrent(); map(params); } else { clear(); @@ -82,7 +87,7 @@ angular console.log('sendFlow push'); var currentParams = getState(); service.previousStates.push(currentParams); - clear(); + clearCurrent(); map(params); }; }; From a2dff98c63c67b19c93fad058fa504e9818e0418 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 13:12:44 +1200 Subject: [PATCH 13/26] Back button on Review Transaction screen works with sendFlowService. --- src/js/controllers/review.controller.js | 6 ++++++ www/views/review.html | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index 886da26b8..e2e393501 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -49,6 +49,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit vm.memoExpanded = false; // Functions + vm.goBack = goBack; vm.onSuccessConfirm = onSuccessConfirm; var sendFlowData; @@ -395,6 +396,11 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit }; } + function goBack() { + sendFlowService.popState(); + $ionicHistory.goBack(); + } + function handleDestinationAsAddress(address, originCoin) { if (!address) { return; diff --git a/www/views/review.html b/www/views/review.html index cb7f21fbc..1eb648a01 100644 --- a/www/views/review.html +++ b/www/views/review.html @@ -3,8 +3,7 @@ {{'Review Transaction' | translate}} - - + From 0410182d4f151b1880443cc52898250c5cd3bc92 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 13:24:13 +1200 Subject: [PATCH 14/26] Incoming data working with sendFlowService. --- src/js/services/incomingData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index 934f53cc7..76b5885d4 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -82,7 +82,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat }); // Timeout is required to enable the "Back" button $timeout(function() { - var params = {}; + var params = sendFlowService.getState(); if (amount) { params.amount = amount; From 188ddcba586054f87566f536f358708bb46435a2 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 13:25:06 +1200 Subject: [PATCH 15/26] Review transation copying state at startup so it doesn't contaminate the sendFlowController. --- src/js/controllers/review.controller.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index e2e393501..2b42339ce 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -75,8 +75,9 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit function onBeforeEnter(event, data) { + console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.getState()); defaults = configService.getDefaults(); - sendFlowData = sendFlowService; + sendFlowData = sendFlowService.getState(); originWalletId = sendFlowData.fromWalletId; satoshis = parseInt(sendFlowData.amount, 10); toAddress = sendFlowData.toAddress; From e18364329805475d33a42e64b10cbf3e6b1c7baf Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 12:35:39 +0900 Subject: [PATCH 16/26] Remove from the route the stateparams, adapt some controllers in the new sendflowservice --- src/js/controllers/addressbookView.js | 8 +++++-- src/js/controllers/amount.js | 13 ++-------- src/js/controllers/shapeshift.js | 10 ++++---- src/js/controllers/tab-send.js | 24 +++++++++++++++---- .../controllers/walletSelectorController.js | 8 ++++--- src/js/routes.js | 8 +++---- src/js/services/incomingData.js | 12 ++++++---- 7 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/js/controllers/addressbookView.js b/src/js/controllers/addressbookView.js index 5f6881d10..89c1cd924 100644 --- a/src/js/controllers/addressbookView.js +++ b/src/js/controllers/addressbookView.js @@ -32,12 +32,16 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f } else { to = $scope.addressbookEntry.address; } - $state.transitionTo('tabs.send.amount', { + + var stateParams = { toAddress: to, toName: $scope.addressbookEntry.name, toEmail: $scope.addressbookEntry.email, coin: $scope.addressbookEntry.coin - }); + }; + + sendFlowService.pushState(stateParams); + $state.transitionTo('tabs.send.origin'); }, 100); }; diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 6f513663c..d07f77c3f 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -78,7 +78,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, vm.maxAmount = parseFloat(passthroughParams.maxAmount); if (passthroughParams.thirdParty) { - vm.thirdParty = JSON.parse(passthroughParams.thirdParty); // Parse stringified JSON-object + vm.thirdParty = passthroughParams.thirdParty; // Parse stringified JSON-object if (vm.thirdParty) { if (vm.thirdParty.id === 'shapeshift') { if (!vm.thirdParty.data) { @@ -211,16 +211,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, function goBack() { sendFlowService.popState(); - if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') { - $state.go('tabs.send').then(function() { - $ionicHistory.clearHistory(); - $state.go('tabs.home').then(function() { - $state.transitionTo('tabs.shapeshift'); - }); - }); - } else { - $ionicHistory.goBack(); - } + $ionicHistory.goBack(); } function paste(value) { diff --git a/src/js/controllers/shapeshift.js b/src/js/controllers/shapeshift.js index fcb43026d..4ede8a94f 100644 --- a/src/js/controllers/shapeshift.js +++ b/src/js/controllers/shapeshift.js @@ -63,16 +63,18 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi }; $scope.shapeshift = function() { - var params = { - thirdParty: JSON.stringify({id: 'shapeshift'}) + var stateParams = { + thirdParty: { + id: 'shapeshift' + } }; - sendFlowService.clear(); $state.go('tabs.home').then(function() { $ionicHistory.clearHistory(); $state.go('tabs.send').then(function() { $timeout(function () { - $state.transitionTo('tabs.send.origin', params); + sendFlowService.pushState(stateParams); + $state.transitionTo('tabs.send.origin'); }, 60); }); }); diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 3f2c1a250..55087859d 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -179,11 +179,18 @@ angular.module('copayApp.controllers').controller('tabSendController', function( } $log.debug('Got toAddress:' + toAddress + ' | ' + item.name); + + var stateParams = sendFlowService.getState(); + stateParams.toAddress = toAddress, + stateParams.coin = item.coin; + sendFlowService.pushState(stateParams); + + if (!stateParams.fromWalletId) { // If we have no toAddress or fromWallet + $state.transitionTo('tabs.send.origin'); + } else { + $state.transitionTo('tabs.send.amount'); + } - return $state.transitionTo('tabs.send.origin', { - toAddress: toAddress, - coin: item.coin - }); }); }; @@ -210,6 +217,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }; $scope.$on("$ionicView.beforeEnter", function(event, data) { + console.log(data); console.log('tab-send onBeforeEnter sendflow ', sendFlowService.getState()); $scope.isIOS = platformInfo.isIOS && platformInfo.isCordova; $scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false; @@ -225,5 +233,11 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $scope.displayBalanceAsFiat = _config.wallet.settings.priceDisplay === 'fiat'; }); + var state = sendFlowService.getState(); + + if (data.direction == "back") { + sendFlowService.clear(); + } + }); -}); +}); \ No newline at end of file diff --git a/src/js/controllers/walletSelectorController.js b/src/js/controllers/walletSelectorController.js index 1c23bb24b..f4448486f 100644 --- a/src/js/controllers/walletSelectorController.js +++ b/src/js/controllers/walletSelectorController.js @@ -10,6 +10,8 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu $scope.$on("$ionicView.beforeEnter", function(event, data) { console.log('walletSelector onBeforeEnter sendflow', sendFlowService.getState()); + var stateParams = sendFlowService.getState(); + var config = configService.getSync().wallet.settings; priceDisplayAsFiat = config.priceDisplay === 'fiat'; unitDecimals = config.unitDecimals; @@ -20,7 +22,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu $scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer'); break; case 'tabs.send.destination': - if (data.stateParams.fromWalletId) { + if (stateParams.fromWalletId) { $scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer'); } break; @@ -47,7 +49,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu $scope.isPaymentRequest = true; } if ($scope.params.thirdParty) { - $scope.thirdParty = JSON.parse($scope.params.thirdParty); // Parse stringified JSON-object + $scope.thirdParty = $scope.params.thirdParty; } }); @@ -96,7 +98,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu function getNextStep() { if ($scope.thirdParty) { - $scope.params.thirdParty = JSON.stringify($scope.thirdParty) // re-stringify JSON-object + $scope.params.thirdParty = $scope.thirdParty } if (!$scope.params.toWalletId && !$scope.params.toAddress) { // If we have no toAddress or fromWallet return 'tabs.send.destination'; diff --git a/src/js/routes.js b/src/js/routes.js index dea46a2cf..5dbcbe6a3 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -287,7 +287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr */ .state('tabs.send.amount', { - url: '/amount/:thirdParty/:fromWalletId/:maxAmount/:minAmount/:toWalletId/:toAddress', + url: '/amount', views: { 'tab-send@tabs': { controller: 'amountController', @@ -306,7 +306,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('tabs.send.origin', { - url: '/origin/:thirdParty/:amount/:toAddress/:toWalletId/:coin', + url: '/origin', views: { 'tab-send@tabs': { controller: 'walletSelectorController', @@ -315,7 +315,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('tabs.send.destination', { - url: '/destination/:thirdParty/:amount/:fromWalletId', + url: '/destination', views: { 'tab-send@tabs': { controller: 'walletSelectorController', @@ -324,7 +324,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) .state('tabs.send.confirm', { - url: '/confirm/:thirdParty/:amount/:fromWalletId/:toWalletId/:toAddress', + url: '/confirm', views: { 'tab-send@tabs': { controller: 'confirmController', diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index 76b5885d4..86c928a5e 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -106,10 +106,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat params.thirdParty.id = serviceId; params.thirdParty.data = serviceData; sendFlowService.pushState(params); - $state.transitionTo('tabs.send.amount', params); + $state.transitionTo('tabs.send.amount'); } else { sendFlowService.pushState(params); - $state.transitionTo('tabs.send.origin', params); + $state.transitionTo('tabs.send.origin'); } }, 100); } @@ -388,11 +388,13 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat 'notify': $state.current.name == 'tabs.send' ? false : true }); $timeout(function() { - $state.transitionTo('tabs.send.origin', { + var stateParams = { toAddress: toAddress, coin: coin, noPrefix: 1 - }); + }; + sendFlowService.pushState(stateParams); + $state.transitionTo('tabs.send.origin'); }, 100); } @@ -460,7 +462,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat }).then(function() { $timeout(function() { sendFlowService.pushState(stateParams); // Need to do more here - $state.transitionTo('tabs.send.origin', stateParams); + $state.transitionTo('tabs.send.origin'); }); }); } From 647e1261698eba7a9526d5abe93ff85a76ce2b3d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 12:49:35 +0900 Subject: [PATCH 17/26] Fix style css for the from wallet & activate the from wallet in the send tab --- src/js/controllers/tab-send.js | 3 ++ src/sass/views/tab-send.scss | 14 ++++---- www/css/main.css | 64 ++++++++++++---------------------- 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 55087859d..911548455 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -33,6 +33,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function( text = text.substring(0, 200); } + var stateParams = sendFlowService.getState(); + $scope.fromWallet = profileService.getWallet(stateParams.fromWalletId); + $scope.clipboardHasAddress = false; $scope.clipboardHasContent = false; if ((text.indexOf('bitcoincash:') === 0 || text[0] === 'C' || text[0] === 'H' || text[0] === 'p' || text[0] === 'q') && text.replace('bitcoincash:', '').length === 42) { // CashAddr diff --git a/src/sass/views/tab-send.scss b/src/sass/views/tab-send.scss index 82b6f8d02..bf77984fd 100644 --- a/src/sass/views/tab-send.scss +++ b/src/sass/views/tab-send.scss @@ -2,15 +2,15 @@ @extend .deflash-blue; &-header{ - height: 300px; + //height: 300px; width: 100%; } &-contacts { - height: calc(100vh - 300px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */ + //height: calc(100vh - 300px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */ &.ios { - height: calc(100vh - 300px - 50px - 44px - 18px); // Remove the notification-bar height on iOS + //height: calc(100vh - 300px - 50px - 44px - 18px); // Remove the notification-bar height on iOS } - overflow: scroll; + //overflow: scroll; } .input { @@ -223,12 +223,12 @@ } } #tab-send-header { - height: 270px; + //height: 270px; } #tab-send-contacts { - height: calc(100vh - 270px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */ + //height: calc(100vh - 270px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */ &.ios { - height: calc(100vh - 270px - 50px - 44px - 18px); // Remove the notification-bar height on iOS + //height: calc(100vh - 270px - 50px - 44px - 18px); // Remove the notification-bar height on iOS } } } diff --git a/www/css/main.css b/www/css/main.css index 9845340ae..8602ba35d 100644 --- a/www/css/main.css +++ b/www/css/main.css @@ -11168,16 +11168,8 @@ qrcode { background-color: #fab915 !important; } #tab-send-header { - height: 300px; width: 100%; } -#tab-send-contacts { - height: calc(100vh - 300px - 50px - 44px); - /* screen size - button container - bottom-tab-menu - header top */ - overflow: scroll; } - #tab-send-contacts.ios { - height: calc(100vh - 300px - 50px - 44px - 18px); } - #tab-send .input { width: 100%; } #tab-send .input input { @@ -11358,14 +11350,7 @@ qrcode { #tab-send .send-wrapper .buttons .button-qr { height: 60px; } #tab-send .send-wrapper .buttons .button-qr span { - font-size: 16px; } - #tab-send #tab-send-header { - height: 270px; } - #tab-send #tab-send-contacts { - height: calc(100vh - 270px - 50px - 44px); - /* screen size - button container - bottom-tab-menu - header top */ } - #tab-send #tab-send-contacts.ios { - height: calc(100vh - 270px - 50px - 44px - 18px); } } + font-size: 16px; } } #wallet-origin-destination .header--request { padding: 30px 24px; @@ -15374,8 +15359,6 @@ log-options #check-bar .checkbox-icon { #view-review .fee-summary { position: absolute; bottom: 92px; } - #view-review .fee-summary-spacer { - height: 15px; } #view-review .shapeshift-banner, #view-review .bitpay-banner, #view-review .egifter-banner { box-shadow: none; } #view-review .warning { @@ -15551,31 +15534,28 @@ ion-content.padded-bottom-cta-with-summary { .fee-summary .amount .fee-crypto { color: #A7A7A7; } -.amount .start, -.amount .middle, -.amount .end, -.amount .currency { +.formatted-amount { display: inline-block; } - -.amount .start { - font-size: 1em; } - -.amount .middle { - font-size: 0.7857em; - margin-left: 5px; } - -.amount .end { - font-size: 0.7857em; - margin-left: 5px; } - -.amount.size-equal .middle, -.amount.size-equal .end { - font-size: 1em; } - -.amount .currency { - font-size: 1em; - margin-left: 5px; - text-transform: uppercase; } + .formatted-amount .start, + .formatted-amount .middle, + .formatted-amount .end, + .formatted-amount .currency { + display: inline-block; } + .formatted-amount .start { + font-size: 1em; } + .formatted-amount .middle { + font-size: 0.7857em; + margin-left: 5px; } + .formatted-amount .end { + font-size: 0.7857em; + margin-left: 5px; } + .formatted-amount.size-equal .middle, + .formatted-amount.size-equal .end { + font-size: 1em; } + .formatted-amount .currency { + font-size: 1em; + margin-left: 5px; + text-transform: uppercase; } /* This is for rules that don't yet have a home. * Our goal is to delete this file. Search the regex: /class=".*CLASS.*?"/ From a490f0ce1f42960fd87df7a3e561239fe5e42ee2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 13:06:52 +0900 Subject: [PATCH 18/26] dead code --- src/js/controllers/tab-send.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 911548455..81b3e4ca5 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -236,8 +236,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $scope.displayBalanceAsFiat = _config.wallet.settings.priceDisplay === 'fiat'; }); - var state = sendFlowService.getState(); - if (data.direction == "back") { sendFlowService.clear(); } From 7ce562ec648746153ae86e95c989d7f791469baa Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 16:11:29 +1200 Subject: [PATCH 19/26] Fix for Shapeshift now appearing again on Review Transaction screen. --- src/js/controllers/review.controller.js | 8 +++----- src/js/controllers/shapeshift.js | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index 2b42339ce..0e5ceedce 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -88,11 +88,9 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit coin = vm.originWallet.coin; if (sendFlowData.thirdParty) { - // vm.thirdParty = JSON.parse(sendFlowData.thirdParty); // Parse stringified JSON-object - if (vm.thirdParty) { - handleThirdPartyInitIfBip70(); - handleThirdPartyInitIfShapeshift(); - } + vm.thirdParty = sendFlowData.thirdParty; + handleThirdPartyInitIfBip70(); + handleThirdPartyInitIfShapeshift(); } configService.get(function onConfig(err, configCache) { diff --git a/src/js/controllers/shapeshift.js b/src/js/controllers/shapeshift.js index 4ede8a94f..3538ebe1a 100644 --- a/src/js/controllers/shapeshift.js +++ b/src/js/controllers/shapeshift.js @@ -69,6 +69,8 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi } }; + // Starting new send flow, so ensure everything is reset + sendFlowService.clear(); $state.go('tabs.home').then(function() { $ionicHistory.clearHistory(); $state.go('tabs.send').then(function() { From 0ea97fc1c61fa3860e2eed4b80c202b3503c3d64 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 13:14:44 +0900 Subject: [PATCH 20/26] Fix state pop on the send flow --- src/js/controllers/review.controller.js | 1 - src/js/controllers/walletSelectorController.js | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index 2b42339ce..70a349b37 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -398,7 +398,6 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit } function goBack() { - sendFlowService.popState(); $ionicHistory.goBack(); } diff --git a/src/js/controllers/walletSelectorController.js b/src/js/controllers/walletSelectorController.js index f4448486f..74ed874d4 100644 --- a/src/js/controllers/walletSelectorController.js +++ b/src/js/controllers/walletSelectorController.js @@ -7,9 +7,16 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu var unitDecimals = 0; var unitsFromSatoshis = 0; - $scope.$on("$ionicView.beforeEnter", function(event, data) { + $scope.$on("$ionicView.beforeEnter", onBeforeEnter); + $scope.$on("$ionicView.enter", onEnter); + + function onBeforeEnter(event, data) { console.log('walletSelector onBeforeEnter sendflow', sendFlowService.getState()); + if (data.direction == "back") { + sendFlowService.popState(); + } + var stateParams = sendFlowService.getState(); var config = configService.getSync().wallet.settings; @@ -51,9 +58,9 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu if ($scope.params.thirdParty) { $scope.thirdParty = $scope.params.thirdParty; } - }); + }; - $scope.$on("$ionicView.enter", function(event, data) { + function onEnter (event, data) { configService.whenAvailable(function(config) { $scope.selectedPriceDisplay = config.wallet.settings.priceDisplay; }); @@ -65,7 +72,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu prepareWalletLists(); formatRequestedAmount(); - }); + }; function formatRequestedAmount() { if ($scope.params.amount) { @@ -197,7 +204,6 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu }; $scope.goBack = function() { - sendFlowService.popState(); $ionicHistory.goBack(); } From 77f62100760a60fb46d2d3e578d86dc6f900c15b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 13:15:21 +0900 Subject: [PATCH 21/26] Fix pop state on the send flow --- src/js/controllers/amount.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index d07f77c3f..b945be92c 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -68,6 +68,10 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, function onBeforeEnter(event, data) { console.log('amount onBeforeEnter sendflow ', sendFlowService.getState()); + if (data.direction == "back") { + sendFlowService.popState(); + } + initCurrencies(); passthroughParams = sendFlowService; @@ -210,7 +214,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } function goBack() { - sendFlowService.popState(); $ionicHistory.goBack(); } From cbf66a2176224d8190d0eac14bb47a9c7983aaba Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 9 Aug 2018 17:54:20 +1200 Subject: [PATCH 22/26] Fix for formatting amounts on Android 4.4. --- src/js/directives/formattedAmount.js | 48 ++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/js/directives/formattedAmount.js b/src/js/directives/formattedAmount.js index d3e2e6347..c0c341631 100644 --- a/src/js/directives/formattedAmount.js +++ b/src/js/directives/formattedAmount.js @@ -33,10 +33,15 @@ angular.module('bitcoincom.directives') '8': ['BCH', 'BTC'] }; var localizeNumbers = function(x, minimumFractionDigits) { - return parseFloat(x).toLocaleString(uxLanguage.getCurrentLanguage(), { + var parsed = parseFloat(x); + var opts = { minimumFractionDigits: minimumFractionDigits, useGrouping: true - }); + }; + var lang = uxLanguage.getCurrentLanguage(); + var localized = parsed.toLocaleString(lang, opts); + var corrected = ensureEnoughFractionalDigits(localized, x, minimumFractionDigits); + return corrected; }; var buildAmount = function(start, middle, end) { @@ -61,7 +66,6 @@ angular.module('bitcoincom.directives') }; var formatNumbers = function() { - // During watch, may be changed from having a separate currency value, // to both being in value. Don't want to use previous currency value. // Try to extract currency from value.. @@ -128,6 +132,44 @@ angular.module('bitcoincom.directives') $scope.$watchGroup(['currency', 'value'], function onFormattedAmountWatch() { formatNumbers(); }); + + /** + * On Android 4.4, toLocaleString() only returns 3 fractional digits when 8 is specified. + */ + function ensureEnoughFractionalDigits(localizedString, number, desiredFractionDigits) { + if (desiredFractionDigits === 0) { + // Assume it is OK + return localizedString; + } + var fractionalRe = /^(\d*\D)(\d+)$/; + var match = fractionalRe.exec(localizedString); + if (match.length !== 3) { + // Don't know what's happening, just return what we have + return localizedString; + } + + var decimals = match[2]; + var decimalCount = decimals.length; + if (decimalCount >= desiredFractionDigits) { + // Everything is OK. + return localizedString; + } + + if (typeof number !== 'number') { + number = parseFloat(number); + } + + var fixed = number.toFixed(desiredFractionDigits); + var fixedMatch = fractionalRe.exec(fixed); + if (fixedMatch.length !== 3) { + // Don't know what's happening, just return what we have + return localizedString; + } + + // Keeps locale decimal separator. + var enough = match[1] + fixedMatch[2]; + return enough; + } }); } }; From c68b1e77f66f22458c476d8af07c63ff38fc6e40 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 15:09:43 +0900 Subject: [PATCH 23/26] clean controller and remove old firebase event --- src/js/controllers/backup.js | 5 +++-- src/js/controllers/confirm.js | 4 +--- src/js/controllers/create.js | 4 ++-- src/js/controllers/tab-home.js | 4 +--- src/js/routes.js | 7 ++++++- src/js/services/firebaseEventsService.js | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index 0eec71f12..6ec7089c6 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('backupController', - function($scope, $timeout, $log, $state, $stateParams, $ionicHistory, lodash, profileService, bwcService, walletService, ongoingProcess, popupService, gettextCatalog, $ionicModal, firebaseEventsService) { + function($scope, $timeout, $log, $state, $stateParams, $ionicHistory, lodash, profileService, bwcService, walletService, ongoingProcess, popupService, gettextCatalog, $ionicModal) { if ($state.current.name == 'onboarding.backup') { $scope.onboarding = true; @@ -89,7 +89,8 @@ angular.module('copayApp.controllers').controller('backupController', $scope.setFlow(2); }) } else { - firebaseEventsService.logEvent('backed_up_wallet'); + + //firebaseEventsService.logEvent('backed_up_wallet'); openConfirmBackupModal(); } }; diff --git a/src/js/controllers/confirm.js b/src/js/controllers/confirm.js index c98064fcc..76950df73 100644 --- a/src/js/controllers/confirm.js +++ b/src/js/controllers/confirm.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, $ionicLoading, ionicToast, addressbookService, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bitcoinCashJsService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService, clipboardService) { +angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $timeout, $ionicScrollDelegate, $ionicLoading, ionicToast, addressbookService, gettextCatalog, walletService, platformInfo, lodash, configService, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, feeService, bitcoinCashJsService, bwcError, txConfirmNotification, soundService, clipboardService) { var countDown = null; var FEE_TOO_HIGH_LIMIT_PER = 15; @@ -708,8 +708,6 @@ angular.module('copayApp.controllers').controller('confirmController', function( }], [channel, "adjust"]); window.BitAnalytics.LogEventHandlers.postEvent(log); - // Should be removed - firebaseEventsService.logEvent('sent_bitcoin', { coin: $scope.wallet.coin }); $timeout(function() { $scope.$digest(); }, 100); diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index a25300a4a..a21053e2d 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, $state, $ionicScrollDelegate, $ionicHistory, profileService, configService, gettextCatalog, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, storageService, popupService, appConfigService, pushNotificationsService, firebaseEventsService, $ionicNavBarDelegate) { + function($scope, $timeout, $log, lodash, $state, $ionicScrollDelegate, $ionicHistory, profileService, configService, gettextCatalog, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, popupService, appConfigService, pushNotificationsService, $ionicNavBarDelegate) { /* For compressed keys, m*73 + n*34 <= 496 */ var COPAYER_PAIR_LIMITS = { @@ -268,7 +268,7 @@ angular.module('copayApp.controllers').controller('createController', }, 100); } else { - firebaseEventsService.logEvent('wallet_created', { coin: opts.coin }); + //firebaseEventsService.logEvent('wallet_created', { coin: opts.coin }); $state.go('tabs.home'); } } diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 3d63ae41f..32e320932 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, sendFlowService, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { + function($rootScope, sendFlowService, $timeout, $scope, $state, $stateParams, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, $ionicNavBarDelegate) { var wallet; var listeners = []; var notifications = []; @@ -98,8 +98,6 @@ angular.module('copayApp.controllers').controller('tabHomeController', } $scope.showServices = true; - pushNotificationsService.init(); - firebaseEventsService.init(); $timeout(function() { $ionicScrollDelegate.resize(); diff --git a/src/js/routes.js b/src/js/routes.js index 5dbcbe6a3..b5a9c91fe 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1207,7 +1207,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService, rateService) { + .run(function($rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, pushNotificationsService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService, rateService) { $ionicPlatform.ready(function() { @@ -1231,6 +1231,11 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); + configService.whenAvailable(function(config) { + pushNotificationsService.init(); + }); + //firebaseEventsService.init(); + var channel = "ga"; if (platformInfo.isCordova) { channel = "firebase"; diff --git a/src/js/services/firebaseEventsService.js b/src/js/services/firebaseEventsService.js index d81e682d7..d6ce6f1cc 100644 --- a/src/js/services/firebaseEventsService.js +++ b/src/js/services/firebaseEventsService.js @@ -1,5 +1,5 @@ 'use strict'; -angular.module('copayApp.services').factory('firebaseEventsService', function firebaseEventsService($log, $state, $ionicHistory, sjcl, platformInfo, lodash, appConfigService, profileService, configService) { +angular.module('copayApp.services').factory('firebaseEventsService', function firebaseEventsService($log, platformInfo) { var root = {}; var useEvents = platformInfo.isCordova && !platformInfo.isWP; From b742eadd4e1f24329326ea7ca5711f1013d7bd61 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 15:13:29 +0900 Subject: [PATCH 24/26] clean and remove bug home --- src/js/controllers/tab-home.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 32e320932..b6fec52d4 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -20,7 +20,12 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.bannerUrl = ''; - $scope.$on("$ionicView.afterEnter", function() { + $scope.$on("$ionicView.beforeEnter", onBeforeEnter); + $scope.$on("$ionicView.enter", onEnter); + $scope.$on("$ionicView.afterEnter", onAfterEnter); + $scope.$on("$ionicView.leave", onLeave); + + function onAfterEnter () { startupService.ready(); bannerService.getBanner(function (banner) { @@ -28,9 +33,9 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.bannerUrl = banner.url; $scope.bannerIsLoading = false; }); - }); + }; - $scope.$on("$ionicView.beforeEnter", function(event, data) { + function onBeforeEnter (event, data) { if (!$scope.homeTip) { storageService.getHomeTipAccepted(function(error, value) { @@ -52,11 +57,10 @@ angular.module('copayApp.controllers').controller('tabHomeController', } }); } - }); - - $scope.$on("$ionicView.enter", function(event, data) { + }; + + function onEnter(event, data) { $ionicNavBarDelegate.showBar(true); - updateAllWallets(); addressbookService.list(function(err, ab) { if (err) $log.error(err); @@ -104,13 +108,13 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.$apply(); }, 10); }); - }); + }; - $scope.$on("$ionicView.leave", function(event, data) { + function onLeave (event, data) { lodash.each(listeners, function(x) { x(); }); - }); + }; $scope.createdWithinPastDay = function(time) { return timeService.withinPastDay(time); From 9076ad209809c5feef52c7690eab1ef6a0fa2676 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 15:35:03 +0900 Subject: [PATCH 25/26] add update wallet --- src/js/controllers/tab-home.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index b6fec52d4..51d500de7 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -61,6 +61,7 @@ angular.module('copayApp.controllers').controller('tabHomeController', function onEnter(event, data) { $ionicNavBarDelegate.showBar(true); + updateAllWallets(); addressbookService.list(function(err, ab) { if (err) $log.error(err); From 4cf68076a01a0b3e27ff9286113e8c3f5c330066 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 9 Aug 2018 15:35:31 +0900 Subject: [PATCH 26/26] remove comment on bitanalytics --- bitanalytics/bitanalytics.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bitanalytics/bitanalytics.js b/bitanalytics/bitanalytics.js index c8c0d8870..d04b2a0bd 100644 --- a/bitanalytics/bitanalytics.js +++ b/bitanalytics/bitanalytics.js @@ -6256,7 +6256,6 @@ var ClickAction = /** @class */ (function (_super) { // Add event listener to all the elements found for (var i = 0; i < elements.length; i++) { var element = elements[i]; - console.log('init ' + this.name); element.addEventListener('click', this.listener); } }; @@ -6413,7 +6412,6 @@ var AdjustChannel = /** @class */ (function (_super) { _this.eventTypes = config.eventTypes; var os = _this.adjustedOs(config.os); _this.advertisingId = _this.getAdvertisingId(os); - console.log('Advertising ID for adjust: ' + _this.advertisingId); // TODO: Different initialisation for Cordova. var sessionParams = { app_version: config.appVersion, @@ -6656,7 +6654,7 @@ var MixpanelChannel = /** @class */ (function (_super) { function MixpanelChannel(name, config) { var _this = _super.call(this, name) || this; if (!config.token) { - throw new DOMException('[BitAnalytics] Config incorrect.'); + throw new Error('[BitAnalytics] Config incorrect.'); } _this.mixpanelInstance = mixpanel; mixpanel.init(config.token, config.config); @@ -7037,7 +7035,7 @@ var LogEventHandlers = /** @class */ (function () { _this.channels.push(channel); } catch (error) { - console.log('[BitAnalytics] ' + error.name + ': ' + error.message); + console.log(error.message); } }); };