mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-21 20:09:37 +00:00
feat(@dekstop/wallet) use user input resolution for Send/Bridge modals
Fixes #9459
This commit is contained in:
parent
ed1a0d04a0
commit
fa1c3beb25
@ -50,22 +50,38 @@ QtObject {
|
||||
return NaN
|
||||
}
|
||||
|
||||
// Parse options
|
||||
var optShowOnlyAmount = false
|
||||
var optDisplayDecimals = currencyAmount.displayDecimals
|
||||
var optStripTrailingZeroes = currencyAmount.stripTrailingZeroes
|
||||
if (options) {
|
||||
if (options.onlyAmount !== undefined) {
|
||||
optShowOnlyAmount = true
|
||||
}
|
||||
if (options.minDecimals !== undefined && options.minDecimals > optDisplayDecimals) {
|
||||
optDisplayDecimals = options.minDecimals
|
||||
}
|
||||
if (options.stripTrailingZeroes !== undefined) {
|
||||
optStripTrailingZeroes = options.stripTrailingZeroes
|
||||
}
|
||||
}
|
||||
|
||||
var amountStr
|
||||
let minAmount = 10**-currencyAmount.displayDecimals
|
||||
if (currencyAmount.amount > 0 && currencyAmount.amount < minAmount && !(options && options.onlyAmount))
|
||||
let minAmount = 10**-optDisplayDecimals
|
||||
if (currencyAmount.amount > 0 && currencyAmount.amount < minAmount && !optShowOnlyAmount)
|
||||
{
|
||||
// Handle amounts smaller than resolution
|
||||
amountStr = "<%1".arg(numberToLocaleString(minAmount, currencyAmount.displayDecimals, locale))
|
||||
amountStr = "<%1".arg(numberToLocaleString(minAmount, optDisplayDecimals, locale))
|
||||
} else {
|
||||
// Normal formatting
|
||||
amountStr = numberToLocaleString(currencyAmount.amount, currencyAmount.displayDecimals, locale)
|
||||
if (currencyAmount.stripTrailingZeroes) {
|
||||
amountStr = numberToLocaleString(currencyAmount.amount, optDisplayDecimals, locale)
|
||||
if (optStripTrailingZeroes) {
|
||||
amountStr = stripTrailingZeroes(amountStr, locale)
|
||||
}
|
||||
}
|
||||
|
||||
// Add symbol
|
||||
if (currencyAmount.symbol && !(options && options.onlyAmount)) {
|
||||
if (currencyAmount.symbol && !optShowOnlyAmount) {
|
||||
amountStr = "%1 %2".arg(amountStr).arg(currencyAmount.symbol)
|
||||
}
|
||||
|
||||
|
@ -298,6 +298,8 @@ StatusDialog {
|
||||
isBridgeTx: popup.isBridgeTx
|
||||
cryptoValueToReceive: d.totalAmountToReceive
|
||||
inputIsFiat: amountToSendInput.inputIsFiat
|
||||
minCryptoDecimals: amountToSendInput.minReceiveCryptoDecimals
|
||||
minFiatDecimals: amountToSendInput.minReceiveFiatDecimals
|
||||
currentCurrency: popup.store.currentCurrency
|
||||
getFiatValue: function(cryptoValue) {
|
||||
return popup.currencyStore.getFiatValue(cryptoValue, selectedSymbol, currentCurrency)
|
||||
@ -445,6 +447,8 @@ StatusDialog {
|
||||
selectedAccount: popup.selectedAccount
|
||||
ensAddressOrEmpty: d.isENSValid ? d.resolvedENSAddress : ""
|
||||
amountToSend: amountToSendInput.cryptoValueToSend
|
||||
minSendCryptoDecimals: amountToSendInput.minSendCryptoDecimals
|
||||
minReceiveCryptoDecimals: amountToSendInput.minReceiveCryptoDecimals
|
||||
requiredGasInEth: d.totalFeesInEth
|
||||
selectedAsset: assetSelector.selectedAsset
|
||||
onReCalculateSuggestedRoute: popup.recalculateRoutesAndFees()
|
||||
|
@ -17,6 +17,8 @@ ColumnLayout {
|
||||
property bool isBridgeTx: false
|
||||
property bool inputIsFiat: false
|
||||
property string currentCurrency
|
||||
property int minCryptoDecimals: 0
|
||||
property int minFiatDecimals: 0
|
||||
property var getFiatValue: function(cryptoValue) {}
|
||||
property var formatCurrencyAmount: function() {}
|
||||
|
||||
@ -26,12 +28,12 @@ ColumnLayout {
|
||||
if(!root.selectedSymbol || !cryptoValueToReceive)
|
||||
return LocaleUtils.numberToLocaleString(0, 2)
|
||||
let fiatValue = root.getFiatValue(cryptoValueToReceive, root.selectedSymbol, root.currentCurrency)
|
||||
return root.formatCurrencyAmount(fiatValue, root.currentCurrency)
|
||||
return root.formatCurrencyAmount(fiatValue, root.currentCurrency, inputIsFiat ? {"minDecimals": root.minFiatDecimals, "stripTrailingZeroes": true} : {})
|
||||
}
|
||||
readonly property string cryptoValue: {
|
||||
if(!root.selectedSymbol || !cryptoValueToReceive)
|
||||
return LocaleUtils.numberToLocaleString(0, 2)
|
||||
return root.formatCurrencyAmount(cryptoValueToReceive, root.selectedSymbol)
|
||||
return root.formatCurrencyAmount(cryptoValueToReceive, root.selectedSymbol, !inputIsFiat ? {"minDecimals": root.minCryptoDecimals, "stripTrailingZeroes": true} : {})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,10 @@ ColumnLayout {
|
||||
|
||||
property alias input: topAmountToSendInput
|
||||
readonly property double inputNumber: topAmountToSendInput.text ? LocaleUtils.numberFromLocaleString(topAmountToSendInput.text) : 0
|
||||
readonly property int minSendCryptoDecimals: !inputIsFiat ? LocaleUtils.fractionalPartLength(inputNumber) : 0
|
||||
readonly property int minReceiveCryptoDecimals: !inputIsFiat ? minSendCryptoDecimals + 1 : 0
|
||||
readonly property int minSendFiatDecimals: inputIsFiat ? LocaleUtils.fractionalPartLength(inputNumber) : 0
|
||||
readonly property int minReceiveFiatDecimals: inputIsFiat ? minSendFiatDecimals + 1 : 0
|
||||
|
||||
property string selectedSymbol
|
||||
property bool isBridgeTx: false
|
||||
|
@ -1,4 +1,4 @@
|
||||
import QtQuick 2.13
|
||||
import QtQuick 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
|
||||
import utils 1.0
|
||||
@ -25,6 +25,8 @@ Item {
|
||||
property var allNetworks
|
||||
property bool customMode: false
|
||||
property double amountToSend
|
||||
property int minSendCryptoDecimals: 0
|
||||
property int minReceiveCryptoDecimals: 0
|
||||
property double requiredGasInEth
|
||||
property bool errorMode: d.customAmountToSend > root.amountToSend
|
||||
property bool interactive: true
|
||||
@ -101,7 +103,7 @@ Item {
|
||||
|
||||
primaryText: model.chainName
|
||||
secondaryText: (tokenBalanceOnChain == 0 && root.amountToSend > 0) ?
|
||||
qsTr("No Balance") : !hasGas ? qsTr("No Gas") : root.currencyStore.formatCurrencyAmount(advancedInputCurrencyAmount, root.selectedSymbol)
|
||||
qsTr("No Balance") : !hasGas ? qsTr("No Gas") : root.currencyStore.formatCurrencyAmount(advancedInputCurrencyAmount, root.selectedSymbol, {"minDecimals": root.minSendCryptoDecimals})
|
||||
tertiaryText: root.errorMode && advancedInputCurrencyAmount > 0 ? qsTr("EXCEEDS SEND AMOUNT"): qsTr("BALANCE: ") + root.currencyStore.formatCurrencyAmount(tokenBalanceOnChain, root.selectedSymbol)
|
||||
locked: store.lockedInAmounts.findIndex(lockedItem => lockedItem !== undefined && lockedItem.chainID === model.chainId) !== -1
|
||||
preCalculatedAdvancedText: {
|
||||
@ -191,7 +193,7 @@ Item {
|
||||
property var preferredChains: store.preferredChainIds
|
||||
property bool preferred: store.preferredChainIds.includes(model.chainId)
|
||||
primaryText: model.chainName
|
||||
secondaryText: root.currencyStore.formatCurrencyAmount(amountToReceive, root.selectedSymbol)
|
||||
secondaryText: root.currencyStore.formatCurrencyAmount(amountToReceive, root.selectedSymbol, {"minDecimals": root.minReceiveCryptoDecimals})
|
||||
tertiaryText: state === "unpreferred" ? qsTr("UNPREFERRED") : ""
|
||||
state: !preferred ? "unpreferred" : "default"
|
||||
opacity: preferred || showPreferredChains ? 1 : 0
|
||||
|
@ -1,4 +1,4 @@
|
||||
import QtQuick 2.13
|
||||
import QtQuick 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
|
||||
import utils 1.0
|
||||
@ -23,6 +23,8 @@ Item {
|
||||
property string ensAddressOrEmpty: ""
|
||||
property var selectedAsset
|
||||
property var amountToSend
|
||||
property int minSendCryptoDecimals: 0
|
||||
property int minReceiveCryptoDecimals: 0
|
||||
property var requiredGasInEth
|
||||
property var bestRoutes
|
||||
property bool isLoading: false
|
||||
@ -79,6 +81,7 @@ Item {
|
||||
bestRoutes: root.bestRoutes
|
||||
isBridgeTx: root.isBridgeTx
|
||||
amountToSend: root.amountToSend
|
||||
minReceiveCryptoDecimals: root.minReceiveCryptoDecimals
|
||||
isLoading: root.isLoading
|
||||
store: root.store
|
||||
selectedAsset: root.selectedAsset
|
||||
@ -111,6 +114,8 @@ Item {
|
||||
ensAddressOrEmpty: root.ensAddressOrEmpty
|
||||
amountToSend: root.amountToSend
|
||||
requiredGasInEth: root.requiredGasInEth
|
||||
minSendCryptoDecimals: root.minSendCryptoDecimals
|
||||
minReceiveCryptoDecimals: root.minReceiveCryptoDecimals
|
||||
selectedAsset: root.selectedAsset
|
||||
onReCalculateSuggestedRoute: root.reCalculateSuggestedRoute()
|
||||
bestRoutes: root.bestRoutes
|
||||
|
@ -1,4 +1,4 @@
|
||||
import QtQuick 2.13
|
||||
import QtQuick 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
|
||||
import utils 1.0
|
||||
@ -18,6 +18,8 @@ ColumnLayout {
|
||||
property var selectedAccount
|
||||
property string ensAddressOrEmpty: ""
|
||||
property double amountToSend
|
||||
property int minSendCryptoDecimals: 0
|
||||
property int minReceiveCryptoDecimals: 0
|
||||
property double requiredGasInEth
|
||||
property bool customMode: false
|
||||
property var selectedAsset
|
||||
@ -86,6 +88,8 @@ ColumnLayout {
|
||||
ensAddressOrEmpty: root.ensAddressOrEmpty
|
||||
allNetworks: root.store.allNetworks
|
||||
amountToSend: root.amountToSend
|
||||
minSendCryptoDecimals: root.minSendCryptoDecimals
|
||||
minReceiveCryptoDecimals: root.minReceiveCryptoDecimals
|
||||
customMode: root.customMode
|
||||
requiredGasInEth: root.requiredGasInEth
|
||||
selectedAsset: root.selectedAsset
|
||||
|
@ -1,4 +1,4 @@
|
||||
import QtQuick 2.13
|
||||
import QtQuick 2.13
|
||||
import QtQuick.Controls 2.13
|
||||
import QtQuick.Layouts 1.13
|
||||
|
||||
@ -18,6 +18,7 @@ RowLayout {
|
||||
property var store
|
||||
property var bestRoutes
|
||||
property double amountToSend
|
||||
property int minReceiveCryptoDecimals: 0
|
||||
property bool isLoading: false
|
||||
property bool isBridgeTx: false
|
||||
property var selectedAsset
|
||||
@ -107,7 +108,7 @@ RowLayout {
|
||||
else {
|
||||
amountOut = root.weiToEth(parseInt(store.lockedInAmounts[index].value, 16))
|
||||
}
|
||||
return root.formatCurrencyAmount(amountOut, selectedAsset.symbol)
|
||||
return root.formatCurrencyAmount(amountOut, selectedAsset.symbol, {"minDecimals": root.minReceiveCryptoDecimals})
|
||||
}
|
||||
statusListItemSubTitle.color: root.errorMode ? Theme.palette.dangerColor1 : Theme.palette.primaryColor1
|
||||
asset.width: 32
|
||||
|
Loading…
x
Reference in New Issue
Block a user