From d8b39f327fb5dfae45d29e726fd39c1f6cab6678 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Fri, 18 Dec 2020 01:26:58 +0800 Subject: [PATCH] fix transaction amount overflow bug --- src/views/mobile/transactions/Edit.vue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/views/mobile/transactions/Edit.vue b/src/views/mobile/transactions/Edit.vue index 054ede82..d1352f8e 100644 --- a/src/views/mobile/transactions/Edit.vue +++ b/src/views/mobile/transactions/Edit.vue @@ -251,11 +251,21 @@ export default { } if (sourceAccount && destinationAccount && sourceAccount.currency !== destinationAccount.currency) { - oldValue = Math.floor(this.$exchangeRates.getOtherCurrencyAmount(oldValue, sourceAccount.currency, destinationAccount.currency)); - newValue = Math.floor(this.$exchangeRates.getOtherCurrencyAmount(newValue, sourceAccount.currency, destinationAccount.currency)); + const exchangedOldValue = this.$exchangeRates.getOtherCurrencyAmount(oldValue, sourceAccount.currency, destinationAccount.currency); + const exchangedNewValue = this.$exchangeRates.getOtherCurrencyAmount(newValue, sourceAccount.currency, destinationAccount.currency); + + if (this.$utilities.isNumber(exchangedOldValue)) { + oldValue = Math.floor(exchangedOldValue); + } + + if (this.$utilities.isNumber(exchangedNewValue)) { + newValue = Math.floor(exchangedNewValue); + } } - if (!sourceAccount || !destinationAccount || this.transaction.destinationAmount === oldValue) { + if ((!sourceAccount || !destinationAccount || this.transaction.destinationAmount === oldValue) && + (this.$utilities.stringCurrencyToNumeric(this.$constants.transaction.minAmount) <= newValue && + newValue <= this.$utilities.stringCurrencyToNumeric(this.$constants.transaction.maxAmount))) { this.transaction.destinationAmount = newValue; } }