From 8ef930a0a9ef82b41ac4acc42d2faf17c1214afb Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Thu, 27 Sep 2018 11:56:21 +0200 Subject: [PATCH 1/2] Fix init variable when enter in the screen (remove caching) --- src/js/controllers/amount.controller.js | 87 +++++++---- src/js/controllers/review.controller.js | 137 ++++++++++-------- .../controllers/wallet-selector.controller.js | 15 ++ 3 files changed, 146 insertions(+), 93 deletions(-) diff --git a/src/js/controllers/amount.controller.js b/src/js/controllers/amount.controller.js index f837ff2f3..219245e54 100644 --- a/src/js/controllers/amount.controller.js +++ b/src/js/controllers/amount.controller.js @@ -8,31 +8,7 @@ angular function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, ongoingProcess, popupService, profileService, walletService, $window) { var vm = this; - - // Variables - vm.allowSend = false; - vm.altCurrencyList = []; - vm.alternativeAmount = ''; - vm.alternativeUnit = ''; - vm.amount = '0'; - vm.availableFunds = ''; - vm.canSendAllAvailableFunds = true; - vm.errorMessage = ''; - // Use insufficient for logic, as when the amount is invalid, funds being - // either sufficent or insufficient doesn't make sense. - vm.fundsAreInsufficient = false; - vm.globalResult = ''; - vm.isRequestingSpecificAmount = false; - vm.listComplete = false; - vm.lastUsedPopularList = []; - vm.maxAmount = 0; - vm.minAmount = 0; - vm.sendableFunds = ''; - vm.showSendMaxButton = false; - vm.showSendLimitMaxButton = false; - vm.thirdParty = null; - vm.unit = ''; - + // Functions vm.changeUnit = changeUnit; vm.close = close; @@ -46,7 +22,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, vm.removeDigit = removeDigit; vm.save = save; vm.sendMax = sendMax; - $scope.$on('$ionicView.beforeEnter', onBeforeEnter); $scope.$on('$ionicView.leave', onLeave); @@ -79,8 +54,55 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, satoshis: null }; - function onLeave() { - angular.element($window).off('keydown'); + function initVariables() { + // Private variables + altCurrencyModal = null; + altUnitIndex = 0; + availableUnits = []; + canSendMax = true; + fiatCode; + isNW = platformInfo.isNW; + isAndroid = platformInfo.isAndroid; + isIos = platformInfo.isIOS; + lastUsedAltCurrencyList = []; + passthroughParams = {}; + satToUnit; + transactionSendableAmount = { + crypto: '', + satoshis: null + }; + unitDecimals; + unitIndex = 0; + unitToSatoshi; + useSendMax = false; + walletSpendableAmount = { + crypto: '', + satoshis: null + }; + + // Public variables + vm.allowSend = false; + vm.altCurrencyList = []; + vm.alternativeAmount = ''; + vm.alternativeUnit = ''; + vm.amount = '0'; + vm.availableFunds = ''; + vm.canSendAllAvailableFunds = true; + vm.errorMessage = ''; + // Use insufficient for logic, as when the amount is invalid, funds being + // either sufficent or insufficient doesn't make sense. + vm.fundsAreInsufficient = false; + vm.globalResult = ''; + vm.isRequestingSpecificAmount = false; + vm.listComplete = false; + vm.lastUsedPopularList = []; + vm.maxAmount = 0; + vm.minAmount = 0; + vm.sendableFunds = ''; + vm.showSendMaxButton = false; + vm.showSendLimitMaxButton = false; + vm.thirdParty = null; + vm.unit = ''; } function onBeforeEnter(event, data) { @@ -89,12 +111,15 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } - + // Init before entering on this screen + initVariables(); initCurrencies(); + // Then start passthroughParams = sendFlowService.state.getClone(); console.log('amount onBeforeEnter after back sendflow ', passthroughParams); + // Init thirdParty, should be done for all the variable vm.thirdParty = null; @@ -223,6 +248,10 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } } + function onLeave() { + angular.element($window).off('keydown'); + } + function goBack() { sendFlowService.router.goBack(); } diff --git a/src/js/controllers/review.controller.js b/src/js/controllers/review.controller.js index c4923a5f4..5352d609a 100644 --- a/src/js/controllers/review.controller.js +++ b/src/js/controllers/review.controller.js @@ -9,55 +9,6 @@ angular function reviewController(addressbookService, externalLinkService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, clipboardService, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, ionicToast, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, sendFlowService, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) { var vm = this; - vm.buttonText = ''; - vm.destination = { - address: '', - balanceAmount: '', - balanceCurrency: '', - coin: '', - color: '', - currency: '', - currencyColor: '', - kind: '', // 'address', 'contact', 'wallet' - name: '' - }; - vm.displayAddress = ''; - vm.feeCrypto = ''; - vm.feeFiat = ''; - vm.fiatCurrency = ''; - vm.feeIsHigh = false; - vm.feeLessThanACent = false; - vm.isCordova = platformInfo.isCordova; - vm.memo = ''; - vm.notReadyMessage = ''; - vm.origin = { - balanceAmount: '', - balanceCurrency: '', - currency: '', - currencyColor: '', - }; - vm.originWallet = null; - vm.paymentExpired = false; - vm.personalNotePlaceholder = gettextCatalog.getString('Enter text here'); - vm.primaryAmount = ''; - vm.primaryCurrency = ''; - vm.usingMerchantFee = false; - vm.readyToSend = false; - vm.remainingTimeStr = ''; - vm.secondaryAmount = ''; - vm.secondaryCurrency = ''; - vm.sendingTitle = gettextCatalog.getString('You are sending'); - vm.sendStatus = ''; - vm.showAddress = true; - vm.thirdParty = null; - vm.wallet = null; - vm.memoExpanded = false; - - // Functions - vm.goBack = goBack; - vm.onSuccessConfirm = onSuccessConfirm; - vm.onShareTransaction = onShareTransaction; - var sendFlowData; var config = null; var coin = ''; @@ -76,14 +27,85 @@ angular var unitFromSat = 0; var FEE_TOO_HIGH_LIMIT_PERCENTAGE = 15; + + // Functions + vm.goBack = goBack; + vm.onSuccessConfirm = onSuccessConfirm; + vm.onShareTransaction = onShareTransaction; + + function initVariables() { + // Private variables + sendFlowData; + config = null; + coin = ''; + countDown = null; + defaults = {}; + usingCustomFee = false; + usingMerchantFee = false; + destinationWalletId = ''; + lastTxId = ''; + originWalletId = ''; + priceDisplayIsFiat = true; + satoshis = null; + toAddress = ''; + tx = {}; + txPayproData = null; + unitFromSat = 0; + + // Public variables + vm.buttonText = ''; + vm.destination = { + address: '', + balanceAmount: '', + balanceCurrency: '', + coin: '', + color: '', + currency: '', + currencyColor: '', + kind: '', // 'address', 'contact', 'wallet' + name: '' + }; + vm.displayAddress = ''; + vm.feeCrypto = ''; + vm.feeFiat = ''; + vm.fiatCurrency = ''; + vm.feeIsHigh = false; + vm.feeLessThanACent = false; + vm.isCordova = platformInfo.isCordova; + vm.memo = ''; + vm.notReadyMessage = ''; + vm.origin = { + balanceAmount: '', + balanceCurrency: '', + currency: '', + currencyColor: '', + }; + vm.originWallet = null; + vm.paymentExpired = false; + vm.personalNotePlaceholder = gettextCatalog.getString('Enter text here'); + vm.primaryAmount = ''; + vm.primaryCurrency = ''; + vm.usingMerchantFee = false; + vm.readyToSend = false; + vm.remainingTimeStr = ''; + vm.secondaryAmount = ''; + vm.secondaryCurrency = ''; + vm.sendingTitle = gettextCatalog.getString('You are sending'); + vm.sendStatus = ''; + vm.showAddress = true; + vm.thirdParty = null; + vm.wallet = null; + vm.memoExpanded = false; + } $scope.$on("$ionicView.beforeEnter", onBeforeEnter); function onBeforeEnter(event, data) { $log.debug('reviewController onBeforeEnter sendflow ', sendFlowService.state); - // Reset from last time - vm.thirdParty = null; + // Init before entering on this screen + initVariables(); + // Then start defaults = configService.getDefaults(); sendFlowData = sendFlowService.state.getClone(); @@ -727,20 +749,7 @@ angular $timeout(function onTimeout() { $scope.$apply(); }, 10); - }); - - // setWalletSelector(tx.coin, tx.network, tx.amount, function(err) { - // if (err) { - // return exitWithError('Could not update wallets'); - // } - // - // if (vm.wallets.length > 1) { - // vm.showWalletSelector(); - // } else if (vm.wallets.length) { - // setWallet(vm.wallets[0], tx); - // } - // }); } function showSendMaxWarning(wallet, sendMaxInfo) { diff --git a/src/js/controllers/wallet-selector.controller.js b/src/js/controllers/wallet-selector.controller.js index 0ccb3bd1f..7a5cc2d87 100644 --- a/src/js/controllers/wallet-selector.controller.js +++ b/src/js/controllers/wallet-selector.controller.js @@ -12,6 +12,17 @@ angular var unitDecimals = 0; var unitsFromSatoshis = 0; + // + // Needs to migrate $scope to vm. + // + function initVariables() { + // Private variables + fromWalletId = ''; + priceDisplayAsFiat = false; + unitDecimals = 0; + unitsFromSatoshis = 0; + } + $scope.$on("$ionicView.beforeEnter", onBeforeEnter); $scope.$on("$ionicView.enter", onEnter); @@ -20,6 +31,10 @@ angular sendFlowService.state.pop(); } + // Init before entering on this screen + initVariables(); + // Then start + $scope.params = sendFlowService.state.getClone(); console.log('walletSelector onBeforeEnter after back sendflow', $scope.params); From 9a94bc2f498733a276807425a975478a5edffea7 Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Thu, 27 Sep 2018 13:31:48 +0200 Subject: [PATCH 2/2] Address without prefix not working bug fix. --- src/js/directives/incomingDataMenu.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/directives/incomingDataMenu.js b/src/js/directives/incomingDataMenu.js index 78856e62f..e093cb5e3 100644 --- a/src/js/directives/incomingDataMenu.js +++ b/src/js/directives/incomingDataMenu.js @@ -16,8 +16,8 @@ angular.module('copayApp.directives') scope.type = "url"; } else if (scope.data.parsed.publicAddress) { scope.type = "bitcoinAddress"; - var prefix = scope.data.parsed.isTestnet ? 'bchtest:' : 'bitcoincash:'; - scope.data.toAddress = (prefix + scope.data.parsed.publicAddress.cashAddr) || scope.data.parsed.publicAddress.legacy || scope.data.parsed.publicAddress.bitpay; + var prefix = scope.data.coin === 'bch' ? (scope.data.parsed.isTestnet ? 'bchtest:' : 'bitcoincash:') : ''; + scope.data.toAddress = (scope.data.parsed.publicAddress.cashAddr ? prefix + scope.data.parsed.publicAddress.cashAddr : false) || scope.data.parsed.publicAddress.legacy || scope.data.parsed.publicAddress.bitpay; } else { scope.type = "text"; }