Transfer page: validate amount

This commit is contained in:
Ilya Kitaev 2016-08-23 16:07:52 +03:00
parent 10c303770b
commit 4fa8ad3b19
6 changed files with 68 additions and 26 deletions

View File

@ -47,7 +47,10 @@ Item {
height: parent.height - 1
y: buttonArea.pressed ? 0 : 1
//radius: 4
color: buttonArea.pressed ? parent.shadowPressedColor : parent.shadowReleasedColor
color: {
parent.enabled ? (buttonArea.pressed ? parent.shadowPressedColor : parent.shadowReleasedColor)
: Qt.lighter(parent.shadowReleasedColor)
}
}
Rectangle {
@ -55,7 +58,11 @@ Item {
anchors.right: parent.right
height: parent.height - 1
y: buttonArea.pressed ? 1 : 0
color: buttonArea.pressed ? parent.pressedColor : parent.releasedColor
color: {
parent.enabled ? (buttonArea.pressed ? parent.pressedColor : parent.releasedColor)
: Qt.lighter(parent.releasedColor)
}
//radius: 4
}

View File

@ -114,7 +114,7 @@ int main(int argc, char *argv[])
QObject::connect(eventFilter, SIGNAL(mousePressed(QVariant,QVariant,QVariant)), rootObject, SLOT(mousePressed(QVariant,QVariant,QVariant)));
QObject::connect(eventFilter, SIGNAL(mouseReleased(QVariant,QVariant,QVariant)), rootObject, SLOT(mouseReleased(QVariant,QVariant,QVariant)));
WalletManager::instance()->setLogLevel(WalletManager::LogLevel_Max);
WalletManager::instance()->setLogLevel(WalletManager::LogLevel_Silent);
return app.exec();
}

View File

@ -135,7 +135,7 @@ ApplicationWindow {
}
middlePanel.paymentClicked.connect(handlePayment);
basicPanel.paymentClicked.connect(handlePayment);
// basicPanel.paymentClicked.connect(handlePayment);
// wallet already opened with wizard, we just need to initialize it
@ -240,10 +240,25 @@ ApplicationWindow {
", mixins: ", mixinCount,
", priority: ", priority);
var amountxmr = walletManager.amountFromString(amount);
// validate amount;
var amountxmr = walletManager.amountFromString(amount);
console.log("integer amount: ", amountxmr);
transaction = wallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority);
if (amountxmr <= 0) {
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())
+ translationManager.emptyString
informationPopup.icon = StandardIcon.Critical
informationPopup.onCloseCallback = null
informationPopup.open()
return;
}
// validate address;
transaction = currentWallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority);
if (transaction.status !== PendingTransaction.Status_Ok) {
console.error("Can't create transaction: ", transaction.errorString);
informationPopup.title = qsTr("Error") + translationManager.emptyString;
@ -252,7 +267,7 @@ ApplicationWindow {
informationPopup.onCloseCallback = null
informationPopup.open();
// deleting transaction object, we don't want memleaks
wallet.disposeTransaction(transaction);
currentWallet.disposeTransaction(transaction);
} else {
console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount)
@ -287,8 +302,8 @@ ApplicationWindow {
}
informationPopup.onCloseCallback = null
informationPopup.open()
wallet.refresh()
wallet.disposeTransaction(transaction)
currentWallet.refresh()
currentWallet.disposeTransaction(transaction)
}
// blocks UI if wallet can't be opened or no connection to the daemon

View File

@ -32,6 +32,7 @@ import "../components"
Rectangle {
id: root
signal paymentClicked(string address, string paymentId, double amount, int mixinCount,
int priority)
@ -88,6 +89,11 @@ Rectangle {
id: amountLine
placeholderText: qsTr("Amount...") + translationManager.emptyString
width: parent.width - 37 - 17
validator: DoubleValidator {
bottom: 0.0
notation: DoubleValidator.StandardNotation
locale: "C"
}
}
}
@ -170,7 +176,7 @@ Rectangle {
textFormat: Text.RichText
text: qsTr("<style type='text/css'>a {text-decoration: none; color: #FF6C3C; font-size: 14px;}</style>\
Address <font size='2'> ( Type in or select from </font> <a href='#'>Address</a><font size='2'> book )</font>")
+ translationManager.emptyString
+ translationManager.emptyString
onLinkActivated: appWindow.showPageRequest("AddressBook")
}
@ -220,7 +226,7 @@ Rectangle {
anchors.topMargin: 17
fontSize: 14
text: qsTr("Description <font size='2'>( An optional description that will be saved to the local address book if entered )</font>")
+ translationManager.emptyString
+ translationManager.emptyString
}
LineEdit {
@ -245,16 +251,15 @@ Rectangle {
shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C"
pressedColor: "#FF4304"
enabled : addressLine.text.length > 0 && amountLine.text.length > 0
onClicked: {
// do more smart validation
if (addressLine.text.length > 0 && amountLine.text.length > 0) {
console.log("paymentClicked")
var priority = priorityModel.get(priorityDropdown.currentIndex).priority
console.log("priority: " + priority)
paymentClicked(addressLine.text, paymentIdLine.text, amountLine.text, scaleValueToMixinCount(privacyLevelItem.fillLevel),
priority)
}
console.log("Transfer: paymentClicked")
var priority = priorityModel.get(priorityDropdown.currentIndex).priority
console.log("priority: " + priority)
console.log("amount: " + amountLine.text)
root.paymentClicked(addressLine.text, paymentIdLine.text, amountLine.text, scaleValueToMixinCount(privacyLevelItem.fillLevel),
priority)
}
}
}

View File

@ -122,17 +122,27 @@ QString WalletManager::walletLanguage(const QString &locale)
return "English";
}
QString WalletManager::displayAmount(quint64 amount)
quint64 WalletManager::maximumAllowedAmount() const
{
return Bitmonero::Wallet::maximumAllowedAmount();
}
QString WalletManager::maximumAllowedAmountAsSting() const
{
return WalletManager::displayAmount(WalletManager::maximumAllowedAmount());
}
QString WalletManager::displayAmount(quint64 amount) const
{
return QString::fromStdString(Bitmonero::Wallet::displayAmount(amount));
}
quint64 WalletManager::amountFromString(const QString &amount)
quint64 WalletManager::amountFromString(const QString &amount) const
{
return Bitmonero::Wallet::amountFromString(amount.toStdString());
}
quint64 WalletManager::amountFromDouble(double amount)
quint64 WalletManager::amountFromDouble(double amount) const
{
return Bitmonero::Wallet::amountFromDouble(amount);
}

View File

@ -12,6 +12,7 @@ namespace Bitmonero {
class WalletManager : public QObject
{
Q_OBJECT
public:
enum LogLevel {
LogLevel_Silent = Bitmonero::WalletManagerFactory::LogLevel_Silent,
@ -79,9 +80,13 @@ public:
//! since we can't call static method from QML, move it to this class
Q_INVOKABLE QString displayAmount(quint64 amount);
Q_INVOKABLE quint64 amountFromString(const QString &amount);
Q_INVOKABLE quint64 amountFromDouble(double amount);
Q_INVOKABLE QString displayAmount(quint64 amount) const;
Q_INVOKABLE quint64 amountFromString(const QString &amount) const;
Q_INVOKABLE quint64 amountFromDouble(double amount) const;
Q_INVOKABLE quint64 maximumAllowedAmount() const;
// QML JS engine doesn't support unsigned integers
Q_INVOKABLE QString maximumAllowedAmountAsSting() const;
void setLogLevel(int logLevel);