#36 - Format decimals properly

This commit is contained in:
adityapk00
2018-11-10 08:56:15 -08:00
parent 1b3c06f1a5
commit 13d48f80ca
3 changed files with 14 additions and 19 deletions

View File

@@ -567,24 +567,13 @@ void MainWindow::sendButton() {
}
QString MainWindow::doSendTxValidations(Tx tx) {
// 1. Addresses have valid format.
QRegExp zcexp("^z[a-z0-9]{94}$", Qt::CaseInsensitive);
QRegExp zsexp("^z[a-z0-9]{77}$", Qt::CaseInsensitive);
QRegExp ztsexp("^ztestsapling[a-z0-9]{76}", Qt::CaseInsensitive);
QRegExp texp("^t[a-z0-9]{34}$", Qt::CaseInsensitive);
auto matchesAnyAddr = [&] (QString addr) {
return zcexp.exactMatch(addr) ||
texp.exactMatch(addr) ||
ztsexp.exactMatch(addr) ||
zsexp.exactMatch(addr);
};
if (!matchesAnyAddr(tx.fromAddr)) return QString("From Address is Invalid");
if (!Settings::isValidAddress(tx.fromAddr)) return QString("From Address is Invalid");
for (auto toAddr : tx.toAddrs) {
if (!matchesAnyAddr(toAddr.addr))
return QString("Recipient Address ") % toAddr.addr.left(100) % " is Invalid";
if (!Settings::isValidAddress(toAddr.addr)) {
QString addr = (toAddr.addr.length() > 100 ? toAddr.addr.left(100) + "..." : toAddr.addr);
return QString("Recipient Address ") % addr % " is Invalid";
}
}
return QString();

View File

@@ -110,7 +110,13 @@ QString Settings::getUSDFormat(double bal) {
}
QString Settings::getZECDisplayFormat(double bal) {
return QString::number(bal, 'g', 8) % " " % Settings::getTokenName();
// This is idiotic. Why doesn't QString have a way to do this?
QString f = QString::number(bal, 'f', 8);
while (f.contains(".") && (f.right(1) == "0" || f.right(1) == ".")) {
f = f.left(f.length() - 1);
}
return f % " " % Settings::getTokenName();
}
QString Settings::getZECUSDDisplayFormat(double bal) {

View File

@@ -71,7 +71,7 @@ public:
static QString getZboardAddr();
static double getDevFee();
static double getTotalFee();
static bool isValidAddress(QString addr);
static const int updateSpeed = 20 * 1000; // 20 sec
@@ -81,7 +81,7 @@ public:
private:
// This class can only be accessed through Settings::getInstance()
Settings() = default;
~Settings();
~Settings() = default;
static Settings* instance;