mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-22 19:49:34 +00:00
Merge pull request #3687
f327d20
qml: use libwalletqt make_uri function (selsta)dcc16a4
libwalletqt: add make_uri function (selsta)
This commit is contained in:
commit
96762ebf09
7 changed files with 24 additions and 35 deletions
|
@ -73,30 +73,3 @@ function isValidOpenAliasAddress(address) {
|
|||
// we can get an awful lot of valid domains, including non ASCII chars... accept anything
|
||||
return true
|
||||
}
|
||||
|
||||
function makeQRCodeString(addr, amount, txDescription, recipientName) {
|
||||
var XMR_URI_SCHEME = "monero:"
|
||||
var XMR_AMOUNT = "tx_amount"
|
||||
var XMR_RECIPIENT_NAME = "recipient_name"
|
||||
var XMR_TX_DESCRIPTION = "tx_description"
|
||||
var qrCodeString =""
|
||||
qrCodeString += (XMR_URI_SCHEME + addr)
|
||||
if (amount !== undefined && amount !== ""){
|
||||
qrCodeString += ("?" + XMR_AMOUNT + "=" + amount)
|
||||
}
|
||||
if (txDescription !== undefined && txDescription !== ""){
|
||||
if (amount == ""){
|
||||
qrCodeString += ("?" + XMR_TX_DESCRIPTION + "=" + encodeURI(txDescription))
|
||||
} else {
|
||||
qrCodeString += ("&" + XMR_TX_DESCRIPTION + "=" + encodeURI(txDescription))
|
||||
}
|
||||
}
|
||||
if (recipientName !== undefined && recipientName !== ""){
|
||||
if (amount == "" && txDescription == ""){
|
||||
qrCodeString += ("?" + XMR_RECIPIENT_NAME + "=" + encodeURI(recipientName))
|
||||
} else {
|
||||
qrCodeString += ("&" + XMR_RECIPIENT_NAME + "=" + encodeURI(recipientName))
|
||||
}
|
||||
}
|
||||
return qrCodeString
|
||||
}
|
||||
|
|
|
@ -63,12 +63,11 @@ Rectangle {
|
|||
|
||||
function generateQRCodeString() {
|
||||
if (pageReceive.state == "PaymentRequest") {
|
||||
return TxUtils.makeQRCodeString(appWindow.current_address,
|
||||
(amountToReceiveXMR.text != "" && parseFloat(amountToReceiveXMR.text) != 0 ? amountToReceiveXMR.text : ""),
|
||||
(txDescriptionInput.text != "" ? txDescriptionInput.text : ""),
|
||||
(receiverNameInput.text != "" ? receiverNameInput.text : ""));
|
||||
return walletManager.make_uri(appWindow.current_address,
|
||||
walletManager.amountFromString(amountToReceiveXMR.text),
|
||||
txDescriptionInput.text, receiverNameInput.text);
|
||||
} else {
|
||||
return TxUtils.makeQRCodeString(appWindow.current_address);
|
||||
return walletManager.make_uri(appWindow.current_address);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ Item {
|
|||
|
||||
smooth: false
|
||||
fillMode: Image.PreserveAspectFit
|
||||
source: "image://qrcode/" + TxUtils.makeQRCodeString(appWindow.current_address, amountToReceive.text)
|
||||
source: "image://qrcode/" + walletManager.make_uri(appWindow.current_address, walletManager.amountFromString(amountToReceive.text))
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
|
@ -400,7 +400,7 @@ Item {
|
|||
font.pixelSize: 12
|
||||
font.bold: true
|
||||
color: _color
|
||||
text: TxUtils.makeQRCodeString(appWindow.current_address, amountToReceive.text)
|
||||
text: walletManager.make_uri(appWindow.current_address, walletManager.amountFromString(amountToReceive.text))
|
||||
themeTransition: false
|
||||
|
||||
MouseArea {
|
||||
|
@ -685,7 +685,7 @@ Item {
|
|||
selectExisting: false
|
||||
nameFilters: ["Image (*.png)"]
|
||||
onAccepted: {
|
||||
if(!walletManager.saveQrCode(TxUtils.makeQRCodeString(appWindow.current_address, amountToReceive.text), walletManager.urlToLocalPath(fileUrl))) {
|
||||
if (!walletManager.saveQrCode(walletManager.make_uri(appWindow.current_address, walletManager.amountFromString(amountToReceive.text)), walletManager.urlToLocalPath(fileUrl))) {
|
||||
console.log("Failed to save QrCode to file " + walletManager.urlToLocalPath(fileUrl) )
|
||||
receivePageDialog.title = qsTr("Save QrCode") + translationManager.emptyString;
|
||||
receivePageDialog.text = qsTr("Failed to save QrCode to ") + walletManager.urlToLocalPath(fileUrl) + translationManager.emptyString;
|
||||
|
|
|
@ -933,6 +933,12 @@ bool Wallet::parse_uri(const QString &uri, QString &address, QString &payment_id
|
|||
return res;
|
||||
}
|
||||
|
||||
QString Wallet::make_uri(const QString &address, const quint64 &amount, const QString &tx_description, const QString &recipient_name) const
|
||||
{
|
||||
std::string error;
|
||||
return QString::fromStdString(m_walletImpl->make_uri(address.toStdString(), "", amount, tx_description.toStdString(), recipient_name.toStdString(), error));
|
||||
}
|
||||
|
||||
bool Wallet::rescanSpent()
|
||||
{
|
||||
QMutexLocker locker(&m_asyncMutex);
|
||||
|
|
|
@ -300,6 +300,8 @@ public:
|
|||
|
||||
//! Parse URI
|
||||
Q_INVOKABLE bool parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector<QString> &unknown_parameters, QString &error);
|
||||
//! Make URI
|
||||
Q_INVOKABLE QString make_uri(const QString &address, const quint64 &amount = 0, const QString &tx_description = "", const QString &recipient_name = "") const;
|
||||
|
||||
//! Namespace your cacheAttribute keys to avoid collisions
|
||||
Q_INVOKABLE bool setCacheAttribute(const QString &key, const QString &val);
|
||||
|
|
|
@ -441,6 +441,14 @@ QVariantMap WalletManager::parse_uri_to_object(const QString &uri) const
|
|||
return result;
|
||||
}
|
||||
|
||||
QString WalletManager::make_uri(const QString &address, const quint64 &amount, const QString &tx_description, const QString &recipient_name) const
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (m_currentWallet)
|
||||
return m_currentWallet->make_uri(address, amount, tx_description, recipient_name);
|
||||
return "";
|
||||
}
|
||||
|
||||
void WalletManager::setLogLevel(int logLevel)
|
||||
{
|
||||
Monero::WalletManagerFactory::setLogLevel(logLevel);
|
||||
|
|
|
@ -179,6 +179,7 @@ public:
|
|||
Q_INVOKABLE QString resolveOpenAlias(const QString &address) const;
|
||||
Q_INVOKABLE bool parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector<QString> &unknown_parameters, QString &error) const;
|
||||
Q_INVOKABLE QVariantMap parse_uri_to_object(const QString &uri) const;
|
||||
Q_INVOKABLE QString make_uri(const QString &address, const quint64 &amount = 0, const QString &tx_description = "", const QString &recipient_name = "") const;
|
||||
Q_INVOKABLE bool saveQrCode(const QString &, const QString &) const;
|
||||
Q_INVOKABLE void saveQrCodeToClipboard(const QString &) const;
|
||||
Q_INVOKABLE void checkUpdatesAsync(
|
||||
|
|
Loading…
Reference in a new issue