diff --git a/libs/Wallet/CMakeLists.txt b/libs/Wallet/CMakeLists.txt index 5c1bfae536..088c3d65f1 100644 --- a/libs/Wallet/CMakeLists.txt +++ b/libs/Wallet/CMakeLists.txt @@ -23,7 +23,8 @@ qt6_add_qml_module(Wallet qml/Status/Wallet/AssetView.qml qml/Status/Wallet/WalletContentView.qml qml/Status/Wallet/WalletView.qml - qml/Status/Wallet/SavedAddressesView.qml + qml/Status/Wallet/SavedAddresses/SavedAddressesView.qml + qml/Status/Wallet/SavedAddresses/AddSavedAddressesView.qml # Required to suppress "qmllint may not work" warning OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Status/Wallet/ @@ -80,6 +81,8 @@ target_sources(Wallet src/WalletAsset.cpp include/Status/Wallet/WalletController.h src/WalletController.cpp + include/Status/Wallet/SavedAddress.h + src/SavedAddress.cpp include/Status/Wallet/SavedAddressesController.h src/SavedAddressesController.cpp ) diff --git a/libs/Wallet/include/Status/Wallet/SavedAddress.h b/libs/Wallet/include/Status/Wallet/SavedAddress.h new file mode 100644 index 0000000000..3c4d8d9504 --- /dev/null +++ b/libs/Wallet/include/Status/Wallet/SavedAddress.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace Status::Wallet +{ +class SavedAddress : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_UNCREATABLE("C++ only") + + Q_PROPERTY(QString address READ address CONSTANT) + Q_PROPERTY(QString name READ name CONSTANT) + +public: + SavedAddress(const QString& address = QString(), const QString& name = QString(), QObject *parent = nullptr); + + const QString& address() const; + const QString& name() const; + +private: + const QString m_address; + const QString m_name; +}; +} diff --git a/libs/Wallet/include/Status/Wallet/SavedAddressesController.h b/libs/Wallet/include/Status/Wallet/SavedAddressesController.h index 6de1629453..408c4c3d7e 100644 --- a/libs/Wallet/include/Status/Wallet/SavedAddressesController.h +++ b/libs/Wallet/include/Status/Wallet/SavedAddressesController.h @@ -2,6 +2,10 @@ #include +#include + +#include "SavedAddress.h" + namespace Status::Wallet { @@ -11,8 +15,30 @@ class SavedAddressesController : public QObject QML_ELEMENT QML_UNCREATABLE("C++ only") + Q_PROPERTY(QAbstractListModel* savedAddresses READ savedAddresses CONSTANT) + public: + enum Error + { + NoneError, + UnknownAddressError, + AddressAlreadyPresentError + }; + Q_ENUM(Error) + SavedAddressesController(QObject* parent = nullptr); + + QAbstractListModel* savedAddresses() const; + + Q_INVOKABLE void saveAddress(const QString& address, const QString& name); + // Q_INVOKABLE void removeAddress(const QString& address); + +signals: + void error(Status::Wallet::SavedAddressesController::Error error); + +private: + using SavedAddressesModel = Helpers::QObjectVectorModel; + std::shared_ptr m_savedAddresses; }; } // namespace Status::Wallet diff --git a/libs/Wallet/include/Status/Wallet/WalletController.h b/libs/Wallet/include/Status/Wallet/WalletController.h index b652d3ce08..ddd1e9c5e4 100644 --- a/libs/Wallet/include/Status/Wallet/WalletController.h +++ b/libs/Wallet/include/Status/Wallet/WalletController.h @@ -1,7 +1,6 @@ #pragma once #include "Status/Wallet/WalletAccount.h" -#include "Status/Wallet/DerivedWalletAddress.h" #include @@ -16,6 +15,7 @@ namespace Status::Wallet { class NewWalletAccountController; class AccountAssetsController; +class SavedAddressesController; /// \todo move account creation to its own controller class WalletController: public QObject @@ -38,6 +38,7 @@ public: /// \todo consider if complex approach of keeping ownership here and enforcing a unique instance /// or not reusing the account list and make it singleton are better options Q_INVOKABLE [[nodiscard]] Status::Wallet::NewWalletAccountController* createNewWalletAccountController() const; + Q_INVOKABLE [[nodiscard]] Status::Wallet::SavedAddressesController* createSavedAddressesController() const; QAbstractListModel *accountsModel() const; diff --git a/libs/Wallet/qml/Status/Wallet/SavedAddresses/AddSavedAddressesView.qml b/libs/Wallet/qml/Status/Wallet/SavedAddresses/AddSavedAddressesView.qml new file mode 100644 index 0000000000..4f4971629a --- /dev/null +++ b/libs/Wallet/qml/Status/Wallet/SavedAddresses/AddSavedAddressesView.qml @@ -0,0 +1,38 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +import Status.Wallet +import Status.Containers + +Popup { + id: root + + required property SavedAddressesController savedAddressesController + + GridLayout { + anchors.fill: parent + columns: 2 + + Label { text: qsTr("Address") ; Layout.fillWidth: true } + TextField { + id: addressFiled + } + + Label { text: qsTr("Name") ; Layout.fillWidth: true } + TextField { + id: nameFiled + } + + Button { + text: qsTr("Confirm") + enabled: addressFiled.text.length && nameFiled.text.length + onClicked: { + savedAddressesController.saveAddress(addressFiled.text, nameFiled.text); + root.close(); + } + GridLayout.columnSpan: 2 + Layout.fillWidth: true + } + } +} diff --git a/libs/Wallet/qml/Status/Wallet/SavedAddresses/SavedAddressesView.qml b/libs/Wallet/qml/Status/Wallet/SavedAddresses/SavedAddressesView.qml new file mode 100644 index 0000000000..27829c3d2c --- /dev/null +++ b/libs/Wallet/qml/Status/Wallet/SavedAddresses/SavedAddressesView.qml @@ -0,0 +1,46 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +import Status.Wallet +import Status.Containers + +Item { + id: root + + required property SavedAddressesController savedAddressesController + + ListView { + id: list + anchors.fill: parent + model: SavedAddressesController.savedAddresses + + delegate: RowLayout { + width: list.width + spacing: 0 + + Label { + text: savedAddress.address + Layout.fillWidth: true + } + + Label { + text: savedAddress.name + Layout.fillWidth: true + } + } + } + + RoundButton { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + text: "+" + onClicked: addView.open() + + AddSavedAddressesView { + id: addView + y: parent.height - height + savedAddressesController: root.savedAddressesController + } + } +} diff --git a/libs/Wallet/qml/Status/Wallet/SavedAddressesView.qml b/libs/Wallet/qml/Status/Wallet/SavedAddressesView.qml deleted file mode 100644 index 39143cdf49..0000000000 --- a/libs/Wallet/qml/Status/Wallet/SavedAddressesView.qml +++ /dev/null @@ -1,11 +0,0 @@ -import QtQuick -import QtQuick.Controls -import QtQuick.Layouts - -import Status.Wallet -import Status.Containers - -Item { - id: root - -} diff --git a/libs/Wallet/qml/Status/Wallet/WalletContentView.qml b/libs/Wallet/qml/Status/Wallet/WalletContentView.qml index 4ec89a8e0a..684b17827b 100644 --- a/libs/Wallet/qml/Status/Wallet/WalletContentView.qml +++ b/libs/Wallet/qml/Status/Wallet/WalletContentView.qml @@ -5,11 +5,14 @@ import QtQml.Models import Status.Wallet +import "SavedAddresses" + Item { id: root required property WalletAccount account required property AccountAssetsController assetController + required property SavedAddressesController savedAddressesController ColumnLayout { anchors.fill: parent @@ -76,7 +79,7 @@ Item { Loader { active: SwipeView.isCurrentItem sourceComponent: SavedAddressesView { - + savedAddressesController: root.savedAddressesController } } } diff --git a/libs/Wallet/qml/Status/Wallet/WalletView.qml b/libs/Wallet/qml/Status/Wallet/WalletView.qml index 3e6bb2bd6e..225910c1a4 100644 --- a/libs/Wallet/qml/Status/Wallet/WalletView.qml +++ b/libs/Wallet/qml/Status/Wallet/WalletView.qml @@ -38,6 +38,7 @@ PanelAndContentBase { account: WalletController.currentAccount assetController: panel.currentAssetController + savedAddressesController: WalletController.createSavedAddressesController() } } } diff --git a/libs/Wallet/src/SavedAddress.cpp b/libs/Wallet/src/SavedAddress.cpp new file mode 100644 index 0000000000..e72a25a113 --- /dev/null +++ b/libs/Wallet/src/SavedAddress.cpp @@ -0,0 +1,23 @@ +#include "Status/Wallet/SavedAddress.h" + +namespace Status::Wallet +{ + +SavedAddress::SavedAddress(const QString& address, const QString& name, QObject *parent) + : QObject(parent) + , m_address(address) + , m_name(name) +{ +} + +const QString& SavedAddress::address() const +{ + return m_address; +} + +const QString& SavedAddress::name() const +{ + return m_name; +} + +} diff --git a/libs/Wallet/src/SavedAddressesController.cpp b/libs/Wallet/src/SavedAddressesController.cpp index 4bbafc96d3..c09806bfe1 100644 --- a/libs/Wallet/src/SavedAddressesController.cpp +++ b/libs/Wallet/src/SavedAddressesController.cpp @@ -1,9 +1,31 @@ #include "Status/Wallet/SavedAddressesController.h" +#include "Helpers/helpers.h" namespace Status::Wallet { SavedAddressesController::SavedAddressesController(QObject* parent) : QObject(parent) -{ } + , m_savedAddresses(Helpers::makeSharedQObject( + /* TODO: std::move(getWalletAccounts()), */"savedAddress")) +{ +} + +QAbstractListModel* SavedAddressesController::savedAddresses() const +{ + return m_savedAddresses.get(); +} + +void SavedAddressesController::saveAddress(const QString &address, const QString &name) +{ +// TODO: check present addresses +// { +// emit error(AddressAlreadyPresentError); +// return; +// } + + auto item = Helpers::makeSharedQObject(address, name); + m_savedAddresses->push_back(item); +} + } // namespace Status::Wallet diff --git a/libs/Wallet/src/WalletController.cpp b/libs/Wallet/src/WalletController.cpp index 4ecc901609..9362a70380 100644 --- a/libs/Wallet/src/WalletController.cpp +++ b/libs/Wallet/src/WalletController.cpp @@ -1,7 +1,7 @@ #include "Status/Wallet/WalletController.h" -#include "NewWalletAccountController.h" -#include "AccountAssetsController.h" +#include +#include #include @@ -14,8 +14,9 @@ #include -#include -#include +#include "NewWalletAccountController.h" +#include "AccountAssetsController.h" +#include "SavedAddressesController.h" namespace GoAccounts = Status::StatusGo::Accounts; namespace WalletGo = Status::StatusGo::Wallet; @@ -40,6 +41,11 @@ NewWalletAccountController* WalletController::createNewWalletAccountController() return new NewWalletAccountController(m_accounts); } +SavedAddressesController *WalletController::createSavedAddressesController() const +{ + return new SavedAddressesController(); +} + QAbstractListModel* WalletController::accountsModel() const { return m_accounts.get();