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