Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transfer: paste Payment URL to fill the payment form fields #1768

Merged
merged 1 commit into from
Dec 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clipboardAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ void clipboardAdapter::setText(const QString &text) {
m_pClipboard->setText(text, QClipboard::Clipboard);
m_pClipboard->setText(text, QClipboard::Selection);
}

QString clipboardAdapter::text() const {
return m_pClipboard->text();
}
1 change: 1 addition & 0 deletions clipboardAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class clipboardAdapter : public QObject
public:
explicit clipboardAdapter(QObject *parent = 0);
Q_INVOKABLE void setText(const QString &text);
Q_INVOKABLE QString text() const;

private:
QClipboard *m_pClipboard;
Expand Down
46 changes: 30 additions & 16 deletions components/LineEditMulti.qml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ ColumnLayout {
property bool mouseSelection: true
property alias readOnly: input.readOnly
property bool copyButton: false
property bool pasteButton: false
property var onPaste: function(clipboardText) {
item.text = clipboardText;
}
property bool showingHeader: true
property var wrapMode: Text.NoWrap
property alias addressValidation: input.addressValidation
Expand Down Expand Up @@ -109,25 +113,35 @@ ColumnLayout {
}
}

MoneroComponents.LabelButton {
id: labelButton
onClicked: labelButtonClicked()
visible: labelButtonVisible
}
RowLayout {
anchors.right: parent.right
spacing: 16 * scaleRatio

MoneroComponents.LabelButton {
id: labelButton
onClicked: labelButtonClicked()
visible: labelButtonVisible
}

MoneroComponents.LabelButton {
id: copyButtonId
visible: copyButton && input.text !== ""
text: qsTr("Copy")
anchors.right: labelButton.visible ? inputLabel.right : parent.right
anchors.rightMargin: labelButton.visible? 4 : 0
onClicked: {
if (input.text.length > 0) {
console.log("Copied to clipboard");
clipboard.setText(input.text);
appWindow.showStatusMessage(qsTr("Copied to clipboard"), 3);
MoneroComponents.LabelButton {
id: copyButtonId
visible: copyButton && input.text !== ""
text: qsTr("Copy")
onClicked: {
if (input.text.length > 0) {
console.log("Copied to clipboard");
clipboard.setText(input.text);
appWindow.showStatusMessage(qsTr("Copied to clipboard"), 3);
}
}
}

MoneroComponents.LabelButton {
id: pasteButtonId
onClicked: item.onPaste(clipboard.text())
text: qsTr("Paste")
visible: pasteButton
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions pages/Transfer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ Rectangle {
wrapMode: Text.WrapAnywhere
addressValidation: true
onInputLabelLinkActivated: { appWindow.showPageRequest("AddressBook") }
pasteButton: true
onPaste: function(clipboardText) {
const parsed = walletManager.parse_uri_to_object(clipboardText);
if (!parsed.error) {
addressLine.text = parsed.address;
paymentIdLine.text = parsed.payment_id;
amountLine.text = parsed.amount;
descriptionLine.text = parsed.tx_description;
} else {
addressLine.text = clipboardText;
}
}
}

StandardButton {
Expand Down
26 changes: 25 additions & 1 deletion src/libwalletqt/WalletManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,37 @@ QString WalletManager::resolveOpenAlias(const QString &address) const
res = std::string(dnssec_valid ? "true" : "false") + "|" + res;
return QString::fromStdString(res);
}
bool WalletManager::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)
bool WalletManager::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
{
if (m_currentWallet)
return m_currentWallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
return false;
}

QVariantMap WalletManager::parse_uri_to_object(const QString &uri) const
{
QString address;
QString payment_id;
uint64_t amount;
QString tx_description;
QString recipient_name;
QVector<QString> unknown_parameters;
QString error;

QVariantMap result;
if (this->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error)) {
result.insert("address", address);
result.insert("payment_id", payment_id);
result.insert("amount", this->displayAmount(amount));
result.insert("tx_description", tx_description);
result.insert("recipient_name", recipient_name);
} else {
result.insert("error", error);
}

return result;
}

void WalletManager::setLogLevel(int logLevel)
{
Monero::WalletManagerFactory::setLogLevel(logLevel);
Expand Down
4 changes: 3 additions & 1 deletion src/libwalletqt/WalletManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef WALLETMANAGER_H
#define WALLETMANAGER_H

#include <QVariant>
#include <QObject>
#include <QUrl>
#include <wallet/api/wallet2_api.h>
Expand Down Expand Up @@ -141,7 +142,8 @@ class WalletManager : public QObject
#endif

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);
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 bool saveQrCode(const QString &, const QString &) const;
Q_INVOKABLE void checkUpdatesAsync(const QString &software, const QString &subdir) const;
Q_INVOKABLE QString checkUpdates(const QString &software, const QString &subdir) const;
Expand Down