Merge pull request #367 from Bitcoin-com/wallet/task/546

Fix - Init variable when enter in the screens (send flow)
This commit is contained in:
Jean-Baptiste Dominguez 2018-09-28 00:32:47 +02:00 committed by GitHub
commit 21f89a2f62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 148 additions and 95 deletions

View file

@ -9,30 +9,6 @@ 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;
@ -47,7 +23,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
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();
}

View file

@ -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 = '';
@ -77,13 +28,84 @@ angular
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) {

View file

@ -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);

View file

@ -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";
}