feat(CPP): Continue saved addresses section

This commit is contained in:
MishkaRogachev 2022-09-06 19:26:06 +04:00 committed by Mikhail Rogachev
parent 89bd073eed
commit 24099e83c6
12 changed files with 203 additions and 19 deletions

View File

@ -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
)

View File

@ -0,0 +1,26 @@
#pragma once
#include <QtQmlIntegration>
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;
};
}

View File

@ -2,6 +2,10 @@
#include <QtQmlIntegration>
#include <Helpers/QObjectVectorModel.h>
#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<SavedAddress>;
std::shared_ptr<SavedAddressesModel> m_savedAddresses;
};
} // namespace Status::Wallet

View File

@ -1,7 +1,6 @@
#pragma once
#include "Status/Wallet/WalletAccount.h"
#include "Status/Wallet/DerivedWalletAddress.h"
#include <Helpers/QObjectVectorModel.h>
@ -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;

View File

@ -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
}
}
}

View File

@ -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
}
}
}

View File

@ -1,11 +0,0 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Status.Wallet
import Status.Containers
Item {
id: root
}

View File

@ -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
}
}
}

View File

@ -38,6 +38,7 @@ PanelAndContentBase {
account: WalletController.currentAccount
assetController: panel.currentAssetController
savedAddressesController: WalletController.createSavedAddressesController()
}
}
}

View File

@ -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;
}
}

View File

@ -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<SavedAddressesModel>(
/* 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<SavedAddress>(address, name);
m_savedAddresses->push_back(item);
}
} // namespace Status::Wallet

View File

@ -1,7 +1,7 @@
#include "Status/Wallet/WalletController.h"
#include "NewWalletAccountController.h"
#include "AccountAssetsController.h"
#include <QQmlEngine>
#include <QJSEngine>
#include <StatusGo/Wallet/WalletApi.h>
@ -14,8 +14,9 @@
#include <Onboarding/Common/Constants.h>
#include <QQmlEngine>
#include <QJSEngine>
#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();