mirror of
https://github.com/monero-project/monero-gui
synced 2024-11-29 09:05:11 +01:00
Transfer: improve warning flow
This commit is contained in:
parent
46227bdad0
commit
a83adb70ad
19
main.qml
19
main.qml
@ -401,6 +401,13 @@ ApplicationWindow {
|
||||
return path.replace(/.*[\/\\]/, '').replace(/\.keys$/, '')
|
||||
}
|
||||
|
||||
function getUnlockedBalance() {
|
||||
if(!currentWallet){
|
||||
return 0
|
||||
}
|
||||
return currentWallet.unlockedBalance()
|
||||
}
|
||||
|
||||
function updateBalance() {
|
||||
if (!currentWallet)
|
||||
return;
|
||||
@ -408,8 +415,8 @@ ApplicationWindow {
|
||||
var balance = "?.??";
|
||||
var balanceU = "?.??";
|
||||
if(!hideBalanceForced && !persistentSettings.hideBalance){
|
||||
balance = walletManager.displayAmount(currentWallet.balance(currentWallet.currentSubaddressAccount));
|
||||
balanceU = walletManager.displayAmount(currentWallet.unlockedBalance(currentWallet.currentSubaddressAccount));
|
||||
balance = walletManager.displayAmount(currentWallet.balance());
|
||||
balanceU = walletManager.displayAmount(currentWallet.unlockedBalance());
|
||||
}
|
||||
|
||||
if (persistentSettings.fiatPriceEnabled) {
|
||||
@ -858,24 +865,24 @@ ApplicationWindow {
|
||||
if (amount !== "(all)") {
|
||||
var amountxmr = walletManager.amountFromString(amount);
|
||||
console.log("integer amount: ", amountxmr);
|
||||
console.log("integer unlocked",currentWallet.unlockedBalance)
|
||||
console.log("integer unlocked", currentWallet.unlockedBalance())
|
||||
if (amountxmr <= 0) {
|
||||
hideProcessingSplash()
|
||||
informationPopup.title = qsTr("Error") + translationManager.emptyString;
|
||||
informationPopup.text = qsTr("Amount is wrong: expected number from %1 to %2")
|
||||
.arg(walletManager.displayAmount(0))
|
||||
.arg(walletManager.maximumAllowedAmountAsSting())
|
||||
.arg(walletManager.displayAmount(currentWallet.unlockedBalance()))
|
||||
+ translationManager.emptyString
|
||||
|
||||
informationPopup.icon = StandardIcon.Critical
|
||||
informationPopup.onCloseCallback = null
|
||||
informationPopup.open()
|
||||
return;
|
||||
} else if (amountxmr > currentWallet.unlockedBalance) {
|
||||
} else if (amountxmr > currentWallet.unlockedBalance()) {
|
||||
hideProcessingSplash()
|
||||
informationPopup.title = qsTr("Error") + translationManager.emptyString;
|
||||
informationPopup.text = qsTr("Insufficient funds. Unlocked balance: %1")
|
||||
.arg(walletManager.displayAmount(currentWallet.unlockedBalance))
|
||||
.arg(walletManager.displayAmount(currentWallet.unlockedBalance()))
|
||||
+ translationManager.emptyString
|
||||
|
||||
informationPopup.icon = StandardIcon.Critical
|
||||
|
@ -193,6 +193,7 @@ Rectangle {
|
||||
amountLine.cursorPosition = 1;
|
||||
}
|
||||
}
|
||||
amountLine.error = walletManager.amountFromString(amountLine.text) > appWindow.getUnlockedBalance()
|
||||
}
|
||||
|
||||
validator: RegExpValidator {
|
||||
@ -444,22 +445,8 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
function checkInformation(amount, address, payment_id, nettype) {
|
||||
address = address.trim()
|
||||
payment_id = payment_id.trim()
|
||||
|
||||
var amount_ok = amount.length > 0
|
||||
var address_ok = walletManager.addressValid(address, nettype)
|
||||
var payment_id_ok = payment_id.length == 0 || (payment_id.length == 64 && walletManager.paymentIdValid(payment_id))
|
||||
var ipid = walletManager.paymentIdFromAddress(address, nettype)
|
||||
if (ipid.length > 0 && payment_id.length > 0)
|
||||
payment_id_ok = false
|
||||
|
||||
addressLine.error = !address_ok
|
||||
amountLine.error = !amount_ok
|
||||
paymentIdLine.error = !payment_id_ok
|
||||
|
||||
return amount_ok && address_ok && payment_id_ok
|
||||
function checkInformation(amount, address, nettype) {
|
||||
return amount.length > 0 && walletManager.amountFromString(amountLine.text) <= appWindow.getUnlockedBalance() && TxUtils.checkAddress(address, nettype)
|
||||
}
|
||||
|
||||
} // pageRoot
|
||||
@ -505,7 +492,7 @@ Rectangle {
|
||||
id: saveTxButton
|
||||
text: qsTr("Create tx file") + translationManager.emptyString
|
||||
visible: appWindow.viewOnly
|
||||
enabled: pageRoot.checkInformation(amountLine.text, addressLine.text, paymentIdLine.text, appWindow.persistentSettings.nettype)
|
||||
enabled: pageRoot.checkInformation(amountLine.text, addressLine.text, appWindow.persistentSettings.nettype)
|
||||
small: true
|
||||
onClicked: {
|
||||
console.log("Transfer: saveTx Clicked")
|
||||
@ -772,7 +759,7 @@ Rectangle {
|
||||
}
|
||||
|
||||
// There are sufficient unlocked funds available
|
||||
if(parseFloat(amountLine.text) > parseFloat(middlePanel.unlockedBalanceText)){
|
||||
if(walletManager.amountFromString(amountLine.text) > appWindow.getUnlockedBalance()){
|
||||
root.sendButtonWarning = qsTr("Amount is more than unlocked balance.") + translationManager.emptyString;
|
||||
return false;
|
||||
}
|
||||
@ -782,10 +769,19 @@ Rectangle {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The transactional information is correct
|
||||
if(!pageRoot.checkInformation(amountLine.text, addressLine.text, paymentIdLine.text, appWindow.persistentSettings.nettype)){
|
||||
if(amountLine.text && addressLine.text)
|
||||
root.sendButtonWarning = qsTr("Transaction information is incorrect.") + translationManager.emptyString;
|
||||
if (addressLine.text == "") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Address is valid
|
||||
if(!TxUtils.checkAddress(addressLine.text, appWindow.persistentSettings.nettype)){
|
||||
root.sendButtonWarning = qsTr("Address is invalid.") + translationManager.emptyString;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Amount is nonzero
|
||||
if (!amountLine.text || parseFloat(amountLine.text) <= 0) {
|
||||
root.sendButtonWarning = qsTr("Enter an amount.") + translationManager.emptyString;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -289,6 +289,11 @@ bool Wallet::viewOnly() const
|
||||
return m_walletImpl->watchOnly();
|
||||
}
|
||||
|
||||
quint64 Wallet::balance() const
|
||||
{
|
||||
return balance(m_currentSubaddressAccount);
|
||||
}
|
||||
|
||||
quint64 Wallet::balance(quint32 accountIndex) const
|
||||
{
|
||||
return m_walletImpl->balance(accountIndex);
|
||||
@ -299,6 +304,11 @@ quint64 Wallet::balanceAll() const
|
||||
return m_walletImpl->balanceAll();
|
||||
}
|
||||
|
||||
quint64 Wallet::unlockedBalance() const
|
||||
{
|
||||
return unlockedBalance(m_currentSubaddressAccount);
|
||||
}
|
||||
|
||||
quint64 Wallet::unlockedBalance(quint32 accountIndex) const
|
||||
{
|
||||
return m_walletImpl->unlockedBalance(accountIndex);
|
||||
|
@ -160,10 +160,12 @@ public:
|
||||
Q_INVOKABLE void setTrustedDaemon(bool arg);
|
||||
|
||||
//! returns balance
|
||||
Q_INVOKABLE quint64 balance() const;
|
||||
Q_INVOKABLE quint64 balance(quint32 accountIndex) const;
|
||||
Q_INVOKABLE quint64 balanceAll() const;
|
||||
|
||||
//! returns unlocked balance
|
||||
Q_INVOKABLE quint64 unlockedBalance() const;
|
||||
Q_INVOKABLE quint64 unlockedBalance(quint32 accountIndex) const;
|
||||
Q_INVOKABLE quint64 unlockedBalanceAll() const;
|
||||
|
||||
|
@ -260,7 +260,7 @@ quint64 WalletManager::maximumAllowedAmount() const
|
||||
return Monero::Wallet::maximumAllowedAmount();
|
||||
}
|
||||
|
||||
QString WalletManager::maximumAllowedAmountAsSting() const
|
||||
QString WalletManager::maximumAllowedAmountAsString() const
|
||||
{
|
||||
return WalletManager::displayAmount(WalletManager::maximumAllowedAmount());
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public:
|
||||
Q_INVOKABLE quint64 maximumAllowedAmount() const;
|
||||
|
||||
// QML JS engine doesn't support unsigned integers
|
||||
Q_INVOKABLE QString maximumAllowedAmountAsSting() const;
|
||||
Q_INVOKABLE QString maximumAllowedAmountAsString() const;
|
||||
|
||||
Q_INVOKABLE bool paymentIdValid(const QString &payment_id) const;
|
||||
Q_INVOKABLE bool addressValid(const QString &address, NetworkType::Type nettype) const;
|
||||
|
Loading…
Reference in New Issue
Block a user