style(@desktop/cpp): apply clang-format on src-cpp/*
This commit is contained in:
parent
f27fd6ea61
commit
00156cc9c0
|
@ -10,7 +10,7 @@
|
|||
BasedOnStyle: WebKit
|
||||
TabWidth: 4
|
||||
IndentWidth: 4
|
||||
UseTab: Always
|
||||
UseTab: Never
|
||||
ColumnLimit: 120
|
||||
|
||||
# Other languages JavaScript, Proto
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "app_controller.h"
|
||||
#include "accounts/service.h"
|
||||
#include "app_service.h"
|
||||
#include "modules/startup/module.h"
|
||||
#include "modules/main/module.h"
|
||||
#include "modules/startup/module.h"
|
||||
#include <QDebug>
|
||||
|
||||
AppController::AppController()
|
||||
|
@ -68,32 +68,32 @@ AppController::AppController()
|
|||
m_startupModule = new Modules::Startup::Module(this, /*keychainService,*/ m_accountsService);
|
||||
|
||||
m_mainModulePtr = new Modules::Main::Module(m_walletServicePtr, this);
|
||||
// statusFoundation.status.events,
|
||||
// result.keychainService,
|
||||
// result.accountsService,
|
||||
// result.chatService,
|
||||
// result.communityService,
|
||||
// result.messageService,
|
||||
// result.tokenService,
|
||||
// result.transactionService,
|
||||
// result.collectibleService,
|
||||
// result.walletAccountService,
|
||||
// result.bookmarkService,
|
||||
// result.profileService,
|
||||
// result.settingsService,
|
||||
// result.contactsService,
|
||||
// result.aboutService,
|
||||
// result.dappPermissionsService,
|
||||
// result.languageService,
|
||||
// # result.mnemonicService,
|
||||
// result.privacyService,
|
||||
// result.providerService,
|
||||
// result.stickersService,
|
||||
// result.activityCenterService,
|
||||
// result.savedAddressService,
|
||||
// result.nodeConfigurationService,
|
||||
// result.devicesService,
|
||||
// result.mailserversService
|
||||
// statusFoundation.status.events,
|
||||
// result.keychainService,
|
||||
// result.accountsService,
|
||||
// result.chatService,
|
||||
// result.communityService,
|
||||
// result.messageService,
|
||||
// result.tokenService,
|
||||
// result.transactionService,
|
||||
// result.collectibleService,
|
||||
// result.walletAccountService,
|
||||
// result.bookmarkService,
|
||||
// result.profileService,
|
||||
// result.settingsService,
|
||||
// result.contactsService,
|
||||
// result.aboutService,
|
||||
// result.dappPermissionsService,
|
||||
// result.languageService,
|
||||
// # result.mnemonicService,
|
||||
// result.privacyService,
|
||||
// result.providerService,
|
||||
// result.stickersService,
|
||||
// result.activityCenterService,
|
||||
// result.savedAddressService,
|
||||
// result.nodeConfigurationService,
|
||||
// result.devicesService,
|
||||
// result.mailserversService
|
||||
|
||||
// # Do connections
|
||||
connect();
|
||||
|
@ -174,13 +174,13 @@ void AppController::load()
|
|||
|
||||
// # load main module
|
||||
m_mainModulePtr->load(
|
||||
// self.statusFoundation.status.events,
|
||||
// self.settingsService,
|
||||
// self.contactsService,
|
||||
// self.chatService,
|
||||
// self.communityService,
|
||||
// self.messageService
|
||||
);
|
||||
// self.statusFoundation.status.events,
|
||||
// self.settingsService,
|
||||
// self.contactsService,
|
||||
// self.chatService,
|
||||
// self.communityService,
|
||||
// self.messageService
|
||||
);
|
||||
}
|
||||
|
||||
void AppController::userLoggedIn()
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "accounts/service.h"
|
||||
#include "wallet_accounts/service.h"
|
||||
#include "../modules/main/interfaces/module_access_interface.h"
|
||||
#include "../modules/startup/module_access_interface.h"
|
||||
#include "accounts/service.h"
|
||||
#include "app_controller_delegate.h"
|
||||
#include "app_service.h"
|
||||
#include "wallet_accounts/service.h"
|
||||
|
||||
class AppController : public QObject, AppControllerDelegate
|
||||
{
|
||||
|
@ -37,6 +37,7 @@ public:
|
|||
void start();
|
||||
public slots:
|
||||
void mainDidLoad();
|
||||
|
||||
private:
|
||||
void connect();
|
||||
void startupDidLoad() override;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class AppControllerDelegate
|
||||
{
|
||||
public:
|
||||
virtual void startupDidLoad() = 0;
|
||||
virtual void startupDidLoad() = 0;
|
||||
|
||||
virtual void userLoggedIn() = 0;
|
||||
virtual void userLoggedIn() = 0;
|
||||
};
|
||||
|
|
|
@ -13,79 +13,79 @@ Manager* Manager::theInstance;
|
|||
|
||||
Manager* Manager::instance()
|
||||
{
|
||||
if(theInstance == 0) theInstance = new Manager();
|
||||
return theInstance;
|
||||
if(theInstance == 0) theInstance = new Manager();
|
||||
return theInstance;
|
||||
}
|
||||
|
||||
std::map<QString, SignalType> Manager::signalMap;
|
||||
|
||||
Manager::Manager(QObject* parent)
|
||||
: QObject(parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
SetSignalEventCallback((void*)&Manager::signalCallback);
|
||||
SetSignalEventCallback((void*)&Manager::signalCallback);
|
||||
|
||||
signalMap = {{"node.ready", SignalType::NodeReady},
|
||||
{"node.started", SignalType::NodeStarted},
|
||||
{"node.stopped", SignalType::NodeStopped},
|
||||
{"node.login", SignalType::NodeLogin},
|
||||
{"node.crashed", SignalType::NodeCrashed}};
|
||||
signalMap = {{"node.ready", SignalType::NodeReady},
|
||||
{"node.started", SignalType::NodeStarted},
|
||||
{"node.stopped", SignalType::NodeStopped},
|
||||
{"node.login", SignalType::NodeLogin},
|
||||
{"node.crashed", SignalType::NodeCrashed}};
|
||||
}
|
||||
|
||||
void Manager::processSignal(QString statusSignal)
|
||||
{
|
||||
try
|
||||
{
|
||||
QJsonParseError json_error;
|
||||
const QJsonDocument signalEventDoc(QJsonDocument::fromJson(statusSignal.toUtf8(), &json_error));
|
||||
if(json_error.error != QJsonParseError::NoError)
|
||||
{
|
||||
qWarning() << "Invalid signal received";
|
||||
return;
|
||||
}
|
||||
decode(signalEventDoc.object());
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << "Error decoding signal, err: ", e.what();
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
QJsonParseError json_error;
|
||||
const QJsonDocument signalEventDoc(QJsonDocument::fromJson(statusSignal.toUtf8(), &json_error));
|
||||
if(json_error.error != QJsonParseError::NoError)
|
||||
{
|
||||
qWarning() << "Invalid signal received";
|
||||
return;
|
||||
}
|
||||
decode(signalEventDoc.object());
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
qWarning() << "Error decoding signal, err: ", e.what();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::decode(const QJsonObject& signalEvent)
|
||||
{
|
||||
SignalType signalType(Unknown);
|
||||
if(!signalMap.count(signalEvent["type"].toString()))
|
||||
{
|
||||
qWarning() << "Unknown signal received: " << signalEvent["type"].toString();
|
||||
return;
|
||||
}
|
||||
SignalType signalType(Unknown);
|
||||
if(!signalMap.count(signalEvent["type"].toString()))
|
||||
{
|
||||
qWarning() << "Unknown signal received: " << signalEvent["type"].toString();
|
||||
return;
|
||||
}
|
||||
|
||||
signalType = signalMap[signalEvent["type"].toString()];
|
||||
signalType = signalMap[signalEvent["type"].toString()];
|
||||
|
||||
switch(signalType)
|
||||
{
|
||||
// TODO: create extractor functions like in nim
|
||||
case NodeLogin: emit instance()->nodeLogin(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break;
|
||||
case NodeReady: emit instance()->nodeReady(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break;
|
||||
case NodeStarted:
|
||||
emit instance()->nodeStarted(NodeSignal{signalType, signalEvent["event"]["error"].toString()});
|
||||
break;
|
||||
case NodeStopped:
|
||||
emit instance()->nodeStopped(NodeSignal{signalType, signalEvent["event"]["error"].toString()});
|
||||
break;
|
||||
case NodeCrashed: {
|
||||
auto signal = NodeSignal{signalType, signalEvent["event"]["error"].toString()};
|
||||
qWarning() << "node.crashed, error: " << signal.error;
|
||||
emit instance()->nodeCrashed(signal);
|
||||
break;
|
||||
}
|
||||
default: qWarning() << "Signal decoding not implemented: " << signalEvent; break;
|
||||
}
|
||||
switch(signalType)
|
||||
{
|
||||
// TODO: create extractor functions like in nim
|
||||
case NodeLogin: emit instance()->nodeLogin(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break;
|
||||
case NodeReady: emit instance()->nodeReady(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break;
|
||||
case NodeStarted:
|
||||
emit instance()->nodeStarted(NodeSignal{signalType, signalEvent["event"]["error"].toString()});
|
||||
break;
|
||||
case NodeStopped:
|
||||
emit instance()->nodeStopped(NodeSignal{signalType, signalEvent["event"]["error"].toString()});
|
||||
break;
|
||||
case NodeCrashed: {
|
||||
auto signal = NodeSignal{signalType, signalEvent["event"]["error"].toString()};
|
||||
qWarning() << "node.crashed, error: " << signal.error;
|
||||
emit instance()->nodeCrashed(signal);
|
||||
break;
|
||||
}
|
||||
default: qWarning() << "Signal decoding not implemented: " << signalEvent; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::signalCallback(const char* data)
|
||||
{
|
||||
QtConcurrent::run(instance(), &Manager::processSignal, QString(data));
|
||||
QtConcurrent::run(instance(), &Manager::processSignal, QString(data));
|
||||
}
|
||||
|
||||
} // namespace Signals
|
||||
} // namespace Signals
|
||||
|
|
|
@ -7,17 +7,17 @@ Singleton* Singleton::theInstance;
|
|||
|
||||
Singleton* Singleton::instance()
|
||||
{
|
||||
if(theInstance == 0) theInstance = new Singleton();
|
||||
return theInstance;
|
||||
if(theInstance == 0) theInstance = new Singleton();
|
||||
return theInstance;
|
||||
}
|
||||
|
||||
Singleton::Singleton()
|
||||
{
|
||||
m_engine = new QQmlApplicationEngine();
|
||||
m_engine = new QQmlApplicationEngine();
|
||||
}
|
||||
|
||||
QQmlApplicationEngine* Singleton::engine()
|
||||
{
|
||||
return m_engine;
|
||||
return m_engine;
|
||||
}
|
||||
} // namespace Global
|
||||
|
|
|
@ -11,52 +11,52 @@ Q_NAMESPACE
|
|||
|
||||
enum SignalType
|
||||
{
|
||||
Unknown,
|
||||
NodeLogin,
|
||||
NodeReady,
|
||||
NodeStarted,
|
||||
NodeStopped,
|
||||
NodeCrashed
|
||||
Unknown,
|
||||
NodeLogin,
|
||||
NodeReady,
|
||||
NodeStarted,
|
||||
NodeStopped,
|
||||
NodeCrashed
|
||||
};
|
||||
|
||||
Q_ENUM_NS(SignalType)
|
||||
|
||||
struct Signal
|
||||
{
|
||||
SignalType signalType;
|
||||
SignalType signalType;
|
||||
};
|
||||
|
||||
struct NodeSignal : Signal
|
||||
{
|
||||
QString error;
|
||||
QString error;
|
||||
};
|
||||
|
||||
class Manager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static Manager* instance();
|
||||
static Manager* instance();
|
||||
|
||||
signals:
|
||||
void signal(SignalType signal);
|
||||
void signal(SignalType signal);
|
||||
|
||||
void nodeReady(NodeSignal signal);
|
||||
void nodeStarted(NodeSignal signal);
|
||||
void nodeStopped(NodeSignal signal);
|
||||
void nodeLogin(NodeSignal signal);
|
||||
void nodeCrashed(NodeSignal signal);
|
||||
void nodeReady(NodeSignal signal);
|
||||
void nodeStarted(NodeSignal signal);
|
||||
void nodeStopped(NodeSignal signal);
|
||||
void nodeLogin(NodeSignal signal);
|
||||
void nodeCrashed(NodeSignal signal);
|
||||
|
||||
private:
|
||||
static Manager* theInstance;
|
||||
explicit Manager(QObject* parent = nullptr);
|
||||
static std::map<QString, SignalType> signalMap;
|
||||
static void signalCallback(const char* data);
|
||||
void processSignal(QString ev);
|
||||
void decode(const QJsonObject& signalEvent);
|
||||
static Manager* theInstance;
|
||||
explicit Manager(QObject* parent = nullptr);
|
||||
static std::map<QString, SignalType> signalMap;
|
||||
static void signalCallback(const char* data);
|
||||
void processSignal(QString ev);
|
||||
void decode(const QJsonObject& signalEvent);
|
||||
};
|
||||
|
||||
} // namespace Signals
|
||||
|
||||
Q_DECLARE_METATYPE(Signals::Signal)
|
||||
Q_DECLARE_METATYPE(Signals::NodeSignal)
|
||||
Q_DECLARE_METATYPE(Signals::NodeSignal)
|
||||
|
|
|
@ -8,13 +8,13 @@ namespace Global
|
|||
class Singleton
|
||||
{
|
||||
public:
|
||||
QQmlApplicationEngine* engine();
|
||||
static Singleton* instance();
|
||||
QQmlApplicationEngine* engine();
|
||||
static Singleton* instance();
|
||||
|
||||
private:
|
||||
static Singleton* theInstance;
|
||||
explicit Singleton();
|
||||
QQmlApplicationEngine* m_engine;
|
||||
static Singleton* theInstance;
|
||||
explicit Singleton();
|
||||
QQmlApplicationEngine* m_engine;
|
||||
};
|
||||
|
||||
} // namespace Global
|
||||
} // namespace Global
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "controller.h"
|
||||
|
||||
namespace Modules:: Main
|
||||
namespace Modules::Main
|
||||
{
|
||||
Controller::Controller(QObject* parent)
|
||||
: QObject(parent)
|
||||
|
|
|
@ -21,4 +21,3 @@ public:
|
|||
} // namespace Modules::Main
|
||||
|
||||
#endif // CONTROLLER_H
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#include <QDebug>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include "module.h"
|
||||
#include "singleton.h"
|
||||
#include "modules/main/wallet/module.h"
|
||||
#include "../shared/section_item.h"
|
||||
#include "module.h"
|
||||
#include "modules/main/wallet/module.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace Modules::Main
|
||||
{
|
||||
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent): QObject(parent)
|
||||
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_controllerPtr = new Controller(this);
|
||||
m_viewPtr = new View(this);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "view.h"
|
||||
#include "../global/app_sections_config.h"
|
||||
|
||||
|
||||
namespace Modules::Main
|
||||
{
|
||||
View::View(QObject* parent)
|
||||
|
@ -13,7 +12,15 @@ View::View(QObject* parent)
|
|||
void View::load()
|
||||
{
|
||||
// Add Wallet Section to Sections model
|
||||
auto walletSectionItem = new Shared::Models::SectionItem(WALLET_SECTION_ID, Shared::Models::SectionType::Wallet, WALLET_SECTION_NAME, "", "", WALLET_SECTION_ICON, "", false, this);
|
||||
auto walletSectionItem = new Shared::Models::SectionItem(WALLET_SECTION_ID,
|
||||
Shared::Models::SectionType::Wallet,
|
||||
WALLET_SECTION_NAME,
|
||||
"",
|
||||
"",
|
||||
WALLET_SECTION_ICON,
|
||||
"",
|
||||
false,
|
||||
this);
|
||||
addItem(walletSectionItem);
|
||||
setActiveSection(WALLET_SECTION_ID);
|
||||
|
||||
|
@ -36,7 +43,7 @@ Shared::Models::SectionItem* View::getActiveSection()
|
|||
return m_sectionModelPtr->getActiveItem();
|
||||
}
|
||||
|
||||
void View::setActiveSection(const QString &Id)
|
||||
void View::setActiveSection(const QString& Id)
|
||||
{
|
||||
if(m_sectionModelPtr->getActiveItem().isNull() || (m_sectionModelPtr->getActiveItem()->getId() != Id))
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
~View() = default;
|
||||
void load();
|
||||
|
||||
void addItem(Shared::Models::SectionItem *item);
|
||||
void addItem(Shared::Models::SectionItem* item);
|
||||
|
||||
Shared::Models::SectionModel* getSectionsModel();
|
||||
Shared::Models::SectionItem* getActiveSection();
|
||||
|
@ -36,4 +36,3 @@ private:
|
|||
} // namespace Modules::Main
|
||||
|
||||
#endif // VIEW_H
|
||||
|
||||
|
|
|
@ -4,21 +4,17 @@
|
|||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService,
|
||||
QObject* parent)
|
||||
: m_walletServicePtr(walletService),
|
||||
QObject(parent)
|
||||
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService, QObject* parent)
|
||||
: m_walletServicePtr(walletService)
|
||||
, QObject(parent)
|
||||
{ }
|
||||
|
||||
void Controller::init()
|
||||
{
|
||||
}
|
||||
void Controller::init() { }
|
||||
|
||||
QList<Wallets::WalletAccountDto> Controller::getWalletAccounts()
|
||||
{
|
||||
QList<Wallets::WalletAccountDto> wallet_accounts;
|
||||
if(nullptr != m_walletServicePtr)
|
||||
wallet_accounts = m_walletServicePtr->getWalletAccounts();
|
||||
if(nullptr != m_walletServicePtr) wallet_accounts = m_walletServicePtr->getWalletAccounts();
|
||||
|
||||
return wallet_accounts;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "wallet_accounts/wallet_account.h"
|
||||
#include "wallet_accounts/service_interface.h"
|
||||
#include "interfaces/controller_interface.h"
|
||||
#include "signals.h"
|
||||
#include "wallet_accounts/service_interface.h"
|
||||
#include "wallet_accounts/wallet_account.h"
|
||||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
|
|
|
@ -2,16 +2,24 @@
|
|||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
Item::Item(QString name, QString address, QString path, QString color, QString publicKey, QString walletType, bool isWallet, bool isChat, float currencyBalance)
|
||||
: m_name(name),
|
||||
m_address(address),
|
||||
m_path(path),
|
||||
m_color(color),
|
||||
m_publicKey(publicKey),
|
||||
m_walletType(walletType),
|
||||
m_isWallet(isWallet),
|
||||
m_isChat(isChat),
|
||||
m_currencyBalance(currencyBalance)
|
||||
Item::Item(QString name,
|
||||
QString address,
|
||||
QString path,
|
||||
QString color,
|
||||
QString publicKey,
|
||||
QString walletType,
|
||||
bool isWallet,
|
||||
bool isChat,
|
||||
float currencyBalance)
|
||||
: m_name(name)
|
||||
, m_address(address)
|
||||
, m_path(path)
|
||||
, m_color(color)
|
||||
, m_publicKey(publicKey)
|
||||
, m_walletType(walletType)
|
||||
, m_isWallet(isWallet)
|
||||
, m_isChat(isChat)
|
||||
, m_currencyBalance(currencyBalance)
|
||||
{ }
|
||||
|
||||
const QString& Item::getName() const
|
||||
|
@ -54,7 +62,7 @@ bool Item::getIsChat() const
|
|||
return m_isChat;
|
||||
}
|
||||
|
||||
float Item::getCurrencyBalance() const
|
||||
float Item::getCurrencyBalance() const
|
||||
{
|
||||
return m_currencyBalance;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,15 @@ private:
|
|||
float m_currencyBalance;
|
||||
|
||||
public:
|
||||
Item(QString name, QString address, QString path, QString color, QString publicKey, QString walletType, bool isWallet, bool isChat, float currencyBalance);
|
||||
Item(QString name,
|
||||
QString address,
|
||||
QString path,
|
||||
QString color,
|
||||
QString publicKey,
|
||||
QString walletType,
|
||||
bool isWallet,
|
||||
bool isChat,
|
||||
float currencyBalance);
|
||||
~Item() = default;
|
||||
|
||||
const QString& getName() const;
|
||||
|
|
|
@ -50,7 +50,8 @@ QVariant Model::data(const QModelIndex& index, int role) const
|
|||
case PublicKey: return QVariant(item.getPublicKey());
|
||||
case WalletType: return QVariant(item.getWalletType());
|
||||
case IsWallet: return QVariant(item.getIsWallet());
|
||||
case IsChat: return QVariant(item.getIsChat());
|
||||
case IsChat:
|
||||
return QVariant(item.getIsChat());
|
||||
// case Assets: return QVariant(item.ge());
|
||||
case CurrencyBalance: return QVariant(item.getCurrencyBalance());
|
||||
}
|
||||
|
@ -58,7 +59,7 @@ QVariant Model::data(const QModelIndex& index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
void Model::setItems(QVector<Item> &items)
|
||||
void Model::setItems(QVector<Item>& items)
|
||||
{
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
int rowCount(const QModelIndex&) const override;
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
void setItems(QVector<Item> &items);
|
||||
void setItems(QVector<Item>& items);
|
||||
|
||||
private:
|
||||
QVector<Item> m_items;
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject *parent): QObject(parent)
|
||||
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_controllerPtr = new Controller(walletsService, this);
|
||||
m_viewPtr = new View(this);
|
||||
|
@ -49,14 +50,15 @@ void Module::refreshWalletAccounts()
|
|||
QVector<Item> items;
|
||||
foreach(const auto& acc, walletAccounts)
|
||||
{
|
||||
items << Item(acc.name, acc.address, acc.path, acc.color, acc.publicKey, acc.walletType, acc.isWallet, acc.isChat, 0);
|
||||
items << Item(
|
||||
acc.name, acc.address, acc.path, acc.color, acc.publicKey, acc.walletType, acc.isWallet, acc.isChat, 0);
|
||||
}
|
||||
|
||||
m_viewPtr->setModelItems(items);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning()<<"No accounts found!";
|
||||
qWarning() << "No accounts found!";
|
||||
}
|
||||
}
|
||||
} // namespace Modules::Main::Wallet::Accounts
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "wallet_accounts/service_interface.h"
|
||||
#include "interfaces/module_access_interface.h"
|
||||
#include "controller.h"
|
||||
#include "interfaces/module_access_interface.h"
|
||||
#include "view.h"
|
||||
#include "wallet_accounts/service_interface.h"
|
||||
|
||||
namespace Modules::Main::Wallet::Accounts
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ private:
|
|||
|
||||
void connect();
|
||||
void refreshWalletAccounts();
|
||||
|
||||
public:
|
||||
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent);
|
||||
~Module() = default;
|
||||
|
|
|
@ -20,7 +20,8 @@ Model* View::getModel()
|
|||
return m_modelPtr;
|
||||
}
|
||||
|
||||
void View::setModelItems(QVector<Item> &accounts) {
|
||||
void View::setModelItems(QVector<Item>& accounts)
|
||||
{
|
||||
m_modelPtr->setItems(accounts);
|
||||
modelChanged();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
~View() = default;
|
||||
|
||||
void load();
|
||||
void setModelItems(QVector<Item> &accounts);
|
||||
void setModelItems(QVector<Item>& accounts);
|
||||
|
||||
private:
|
||||
Model* m_modelPtr;
|
||||
|
|
|
@ -4,13 +4,10 @@
|
|||
|
||||
namespace Modules::Main::Wallet
|
||||
{
|
||||
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService,
|
||||
QObject* parent)
|
||||
: m_walletService(walletService),
|
||||
QObject(parent)
|
||||
Controller::Controller(std::shared_ptr<Wallets::ServiceInterface> walletService, QObject* parent)
|
||||
: m_walletService(walletService)
|
||||
, QObject(parent)
|
||||
{ }
|
||||
|
||||
void Controller::init()
|
||||
{
|
||||
}
|
||||
void Controller::init() { }
|
||||
} // namespace Modules::Main::Wallet
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "wallet_accounts/service_interface.h"
|
||||
#include "interfaces/controller_interface.h"
|
||||
#include "signals.h"
|
||||
#include "wallet_accounts/service_interface.h"
|
||||
|
||||
namespace Modules::Main::Wallet
|
||||
{
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#include <QDebug>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include "accounts/module.h"
|
||||
#include "module.h"
|
||||
#include "singleton.h"
|
||||
#include "accounts/module.h"
|
||||
|
||||
namespace Modules::Main::Wallet
|
||||
{
|
||||
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject *parent): QObject(parent)
|
||||
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_controllerPtr = new Controller(walletsService, this);
|
||||
m_viewPtr = new View(this);
|
||||
|
@ -49,7 +50,7 @@ void Module::checkIfModuleDidLoad()
|
|||
}
|
||||
|
||||
void Module::viewDidLoad()
|
||||
{
|
||||
{
|
||||
checkIfModuleDidLoad();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ private:
|
|||
bool m_moduleLoaded;
|
||||
|
||||
void connect();
|
||||
|
||||
public:
|
||||
explicit Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject* parent);
|
||||
~Module() = default;
|
||||
|
|
|
@ -6,8 +6,7 @@ namespace Modules::Main::Wallet
|
|||
{
|
||||
View::View(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
void View::load()
|
||||
{
|
||||
|
|
|
@ -21,4 +21,3 @@ signals:
|
|||
} // namespace Modules::Main::Wallet
|
||||
|
||||
#endif // WALLET_VIEW_H
|
||||
|
||||
|
|
|
@ -23,41 +23,40 @@ SectionItem::SectionItem(QString id,
|
|||
bool canRequestAccess,
|
||||
int access,
|
||||
bool ensOnly,
|
||||
QObject *parent):
|
||||
QObject(parent),
|
||||
m_id(id),
|
||||
m_sectionType(sectionType) ,
|
||||
m_name(name),
|
||||
m_amISectionAdmin(amISectionAdmin),
|
||||
m_description(description),
|
||||
m_image(image),
|
||||
m_icon(icon),
|
||||
m_color(color),
|
||||
m_hasNotification(hasNotification),
|
||||
m_notificationsCount(notificationsCount),
|
||||
m_active(active),
|
||||
m_enabled(enabled),
|
||||
m_isMember(isMember),
|
||||
m_joined(joined),
|
||||
m_canJoin(canJoin),
|
||||
m_canManageUsers(canManageUsers),
|
||||
m_canRequestAccess(canRequestAccess),
|
||||
m_access(access),
|
||||
m_ensOnly(ensOnly)
|
||||
{
|
||||
}
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_id(id)
|
||||
, m_sectionType(sectionType)
|
||||
, m_name(name)
|
||||
, m_amISectionAdmin(amISectionAdmin)
|
||||
, m_description(description)
|
||||
, m_image(image)
|
||||
, m_icon(icon)
|
||||
, m_color(color)
|
||||
, m_hasNotification(hasNotification)
|
||||
, m_notificationsCount(notificationsCount)
|
||||
, m_active(active)
|
||||
, m_enabled(enabled)
|
||||
, m_isMember(isMember)
|
||||
, m_joined(joined)
|
||||
, m_canJoin(canJoin)
|
||||
, m_canManageUsers(canManageUsers)
|
||||
, m_canRequestAccess(canRequestAccess)
|
||||
, m_access(access)
|
||||
, m_ensOnly(ensOnly)
|
||||
{ }
|
||||
|
||||
SectionType SectionItem::getSectionType() const
|
||||
{
|
||||
return m_sectionType;
|
||||
}
|
||||
|
||||
const QString& SectionItem::getId() const
|
||||
const QString& SectionItem::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
const QString& SectionItem::getName() const
|
||||
const QString& SectionItem::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
@ -67,22 +66,22 @@ bool SectionItem::getAmISectionAdmin() const
|
|||
return m_amISectionAdmin;
|
||||
}
|
||||
|
||||
const QString& SectionItem::getDescription() const
|
||||
const QString& SectionItem::getDescription() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
const QString& SectionItem::getImage() const
|
||||
const QString& SectionItem::getImage() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
const QString& SectionItem::getIcon() const
|
||||
const QString& SectionItem::getIcon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
const QString& SectionItem::getColor() const
|
||||
const QString& SectionItem::getColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ enum SectionType
|
|||
ProfileSettings,
|
||||
NodeManagement
|
||||
};
|
||||
class SectionItem: public QObject
|
||||
class SectionItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString id READ getId)
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
bool amISectionAdmin = false,
|
||||
bool hasNotification = false,
|
||||
int notificationsCount = 0,
|
||||
bool isMember = false,
|
||||
bool isMember = false,
|
||||
bool joined = false,
|
||||
bool canJoin = false,
|
||||
bool canManageUsers = false,
|
||||
|
|
|
@ -73,7 +73,8 @@ QVariant SectionModel::data(const QModelIndex& index, int role) const
|
|||
case CanManageUsers: return QVariant(item->getCanManageUsers());
|
||||
case CanRequestAccess: return QVariant(item->getCanRequestAccess());
|
||||
case Access: return QVariant(item->getAccess());
|
||||
case EnsOnly: return QVariant(item->getIsEnsOnly());
|
||||
case EnsOnly:
|
||||
return QVariant(item->getIsEnsOnly());
|
||||
// To Do
|
||||
case MembersModel: return QVariant();
|
||||
case PendingRequestsToJoinModel: return QVariant();
|
||||
|
@ -89,18 +90,18 @@ void SectionModel::addItem(SectionItem* item)
|
|||
endInsertRows();
|
||||
}
|
||||
|
||||
void SectionModel::setActiveSection(const QString &Id)
|
||||
void SectionModel::setActiveSection(const QString& Id)
|
||||
{
|
||||
|
||||
for (int i = 0; i < m_items.size(); ++i) {
|
||||
for(int i = 0; i < m_items.size(); ++i)
|
||||
{
|
||||
auto newIndex = createIndex(i, 0, nullptr);
|
||||
if(m_items.at(i)->getIsActive())
|
||||
{
|
||||
m_items.at(i)->setIsActive(false);
|
||||
dataChanged(newIndex, newIndex, QVector<int>(ModelRole::Active));
|
||||
|
||||
}
|
||||
if (m_items.at(i)->getId() == Id)
|
||||
if(m_items.at(i)->getId() == Id)
|
||||
{
|
||||
m_items.at(i)->setIsActive(true);
|
||||
dataChanged(newIndex, newIndex, QVector<int>(ModelRole::Active));
|
||||
|
@ -115,10 +116,10 @@ QPointer<SectionItem> SectionModel::getActiveItem()
|
|||
{
|
||||
if(item->getIsActive())
|
||||
{
|
||||
activeItem = item;
|
||||
break;
|
||||
activeItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return activeItem;
|
||||
return activeItem;
|
||||
}
|
||||
} // namespace Shared::Models
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
#include <QAbstractListModel>
|
||||
#include <QHash>
|
||||
#include <QPointer>
|
||||
#include <QVector>
|
||||
#include <memory>
|
||||
#include <QPointer>
|
||||
|
||||
#include "section_item.h"
|
||||
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
|
||||
void addItem(SectionItem* item);
|
||||
void setActiveSection(const QString &Id);
|
||||
void setActiveSection(const QString& Id);
|
||||
QPointer<SectionItem> getActiveItem();
|
||||
|
||||
// To add other api's later as needed
|
||||
|
|
|
@ -9,47 +9,47 @@ namespace Modules
|
|||
namespace Startup
|
||||
{
|
||||
Controller::Controller(ModuleControllerDelegateInterface* delegate,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_accountsService(accountsService)
|
||||
, m_delegate(delegate)
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_accountsService(accountsService)
|
||||
, m_delegate(delegate)
|
||||
{ }
|
||||
|
||||
void Controller::init()
|
||||
{
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin);
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeStopped, this, &Controller::onNodeStopped);
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeReady, this, &Controller::onNodeReady);
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin);
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeStopped, this, &Controller::onNodeStopped);
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeReady, this, &Controller::onNodeReady);
|
||||
}
|
||||
|
||||
void Controller::onLogin(Signals::NodeSignal signal)
|
||||
{
|
||||
if(signal.error.isEmpty())
|
||||
{
|
||||
m_delegate->userLoggedIn();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "error: methodName=init, errDescription=login error " << signal.error;
|
||||
}
|
||||
if(signal.error.isEmpty())
|
||||
{
|
||||
m_delegate->userLoggedIn();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "error: methodName=init, errDescription=login error " << signal.error;
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::onNodeStopped(Signals::NodeSignal signal)
|
||||
{
|
||||
// self.events.emit("nodeStopped", Args())
|
||||
m_accountsService->clear();
|
||||
m_delegate->emitLogOut();
|
||||
// self.events.emit("nodeStopped", Args())
|
||||
m_accountsService->clear();
|
||||
m_delegate->emitLogOut();
|
||||
}
|
||||
|
||||
void Controller::onNodeReady(Signals::NodeSignal signal)
|
||||
{
|
||||
// self.events.emit("nodeReady", Args())
|
||||
// self.events.emit("nodeReady", Args())
|
||||
}
|
||||
|
||||
bool Controller::shouldStartWithOnboardingScreen()
|
||||
{
|
||||
return m_accountsService->openedAccounts().size() == 0;
|
||||
return m_accountsService->openedAccounts().size() == 0;
|
||||
}
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -14,19 +14,19 @@ namespace Startup
|
|||
class Controller : public QObject, ControllerInterface
|
||||
{
|
||||
public:
|
||||
Controller(ModuleControllerDelegateInterface* delegate,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent = nullptr);
|
||||
void init() override;
|
||||
bool shouldStartWithOnboardingScreen() override;
|
||||
void onLogin(Signals::NodeSignal signal);
|
||||
void onNodeStopped(Signals::NodeSignal signal);
|
||||
void onNodeReady(Signals::NodeSignal signal);
|
||||
Controller(ModuleControllerDelegateInterface* delegate,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent = nullptr);
|
||||
void init() override;
|
||||
bool shouldStartWithOnboardingScreen() override;
|
||||
void onLogin(Signals::NodeSignal signal);
|
||||
void onNodeStopped(Signals::NodeSignal signal);
|
||||
void onNodeReady(Signals::NodeSignal signal);
|
||||
|
||||
private:
|
||||
Accounts::ServiceInterface* m_accountsService;
|
||||
ModuleControllerDelegateInterface* m_delegate;
|
||||
Accounts::ServiceInterface* m_accountsService;
|
||||
ModuleControllerDelegateInterface* m_delegate;
|
||||
};
|
||||
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -10,9 +10,9 @@ namespace Startup
|
|||
class ControllerInterface
|
||||
{
|
||||
public:
|
||||
virtual void init() = 0;
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual bool shouldStartWithOnboardingScreen() = 0;
|
||||
virtual bool shouldStartWithOnboardingScreen() = 0;
|
||||
};
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -7,9 +7,9 @@ namespace Startup
|
|||
class ModuleControllerDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void userLoggedIn() = 0;
|
||||
virtual void userLoggedIn() = 0;
|
||||
|
||||
virtual void emitLogOut() = 0;
|
||||
virtual void emitLogOut() = 0;
|
||||
};
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Startup
|
|||
class ModuleLoginDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void loginDidLoad() = 0;
|
||||
virtual void loginDidLoad() = 0;
|
||||
};
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Startup
|
|||
class ModuleOnboardingDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void onboardingDidLoad() = 0;
|
||||
virtual void onboardingDidLoad() = 0;
|
||||
};
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Startup
|
|||
class ModuleViewDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void viewDidLoad() = 0;
|
||||
virtual void viewDidLoad() = 0;
|
||||
};
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -14,77 +14,77 @@ namespace Startup
|
|||
namespace Login
|
||||
{
|
||||
Controller::Controller(ModuleControllerDelegateInterface* delegate,
|
||||
// keychainService
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_accountsService(accountsService)
|
||||
, m_delegate(delegate)
|
||||
// keychainService
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_accountsService(accountsService)
|
||||
, m_delegate(delegate)
|
||||
{ }
|
||||
|
||||
void Controller::init()
|
||||
{
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin);
|
||||
// keychainServiceSuccess see src-cpp/app/modules/startup/login/controller.nim line 43
|
||||
// keychainServiceError see src-cpp/app/modules/startup/login/controller.nim line 47
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin);
|
||||
// keychainServiceSuccess see src-cpp/app/modules/startup/login/controller.nim line 43
|
||||
// keychainServiceError see src-cpp/app/modules/startup/login/controller.nim line 47
|
||||
}
|
||||
|
||||
void Controller::onLogin(Signals::NodeSignal signal)
|
||||
{
|
||||
if(!signal.error.isEmpty())
|
||||
{
|
||||
m_delegate->emitAccountLoginError(signal.error);
|
||||
}
|
||||
if(!signal.error.isEmpty())
|
||||
{
|
||||
m_delegate->emitAccountLoginError(signal.error);
|
||||
}
|
||||
}
|
||||
|
||||
QVector<Accounts::AccountDto> Controller::getOpenedAccounts()
|
||||
{
|
||||
return m_accountsService->openedAccounts();
|
||||
return m_accountsService->openedAccounts();
|
||||
}
|
||||
|
||||
Accounts::AccountDto Controller::getSelectedAccount()
|
||||
{
|
||||
auto openedAccounts = Controller::getOpenedAccounts();
|
||||
foreach(const Accounts::AccountDto& acc, openedAccounts)
|
||||
{
|
||||
if(acc.keyUid == m_selectedAccountKeyUid)
|
||||
{
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
auto openedAccounts = Controller::getOpenedAccounts();
|
||||
foreach(const Accounts::AccountDto& acc, openedAccounts)
|
||||
{
|
||||
if(acc.keyUid == m_selectedAccountKeyUid)
|
||||
{
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: For situations like this, should be better to return a std::optional instead?
|
||||
return Accounts::AccountDto();
|
||||
// TODO: For situations like this, should be better to return a std::optional instead?
|
||||
return Accounts::AccountDto();
|
||||
}
|
||||
|
||||
void Controller::setSelectedAccountKeyUid(QString keyUid)
|
||||
{
|
||||
m_selectedAccountKeyUid = keyUid;
|
||||
m_selectedAccountKeyUid = keyUid;
|
||||
|
||||
// Dealing with Keychain is the MacOS only feature
|
||||
// if(not defined(macosx)):
|
||||
// return
|
||||
// Dealing with Keychain is the MacOS only feature
|
||||
// if(not defined(macosx)):
|
||||
// return
|
||||
|
||||
// let selectedAccount = self.getSelectedAccount()
|
||||
// singletonInstance.localAccountSettings.setFileName(selectedAccount.name)
|
||||
// let selectedAccount = self.getSelectedAccount()
|
||||
// singletonInstance.localAccountSettings.setFileName(selectedAccount.name)
|
||||
|
||||
// let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()
|
||||
// if (value != LS_VALUE_STORE):
|
||||
// return
|
||||
// let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()
|
||||
// if (value != LS_VALUE_STORE):
|
||||
// return
|
||||
|
||||
// self.keychainService.tryToObtainPassword(selectedAccount.name)
|
||||
// self.keychainService.tryToObtainPassword(selectedAccount.name)
|
||||
}
|
||||
|
||||
void Controller::login(QString password)
|
||||
{
|
||||
auto selectedAccount = Controller::getSelectedAccount();
|
||||
auto error = m_accountsService->login(selectedAccount, password);
|
||||
if(!error.isEmpty())
|
||||
{
|
||||
m_delegate->emitAccountLoginError(error);
|
||||
}
|
||||
auto selectedAccount = Controller::getSelectedAccount();
|
||||
auto error = m_accountsService->login(selectedAccount, password);
|
||||
if(!error.isEmpty())
|
||||
{
|
||||
m_delegate->emitAccountLoginError(error);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -16,26 +16,26 @@ namespace Login
|
|||
{
|
||||
class Controller : public QObject, ControllerInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Controller(ModuleControllerDelegateInterface* delegate,
|
||||
// keychainService,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent = nullptr);
|
||||
void init() override;
|
||||
QVector<Accounts::AccountDto> getOpenedAccounts() override;
|
||||
Accounts::AccountDto getSelectedAccount();
|
||||
void setSelectedAccountKeyUid(QString keyUid) override;
|
||||
void login(QString password) override;
|
||||
void onLogin(Signals::NodeSignal signal);
|
||||
Controller(ModuleControllerDelegateInterface* delegate,
|
||||
// keychainService,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent = nullptr);
|
||||
void init() override;
|
||||
QVector<Accounts::AccountDto> getOpenedAccounts() override;
|
||||
Accounts::AccountDto getSelectedAccount();
|
||||
void setSelectedAccountKeyUid(QString keyUid) override;
|
||||
void login(QString password) override;
|
||||
void onLogin(Signals::NodeSignal signal);
|
||||
|
||||
private:
|
||||
// Keychain::m_keychainService
|
||||
Accounts::ServiceInterface* m_accountsService;
|
||||
ModuleControllerDelegateInterface* m_delegate;
|
||||
QString m_selectedAccountKeyUid;
|
||||
// Keychain::m_keychainService
|
||||
Accounts::ServiceInterface* m_accountsService;
|
||||
ModuleControllerDelegateInterface* m_delegate;
|
||||
QString m_selectedAccountKeyUid;
|
||||
};
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -14,13 +14,13 @@ namespace Login
|
|||
class ControllerInterface
|
||||
{
|
||||
public:
|
||||
virtual void init() = 0;
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual QVector<Accounts::AccountDto> getOpenedAccounts() = 0;
|
||||
virtual QVector<Accounts::AccountDto> getOpenedAccounts() = 0;
|
||||
|
||||
virtual void setSelectedAccountKeyUid(QString keyUid) = 0;
|
||||
virtual void setSelectedAccountKeyUid(QString keyUid) = 0;
|
||||
|
||||
virtual void login(QString password) = 0;
|
||||
virtual void login(QString password) = 0;
|
||||
};
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
|
|
|
@ -9,12 +9,12 @@ namespace Login
|
|||
class ModuleControllerDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void emitAccountLoginError(QString error) = 0;
|
||||
virtual void emitAccountLoginError(QString error) = 0;
|
||||
|
||||
virtual void emitObtainingPasswordError(QString errorDescription) = 0;
|
||||
virtual void emitObtainingPasswordError(QString errorDescription) = 0;
|
||||
|
||||
virtual void emitObtainingPasswordSuccess(QString password) = 0;
|
||||
virtual void emitObtainingPasswordSuccess(QString password) = 0;
|
||||
};
|
||||
}; // namespace Login
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -11,12 +11,12 @@ namespace Login
|
|||
class ModuleViewDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void viewDidLoad() = 0;
|
||||
virtual void viewDidLoad() = 0;
|
||||
|
||||
virtual void setSelectedAccount(Item item) = 0;
|
||||
virtual void setSelectedAccount(Item item) = 0;
|
||||
|
||||
virtual void login(QString password) = 0;
|
||||
virtual void login(QString password) = 0;
|
||||
};
|
||||
}; // namespace Login
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -10,32 +10,32 @@ namespace Login
|
|||
Item::Item() { }
|
||||
|
||||
Item::Item(QString name, QString identicon, QString thumbnailImage, QString largeImage, QString keyUid)
|
||||
: m_name(name)
|
||||
, m_identicon(identicon)
|
||||
, m_thumbnailImage(thumbnailImage)
|
||||
, m_largeImage(largeImage)
|
||||
, m_keyUid(keyUid)
|
||||
: m_name(name)
|
||||
, m_identicon(identicon)
|
||||
, m_thumbnailImage(thumbnailImage)
|
||||
, m_largeImage(largeImage)
|
||||
, m_keyUid(keyUid)
|
||||
{ }
|
||||
QString Item::getName()
|
||||
{
|
||||
return m_name;
|
||||
return m_name;
|
||||
}
|
||||
QString Item::getIdenticon()
|
||||
{
|
||||
return m_identicon;
|
||||
return m_identicon;
|
||||
}
|
||||
QString Item::getThumbnailImage()
|
||||
{
|
||||
return m_thumbnailImage;
|
||||
return m_thumbnailImage;
|
||||
}
|
||||
QString Item::getLargeImage()
|
||||
{
|
||||
return m_largeImage;
|
||||
return m_largeImage;
|
||||
}
|
||||
QString Item::getKeyUid()
|
||||
{
|
||||
return m_keyUid;
|
||||
return m_keyUid;
|
||||
}
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -11,20 +11,20 @@ namespace Login
|
|||
class Item
|
||||
{
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_identicon;
|
||||
QString m_thumbnailImage;
|
||||
QString m_largeImage;
|
||||
QString m_keyUid;
|
||||
QString m_name;
|
||||
QString m_identicon;
|
||||
QString m_thumbnailImage;
|
||||
QString m_largeImage;
|
||||
QString m_keyUid;
|
||||
|
||||
public:
|
||||
Item();
|
||||
Item(QString name, QString identicon, QString thumbnailImage, QString largeImage, QString keyUid);
|
||||
QString getName();
|
||||
QString getIdenticon();
|
||||
QString getThumbnailImage();
|
||||
QString getLargeImage();
|
||||
QString getKeyUid();
|
||||
Item();
|
||||
Item(QString name, QString identicon, QString thumbnailImage, QString largeImage, QString keyUid);
|
||||
QString getName();
|
||||
QString getIdenticon();
|
||||
QString getThumbnailImage();
|
||||
QString getLargeImage();
|
||||
QString getKeyUid();
|
||||
};
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
|
|
|
@ -9,67 +9,67 @@ namespace Startup
|
|||
namespace Login
|
||||
{
|
||||
Model::Model(QObject* parent)
|
||||
: QAbstractListModel(parent)
|
||||
: QAbstractListModel(parent)
|
||||
{ }
|
||||
|
||||
QHash<int, QByteArray> Model::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Name] = "username";
|
||||
roles[Identicon] = "identicon";
|
||||
roles[ThumbnailImage] = "thumbnailImage";
|
||||
roles[LargeImage] = "largeImage";
|
||||
roles[KeyUid] = "keyUid";
|
||||
return roles;
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Name] = "username";
|
||||
roles[Identicon] = "identicon";
|
||||
roles[ThumbnailImage] = "thumbnailImage";
|
||||
roles[LargeImage] = "largeImage";
|
||||
roles[KeyUid] = "keyUid";
|
||||
return roles;
|
||||
}
|
||||
|
||||
int Model::rowCount(const QModelIndex& parent = QModelIndex()) const
|
||||
{
|
||||
return m_items.size();
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
QVariant Model::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if(!index.isValid())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
if(!index.isValid())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if(index.row() < 0 || index.row() > m_items.size())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
if(index.row() < 0 || index.row() > m_items.size())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Item item = m_items[index.row()];
|
||||
Item item = m_items[index.row()];
|
||||
|
||||
switch(role)
|
||||
{
|
||||
case Name: return QVariant(item.getName());
|
||||
case Identicon: return QVariant(item.getIdenticon());
|
||||
case ThumbnailImage: return QVariant(item.getThumbnailImage());
|
||||
case LargeImage: return QVariant(item.getLargeImage());
|
||||
case KeyUid: return QVariant(item.getKeyUid());
|
||||
}
|
||||
switch(role)
|
||||
{
|
||||
case Name: return QVariant(item.getName());
|
||||
case Identicon: return QVariant(item.getIdenticon());
|
||||
case ThumbnailImage: return QVariant(item.getThumbnailImage());
|
||||
case LargeImage: return QVariant(item.getLargeImage());
|
||||
case KeyUid: return QVariant(item.getKeyUid());
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void Model::setItems(QVector<Item> items)
|
||||
{
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
endResetModel();
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
Item Model::getItemAtIndex(int index)
|
||||
{
|
||||
if(index < 0 || index >= m_items.size())
|
||||
{
|
||||
return Item();
|
||||
}
|
||||
if(index < 0 || index >= m_items.size())
|
||||
{
|
||||
return Item();
|
||||
}
|
||||
|
||||
return m_items[index];
|
||||
return m_items[index];
|
||||
}
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -13,29 +13,29 @@ namespace Login
|
|||
{
|
||||
class Model : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ModelRole
|
||||
{
|
||||
Name = Qt::UserRole + 1,
|
||||
Identicon = Qt::UserRole + 2,
|
||||
ThumbnailImage = Qt::UserRole + 3,
|
||||
LargeImage = Qt::UserRole + 4,
|
||||
KeyUid = Qt::UserRole + 5
|
||||
};
|
||||
enum ModelRole
|
||||
{
|
||||
Name = Qt::UserRole + 1,
|
||||
Identicon = Qt::UserRole + 2,
|
||||
ThumbnailImage = Qt::UserRole + 3,
|
||||
LargeImage = Qt::UserRole + 4,
|
||||
KeyUid = Qt::UserRole + 5
|
||||
};
|
||||
|
||||
explicit Model(QObject* parent = nullptr);
|
||||
explicit Model(QObject* parent = nullptr);
|
||||
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
virtual int rowCount(const QModelIndex&) const;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
void setItems(QVector<Item> items);
|
||||
Item getItemAtIndex(int index);
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
virtual int rowCount(const QModelIndex&) const;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
void setItems(QVector<Item> items);
|
||||
Item getItemAtIndex(int index);
|
||||
|
||||
private:
|
||||
QVector<Item> m_items;
|
||||
QVector<Item> m_items;
|
||||
};
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -18,98 +18,98 @@ namespace Startup
|
|||
namespace Login
|
||||
{
|
||||
Module::Module(Modules::Startup::ModuleLoginDelegateInterface* delegate,
|
||||
// keychainService
|
||||
Accounts::ServiceInterface* accountsService)
|
||||
: m_delegate(delegate)
|
||||
// keychainService
|
||||
Accounts::ServiceInterface* accountsService)
|
||||
: m_delegate(delegate)
|
||||
{
|
||||
m_controller = new Controller(this, accountsService);
|
||||
m_view = new View(this);
|
||||
m_moduleLoaded = false;
|
||||
m_controller = new Controller(this, accountsService);
|
||||
m_view = new View(this);
|
||||
m_moduleLoaded = false;
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
{
|
||||
delete m_controller;
|
||||
delete m_view;
|
||||
delete m_controller;
|
||||
delete m_view;
|
||||
}
|
||||
|
||||
void Module::extractImages(Accounts::AccountDto account, QString& thumbnailImage, QString& largeImage)
|
||||
{
|
||||
foreach(const Accounts::Image& img, account.images)
|
||||
{
|
||||
if(img.imgType == "thumbnail")
|
||||
{
|
||||
thumbnailImage = img.uri;
|
||||
}
|
||||
else if(img.imgType == "large")
|
||||
{
|
||||
largeImage = img.uri;
|
||||
}
|
||||
}
|
||||
foreach(const Accounts::Image& img, account.images)
|
||||
{
|
||||
if(img.imgType == "thumbnail")
|
||||
{
|
||||
thumbnailImage = img.uri;
|
||||
}
|
||||
else if(img.imgType == "large")
|
||||
{
|
||||
largeImage = img.uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Module::load()
|
||||
{
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("loginModule", m_view);
|
||||
m_controller->init();
|
||||
m_view->load();
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("loginModule", m_view);
|
||||
m_controller->init();
|
||||
m_view->load();
|
||||
|
||||
QVector<Accounts::AccountDto> openedAccounts = m_controller->getOpenedAccounts();
|
||||
if(openedAccounts.size() > 0)
|
||||
{
|
||||
QVector<Item> items;
|
||||
foreach(const Accounts::AccountDto& acc, openedAccounts)
|
||||
{
|
||||
QString thumbnailImage;
|
||||
QString largeImage;
|
||||
Module::extractImages(acc, thumbnailImage, largeImage);
|
||||
items << Item(acc.name, acc.identicon, thumbnailImage, largeImage, acc.keyUid);
|
||||
}
|
||||
QVector<Accounts::AccountDto> openedAccounts = m_controller->getOpenedAccounts();
|
||||
if(openedAccounts.size() > 0)
|
||||
{
|
||||
QVector<Item> items;
|
||||
foreach(const Accounts::AccountDto& acc, openedAccounts)
|
||||
{
|
||||
QString thumbnailImage;
|
||||
QString largeImage;
|
||||
Module::extractImages(acc, thumbnailImage, largeImage);
|
||||
items << Item(acc.name, acc.identicon, thumbnailImage, largeImage, acc.keyUid);
|
||||
}
|
||||
|
||||
m_view->setModelItems(items);
|
||||
m_view->setModelItems(items);
|
||||
|
||||
// set the first account as selected one
|
||||
m_controller->setSelectedAccountKeyUid(items[0].getKeyUid());
|
||||
Module::setSelectedAccount(items[0]);
|
||||
}
|
||||
// set the first account as selected one
|
||||
m_controller->setSelectedAccountKeyUid(items[0].getKeyUid());
|
||||
Module::setSelectedAccount(items[0]);
|
||||
}
|
||||
}
|
||||
|
||||
bool Module::isLoaded()
|
||||
{
|
||||
return m_moduleLoaded;
|
||||
return m_moduleLoaded;
|
||||
}
|
||||
|
||||
void Module::viewDidLoad()
|
||||
{
|
||||
m_moduleLoaded = true;
|
||||
m_delegate->loginDidLoad();
|
||||
m_moduleLoaded = true;
|
||||
m_delegate->loginDidLoad();
|
||||
}
|
||||
|
||||
void Module::setSelectedAccount(Item item)
|
||||
{
|
||||
m_controller->setSelectedAccountKeyUid(item.getKeyUid());
|
||||
m_view->setSelectedAccount(item);
|
||||
m_controller->setSelectedAccountKeyUid(item.getKeyUid());
|
||||
m_view->setSelectedAccount(item);
|
||||
}
|
||||
|
||||
void Module::login(QString password)
|
||||
{
|
||||
m_controller->login(password);
|
||||
m_controller->login(password);
|
||||
}
|
||||
|
||||
void Module::emitAccountLoginError(QString error)
|
||||
{
|
||||
m_view->emitAccountLoginError(error);
|
||||
m_view->emitAccountLoginError(error);
|
||||
}
|
||||
|
||||
void Module::emitObtainingPasswordError(QString errorDescription)
|
||||
{
|
||||
m_view->emitObtainingPasswordError(errorDescription);
|
||||
m_view->emitObtainingPasswordError(errorDescription);
|
||||
}
|
||||
|
||||
void Module::emitObtainingPasswordSuccess(QString password)
|
||||
{
|
||||
m_view->emitObtainingPasswordSuccess(password);
|
||||
m_view->emitObtainingPasswordSuccess(password);
|
||||
}
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -20,27 +20,27 @@ namespace Login
|
|||
class Module : public ModuleAccessInterface, ModuleControllerDelegateInterface, ModuleViewDelegateInterface
|
||||
{
|
||||
private:
|
||||
Modules::Startup::ModuleLoginDelegateInterface* m_delegate;
|
||||
View* m_view;
|
||||
Controller* m_controller;
|
||||
bool m_moduleLoaded;
|
||||
Modules::Startup::ModuleLoginDelegateInterface* m_delegate;
|
||||
View* m_view;
|
||||
Controller* m_controller;
|
||||
bool m_moduleLoaded;
|
||||
|
||||
public:
|
||||
Module(Modules::Startup::ModuleLoginDelegateInterface* delegate,
|
||||
// keychainService
|
||||
Accounts::ServiceInterface* accountsService);
|
||||
~Module();
|
||||
void extractImages(Accounts::AccountDto account, QString &thumbnailImage, QString &largeImage);
|
||||
void load() override;
|
||||
bool isLoaded() override;
|
||||
void viewDidLoad() override;
|
||||
void setSelectedAccount(Item item) override;
|
||||
void login(QString password) override;
|
||||
void setupAccountError();
|
||||
void emitAccountLoginError(QString error) override;
|
||||
void emitObtainingPasswordError(QString errorDescription) override;
|
||||
void emitObtainingPasswordSuccess(QString password) override;
|
||||
Module(Modules::Startup::ModuleLoginDelegateInterface* delegate,
|
||||
// keychainService
|
||||
Accounts::ServiceInterface* accountsService);
|
||||
~Module();
|
||||
void extractImages(Accounts::AccountDto account, QString& thumbnailImage, QString& largeImage);
|
||||
void load() override;
|
||||
bool isLoaded() override;
|
||||
void viewDidLoad() override;
|
||||
void setSelectedAccount(Item item) override;
|
||||
void login(QString password) override;
|
||||
void setupAccountError();
|
||||
void emitAccountLoginError(QString error) override;
|
||||
void emitObtainingPasswordError(QString errorDescription) override;
|
||||
void emitObtainingPasswordSuccess(QString password) override;
|
||||
};
|
||||
}; // namespace Login
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace Login
|
|||
class ModuleAccessInterface
|
||||
{
|
||||
public:
|
||||
virtual void load() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
virtual bool isLoaded() = 0;
|
||||
virtual bool isLoaded() = 0;
|
||||
};
|
||||
}; // namespace Login
|
||||
}; // namespace Startup
|
||||
|
|
|
@ -9,36 +9,36 @@ namespace Startup
|
|||
namespace Login
|
||||
{
|
||||
SelectedAccount::SelectedAccount(QObject* parent)
|
||||
: QObject(parent)
|
||||
: QObject(parent)
|
||||
{ }
|
||||
|
||||
void SelectedAccount::setSelectedAccountData(Item item)
|
||||
{
|
||||
m_item = item;
|
||||
m_item = item;
|
||||
}
|
||||
QString SelectedAccount::getName()
|
||||
{
|
||||
return m_item.getName();
|
||||
return m_item.getName();
|
||||
}
|
||||
QString SelectedAccount::getIdenticon()
|
||||
{
|
||||
return m_item.getIdenticon();
|
||||
return m_item.getIdenticon();
|
||||
}
|
||||
|
||||
QString SelectedAccount::getKeyUid()
|
||||
{
|
||||
return m_item.getKeyUid();
|
||||
return m_item.getKeyUid();
|
||||
}
|
||||
|
||||
QString SelectedAccount::getThumbnailImage()
|
||||
{
|
||||
return m_item.getThumbnailImage();
|
||||
return m_item.getThumbnailImage();
|
||||
}
|
||||
|
||||
QString SelectedAccount::getLargeImage()
|
||||
{
|
||||
return m_item.getLargeImage();
|
||||
return m_item.getLargeImage();
|
||||
}
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "item.h"
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include "item.h"
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
|
@ -13,27 +13,27 @@ namespace Login
|
|||
|
||||
class SelectedAccount : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString username READ getName CONSTANT)
|
||||
Q_PROPERTY(QString identicon READ getIdenticon CONSTANT)
|
||||
Q_PROPERTY(QString keyUid READ getKeyUid CONSTANT)
|
||||
Q_PROPERTY(QString thumbnailImage READ getThumbnailImage CONSTANT)
|
||||
Q_PROPERTY(QString largeImage READ getLargeImage CONSTANT)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString username READ getName CONSTANT)
|
||||
Q_PROPERTY(QString identicon READ getIdenticon CONSTANT)
|
||||
Q_PROPERTY(QString keyUid READ getKeyUid CONSTANT)
|
||||
Q_PROPERTY(QString thumbnailImage READ getThumbnailImage CONSTANT)
|
||||
Q_PROPERTY(QString largeImage READ getLargeImage CONSTANT)
|
||||
|
||||
public:
|
||||
explicit SelectedAccount(QObject* parent = nullptr);
|
||||
explicit SelectedAccount(QObject* parent = nullptr);
|
||||
|
||||
private:
|
||||
Item m_item;
|
||||
Item m_item;
|
||||
|
||||
public slots:
|
||||
void setSelectedAccountData(Item item);
|
||||
QString getName();
|
||||
QString getIdenticon();
|
||||
QString getKeyUid();
|
||||
QString getThumbnailImage();
|
||||
QString getLargeImage();
|
||||
void setSelectedAccountData(Item item);
|
||||
QString getName();
|
||||
QString getIdenticon();
|
||||
QString getKeyUid();
|
||||
QString getThumbnailImage();
|
||||
QString getLargeImage();
|
||||
};
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -12,72 +12,72 @@ namespace Startup
|
|||
namespace Login
|
||||
{
|
||||
View::View(ModuleViewDelegateInterface* delegate, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_delegate(delegate)
|
||||
: QObject(parent)
|
||||
, m_delegate(delegate)
|
||||
{
|
||||
m_model = new Model();
|
||||
m_selectedAccount = new SelectedAccount();
|
||||
m_model = new Model();
|
||||
m_selectedAccount = new SelectedAccount();
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{
|
||||
delete m_model;
|
||||
delete m_selectedAccount;
|
||||
delete m_model;
|
||||
delete m_selectedAccount;
|
||||
}
|
||||
|
||||
void View::load()
|
||||
{
|
||||
m_delegate->viewDidLoad();
|
||||
m_delegate->viewDidLoad();
|
||||
}
|
||||
|
||||
Model* View::getModel()
|
||||
{
|
||||
return m_model;
|
||||
return m_model;
|
||||
}
|
||||
|
||||
SelectedAccount* View::getSelectedAccount()
|
||||
{
|
||||
return m_selectedAccount;
|
||||
return m_selectedAccount;
|
||||
}
|
||||
|
||||
void View::setSelectedAccount(Item item)
|
||||
{
|
||||
m_selectedAccount->setSelectedAccountData(item);
|
||||
View::selectedAccountChanged();
|
||||
m_selectedAccount->setSelectedAccountData(item);
|
||||
View::selectedAccountChanged();
|
||||
}
|
||||
|
||||
void View::setSelectedAccountByIndex(int index)
|
||||
{
|
||||
Item item = m_model->getItemAtIndex(index);
|
||||
m_delegate->setSelectedAccount(item);
|
||||
Item item = m_model->getItemAtIndex(index);
|
||||
m_delegate->setSelectedAccount(item);
|
||||
}
|
||||
|
||||
void View::setModelItems(QVector<Item> accounts)
|
||||
{
|
||||
m_model->setItems(accounts);
|
||||
View::modelChanged();
|
||||
m_model->setItems(accounts);
|
||||
View::modelChanged();
|
||||
}
|
||||
|
||||
void View::login(QString password)
|
||||
{
|
||||
m_delegate->login(password);
|
||||
m_delegate->login(password);
|
||||
}
|
||||
|
||||
void View::emitAccountLoginError(QString error)
|
||||
{
|
||||
emit View::accountLoginError(error);
|
||||
emit View::accountLoginError(error);
|
||||
}
|
||||
|
||||
void View::emitObtainingPasswordError(QString errorDescription)
|
||||
{
|
||||
emit View::obtainingPasswordError(errorDescription);
|
||||
emit View::obtainingPasswordError(errorDescription);
|
||||
}
|
||||
|
||||
void View::emitObtainingPasswordSuccess(QString password)
|
||||
{
|
||||
emit View::obtainingPasswordSuccess(password);
|
||||
emit View::obtainingPasswordSuccess(password);
|
||||
}
|
||||
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -16,38 +16,38 @@ namespace Login
|
|||
|
||||
class View : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(SelectedAccount* selectedAccount READ getSelectedAccount NOTIFY selectedAccountChanged)
|
||||
Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(SelectedAccount* selectedAccount READ getSelectedAccount NOTIFY selectedAccountChanged)
|
||||
Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged)
|
||||
|
||||
public:
|
||||
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
~View();
|
||||
void load();
|
||||
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
~View();
|
||||
void load();
|
||||
|
||||
signals:
|
||||
void selectedAccountChanged();
|
||||
void modelChanged();
|
||||
void accountLoginError(QString error);
|
||||
void obtainingPasswordError(QString errorDescription);
|
||||
void obtainingPasswordSuccess(QString password);
|
||||
void selectedAccountChanged();
|
||||
void modelChanged();
|
||||
void accountLoginError(QString error);
|
||||
void obtainingPasswordError(QString errorDescription);
|
||||
void obtainingPasswordSuccess(QString password);
|
||||
|
||||
private:
|
||||
ModuleViewDelegateInterface* m_delegate;
|
||||
Model* m_model;
|
||||
SelectedAccount* m_selectedAccount;
|
||||
ModuleViewDelegateInterface* m_delegate;
|
||||
Model* m_model;
|
||||
SelectedAccount* m_selectedAccount;
|
||||
|
||||
public slots:
|
||||
Model* getModel();
|
||||
SelectedAccount* getSelectedAccount();
|
||||
void setSelectedAccount(Item item);
|
||||
void setSelectedAccountByIndex(int index);
|
||||
void setModelItems(QVector<Item> accounts);
|
||||
void login(QString password);
|
||||
void emitAccountLoginError(QString error);
|
||||
void emitObtainingPasswordError(QString errorDescription);
|
||||
void emitObtainingPasswordSuccess(QString password);
|
||||
Model* getModel();
|
||||
SelectedAccount* getSelectedAccount();
|
||||
void setSelectedAccount(Item item);
|
||||
void setSelectedAccountByIndex(int index);
|
||||
void setModelItems(QVector<Item> accounts);
|
||||
void login(QString password);
|
||||
void emitAccountLoginError(QString error);
|
||||
void emitObtainingPasswordError(QString errorDescription);
|
||||
void emitObtainingPasswordSuccess(QString password);
|
||||
};
|
||||
} // namespace Login
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -15,87 +15,87 @@ namespace Modules
|
|||
namespace Startup
|
||||
{
|
||||
Module::Module(AppControllerDelegate* delegate,
|
||||
/*keychainService,*/
|
||||
Accounts::ServiceInterface* accountsService)
|
||||
: m_delegate(delegate)
|
||||
/*keychainService,*/
|
||||
Accounts::ServiceInterface* accountsService)
|
||||
: m_delegate(delegate)
|
||||
{
|
||||
m_controller = new Controller(this, accountsService);
|
||||
m_view = new View(this);
|
||||
m_controller = new Controller(this, accountsService);
|
||||
m_view = new View(this);
|
||||
|
||||
// Submodules
|
||||
m_onboardingModule = new Modules::Startup::Onboarding::Module(this, accountsService);
|
||||
m_loginModule = new Modules::Startup::Login::Module(this, /*keychainService, */ accountsService);
|
||||
// Submodules
|
||||
m_onboardingModule = new Modules::Startup::Onboarding::Module(this, accountsService);
|
||||
m_loginModule = new Modules::Startup::Login::Module(this, /*keychainService, */ accountsService);
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
{
|
||||
delete m_controller;
|
||||
delete m_view;
|
||||
delete m_onboardingModule;
|
||||
delete m_loginModule;
|
||||
delete m_controller;
|
||||
delete m_view;
|
||||
delete m_onboardingModule;
|
||||
delete m_loginModule;
|
||||
}
|
||||
|
||||
void Module::load()
|
||||
{
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("startupModule", m_view);
|
||||
m_controller->init();
|
||||
m_view->load();
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("startupModule", m_view);
|
||||
m_controller->init();
|
||||
m_view->load();
|
||||
|
||||
AppState initialAppState(AppState::OnboardingState);
|
||||
if(!m_controller->shouldStartWithOnboardingScreen())
|
||||
{
|
||||
initialAppState = AppState::LoginState;
|
||||
}
|
||||
AppState initialAppState(AppState::OnboardingState);
|
||||
if(!m_controller->shouldStartWithOnboardingScreen())
|
||||
{
|
||||
initialAppState = AppState::LoginState;
|
||||
}
|
||||
|
||||
m_view->setAppState(initialAppState);
|
||||
m_view->setAppState(initialAppState);
|
||||
|
||||
m_onboardingModule->load();
|
||||
m_loginModule->load();
|
||||
m_onboardingModule->load();
|
||||
m_loginModule->load();
|
||||
}
|
||||
|
||||
void Module::checkIfModuleDidLoad()
|
||||
{
|
||||
if(!m_onboardingModule->isLoaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!m_onboardingModule->isLoaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(!m_loginModule->isLoaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!m_loginModule->isLoaded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_delegate->startupDidLoad();
|
||||
m_delegate->startupDidLoad();
|
||||
}
|
||||
|
||||
void Module::viewDidLoad()
|
||||
{
|
||||
Module::checkIfModuleDidLoad();
|
||||
Module::checkIfModuleDidLoad();
|
||||
}
|
||||
|
||||
void Module::onboardingDidLoad()
|
||||
{
|
||||
Module::checkIfModuleDidLoad();
|
||||
Module::checkIfModuleDidLoad();
|
||||
}
|
||||
|
||||
void Module::loginDidLoad()
|
||||
{
|
||||
Module::checkIfModuleDidLoad();
|
||||
Module::checkIfModuleDidLoad();
|
||||
}
|
||||
|
||||
void Module::userLoggedIn()
|
||||
{
|
||||
m_delegate->userLoggedIn();
|
||||
m_delegate->userLoggedIn();
|
||||
}
|
||||
|
||||
void Module::moveToAppState()
|
||||
{
|
||||
m_view->setAppState(AppState::MainAppState);
|
||||
m_view->setAppState(AppState::MainAppState);
|
||||
}
|
||||
|
||||
void Module::emitLogOut()
|
||||
{
|
||||
m_view->emitLogOut();
|
||||
m_view->emitLogOut();
|
||||
}
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -18,31 +18,31 @@ namespace Modules
|
|||
namespace Startup
|
||||
{
|
||||
class Module : public ModuleAccessInterface,
|
||||
ModuleOnboardingDelegateInterface,
|
||||
ModuleLoginDelegateInterface,
|
||||
ModuleControllerDelegateInterface,
|
||||
ModuleViewDelegateInterface
|
||||
ModuleOnboardingDelegateInterface,
|
||||
ModuleLoginDelegateInterface,
|
||||
ModuleControllerDelegateInterface,
|
||||
ModuleViewDelegateInterface
|
||||
{
|
||||
private:
|
||||
AppControllerDelegate* m_delegate;
|
||||
View* m_view;
|
||||
Controller* m_controller;
|
||||
AppControllerDelegate* m_delegate;
|
||||
View* m_view;
|
||||
Controller* m_controller;
|
||||
|
||||
Modules::Startup::Onboarding::ModuleAccessInterface* m_onboardingModule;
|
||||
Modules::Startup::Login::ModuleAccessInterface* m_loginModule;
|
||||
Modules::Startup::Onboarding::ModuleAccessInterface* m_onboardingModule;
|
||||
Modules::Startup::Login::ModuleAccessInterface* m_loginModule;
|
||||
|
||||
public:
|
||||
Module(AppControllerDelegate* delegate,
|
||||
/*keychainService,*/ Accounts::ServiceInterface* accountsService);
|
||||
~Module();
|
||||
void load() override;
|
||||
void checkIfModuleDidLoad();
|
||||
void viewDidLoad() override;
|
||||
void onboardingDidLoad();
|
||||
void loginDidLoad();
|
||||
void userLoggedIn() override;
|
||||
void moveToAppState() override;
|
||||
void emitLogOut() override;
|
||||
Module(AppControllerDelegate* delegate,
|
||||
/*keychainService,*/ Accounts::ServiceInterface* accountsService);
|
||||
~Module();
|
||||
void load() override;
|
||||
void checkIfModuleDidLoad();
|
||||
void viewDidLoad() override;
|
||||
void onboardingDidLoad();
|
||||
void loginDidLoad();
|
||||
void userLoggedIn() override;
|
||||
void moveToAppState() override;
|
||||
void emitLogOut() override;
|
||||
};
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace Startup
|
|||
class ModuleAccessInterface
|
||||
{
|
||||
public:
|
||||
virtual void load() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
virtual void moveToAppState() = 0;
|
||||
};
|
||||
|
|
|
@ -14,67 +14,67 @@ namespace Startup
|
|||
namespace Onboarding
|
||||
{
|
||||
Controller::Controller(ModuleControllerDelegateInterface* delegate,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_accountsService(accountsService)
|
||||
, m_delegate(delegate)
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_accountsService(accountsService)
|
||||
, m_delegate(delegate)
|
||||
{ }
|
||||
|
||||
void Controller::init()
|
||||
{
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin);
|
||||
QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin);
|
||||
}
|
||||
|
||||
void Controller::onLogin(Signals::NodeSignal signal)
|
||||
{
|
||||
if(!signal.error.isEmpty())
|
||||
{
|
||||
m_delegate->setupAccountError();
|
||||
}
|
||||
if(!signal.error.isEmpty())
|
||||
{
|
||||
m_delegate->setupAccountError();
|
||||
}
|
||||
}
|
||||
|
||||
QVector<Accounts::GeneratedAccountDto> Controller::getGeneratedAccounts()
|
||||
{
|
||||
return m_accountsService->generatedAccounts();
|
||||
return m_accountsService->generatedAccounts();
|
||||
}
|
||||
|
||||
Accounts::GeneratedAccountDto Controller::getImportedAccount()
|
||||
{
|
||||
return m_accountsService->getImportedAccount();
|
||||
return m_accountsService->getImportedAccount();
|
||||
}
|
||||
|
||||
void Controller::setSelectedAccountByIndex(int index)
|
||||
{
|
||||
auto accounts = Controller::getGeneratedAccounts();
|
||||
m_selectedAccountId = accounts[index].id;
|
||||
auto accounts = Controller::getGeneratedAccounts();
|
||||
m_selectedAccountId = accounts[index].id;
|
||||
}
|
||||
|
||||
void Controller::storeSelectedAccountAndLogin(QString password)
|
||||
{
|
||||
if(!m_accountsService->setupAccount(m_selectedAccountId, password))
|
||||
{
|
||||
m_delegate->setupAccountError();
|
||||
}
|
||||
if(!m_accountsService->setupAccount(m_selectedAccountId, password))
|
||||
{
|
||||
m_delegate->setupAccountError();
|
||||
}
|
||||
}
|
||||
|
||||
QString Controller::validateMnemonic(QString mnemonic)
|
||||
{
|
||||
return m_accountsService->validateMnemonic(mnemonic);
|
||||
return m_accountsService->validateMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
void Controller::importMnemonic(QString mnemonic)
|
||||
{
|
||||
if(m_accountsService->importMnemonic(mnemonic))
|
||||
{
|
||||
m_selectedAccountId = Controller::getImportedAccount().id;
|
||||
m_delegate->importAccountSuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_delegate->importAccountError();
|
||||
}
|
||||
if(m_accountsService->importMnemonic(mnemonic))
|
||||
{
|
||||
m_selectedAccountId = Controller::getImportedAccount().id;
|
||||
m_delegate->importAccountSuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_delegate->importAccountError();
|
||||
}
|
||||
}
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -16,26 +16,26 @@ namespace Onboarding
|
|||
{
|
||||
class Controller : public QObject, ControllerInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Controller(ModuleControllerDelegateInterface* delegate,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent = nullptr);
|
||||
void init() override;
|
||||
QVector<Accounts::GeneratedAccountDto> getGeneratedAccounts() override;
|
||||
Accounts::GeneratedAccountDto getImportedAccount() override;
|
||||
void setSelectedAccountByIndex(int index) override;
|
||||
void storeSelectedAccountAndLogin(QString password) override;
|
||||
QString validateMnemonic(QString mnemonic) override;
|
||||
void importMnemonic(QString mnemonic) override;
|
||||
void onLogin(Signals::NodeSignal signal);
|
||||
Controller(ModuleControllerDelegateInterface* delegate,
|
||||
Accounts::ServiceInterface* accountsService,
|
||||
QObject* parent = nullptr);
|
||||
void init() override;
|
||||
QVector<Accounts::GeneratedAccountDto> getGeneratedAccounts() override;
|
||||
Accounts::GeneratedAccountDto getImportedAccount() override;
|
||||
void setSelectedAccountByIndex(int index) override;
|
||||
void storeSelectedAccountAndLogin(QString password) override;
|
||||
QString validateMnemonic(QString mnemonic) override;
|
||||
void importMnemonic(QString mnemonic) override;
|
||||
void onLogin(Signals::NodeSignal signal);
|
||||
|
||||
private:
|
||||
Accounts::ServiceInterface* m_accountsService;
|
||||
ModuleControllerDelegateInterface* m_delegate;
|
||||
QString m_selectedAccountId;
|
||||
Accounts::ServiceInterface* m_accountsService;
|
||||
ModuleControllerDelegateInterface* m_delegate;
|
||||
QString m_selectedAccountId;
|
||||
};
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -14,19 +14,19 @@ namespace Onboarding
|
|||
class ControllerInterface
|
||||
{
|
||||
public:
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual QVector<Accounts::GeneratedAccountDto> getGeneratedAccounts() = 0;
|
||||
|
||||
virtual void setSelectedAccountByIndex(int index) = 0;
|
||||
|
||||
virtual void storeSelectedAccountAndLogin(QString password) = 0;
|
||||
|
||||
virtual Accounts::GeneratedAccountDto getImportedAccount() = 0;
|
||||
|
||||
virtual QString validateMnemonic(QString mnemonic) = 0;
|
||||
|
||||
virtual void importMnemonic(QString mnemonic) = 0;
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual QVector<Accounts::GeneratedAccountDto> getGeneratedAccounts() = 0;
|
||||
|
||||
virtual void setSelectedAccountByIndex(int index) = 0;
|
||||
|
||||
virtual void storeSelectedAccountAndLogin(QString password) = 0;
|
||||
|
||||
virtual Accounts::GeneratedAccountDto getImportedAccount() = 0;
|
||||
|
||||
virtual QString validateMnemonic(QString mnemonic) = 0;
|
||||
|
||||
virtual void importMnemonic(QString mnemonic) = 0;
|
||||
};
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
|
|
|
@ -9,12 +9,12 @@ namespace Onboarding
|
|||
class ModuleControllerDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void setupAccountError() = 0;
|
||||
virtual void setupAccountError() = 0;
|
||||
|
||||
virtual void importAccountError() = 0;
|
||||
virtual void importAccountError() = 0;
|
||||
|
||||
virtual void importAccountSuccess() = 0;
|
||||
virtual void importAccountSuccess() = 0;
|
||||
};
|
||||
}; // namespace Onboarding
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -11,18 +11,18 @@ namespace Onboarding
|
|||
class ModuleViewDelegateInterface
|
||||
{
|
||||
public:
|
||||
virtual void viewDidLoad() = 0;
|
||||
virtual void viewDidLoad() = 0;
|
||||
|
||||
virtual void setSelectedAccountByIndex(int index) = 0;
|
||||
virtual void setSelectedAccountByIndex(int index) = 0;
|
||||
|
||||
virtual void storeSelectedAccountAndLogin(QString password) = 0;
|
||||
virtual void storeSelectedAccountAndLogin(QString password) = 0;
|
||||
|
||||
virtual Accounts::GeneratedAccountDto getImportedAccount() = 0;
|
||||
virtual Accounts::GeneratedAccountDto getImportedAccount() = 0;
|
||||
|
||||
virtual QString validateMnemonic(QString mnemonic) = 0;
|
||||
virtual QString validateMnemonic(QString mnemonic) = 0;
|
||||
|
||||
virtual void importMnemonic(QString mnemonic) = 0;
|
||||
virtual void importMnemonic(QString mnemonic) = 0;
|
||||
};
|
||||
}; // namespace Onboarding
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -8,32 +8,32 @@ namespace Startup
|
|||
namespace Onboarding
|
||||
{
|
||||
Item::Item(QString id, QString alias, QString identicon, QString address, QString keyUid)
|
||||
: m_id(id)
|
||||
, m_alias(alias)
|
||||
, m_identicon(identicon)
|
||||
, m_address(address)
|
||||
, m_keyUid(keyUid)
|
||||
: m_id(id)
|
||||
, m_alias(alias)
|
||||
, m_identicon(identicon)
|
||||
, m_address(address)
|
||||
, m_keyUid(keyUid)
|
||||
{ }
|
||||
QString Item::getId()
|
||||
{
|
||||
return m_id;
|
||||
return m_id;
|
||||
}
|
||||
QString Item::getAlias()
|
||||
{
|
||||
return m_alias;
|
||||
return m_alias;
|
||||
}
|
||||
QString Item::getIdenticon()
|
||||
{
|
||||
return m_identicon;
|
||||
return m_identicon;
|
||||
}
|
||||
QString Item::getAddress()
|
||||
{
|
||||
return m_address;
|
||||
return m_address;
|
||||
}
|
||||
QString Item::getKeyUid()
|
||||
{
|
||||
return m_keyUid;
|
||||
return m_keyUid;
|
||||
}
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -11,19 +11,19 @@ namespace Onboarding
|
|||
class Item
|
||||
{
|
||||
private:
|
||||
QString m_id;
|
||||
QString m_alias;
|
||||
QString m_identicon;
|
||||
QString m_address;
|
||||
QString m_keyUid;
|
||||
QString m_id;
|
||||
QString m_alias;
|
||||
QString m_identicon;
|
||||
QString m_address;
|
||||
QString m_keyUid;
|
||||
|
||||
public:
|
||||
Item(QString id, QString alias, QString identicon, QString address, QString keyUid);
|
||||
QString getId();
|
||||
QString getAlias();
|
||||
QString getIdenticon();
|
||||
QString getAddress();
|
||||
QString getKeyUid();
|
||||
Item(QString id, QString alias, QString identicon, QString address, QString keyUid);
|
||||
QString getId();
|
||||
QString getAlias();
|
||||
QString getIdenticon();
|
||||
QString getAddress();
|
||||
QString getKeyUid();
|
||||
};
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
|
|
|
@ -9,58 +9,58 @@ namespace Startup
|
|||
namespace Onboarding
|
||||
{
|
||||
Model::Model(QObject* parent)
|
||||
: QAbstractListModel(parent)
|
||||
: QAbstractListModel(parent)
|
||||
{ }
|
||||
|
||||
QHash<int, QByteArray> Model::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Id] = "accountId";
|
||||
roles[Alias] = "username";
|
||||
roles[Identicon] = "identicon";
|
||||
roles[Address] = "address";
|
||||
roles[KeyUid] = "keyUid";
|
||||
return roles;
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[Id] = "accountId";
|
||||
roles[Alias] = "username";
|
||||
roles[Identicon] = "identicon";
|
||||
roles[Address] = "address";
|
||||
roles[KeyUid] = "keyUid";
|
||||
return roles;
|
||||
}
|
||||
|
||||
int Model::rowCount(const QModelIndex& parent = QModelIndex()) const
|
||||
{
|
||||
return m_items.size();
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
QVariant Model::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if(!index.isValid())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
if(!index.isValid())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if(index.row() < 0 || index.row() > m_items.size())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
if(index.row() < 0 || index.row() > m_items.size())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Item item = m_items[index.row()];
|
||||
Item item = m_items[index.row()];
|
||||
|
||||
switch(role)
|
||||
{
|
||||
case Id: return QVariant(item.getId());
|
||||
case Alias: return QVariant(item.getAlias());
|
||||
case Identicon: return QVariant(item.getIdenticon());
|
||||
case Address: return QVariant(item.getAddress());
|
||||
case KeyUid: return QVariant(item.getKeyUid());
|
||||
}
|
||||
switch(role)
|
||||
{
|
||||
case Id: return QVariant(item.getId());
|
||||
case Alias: return QVariant(item.getAlias());
|
||||
case Identicon: return QVariant(item.getIdenticon());
|
||||
case Address: return QVariant(item.getAddress());
|
||||
case KeyUid: return QVariant(item.getKeyUid());
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void Model::setItems(QVector<Item> items)
|
||||
{
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
endResetModel();
|
||||
beginResetModel();
|
||||
m_items = items;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "item.h"
|
||||
#include <QAbstractListModel>
|
||||
#include <QHash>
|
||||
#include <QVector>
|
||||
#include "item.h"
|
||||
|
||||
namespace Modules
|
||||
{
|
||||
|
@ -13,28 +13,28 @@ namespace Onboarding
|
|||
{
|
||||
class Model : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ModelRole
|
||||
{
|
||||
Id = Qt::UserRole + 1,
|
||||
Alias = Qt::UserRole + 2,
|
||||
Identicon = Qt::UserRole + 3,
|
||||
Address = Qt::UserRole + 4,
|
||||
KeyUid = Qt::UserRole + 5
|
||||
};
|
||||
enum ModelRole
|
||||
{
|
||||
Id = Qt::UserRole + 1,
|
||||
Alias = Qt::UserRole + 2,
|
||||
Identicon = Qt::UserRole + 3,
|
||||
Address = Qt::UserRole + 4,
|
||||
KeyUid = Qt::UserRole + 5
|
||||
};
|
||||
|
||||
explicit Model(QObject* parent = nullptr);
|
||||
explicit Model(QObject* parent = nullptr);
|
||||
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
virtual int rowCount(const QModelIndex&) const;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
void setItems(QVector<Item> items);
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
virtual int rowCount(const QModelIndex&) const;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
void setItems(QVector<Item> items);
|
||||
|
||||
private:
|
||||
QVector<Item> m_items;
|
||||
QVector<Item> m_items;
|
||||
};
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -18,85 +18,85 @@ namespace Startup
|
|||
namespace Onboarding
|
||||
{
|
||||
Module::Module(Modules::Startup::ModuleOnboardingDelegateInterface* delegate,
|
||||
Accounts::ServiceInterface* accountsService)
|
||||
: m_delegate(delegate)
|
||||
Accounts::ServiceInterface* accountsService)
|
||||
: m_delegate(delegate)
|
||||
{
|
||||
m_controller = new Controller(this, accountsService);
|
||||
m_view = new View(this);
|
||||
m_moduleLoaded = false;
|
||||
m_controller = new Controller(this, accountsService);
|
||||
m_view = new View(this);
|
||||
m_moduleLoaded = false;
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
{
|
||||
delete m_controller;
|
||||
delete m_view;
|
||||
delete m_controller;
|
||||
delete m_view;
|
||||
}
|
||||
|
||||
void Module::load()
|
||||
{
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("onboardingModule", m_view);
|
||||
m_controller->init();
|
||||
m_view->load();
|
||||
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("onboardingModule", m_view);
|
||||
m_controller->init();
|
||||
m_view->load();
|
||||
|
||||
QVector<Accounts::GeneratedAccountDto> gAcc = m_controller->getGeneratedAccounts();
|
||||
QVector<Item> accounts;
|
||||
foreach(const Accounts::GeneratedAccountDto& acc, gAcc)
|
||||
{
|
||||
accounts << Item(acc.id, acc.alias, acc.identicon, acc.address, acc.keyUid);
|
||||
}
|
||||
QVector<Accounts::GeneratedAccountDto> gAcc = m_controller->getGeneratedAccounts();
|
||||
QVector<Item> accounts;
|
||||
foreach(const Accounts::GeneratedAccountDto& acc, gAcc)
|
||||
{
|
||||
accounts << Item(acc.id, acc.alias, acc.identicon, acc.address, acc.keyUid);
|
||||
}
|
||||
|
||||
m_view->setAccountList(accounts);
|
||||
m_view->setAccountList(accounts);
|
||||
}
|
||||
|
||||
bool Module::isLoaded()
|
||||
{
|
||||
return m_moduleLoaded;
|
||||
return m_moduleLoaded;
|
||||
}
|
||||
|
||||
void Module::viewDidLoad()
|
||||
{
|
||||
m_moduleLoaded = true;
|
||||
m_delegate->onboardingDidLoad();
|
||||
m_moduleLoaded = true;
|
||||
m_delegate->onboardingDidLoad();
|
||||
}
|
||||
|
||||
void Module::setSelectedAccountByIndex(int index)
|
||||
{
|
||||
m_controller->setSelectedAccountByIndex(index);
|
||||
m_controller->setSelectedAccountByIndex(index);
|
||||
}
|
||||
|
||||
void Module::storeSelectedAccountAndLogin(QString password)
|
||||
{
|
||||
m_controller->storeSelectedAccountAndLogin(password);
|
||||
m_controller->storeSelectedAccountAndLogin(password);
|
||||
}
|
||||
void Module::setupAccountError()
|
||||
{
|
||||
m_view->setupAccountError();
|
||||
m_view->setupAccountError();
|
||||
}
|
||||
|
||||
Accounts::GeneratedAccountDto Module::getImportedAccount()
|
||||
{
|
||||
return m_controller->getImportedAccount();
|
||||
return m_controller->getImportedAccount();
|
||||
}
|
||||
|
||||
QString Module::validateMnemonic(QString mnemonic)
|
||||
{
|
||||
return m_controller->validateMnemonic(mnemonic);
|
||||
return m_controller->validateMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
void Module::importMnemonic(QString mnemonic)
|
||||
{
|
||||
m_controller->importMnemonic(mnemonic);
|
||||
m_controller->importMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
void Module::importAccountError()
|
||||
{
|
||||
m_view->importAccountError();
|
||||
m_view->importAccountError();
|
||||
}
|
||||
|
||||
void Module::importAccountSuccess()
|
||||
{
|
||||
m_view->importAccountSuccess();
|
||||
m_view->importAccountSuccess();
|
||||
}
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -19,26 +19,26 @@ namespace Onboarding
|
|||
class Module : public ModuleAccessInterface, ModuleControllerDelegateInterface, ModuleViewDelegateInterface
|
||||
{
|
||||
private:
|
||||
Modules::Startup::ModuleOnboardingDelegateInterface* m_delegate;
|
||||
View* m_view;
|
||||
Controller* m_controller;
|
||||
bool m_moduleLoaded;
|
||||
Modules::Startup::ModuleOnboardingDelegateInterface* m_delegate;
|
||||
View* m_view;
|
||||
Controller* m_controller;
|
||||
bool m_moduleLoaded;
|
||||
|
||||
public:
|
||||
Module(Modules::Startup::ModuleOnboardingDelegateInterface* delegate, Accounts::ServiceInterface* accountsService);
|
||||
~Module();
|
||||
void load() override;
|
||||
bool isLoaded() override;
|
||||
void viewDidLoad() override;
|
||||
void setSelectedAccountByIndex(int index) override;
|
||||
void storeSelectedAccountAndLogin(QString password) override;
|
||||
void setupAccountError() override;
|
||||
Accounts::GeneratedAccountDto getImportedAccount() override;
|
||||
QString validateMnemonic(QString mnemonic) override;
|
||||
void importMnemonic(QString mnemonic) override;
|
||||
void importAccountError() override;
|
||||
void importAccountSuccess() override;
|
||||
Module(Modules::Startup::ModuleOnboardingDelegateInterface* delegate, Accounts::ServiceInterface* accountsService);
|
||||
~Module();
|
||||
void load() override;
|
||||
bool isLoaded() override;
|
||||
void viewDidLoad() override;
|
||||
void setSelectedAccountByIndex(int index) override;
|
||||
void storeSelectedAccountAndLogin(QString password) override;
|
||||
void setupAccountError() override;
|
||||
Accounts::GeneratedAccountDto getImportedAccount() override;
|
||||
QString validateMnemonic(QString mnemonic) override;
|
||||
void importMnemonic(QString mnemonic) override;
|
||||
void importAccountError() override;
|
||||
void importAccountSuccess() override;
|
||||
};
|
||||
}; // namespace Onboarding
|
||||
}; // namespace Startup
|
||||
}; // namespace Modules
|
||||
}; // namespace Modules
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace Onboarding
|
|||
class ModuleAccessInterface
|
||||
{
|
||||
public:
|
||||
virtual void load() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
virtual bool isLoaded() = 0;
|
||||
virtual bool isLoaded() = 0;
|
||||
};
|
||||
}; // namespace Onboarding
|
||||
}; // namespace Startup
|
||||
|
|
|
@ -10,84 +10,84 @@ namespace Startup
|
|||
namespace Onboarding
|
||||
{
|
||||
View::View(ModuleViewDelegateInterface* delegate, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_delegate(delegate)
|
||||
: QObject(parent)
|
||||
, m_delegate(delegate)
|
||||
{
|
||||
m_model = new Model();
|
||||
m_model = new Model();
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{
|
||||
delete m_model;
|
||||
delete m_model;
|
||||
}
|
||||
|
||||
void View::load()
|
||||
{
|
||||
m_delegate->viewDidLoad();
|
||||
m_delegate->viewDidLoad();
|
||||
}
|
||||
|
||||
Model* View::getModel()
|
||||
{
|
||||
return m_model;
|
||||
return m_model;
|
||||
}
|
||||
|
||||
void View::setAccountList(QVector<Item> accounts)
|
||||
{
|
||||
m_model->setItems(accounts);
|
||||
View::modelChanged();
|
||||
m_model->setItems(accounts);
|
||||
View::modelChanged();
|
||||
}
|
||||
|
||||
QString View::getImportedAccountIdenticon()
|
||||
{
|
||||
return m_delegate->getImportedAccount().identicon;
|
||||
return m_delegate->getImportedAccount().identicon;
|
||||
}
|
||||
|
||||
QString View::getImportedAccountAlias()
|
||||
{
|
||||
return m_delegate->getImportedAccount().alias;
|
||||
return m_delegate->getImportedAccount().alias;
|
||||
}
|
||||
|
||||
QString View::getImportedAccountAddress()
|
||||
{
|
||||
return m_delegate->getImportedAccount().address;
|
||||
return m_delegate->getImportedAccount().address;
|
||||
}
|
||||
|
||||
void View::setSelectedAccountByIndex(int index)
|
||||
{
|
||||
m_delegate->setSelectedAccountByIndex(index);
|
||||
m_delegate->setSelectedAccountByIndex(index);
|
||||
}
|
||||
|
||||
void View::storeSelectedAccountAndLogin(QString password)
|
||||
{
|
||||
m_delegate->storeSelectedAccountAndLogin(password);
|
||||
m_delegate->storeSelectedAccountAndLogin(password);
|
||||
}
|
||||
|
||||
void View::setupAccountError()
|
||||
{
|
||||
View::accountSetupError();
|
||||
View::accountSetupError();
|
||||
}
|
||||
|
||||
QString View::validateMnemonic(QString mnemonic)
|
||||
{
|
||||
return m_delegate->validateMnemonic(mnemonic);
|
||||
return m_delegate->validateMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
void View::importMnemonic(QString mnemonic)
|
||||
{
|
||||
m_delegate->importMnemonic(mnemonic);
|
||||
m_delegate->importMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
void View::importAccountError()
|
||||
{
|
||||
// In QML we can connect to this signal and notify a user
|
||||
// before refactoring we didn't have this signal
|
||||
View::accountImportError();
|
||||
// In QML we can connect to this signal and notify a user
|
||||
// before refactoring we didn't have this signal
|
||||
View::accountImportError();
|
||||
}
|
||||
|
||||
void View::importAccountSuccess()
|
||||
{
|
||||
View::importedAccountChanged();
|
||||
View::importedAccountChanged();
|
||||
}
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -15,41 +15,41 @@ namespace Onboarding
|
|||
|
||||
class View : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(QString importedAccountIdenticon READ getImportedAccountIdenticon NOTIFY importedAccountChanged)
|
||||
Q_PROPERTY(QString importedAccountAlias READ getImportedAccountAlias NOTIFY importedAccountChanged)
|
||||
Q_PROPERTY(QString importedAccountAddress READ getImportedAccountAddress NOTIFY importedAccountChanged)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(QString importedAccountIdenticon READ getImportedAccountIdenticon NOTIFY importedAccountChanged)
|
||||
Q_PROPERTY(QString importedAccountAlias READ getImportedAccountAlias NOTIFY importedAccountChanged)
|
||||
Q_PROPERTY(QString importedAccountAddress READ getImportedAccountAddress NOTIFY importedAccountChanged)
|
||||
|
||||
public:
|
||||
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
~View();
|
||||
void load();
|
||||
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
~View();
|
||||
void load();
|
||||
|
||||
signals:
|
||||
void modelChanged();
|
||||
void importedAccountChanged();
|
||||
void accountSetupError();
|
||||
void accountImportError();
|
||||
void modelChanged();
|
||||
void importedAccountChanged();
|
||||
void accountSetupError();
|
||||
void accountImportError();
|
||||
|
||||
private:
|
||||
ModuleViewDelegateInterface* m_delegate;
|
||||
Model* m_model;
|
||||
ModuleViewDelegateInterface* m_delegate;
|
||||
Model* m_model;
|
||||
|
||||
public slots:
|
||||
Model* getModel();
|
||||
void setAccountList(QVector<Item> accounts);
|
||||
QString getImportedAccountIdenticon();
|
||||
QString getImportedAccountAlias();
|
||||
QString getImportedAccountAddress();
|
||||
void setSelectedAccountByIndex(int index);
|
||||
void storeSelectedAccountAndLogin(QString password);
|
||||
QString validateMnemonic(QString mnemonic);
|
||||
void importMnemonic(QString mnemonic);
|
||||
void importAccountError();
|
||||
void setupAccountError();
|
||||
void importAccountSuccess();
|
||||
Model* getModel();
|
||||
void setAccountList(QVector<Item> accounts);
|
||||
QString getImportedAccountIdenticon();
|
||||
QString getImportedAccountAlias();
|
||||
QString getImportedAccountAddress();
|
||||
void setSelectedAccountByIndex(int index);
|
||||
void storeSelectedAccountAndLogin(QString password);
|
||||
QString validateMnemonic(QString mnemonic);
|
||||
void importMnemonic(QString mnemonic);
|
||||
void importAccountError();
|
||||
void setupAccountError();
|
||||
void importAccountSuccess();
|
||||
};
|
||||
} // namespace Onboarding
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -8,37 +8,37 @@ namespace Startup
|
|||
{
|
||||
|
||||
View::View(ModuleViewDelegateInterface* delegate, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_appState(AppState::OnboardingState)
|
||||
, m_delegate(delegate)
|
||||
: QObject(parent)
|
||||
, m_appState(AppState::OnboardingState)
|
||||
, m_delegate(delegate)
|
||||
{ }
|
||||
|
||||
void View::load()
|
||||
{
|
||||
// In some point, here, we will setup some exposed main module related things.
|
||||
m_delegate->viewDidLoad();
|
||||
// In some point, here, we will setup some exposed main module related things.
|
||||
m_delegate->viewDidLoad();
|
||||
}
|
||||
|
||||
int View::getAppState()
|
||||
{
|
||||
return static_cast<int>(m_appState);
|
||||
return static_cast<int>(m_appState);
|
||||
}
|
||||
|
||||
void View::setAppState(AppState state)
|
||||
{
|
||||
if(m_appState == state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(m_appState == state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_appState = state;
|
||||
appStateChanged(static_cast<int>(m_appState));
|
||||
m_appState = state;
|
||||
appStateChanged(static_cast<int>(m_appState));
|
||||
}
|
||||
|
||||
void View::emitLogOut()
|
||||
{
|
||||
logOut();
|
||||
logOut();
|
||||
}
|
||||
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -9,33 +9,33 @@ namespace Startup
|
|||
{
|
||||
enum AppState
|
||||
{
|
||||
OnboardingState = 0,
|
||||
LoginState = 1,
|
||||
MainAppState = 2
|
||||
// TODO: is Pending
|
||||
OnboardingState = 0,
|
||||
LoginState = 1,
|
||||
MainAppState = 2
|
||||
// TODO: is Pending
|
||||
};
|
||||
|
||||
class View : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int appState READ getAppState NOTIFY appStateChanged)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int appState READ getAppState NOTIFY appStateChanged)
|
||||
|
||||
public:
|
||||
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
void emitLogOut();
|
||||
void setAppState(AppState state);
|
||||
void load();
|
||||
|
||||
explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr);
|
||||
void emitLogOut();
|
||||
void setAppState(AppState state);
|
||||
void load();
|
||||
|
||||
signals:
|
||||
void appStateChanged(int state);
|
||||
void logOut();
|
||||
void appStateChanged(int state);
|
||||
void logOut();
|
||||
|
||||
private:
|
||||
ModuleViewDelegateInterface* m_delegate;
|
||||
AppState m_appState;
|
||||
ModuleViewDelegateInterface* m_delegate;
|
||||
AppState m_appState;
|
||||
|
||||
public slots:
|
||||
int getAppState();
|
||||
int getAppState();
|
||||
};
|
||||
} // namespace Startup
|
||||
} // namespace Modules
|
||||
} // namespace Modules
|
||||
|
|
|
@ -6,19 +6,17 @@
|
|||
|
||||
// TODO: merge with constants from backend/
|
||||
|
||||
|
||||
QString Constants::applicationPath(QString path)
|
||||
{
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath();
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath();
|
||||
}
|
||||
|
||||
QString Constants::tmpPath(QString path)
|
||||
{
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath();
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath();
|
||||
}
|
||||
|
||||
QString Constants::cachePath(QString path)
|
||||
{
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath();
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,29 +9,29 @@ namespace Accounts
|
|||
class Image
|
||||
{
|
||||
public:
|
||||
QString keyUid;
|
||||
QString imgType;
|
||||
QString uri;
|
||||
int width;
|
||||
int height;
|
||||
int fileSize;
|
||||
int resizeTarget;
|
||||
QString keyUid;
|
||||
QString imgType;
|
||||
QString uri;
|
||||
int width;
|
||||
int height;
|
||||
int fileSize;
|
||||
int resizeTarget;
|
||||
};
|
||||
|
||||
class AccountDto
|
||||
{
|
||||
public:
|
||||
QString name;
|
||||
long timestamp;
|
||||
QString identicon;
|
||||
QString keycardPairing;
|
||||
QString keyUid;
|
||||
QVector<Image> images;
|
||||
QString name;
|
||||
long timestamp;
|
||||
QString identicon;
|
||||
QString keycardPairing;
|
||||
QString keyUid;
|
||||
QVector<Image> images;
|
||||
|
||||
bool isValid();
|
||||
bool isValid();
|
||||
};
|
||||
|
||||
Image toImage(const QJsonValue jsonObj);
|
||||
|
||||
AccountDto toAccountDto(const QJsonValue jsonObj);
|
||||
} // namespace Accounts
|
||||
} // namespace Accounts
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonDocument>
|
||||
#include <QString>
|
||||
|
||||
namespace Accounts
|
||||
{
|
||||
class DerivedAccountDetails
|
||||
{
|
||||
public:
|
||||
QString publicKey;
|
||||
QString address;
|
||||
QString derivationPath;
|
||||
QString publicKey;
|
||||
QString address;
|
||||
QString derivationPath;
|
||||
};
|
||||
|
||||
class DerivedAccounts
|
||||
{
|
||||
public:
|
||||
DerivedAccountDetails whisper;
|
||||
DerivedAccountDetails walletRoot;
|
||||
DerivedAccountDetails defaultWallet;
|
||||
DerivedAccountDetails eip1581;
|
||||
DerivedAccountDetails whisper;
|
||||
DerivedAccountDetails walletRoot;
|
||||
DerivedAccountDetails defaultWallet;
|
||||
DerivedAccountDetails eip1581;
|
||||
};
|
||||
|
||||
class GeneratedAccountDto
|
||||
{
|
||||
public:
|
||||
QString id;
|
||||
QString publicKey;
|
||||
QString address;
|
||||
QString keyUid;
|
||||
QString mnemonic;
|
||||
DerivedAccounts derivedAccounts;
|
||||
QString id;
|
||||
QString publicKey;
|
||||
QString address;
|
||||
QString keyUid;
|
||||
QString mnemonic;
|
||||
DerivedAccounts derivedAccounts;
|
||||
|
||||
// The following two are set additionally.
|
||||
QString alias;
|
||||
QString identicon;
|
||||
// The following two are set additionally.
|
||||
QString alias;
|
||||
QString identicon;
|
||||
|
||||
bool isValid();
|
||||
bool isValid();
|
||||
};
|
||||
|
||||
DerivedAccountDetails toDerivedAccountDetails(const QJsonValue jsonObj, QString derivationPath);
|
||||
|
|
|
@ -12,61 +12,61 @@ namespace Accounts
|
|||
class Service : public ServiceInterface
|
||||
{
|
||||
private:
|
||||
QVector<GeneratedAccountDto> m_generatedAccounts;
|
||||
QVector<GeneratedAccountDto> m_generatedAccounts;
|
||||
|
||||
bool m_isFirstTimeAccountLogin;
|
||||
AccountDto m_loggedInAccount;
|
||||
GeneratedAccountDto m_importedAccount;
|
||||
bool m_isFirstTimeAccountLogin;
|
||||
AccountDto m_loggedInAccount;
|
||||
GeneratedAccountDto m_importedAccount;
|
||||
|
||||
public:
|
||||
Service();
|
||||
Service();
|
||||
|
||||
void init() override;
|
||||
void init() override;
|
||||
|
||||
virtual QVector<AccountDto> openedAccounts() override;
|
||||
virtual QVector<AccountDto> openedAccounts() override;
|
||||
|
||||
QVector<GeneratedAccountDto> generatedAccounts() override;
|
||||
QVector<GeneratedAccountDto> generatedAccounts() override;
|
||||
|
||||
bool setupAccount(QString accountId, QString password) override;
|
||||
bool setupAccount(QString accountId, QString password) override;
|
||||
|
||||
AccountDto getLoggedInAccount() override;
|
||||
AccountDto getLoggedInAccount() override;
|
||||
|
||||
GeneratedAccountDto getImportedAccount() override;
|
||||
GeneratedAccountDto getImportedAccount() override;
|
||||
|
||||
bool isFirstTimeAccountLogin() override;
|
||||
bool isFirstTimeAccountLogin() override;
|
||||
|
||||
QString validateMnemonic(QString mnemonic) override;
|
||||
QString validateMnemonic(QString mnemonic) override;
|
||||
|
||||
bool importMnemonic(QString mnemonic) override;
|
||||
bool importMnemonic(QString mnemonic) override;
|
||||
|
||||
QString login(AccountDto account, QString password) override;
|
||||
QString login(AccountDto account, QString password) override;
|
||||
|
||||
void clear() override;
|
||||
void clear() override;
|
||||
|
||||
QString generateAlias(QString publicKey) override;
|
||||
QString generateAlias(QString publicKey) override;
|
||||
|
||||
QString generateIdenticon(QString publicKey) override;
|
||||
QString generateIdenticon(QString publicKey) override;
|
||||
|
||||
bool verifyAccountPassword(QString account, QString password) override;
|
||||
bool verifyAccountPassword(QString account, QString password) override;
|
||||
|
||||
DerivedAccounts storeDerivedAccounts(QString accountId, QString hashedPassword, QVector<QString> paths);
|
||||
DerivedAccounts storeDerivedAccounts(QString accountId, QString hashedPassword, QVector<QString> paths);
|
||||
|
||||
QJsonObject getAccountDataForAccountId(QString accountId);
|
||||
QJsonObject getAccountDataForAccountId(QString accountId);
|
||||
|
||||
QJsonArray getSubaccountDataForAccountId(QString accountId);
|
||||
QJsonArray getSubaccountDataForAccountId(QString accountId);
|
||||
|
||||
QJsonObject getAccountSettings(QString accountId, QString installationId);
|
||||
QJsonObject getAccountSettings(QString accountId, QString installationId);
|
||||
|
||||
QJsonObject getDefaultNodeConfig(QString installationId);
|
||||
QJsonObject getDefaultNodeConfig(QString installationId);
|
||||
|
||||
QJsonObject prepareAccountJsonObject(const GeneratedAccountDto account);
|
||||
QJsonObject prepareAccountJsonObject(const GeneratedAccountDto account);
|
||||
|
||||
QJsonArray prepareSubaccountJsonObject(GeneratedAccountDto account);
|
||||
QJsonArray prepareSubaccountJsonObject(GeneratedAccountDto account);
|
||||
|
||||
QJsonObject prepareAccountSettingsJsonObject(const GeneratedAccountDto account, QString installationId);
|
||||
QJsonObject prepareAccountSettingsJsonObject(const GeneratedAccountDto account, QString installationId);
|
||||
|
||||
AccountDto saveAccountAndLogin(
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config);
|
||||
AccountDto saveAccountAndLogin(
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config);
|
||||
};
|
||||
|
||||
} // namespace Accounts
|
||||
} // namespace Accounts
|
||||
|
|
|
@ -13,31 +13,31 @@ namespace Accounts
|
|||
class ServiceInterface : public AppService
|
||||
{
|
||||
public:
|
||||
virtual QVector<AccountDto> openedAccounts() = 0;
|
||||
virtual QVector<AccountDto> openedAccounts() = 0;
|
||||
|
||||
virtual QVector<GeneratedAccountDto> generatedAccounts() = 0;
|
||||
virtual QVector<GeneratedAccountDto> generatedAccounts() = 0;
|
||||
|
||||
virtual bool setupAccount(QString accountId, QString password) = 0;
|
||||
virtual bool setupAccount(QString accountId, QString password) = 0;
|
||||
|
||||
virtual AccountDto getLoggedInAccount() = 0;
|
||||
virtual AccountDto getLoggedInAccount() = 0;
|
||||
|
||||
virtual GeneratedAccountDto getImportedAccount() = 0;
|
||||
virtual GeneratedAccountDto getImportedAccount() = 0;
|
||||
|
||||
virtual bool isFirstTimeAccountLogin() = 0;
|
||||
virtual bool isFirstTimeAccountLogin() = 0;
|
||||
|
||||
virtual QString validateMnemonic(QString mnemonic) = 0;
|
||||
virtual QString validateMnemonic(QString mnemonic) = 0;
|
||||
|
||||
virtual bool importMnemonic(QString mnemonic) = 0;
|
||||
virtual bool importMnemonic(QString mnemonic) = 0;
|
||||
|
||||
virtual QString login(AccountDto account, QString password) = 0;
|
||||
virtual QString login(AccountDto account, QString password) = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
virtual void clear() = 0;
|
||||
|
||||
virtual QString generateAlias(QString publicKey) = 0;
|
||||
virtual QString generateAlias(QString publicKey) = 0;
|
||||
|
||||
virtual QString generateIdenticon(QString publicKey) = 0;
|
||||
virtual QString generateIdenticon(QString publicKey) = 0;
|
||||
|
||||
virtual bool verifyAccountPassword(QString account, QString password) = 0;
|
||||
virtual bool verifyAccountPassword(QString account, QString password) = 0;
|
||||
};
|
||||
|
||||
} // namespace Accounts
|
||||
} // namespace Accounts
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
class AppService
|
||||
{
|
||||
public:
|
||||
virtual void init() = 0;
|
||||
virtual void init() = 0;
|
||||
};
|
||||
|
|
|
@ -28,7 +28,6 @@ const QString Websocket = "websocket";
|
|||
const QString DefaultNetworkName = "mainnet_rpc";
|
||||
//const DEFAULT_NETWORKS_IDS* = @["mainnet_rpc", "testnet_rpc", "rinkeby_rpc", "goerli_rpc", "xdai_rpc", "poa_rpc" ]
|
||||
|
||||
|
||||
const QString DataDir = "/data";
|
||||
const QString Keystore = "/data/keystore";
|
||||
|
||||
|
@ -36,5 +35,4 @@ QString applicationPath(QString path = "");
|
|||
QString tmpPath(QString path = "");
|
||||
QString cachePath(QString path = "");
|
||||
|
||||
|
||||
} // namespace Constants
|
||||
|
|
|
@ -2,38 +2,48 @@
|
|||
#include <array>
|
||||
|
||||
const std::array phrases{
|
||||
"area", "army", "atom", "aunt", "babe", "baby", "back", "bail", "bait", "bake", "ball", "band", "bank", "barn", "base", "bass", "bath", "bead",
|
||||
"beak", "beam", "bean", "bear", "beat", "beef", "beer", "beet", "bell", "belt", "bend", "bike", "bill", "bird", "bite", "blow", "blue", "boar",
|
||||
"boat", "body", "bolt", "bomb", "bone", "book", "boot", "bore", "boss", "bowl", "brow", "bulb", "bull", "burn", "bush", "bust", "cafe", "cake",
|
||||
"calf", "call", "calm", "camp", "cane", "cape", "card", "care", "carp", "cart", "case", "cash", "cast", "cave", "cell", "cent", "chap", "chef",
|
||||
"chin", "chip", "chop", "chub", "chug", "city", "clam", "clef", "clip", "club", "clue", "coal", "coat", "code", "coil", "coin", "coke", "cold",
|
||||
"colt", "comb", "cone", "cook", "cope", "copy", "cord", "cork", "corn", "cost", "crab", "craw", "crew", "crib", "crop", "crow", "curl", "cyst",
|
||||
"dame", "dare", "dark", "dart", "dash", "data", "date", "dead", "deal", "dear", "debt", "deck", "deep", "deer", "desk", "dhow", "diet", "dill",
|
||||
"dime", "dirt", "dish", "disk", "dock", "doll", "door", "dory", "drag", "draw", "drop", "drug", "drum", "duck", "dump", "dust", "duty", "ease",
|
||||
"east", "eave", "eddy", "edge", "envy", "epee", "exam", "exit", "face", "fact", "fail", "fall", "fame", "fang", "farm", "fawn", "fear", "feed",
|
||||
"feel", "feet", "file", "fill", "film", "find", "fine", "fire", "fish", "flag", "flat", "flax", "flow", "foam", "fold", "font", "food", "foot",
|
||||
"fork", "form", "fort", "fowl", "frog", "fuel", "full", "gain", "gale", "galn", "game", "garb", "gate", "gear", "gene", "gift", "girl", "give",
|
||||
"glad", "glen", "glue", "glut", "goal", "goat", "gold", "golf", "gong", "good", "gown", "grab", "gram", "gray", "grey", "grip", "grit", "gyro",
|
||||
"hail", "hair", "half", "hall", "hand", "hang", "harm", "harp", "hate", "hawk", "head", "heat", "heel", "hell", "helo", "help", "hemp", "herb",
|
||||
"hide", "high", "hill", "hire", "hive", "hold", "hole", "home", "hood", "hoof", "hook", "hope", "hops", "horn", "hose", "host", "hour", "hunt",
|
||||
"hurt", "icon", "idea", "inch", "iris", "iron", "item", "jail", "jeep", "jeff", "joey", "join", "joke", "judo", "jump", "junk", "jury", "jute",
|
||||
"kale", "keep", "kick", "kill", "kilt", "kind", "king", "kiss", "kite", "knee", "knot", "lace", "lack", "lady", "lake", "lamb", "lamp", "land",
|
||||
"lark", "lava", "lawn", "lead", "leaf", "leek", "lier", "life", "lift", "lily", "limo", "line", "link", "lion", "lisa", "list", "load", "loaf",
|
||||
"loan", "lock", "loft", "long", "look", "loss", "lout", "love", "luck", "lung", "lute", "lynx", "lyre", "maid", "mail", "main", "make", "male",
|
||||
"mall", "manx", "many", "mare", "mark", "mask", "mass", "mate", "math", "meal", "meat", "meet", "menu", "mess", "mice", "midi", "mile", "milk",
|
||||
"mime", "mind", "mine", "mini", "mint", "miss", "mist", "moat", "mode", "mole", "mood", "moon", "most", "moth", "move", "mule", "mutt", "nail",
|
||||
"name", "neat", "neck", "need", "neon", "nest", "news", "node", "nose", "note", "oboe", "okra", "open", "oval", "oven", "oxen", "pace", "pack",
|
||||
"page", "pail", "pain", "pair", "palm", "pard", "park", "part", "pass", "past", "path", "peak", "pear", "peen", "peer", "pelt", "perp", "pest",
|
||||
"pick", "pier", "pike", "pile", "pimp", "pine", "ping", "pink", "pint", "pipe", "piss", "pith", "plan", "play", "plot", "plow", "poem", "poet",
|
||||
"pole", "polo", "pond", "pony", "poof", "pool", "port", "post", "prow", "pull", "puma", "pump", "pupa", "push", "quit", "race", "rack", "raft",
|
||||
"rage", "rail", "rain", "rake", "rank", "rate", "read", "rear", "reef", "rent", "rest", "rice", "rich", "ride", "ring", "rise", "risk", "road",
|
||||
"robe", "rock", "role", "roll", "roof", "room", "root", "rope", "rose", "ruin", "rule", "rush", "ruth", "sack", "safe", "sage", "sail", "sale",
|
||||
"salt", "sand", "sari", "sash", "save", "scow", "seal", "seat", "seed", "self", "sell", "shed", "shin", "ship", "shoe", "shop", "shot", "show",
|
||||
"sick", "side", "sign", "silk", "sill", "silo", "sing", "sink", "site", "size", "skin", "sled", "slip", "smog", "snob", "snow", "soap", "sock",
|
||||
"soda", "sofa", "soft", "soil", "song", "soot", "sort", "soup", "spot", "spur", "stag", "star", "stay", "stem", "step", "stew", "stop", "stud",
|
||||
"suck", "suit", "swan", "swim", "tail", "tale", "talk", "tank", "tard", "task", "taxi", "team", "tear", "teen", "tell", "temp", "tent", "term",
|
||||
"test", "text", "thaw", "tile", "till", "time", "tire", "toad", "toga", "togs", "tone", "tool", "toot", "tote", "tour", "town", "tram", "tray",
|
||||
"tree", "trim", "trip", "tuba", "tube", "tuna", "tune", "turn", "tutu", "twig", "type", "unit", "user", "vane", "vase", "vast", "veal", "veil",
|
||||
"vein", "vest", "vibe", "view", "vise", "wait", "wake", "walk", "wall", "wash", "wasp", "wave", "wear", "weed", "week", "well", "west", "whip",
|
||||
"wife", "will", "wind", "wine", "wing", "wire", "wish", "wolf", "wood", "wool", "word", "work", "worm", "wrap", "wren", "yard", "yarn", "yawl",
|
||||
"year", "yoga", "yoke", "yurt", "zinc", "zone"};
|
||||
"area", "army", "atom", "aunt", "babe", "baby", "back", "bail", "bait", "bake", "ball", "band", "bank", "barn",
|
||||
"base", "bass", "bath", "bead", "beak", "beam", "bean", "bear", "beat", "beef", "beer", "beet", "bell", "belt",
|
||||
"bend", "bike", "bill", "bird", "bite", "blow", "blue", "boar", "boat", "body", "bolt", "bomb", "bone", "book",
|
||||
"boot", "bore", "boss", "bowl", "brow", "bulb", "bull", "burn", "bush", "bust", "cafe", "cake", "calf", "call",
|
||||
"calm", "camp", "cane", "cape", "card", "care", "carp", "cart", "case", "cash", "cast", "cave", "cell", "cent",
|
||||
"chap", "chef", "chin", "chip", "chop", "chub", "chug", "city", "clam", "clef", "clip", "club", "clue", "coal",
|
||||
"coat", "code", "coil", "coin", "coke", "cold", "colt", "comb", "cone", "cook", "cope", "copy", "cord", "cork",
|
||||
"corn", "cost", "crab", "craw", "crew", "crib", "crop", "crow", "curl", "cyst", "dame", "dare", "dark", "dart",
|
||||
"dash", "data", "date", "dead", "deal", "dear", "debt", "deck", "deep", "deer", "desk", "dhow", "diet", "dill",
|
||||
"dime", "dirt", "dish", "disk", "dock", "doll", "door", "dory", "drag", "draw", "drop", "drug", "drum", "duck",
|
||||
"dump", "dust", "duty", "ease", "east", "eave", "eddy", "edge", "envy", "epee", "exam", "exit", "face", "fact",
|
||||
"fail", "fall", "fame", "fang", "farm", "fawn", "fear", "feed", "feel", "feet", "file", "fill", "film", "find",
|
||||
"fine", "fire", "fish", "flag", "flat", "flax", "flow", "foam", "fold", "font", "food", "foot", "fork", "form",
|
||||
"fort", "fowl", "frog", "fuel", "full", "gain", "gale", "galn", "game", "garb", "gate", "gear", "gene", "gift",
|
||||
"girl", "give", "glad", "glen", "glue", "glut", "goal", "goat", "gold", "golf", "gong", "good", "gown", "grab",
|
||||
"gram", "gray", "grey", "grip", "grit", "gyro", "hail", "hair", "half", "hall", "hand", "hang", "harm", "harp",
|
||||
"hate", "hawk", "head", "heat", "heel", "hell", "helo", "help", "hemp", "herb", "hide", "high", "hill", "hire",
|
||||
"hive", "hold", "hole", "home", "hood", "hoof", "hook", "hope", "hops", "horn", "hose", "host", "hour", "hunt",
|
||||
"hurt", "icon", "idea", "inch", "iris", "iron", "item", "jail", "jeep", "jeff", "joey", "join", "joke", "judo",
|
||||
"jump", "junk", "jury", "jute", "kale", "keep", "kick", "kill", "kilt", "kind", "king", "kiss", "kite", "knee",
|
||||
"knot", "lace", "lack", "lady", "lake", "lamb", "lamp", "land", "lark", "lava", "lawn", "lead", "leaf", "leek",
|
||||
"lier", "life", "lift", "lily", "limo", "line", "link", "lion", "lisa", "list", "load", "loaf", "loan", "lock",
|
||||
"loft", "long", "look", "loss", "lout", "love", "luck", "lung", "lute", "lynx", "lyre", "maid", "mail", "main",
|
||||
"make", "male", "mall", "manx", "many", "mare", "mark", "mask", "mass", "mate", "math", "meal", "meat", "meet",
|
||||
"menu", "mess", "mice", "midi", "mile", "milk", "mime", "mind", "mine", "mini", "mint", "miss", "mist", "moat",
|
||||
"mode", "mole", "mood", "moon", "most", "moth", "move", "mule", "mutt", "nail", "name", "neat", "neck", "need",
|
||||
"neon", "nest", "news", "node", "nose", "note", "oboe", "okra", "open", "oval", "oven", "oxen", "pace", "pack",
|
||||
"page", "pail", "pain", "pair", "palm", "pard", "park", "part", "pass", "past", "path", "peak", "pear", "peen",
|
||||
"peer", "pelt", "perp", "pest", "pick", "pier", "pike", "pile", "pimp", "pine", "ping", "pink", "pint", "pipe",
|
||||
"piss", "pith", "plan", "play", "plot", "plow", "poem", "poet", "pole", "polo", "pond", "pony", "poof", "pool",
|
||||
"port", "post", "prow", "pull", "puma", "pump", "pupa", "push", "quit", "race", "rack", "raft", "rage", "rail",
|
||||
"rain", "rake", "rank", "rate", "read", "rear", "reef", "rent", "rest", "rice", "rich", "ride", "ring", "rise",
|
||||
"risk", "road", "robe", "rock", "role", "roll", "roof", "room", "root", "rope", "rose", "ruin", "rule", "rush",
|
||||
"ruth", "sack", "safe", "sage", "sail", "sale", "salt", "sand", "sari", "sash", "save", "scow", "seal", "seat",
|
||||
"seed", "self", "sell", "shed", "shin", "ship", "shoe", "shop", "shot", "show", "sick", "side", "sign", "silk",
|
||||
"sill", "silo", "sing", "sink", "site", "size", "skin", "sled", "slip", "smog", "snob", "snow", "soap", "sock",
|
||||
"soda", "sofa", "soft", "soil", "song", "soot", "sort", "soup", "spot", "spur", "stag", "star", "stay", "stem",
|
||||
"step", "stew", "stop", "stud", "suck", "suit", "swan", "swim", "tail", "tale", "talk", "tank", "tard", "task",
|
||||
"taxi", "team", "tear", "teen", "tell", "temp", "tent", "term", "test", "text", "thaw", "tile", "till", "time",
|
||||
"tire", "toad", "toga", "togs", "tone", "tool", "toot", "tote", "tour", "town", "tram", "tray", "tree", "trim",
|
||||
"trip", "tuba", "tube", "tuna", "tune", "turn", "tutu", "twig", "type", "unit", "user", "vane", "vase", "vast",
|
||||
"veal", "veil", "vein", "vest", "vibe", "view", "vise", "wait", "wake", "walk", "wall", "wash", "wasp", "wave",
|
||||
"wear", "weed", "week", "well", "west", "whip", "wife", "will", "wind", "wine", "wing", "wire", "wish", "wolf",
|
||||
"wood", "wool", "word", "work", "worm", "wrap", "wren", "yard", "yarn", "yawl", "year", "yoga", "yoke", "yurt",
|
||||
"zinc", "zone"};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef WALLETACCOUNTSSERVICE_H
|
||||
#define WALLETACCOUNTSSERVICE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
#include "wallet_account.h"
|
||||
#include "service_interface.h"
|
||||
#include "wallet_account.h"
|
||||
|
||||
namespace Wallets
|
||||
{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef WALLETACCOUNTDTO_H
|
||||
#define WALLETACCOUNTDTO_H
|
||||
|
||||
#include "wallet_token.h"
|
||||
#include <QJsonValue>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include "wallet_token.h"
|
||||
|
||||
namespace Wallets
|
||||
{
|
||||
|
@ -27,6 +27,6 @@ WalletAccountDto toWalletAccountDto(const QJsonValue jsonObj);
|
|||
//WalletAccountDto getCurrencyBalance*(): float =
|
||||
// return self.tokens.map(t => t.currencyBalance).foldl(a + b, 0.0)
|
||||
|
||||
} // namespace Wallet
|
||||
} // namespace Wallets
|
||||
|
||||
#endif // WALLETACCOUNTDTO_H
|
||||
|
|
|
@ -21,6 +21,6 @@ public:
|
|||
float currencyBalance;
|
||||
};
|
||||
|
||||
} // namespace Wallet
|
||||
} // namespace Wallets
|
||||
|
||||
#endif // WALLETTOKENDTO_H
|
||||
|
|
|
@ -7,38 +7,38 @@
|
|||
|
||||
bool Accounts::AccountDto::isValid()
|
||||
{
|
||||
return name.length() > 0 && keyUid.length() > 0;
|
||||
return name.length() > 0 && keyUid.length() > 0;
|
||||
}
|
||||
|
||||
Accounts::Image Accounts::toImage(const QJsonValue jsonObj)
|
||||
{
|
||||
auto result = Accounts::Image();
|
||||
auto result = Accounts::Image();
|
||||
|
||||
result.keyUid = jsonObj["keyUid"].toString();
|
||||
result.imgType = jsonObj["type"].toString();
|
||||
result.uri = jsonObj["uri"].toString();
|
||||
result.width = jsonObj["width"].toInt();
|
||||
result.height = jsonObj["height"].toInt();
|
||||
result.fileSize = jsonObj["fileSize"].toInt();
|
||||
result.resizeTarget = jsonObj["resizeTarget"].toInt();
|
||||
result.keyUid = jsonObj["keyUid"].toString();
|
||||
result.imgType = jsonObj["type"].toString();
|
||||
result.uri = jsonObj["uri"].toString();
|
||||
result.width = jsonObj["width"].toInt();
|
||||
result.height = jsonObj["height"].toInt();
|
||||
result.fileSize = jsonObj["fileSize"].toInt();
|
||||
result.resizeTarget = jsonObj["resizeTarget"].toInt();
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
Accounts::AccountDto Accounts::toAccountDto(const QJsonValue jsonObj)
|
||||
{
|
||||
auto result = Accounts::AccountDto();
|
||||
auto result = Accounts::AccountDto();
|
||||
|
||||
result.name = jsonObj["name"].toString();
|
||||
result.timestamp = jsonObj["timestamp"].toInt();
|
||||
result.identicon = jsonObj["identicon"].toString();
|
||||
result.keycardPairing = jsonObj["keycard-pairing"].toString();
|
||||
result.keyUid = jsonObj["key-uid"].toString();
|
||||
result.name = jsonObj["name"].toString();
|
||||
result.timestamp = jsonObj["timestamp"].toInt();
|
||||
result.identicon = jsonObj["identicon"].toString();
|
||||
result.keycardPairing = jsonObj["keycard-pairing"].toString();
|
||||
result.keyUid = jsonObj["key-uid"].toString();
|
||||
|
||||
foreach(const QJsonValue& value, jsonObj["images"].toArray())
|
||||
{
|
||||
result.images << Accounts::toImage(value);
|
||||
}
|
||||
foreach(const QJsonValue& value, jsonObj["images"].toArray())
|
||||
{
|
||||
result.images << Accounts::toImage(value);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -8,62 +8,62 @@
|
|||
|
||||
bool Accounts::GeneratedAccountDto::isValid()
|
||||
{
|
||||
return id.length() > 0 && publicKey.length() > 0 && address.length() > 0 && keyUid.length() > 0;
|
||||
return id.length() > 0 && publicKey.length() > 0 && address.length() > 0 && keyUid.length() > 0;
|
||||
}
|
||||
|
||||
Accounts::DerivedAccountDetails Accounts::toDerivedAccountDetails(const QJsonValue jsonObj, QString derivationPath)
|
||||
{
|
||||
// Mapping this DTO is not strightforward since only keys are used for id. We
|
||||
// handle it a bit different.
|
||||
auto result = Accounts::DerivedAccountDetails();
|
||||
// Mapping this DTO is not strightforward since only keys are used for id. We
|
||||
// handle it a bit different.
|
||||
auto result = Accounts::DerivedAccountDetails();
|
||||
|
||||
result.derivationPath = derivationPath;
|
||||
result.publicKey = jsonObj["publicKey"].toString();
|
||||
result.address = jsonObj["address"].toString();
|
||||
result.derivationPath = derivationPath;
|
||||
result.publicKey = jsonObj["publicKey"].toString();
|
||||
result.address = jsonObj["address"].toString();
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
Accounts::DerivedAccounts Accounts::toDerivedAccounts(const QJsonObject jsonObj)
|
||||
{
|
||||
auto result = Accounts::DerivedAccounts();
|
||||
foreach(const QString& derivationPath, jsonObj.keys())
|
||||
{
|
||||
QJsonValue derivedObj = jsonObj.value(derivationPath);
|
||||
if(derivationPath == Backend::Accounts::PATH_WHISPER)
|
||||
{
|
||||
result.whisper = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
else if(derivationPath == Backend::Accounts::PATH_WALLET_ROOT)
|
||||
{
|
||||
result.walletRoot = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
else if(derivationPath == Backend::Accounts::PATH_DEFAULT_WALLET)
|
||||
{
|
||||
result.defaultWallet = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
else if(derivationPath == Backend::Accounts::PATH_EIP_1581)
|
||||
{
|
||||
result.eip1581 = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
}
|
||||
auto result = Accounts::DerivedAccounts();
|
||||
foreach(const QString& derivationPath, jsonObj.keys())
|
||||
{
|
||||
QJsonValue derivedObj = jsonObj.value(derivationPath);
|
||||
if(derivationPath == Backend::Accounts::PATH_WHISPER)
|
||||
{
|
||||
result.whisper = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
else if(derivationPath == Backend::Accounts::PATH_WALLET_ROOT)
|
||||
{
|
||||
result.walletRoot = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
else if(derivationPath == Backend::Accounts::PATH_DEFAULT_WALLET)
|
||||
{
|
||||
result.defaultWallet = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
else if(derivationPath == Backend::Accounts::PATH_EIP_1581)
|
||||
{
|
||||
result.eip1581 = Accounts::toDerivedAccountDetails(derivedObj, derivationPath);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
Accounts::GeneratedAccountDto Accounts::toGeneratedAccountDto(const QJsonValue jsonObj)
|
||||
{
|
||||
auto result = GeneratedAccountDto();
|
||||
auto result = GeneratedAccountDto();
|
||||
|
||||
result.id = jsonObj["id"].toString();
|
||||
result.address = jsonObj["address"].toString();
|
||||
result.keyUid = jsonObj["keyUid"].toString();
|
||||
result.mnemonic = jsonObj["mnemonic"].toString();
|
||||
result.publicKey = jsonObj["publicKey"].toString();
|
||||
if(!jsonObj["derived"].isUndefined())
|
||||
{
|
||||
result.derivedAccounts = Accounts::toDerivedAccounts(jsonObj["derived"].toObject());
|
||||
}
|
||||
result.id = jsonObj["id"].toString();
|
||||
result.address = jsonObj["address"].toString();
|
||||
result.keyUid = jsonObj["keyUid"].toString();
|
||||
result.mnemonic = jsonObj["mnemonic"].toString();
|
||||
result.publicKey = jsonObj["publicKey"].toString();
|
||||
if(!jsonObj["derived"].isUndefined())
|
||||
{
|
||||
result.derivedAccounts = Accounts::toDerivedAccounts(jsonObj["derived"].toObject());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -18,380 +18,380 @@ namespace Accounts
|
|||
{
|
||||
|
||||
Service::Service()
|
||||
: m_isFirstTimeAccountLogin(false)
|
||||
: m_isFirstTimeAccountLogin(false)
|
||||
{ }
|
||||
|
||||
const QVector<QString> PATHS{Backend::Accounts::PATH_WALLET_ROOT,
|
||||
Backend::Accounts::PATH_EIP_1581,
|
||||
Backend::Accounts::PATH_WHISPER,
|
||||
Backend::Accounts::PATH_DEFAULT_WALLET};
|
||||
Backend::Accounts::PATH_EIP_1581,
|
||||
Backend::Accounts::PATH_WHISPER,
|
||||
Backend::Accounts::PATH_DEFAULT_WALLET};
|
||||
|
||||
void Service::init()
|
||||
{
|
||||
auto response = Backend::Accounts::generateAddresses(Accounts::PATHS);
|
||||
foreach(QJsonValue generatedAddressJson, response.m_result)
|
||||
{
|
||||
auto gAcc = toGeneratedAccountDto(generatedAddressJson);
|
||||
gAcc.alias = generateAlias(gAcc.derivedAccounts.whisper.publicKey);
|
||||
gAcc.identicon = generateIdenticon(gAcc.derivedAccounts.whisper.publicKey);
|
||||
m_generatedAccounts << gAcc;
|
||||
}
|
||||
auto response = Backend::Accounts::generateAddresses(Accounts::PATHS);
|
||||
foreach(QJsonValue generatedAddressJson, response.m_result)
|
||||
{
|
||||
auto gAcc = toGeneratedAccountDto(generatedAddressJson);
|
||||
gAcc.alias = generateAlias(gAcc.derivedAccounts.whisper.publicKey);
|
||||
gAcc.identicon = generateIdenticon(gAcc.derivedAccounts.whisper.publicKey);
|
||||
m_generatedAccounts << gAcc;
|
||||
}
|
||||
}
|
||||
|
||||
QVector<AccountDto> Service::openedAccounts()
|
||||
{
|
||||
// TODO: if there's an exception, should we return an empty result? or should we look into using
|
||||
// std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
auto response = Backend::Accounts::openAccounts(Constants::applicationPath(Constants::DataDir));
|
||||
QJsonArray multiAccounts = response.m_result;
|
||||
QVector<AccountDto> result;
|
||||
foreach(const QJsonValue& value, multiAccounts)
|
||||
{
|
||||
result << toAccountDto(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch(Backend::RpcException& e)
|
||||
{
|
||||
qWarning() << "error: methodName=openedAccounts, errDescription=" << e.what();
|
||||
return QVector<AccountDto>();
|
||||
}
|
||||
// TODO: if there's an exception, should we return an empty result? or should we look into using
|
||||
// std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
auto response = Backend::Accounts::openAccounts(Constants::applicationPath(Constants::DataDir));
|
||||
QJsonArray multiAccounts = response.m_result;
|
||||
QVector<AccountDto> result;
|
||||
foreach(const QJsonValue& value, multiAccounts)
|
||||
{
|
||||
result << toAccountDto(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch(Backend::RpcException& e)
|
||||
{
|
||||
qWarning() << "error: methodName=openedAccounts, errDescription=" << e.what();
|
||||
return QVector<AccountDto>();
|
||||
}
|
||||
}
|
||||
|
||||
QVector<GeneratedAccountDto> Service::generatedAccounts()
|
||||
{
|
||||
if(m_generatedAccounts.length() == 0)
|
||||
{
|
||||
qWarning("There was some issue initiating account service");
|
||||
return QVector<GeneratedAccountDto>();
|
||||
}
|
||||
if(m_generatedAccounts.length() == 0)
|
||||
{
|
||||
qWarning("There was some issue initiating account service");
|
||||
return QVector<GeneratedAccountDto>();
|
||||
}
|
||||
|
||||
return m_generatedAccounts;
|
||||
return m_generatedAccounts;
|
||||
}
|
||||
|
||||
bool Service::setupAccount(QString accountId, QString password)
|
||||
{
|
||||
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
QString installationId(QUuid::createUuid().toString(QUuid::WithoutBraces));
|
||||
QJsonObject accountData(Service::getAccountDataForAccountId(accountId));
|
||||
QJsonArray subAccountData(Service::getSubaccountDataForAccountId(accountId));
|
||||
QJsonObject settings(Service::getAccountSettings(accountId, installationId));
|
||||
QJsonObject nodeConfig(Service::getDefaultNodeConfig(installationId));
|
||||
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
QString installationId(QUuid::createUuid().toString(QUuid::WithoutBraces));
|
||||
QJsonObject accountData(Service::getAccountDataForAccountId(accountId));
|
||||
QJsonArray subAccountData(Service::getSubaccountDataForAccountId(accountId));
|
||||
QJsonObject settings(Service::getAccountSettings(accountId, installationId));
|
||||
QJsonObject nodeConfig(Service::getDefaultNodeConfig(installationId));
|
||||
|
||||
QString hashedPassword(Backend::Utils::hashString(password));
|
||||
QString hashedPassword(Backend::Utils::hashString(password));
|
||||
|
||||
Service::storeDerivedAccounts(accountId, hashedPassword, PATHS);
|
||||
Service::storeDerivedAccounts(accountId, hashedPassword, PATHS);
|
||||
|
||||
m_loggedInAccount =
|
||||
Service::saveAccountAndLogin(hashedPassword, accountData, subAccountData, settings, nodeConfig);
|
||||
m_loggedInAccount =
|
||||
Service::saveAccountAndLogin(hashedPassword, accountData, subAccountData, settings, nodeConfig);
|
||||
|
||||
return Service::getLoggedInAccount().isValid();
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
qWarning() << "error: methodName=setupAccount, errDescription=" << e.what();
|
||||
return false;
|
||||
}
|
||||
return Service::getLoggedInAccount().isValid();
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
qWarning() << "error: methodName=setupAccount, errDescription=" << e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AccountDto Service::getLoggedInAccount()
|
||||
{
|
||||
return m_loggedInAccount;
|
||||
return m_loggedInAccount;
|
||||
}
|
||||
|
||||
GeneratedAccountDto Service::getImportedAccount()
|
||||
{
|
||||
return m_importedAccount;
|
||||
return m_importedAccount;
|
||||
}
|
||||
|
||||
bool Service::isFirstTimeAccountLogin()
|
||||
{
|
||||
return m_isFirstTimeAccountLogin;
|
||||
return m_isFirstTimeAccountLogin;
|
||||
}
|
||||
|
||||
QString Service::validateMnemonic(QString mnemonic)
|
||||
{
|
||||
// TODO:
|
||||
return "";
|
||||
// TODO:
|
||||
return "";
|
||||
}
|
||||
|
||||
bool Service::importMnemonic(QString mnemonic)
|
||||
{
|
||||
// TODO:
|
||||
return false;
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
QString Service::login(AccountDto account, QString password)
|
||||
{
|
||||
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
QString hashedPassword(Backend::Utils::hashString(password));
|
||||
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
QString hashedPassword(Backend::Utils::hashString(password));
|
||||
|
||||
QString thumbnailImage;
|
||||
QString largeImage;
|
||||
QString thumbnailImage;
|
||||
QString largeImage;
|
||||
|
||||
foreach(const Accounts::Image& img, account.images)
|
||||
{
|
||||
if(img.imgType == "thumbnail")
|
||||
{
|
||||
thumbnailImage = img.uri;
|
||||
}
|
||||
else if(img.imgType == "large")
|
||||
{
|
||||
largeImage = img.uri;
|
||||
}
|
||||
}
|
||||
foreach(const Accounts::Image& img, account.images)
|
||||
{
|
||||
if(img.imgType == "thumbnail")
|
||||
{
|
||||
thumbnailImage = img.uri;
|
||||
}
|
||||
else if(img.imgType == "large")
|
||||
{
|
||||
largeImage = img.uri;
|
||||
}
|
||||
}
|
||||
|
||||
auto response = Backend::Accounts::login(
|
||||
account.name, account.keyUid, hashedPassword, account.identicon, thumbnailImage, largeImage);
|
||||
// TODO: check response for errors
|
||||
auto response = Backend::Accounts::login(
|
||||
account.name, account.keyUid, hashedPassword, account.identicon, thumbnailImage, largeImage);
|
||||
// TODO: check response for errors
|
||||
|
||||
qDebug() << "Account logged in";
|
||||
qDebug() << "Account logged in";
|
||||
|
||||
m_loggedInAccount = account;
|
||||
m_loggedInAccount = account;
|
||||
|
||||
return "";
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
qWarning() << "error: methodName=login, errDescription=" << e.what();
|
||||
return e.what();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
qWarning() << "error: methodName=login, errDescription=" << e.what();
|
||||
return e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void Service::clear()
|
||||
{
|
||||
m_generatedAccounts.clear();
|
||||
m_loggedInAccount = Accounts::AccountDto();
|
||||
m_importedAccount = Accounts::GeneratedAccountDto();
|
||||
m_isFirstTimeAccountLogin = false;
|
||||
m_generatedAccounts.clear();
|
||||
m_loggedInAccount = Accounts::AccountDto();
|
||||
m_importedAccount = Accounts::GeneratedAccountDto();
|
||||
m_isFirstTimeAccountLogin = false;
|
||||
}
|
||||
|
||||
QString Service::generateAlias(QString publicKey)
|
||||
{
|
||||
return Backend::Accounts::generateAlias(publicKey).m_result;
|
||||
return Backend::Accounts::generateAlias(publicKey).m_result;
|
||||
}
|
||||
|
||||
QString Service::generateIdenticon(QString publicKey)
|
||||
{
|
||||
return Backend::Accounts::generateIdenticon(publicKey).m_result;
|
||||
return Backend::Accounts::generateIdenticon(publicKey).m_result;
|
||||
}
|
||||
|
||||
bool Service::verifyAccountPassword(QString account, QString password)
|
||||
{
|
||||
// TODO:
|
||||
return false;
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
DerivedAccounts Service::storeDerivedAccounts(QString accountId, QString hashedPassword, QVector<QString> paths)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto response = Backend::Accounts::storeDerivedAccounts(accountId, hashedPassword, paths);
|
||||
return toDerivedAccounts(response.m_result);
|
||||
}
|
||||
catch(Backend::RpcException& e)
|
||||
{
|
||||
qWarning() << e.what();
|
||||
return DerivedAccounts(); // TODO: should it return empty?
|
||||
}
|
||||
try
|
||||
{
|
||||
auto response = Backend::Accounts::storeDerivedAccounts(accountId, hashedPassword, paths);
|
||||
return toDerivedAccounts(response.m_result);
|
||||
}
|
||||
catch(Backend::RpcException& e)
|
||||
{
|
||||
qWarning() << e.what();
|
||||
return DerivedAccounts(); // TODO: should it return empty?
|
||||
}
|
||||
}
|
||||
|
||||
Accounts::AccountDto Service::saveAccountAndLogin(
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config)
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config)
|
||||
{
|
||||
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
auto response = Backend::Accounts::saveAccountAndLogin(hashedPassword, account, subaccounts, settings, config);
|
||||
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||
try
|
||||
{
|
||||
auto response = Backend::Accounts::saveAccountAndLogin(hashedPassword, account, subaccounts, settings, config);
|
||||
|
||||
m_isFirstTimeAccountLogin = true;
|
||||
return toAccountDto(account);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
qWarning() << "error: methodName=saveAccountAndLogin, errDescription=" << e.what();
|
||||
return Accounts::AccountDto();
|
||||
}
|
||||
m_isFirstTimeAccountLogin = true;
|
||||
return toAccountDto(account);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
qWarning() << "error: methodName=saveAccountAndLogin, errDescription=" << e.what();
|
||||
return Accounts::AccountDto();
|
||||
}
|
||||
}
|
||||
|
||||
QJsonObject Service::prepareAccountJsonObject(const GeneratedAccountDto account)
|
||||
{
|
||||
return QJsonObject{{"name", account.alias},
|
||||
{"address", account.address},
|
||||
{"photo-path", account.identicon},
|
||||
{"identicon", account.identicon},
|
||||
{"key-uid", account.keyUid},
|
||||
{"keycard-pairing", QJsonValue()}};
|
||||
return QJsonObject{{"name", account.alias},
|
||||
{"address", account.address},
|
||||
{"photo-path", account.identicon},
|
||||
{"identicon", account.identicon},
|
||||
{"key-uid", account.keyUid},
|
||||
{"keycard-pairing", QJsonValue()}};
|
||||
}
|
||||
|
||||
QJsonObject Service::getAccountDataForAccountId(QString accountId)
|
||||
{
|
||||
|
||||
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
||||
{
|
||||
if(acc.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountJsonObject(acc);
|
||||
}
|
||||
}
|
||||
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
||||
{
|
||||
if(acc.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountJsonObject(acc);
|
||||
}
|
||||
}
|
||||
|
||||
if(m_importedAccount.isValid())
|
||||
{
|
||||
if(m_importedAccount.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountJsonObject(m_importedAccount);
|
||||
}
|
||||
}
|
||||
if(m_importedAccount.isValid())
|
||||
{
|
||||
if(m_importedAccount.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountJsonObject(m_importedAccount);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Should we use instead a std::optional?
|
||||
throw std::runtime_error("account not found");
|
||||
// TODO: Should we use instead a std::optional?
|
||||
throw std::runtime_error("account not found");
|
||||
}
|
||||
|
||||
QJsonArray Service::prepareSubaccountJsonObject(GeneratedAccountDto account)
|
||||
{
|
||||
return QJsonArray{QJsonObject{{"public-key", account.derivedAccounts.defaultWallet.publicKey},
|
||||
{"address", account.derivedAccounts.defaultWallet.address},
|
||||
{"color", "#4360df"},
|
||||
{"wallet", true},
|
||||
{"path", Backend::Accounts::PATH_DEFAULT_WALLET},
|
||||
{"name", "Status account"}},
|
||||
QJsonObject{{"public-key", account.derivedAccounts.whisper.publicKey},
|
||||
{"address", account.derivedAccounts.whisper.address},
|
||||
{"path", Backend::Accounts::PATH_WHISPER},
|
||||
{"name", account.alias},
|
||||
{"identicon", account.identicon},
|
||||
{"chat", true}}};
|
||||
return QJsonArray{QJsonObject{{"public-key", account.derivedAccounts.defaultWallet.publicKey},
|
||||
{"address", account.derivedAccounts.defaultWallet.address},
|
||||
{"color", "#4360df"},
|
||||
{"wallet", true},
|
||||
{"path", Backend::Accounts::PATH_DEFAULT_WALLET},
|
||||
{"name", "Status account"}},
|
||||
QJsonObject{{"public-key", account.derivedAccounts.whisper.publicKey},
|
||||
{"address", account.derivedAccounts.whisper.address},
|
||||
{"path", Backend::Accounts::PATH_WHISPER},
|
||||
{"name", account.alias},
|
||||
{"identicon", account.identicon},
|
||||
{"chat", true}}};
|
||||
}
|
||||
|
||||
QJsonArray Service::getSubaccountDataForAccountId(QString accountId)
|
||||
{
|
||||
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
||||
{
|
||||
if(acc.id == accountId)
|
||||
{
|
||||
return prepareSubaccountJsonObject(acc);
|
||||
}
|
||||
}
|
||||
if(m_importedAccount.isValid())
|
||||
{
|
||||
if(m_importedAccount.id == accountId)
|
||||
{
|
||||
return prepareSubaccountJsonObject(m_importedAccount);
|
||||
}
|
||||
}
|
||||
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
||||
{
|
||||
if(acc.id == accountId)
|
||||
{
|
||||
return prepareSubaccountJsonObject(acc);
|
||||
}
|
||||
}
|
||||
if(m_importedAccount.isValid())
|
||||
{
|
||||
if(m_importedAccount.id == accountId)
|
||||
{
|
||||
return prepareSubaccountJsonObject(m_importedAccount);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Should we use instead a std::optional?
|
||||
throw std::runtime_error("account not found");
|
||||
// TODO: Should we use instead a std::optional?
|
||||
throw std::runtime_error("account not found");
|
||||
}
|
||||
|
||||
QString generateSigningPhrase(int count)
|
||||
{
|
||||
QStringList words;
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
words.append(phrases[QRandomGenerator::global()->bounded(static_cast<int>(phrases.size()))]);
|
||||
}
|
||||
return words.join(" ");
|
||||
QStringList words;
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
words.append(phrases[QRandomGenerator::global()->bounded(static_cast<int>(phrases.size()))]);
|
||||
}
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
QJsonObject Service::prepareAccountSettingsJsonObject(const GeneratedAccountDto account, QString installationId)
|
||||
{
|
||||
QFile defaultNetworks(":/resources/default-networks.json");
|
||||
defaultNetworks.open(QIODevice::ReadOnly);
|
||||
QFile defaultNetworks(":/resources/default-networks.json");
|
||||
defaultNetworks.open(QIODevice::ReadOnly);
|
||||
|
||||
QString defaultNetworksContent = defaultNetworks.readAll().replace("%INFURA_KEY%", INFURA_KEY);
|
||||
QJsonArray defaultNetworksJson = QJsonDocument::fromJson(defaultNetworksContent.toUtf8()).array();
|
||||
QString defaultNetworksContent = defaultNetworks.readAll().replace("%INFURA_KEY%", INFURA_KEY);
|
||||
QJsonArray defaultNetworksJson = QJsonDocument::fromJson(defaultNetworksContent.toUtf8()).array();
|
||||
|
||||
return QJsonObject{{"key-uid", account.keyUid},
|
||||
{"mnemonic", account.mnemonic},
|
||||
{"public-key", account.derivedAccounts.whisper.publicKey},
|
||||
{"name", account.alias},
|
||||
{"address", account.address},
|
||||
{"eip1581-address", account.derivedAccounts.eip1581.address},
|
||||
{"dapps-address", account.derivedAccounts.defaultWallet.address},
|
||||
{"wallet-root-address", account.derivedAccounts.walletRoot.address},
|
||||
{"preview-privacy?", true},
|
||||
{"signing-phrase", generateSigningPhrase(3)},
|
||||
{"log-level", "INFO"},
|
||||
{"latest-derived-path", 0},
|
||||
{"networks/networks", defaultNetworksJson},
|
||||
{"currency", "usd"},
|
||||
{"identicon", account.identicon},
|
||||
{"waku-enabled", true},
|
||||
{"wallet/visible-tokens", {{Constants::DefaultNetworkName, QJsonArray{"SNT"}}}},
|
||||
{"appearance", 0},
|
||||
{"networks/current-network", Constants::DefaultNetworkName},
|
||||
{"installation-id", installationId}};
|
||||
return QJsonObject{{"key-uid", account.keyUid},
|
||||
{"mnemonic", account.mnemonic},
|
||||
{"public-key", account.derivedAccounts.whisper.publicKey},
|
||||
{"name", account.alias},
|
||||
{"address", account.address},
|
||||
{"eip1581-address", account.derivedAccounts.eip1581.address},
|
||||
{"dapps-address", account.derivedAccounts.defaultWallet.address},
|
||||
{"wallet-root-address", account.derivedAccounts.walletRoot.address},
|
||||
{"preview-privacy?", true},
|
||||
{"signing-phrase", generateSigningPhrase(3)},
|
||||
{"log-level", "INFO"},
|
||||
{"latest-derived-path", 0},
|
||||
{"networks/networks", defaultNetworksJson},
|
||||
{"currency", "usd"},
|
||||
{"identicon", account.identicon},
|
||||
{"waku-enabled", true},
|
||||
{"wallet/visible-tokens", {{Constants::DefaultNetworkName, QJsonArray{"SNT"}}}},
|
||||
{"appearance", 0},
|
||||
{"networks/current-network", Constants::DefaultNetworkName},
|
||||
{"installation-id", installationId}};
|
||||
}
|
||||
|
||||
QJsonObject Service::getAccountSettings(QString accountId, QString installationId)
|
||||
{
|
||||
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
||||
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
||||
|
||||
if(acc.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountSettingsJsonObject(acc, installationId);
|
||||
}
|
||||
if(acc.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountSettingsJsonObject(acc, installationId);
|
||||
}
|
||||
|
||||
if(m_importedAccount.isValid())
|
||||
{
|
||||
if(m_importedAccount.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountSettingsJsonObject(m_importedAccount, installationId);
|
||||
}
|
||||
}
|
||||
if(m_importedAccount.isValid())
|
||||
{
|
||||
if(m_importedAccount.id == accountId)
|
||||
{
|
||||
return Service::prepareAccountSettingsJsonObject(m_importedAccount, installationId);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Should we use instead a std::optional?
|
||||
throw std::runtime_error("account not found");
|
||||
// TODO: Should we use instead a std::optional?
|
||||
throw std::runtime_error("account not found");
|
||||
}
|
||||
|
||||
QJsonArray getNodes(const QJsonObject fleet, QString nodeType)
|
||||
{
|
||||
auto nodes = fleet[nodeType].toObject();
|
||||
QJsonArray result;
|
||||
for(auto it = nodes.begin(); it != nodes.end(); ++it)
|
||||
result << *it;
|
||||
return result;
|
||||
auto nodes = fleet[nodeType].toObject();
|
||||
QJsonArray result;
|
||||
for(auto it = nodes.begin(); it != nodes.end(); ++it)
|
||||
result << *it;
|
||||
return result;
|
||||
}
|
||||
|
||||
QJsonObject Service::getDefaultNodeConfig(QString installationId)
|
||||
{
|
||||
QFile nodeConfig(":/resources/node-config.json");
|
||||
nodeConfig.open(QIODevice::ReadOnly);
|
||||
QFile nodeConfig(":/resources/node-config.json");
|
||||
nodeConfig.open(QIODevice::ReadOnly);
|
||||
|
||||
QString nodeConfigContent = nodeConfig.readAll();
|
||||
QString nodeConfigContent = nodeConfig.readAll();
|
||||
|
||||
nodeConfigContent = nodeConfigContent.replace("%INSTALLATIONID%", installationId);
|
||||
nodeConfigContent = nodeConfigContent.replace("%INFURA_KEY%", INFURA_KEY);
|
||||
nodeConfigContent = nodeConfigContent.replace("%INSTALLATIONID%", installationId);
|
||||
nodeConfigContent = nodeConfigContent.replace("%INFURA_KEY%", INFURA_KEY);
|
||||
|
||||
QJsonObject nodeConfigJson = QJsonDocument::fromJson(nodeConfigContent.toUtf8()).object();
|
||||
QJsonObject nodeConfigJson = QJsonDocument::fromJson(nodeConfigContent.toUtf8()).object();
|
||||
|
||||
QFile fleets(":/resources/fleets.json");
|
||||
fleets.open(QIODevice::ReadOnly);
|
||||
QJsonObject fleetsJson = QJsonDocument::fromJson(fleets.readAll()).object()["fleets"].toObject();
|
||||
QFile fleets(":/resources/fleets.json");
|
||||
fleets.open(QIODevice::ReadOnly);
|
||||
QJsonObject fleetsJson = QJsonDocument::fromJson(fleets.readAll()).object()["fleets"].toObject();
|
||||
|
||||
auto fleet = fleetsJson[Constants::Fleet::Prod].toObject();
|
||||
auto fleet = fleetsJson[Constants::Fleet::Prod].toObject();
|
||||
|
||||
QJsonObject clusterConfig = nodeConfigJson["ClusterConfig"].toObject();
|
||||
QJsonObject clusterConfig = nodeConfigJson["ClusterConfig"].toObject();
|
||||
|
||||
clusterConfig["Fleet"] = Constants::Fleet::Prod;
|
||||
clusterConfig["BootNodes"] = getNodes(fleet, Constants::FleetNodes::Bootnodes);
|
||||
clusterConfig["TrustedMailServers"] = getNodes(fleet, Constants::FleetNodes::Mailservers);
|
||||
clusterConfig["StaticNodes"] = getNodes(fleet, Constants::FleetNodes::Whisper);
|
||||
clusterConfig["RendezvousNodes"] = getNodes(fleet, Constants::FleetNodes::Rendezvous);
|
||||
clusterConfig["RelayNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
clusterConfig["StoreNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
clusterConfig["FilterNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
clusterConfig["LightpushNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
clusterConfig["Fleet"] = Constants::Fleet::Prod;
|
||||
clusterConfig["BootNodes"] = getNodes(fleet, Constants::FleetNodes::Bootnodes);
|
||||
clusterConfig["TrustedMailServers"] = getNodes(fleet, Constants::FleetNodes::Mailservers);
|
||||
clusterConfig["StaticNodes"] = getNodes(fleet, Constants::FleetNodes::Whisper);
|
||||
clusterConfig["RendezvousNodes"] = getNodes(fleet, Constants::FleetNodes::Rendezvous);
|
||||
clusterConfig["RelayNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
clusterConfig["StoreNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
clusterConfig["FilterNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
clusterConfig["LightpushNodes"] = getNodes(fleet, Constants::FleetNodes::Waku);
|
||||
|
||||
nodeConfigJson["ClusterConfig"] = clusterConfig;
|
||||
nodeConfigJson["ClusterConfig"] = clusterConfig;
|
||||
|
||||
return nodeConfigJson;
|
||||
return nodeConfigJson;
|
||||
}
|
||||
} // namespace Accounts
|
||||
|
|
|
@ -26,8 +26,7 @@ void Service::fetchAccounts()
|
|||
foreach(const QJsonValue& value, response.m_result)
|
||||
{
|
||||
auto account = toWalletAccountDto(value);
|
||||
if(!account.isChat)
|
||||
m_walletAccounts[account.address] = account;
|
||||
if(!account.isChat) m_walletAccounts[account.address] = account;
|
||||
}
|
||||
}
|
||||
catch(Backend::RpcException& e)
|
||||
|
|
|
@ -1,97 +1,97 @@
|
|||
#include "backend/accounts.h"
|
||||
#include "backend/types.h"
|
||||
#include "backend/utils.h"
|
||||
#include "libstatus.h"
|
||||
#include <QDebug>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include "libstatus.h"
|
||||
|
||||
const int NUMBER_OF_ADDRESSES_TO_GENERATE = 5;
|
||||
const int MNEMONIC_PHRASE_LENGTH = 12;
|
||||
|
||||
Backend::RpcResponse<QJsonArray> Backend::Accounts::generateAddresses(QVector<QString> paths)
|
||||
{
|
||||
QJsonObject payload{{"n", NUMBER_OF_ADDRESSES_TO_GENERATE},
|
||||
{"mnemonicPhraseLength", MNEMONIC_PHRASE_LENGTH},
|
||||
{"bip32Passphrase", ""},
|
||||
{"paths", Utils::toJsonArray(paths)}
|
||||
QJsonObject payload{{"n", NUMBER_OF_ADDRESSES_TO_GENERATE},
|
||||
{"mnemonicPhraseLength", MNEMONIC_PHRASE_LENGTH},
|
||||
{"bip32Passphrase", ""},
|
||||
{"paths", Utils::toJsonArray(paths)}
|
||||
|
||||
};
|
||||
const char* result = MultiAccountGenerateAndDeriveAddresses(Utils::jsonToStr(payload).toUtf8().data());
|
||||
return Backend::RpcResponse<QJsonArray>(result, QJsonDocument::fromJson(result).array());
|
||||
};
|
||||
const char* result = MultiAccountGenerateAndDeriveAddresses(Utils::jsonToStr(payload).toUtf8().data());
|
||||
return Backend::RpcResponse<QJsonArray>(result, QJsonDocument::fromJson(result).array());
|
||||
}
|
||||
|
||||
Backend::RpcResponse<QString> Backend::Accounts::generateIdenticon(QString publicKey)
|
||||
{
|
||||
if(!publicKey.isEmpty())
|
||||
{
|
||||
auto identicon = QString(Identicon(publicKey.toUtf8().data()));
|
||||
return Backend::RpcResponse<QString>(identicon, identicon);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Backend::RpcException("publicKey can't be empty1");
|
||||
}
|
||||
if(!publicKey.isEmpty())
|
||||
{
|
||||
auto identicon = QString(Identicon(publicKey.toUtf8().data()));
|
||||
return Backend::RpcResponse<QString>(identicon, identicon);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Backend::RpcException("publicKey can't be empty1");
|
||||
}
|
||||
}
|
||||
|
||||
Backend::RpcResponse<QString> Backend::Accounts::generateAlias(QString publicKey)
|
||||
{
|
||||
if(!publicKey.isEmpty())
|
||||
{
|
||||
auto alias = QString(GenerateAlias(publicKey.toUtf8().data()));
|
||||
return Backend::RpcResponse<QString>(alias, alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Backend::RpcException("publicKey can't be empty2");
|
||||
}
|
||||
if(!publicKey.isEmpty())
|
||||
{
|
||||
auto alias = QString(GenerateAlias(publicKey.toUtf8().data()));
|
||||
return Backend::RpcResponse<QString>(alias, alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Backend::RpcException("publicKey can't be empty2");
|
||||
}
|
||||
}
|
||||
|
||||
Backend::RpcResponse<QJsonObject>
|
||||
Backend::Accounts::storeDerivedAccounts(QString id, QString hashedPassword, QVector<QString> paths)
|
||||
{
|
||||
QJsonObject payload{{"accountID", id}, {"paths", Utils::toJsonArray(paths)}, {"password", hashedPassword}};
|
||||
auto result = MultiAccountStoreDerivedAccounts(Utils::jsonToStr(payload).toUtf8().data());
|
||||
auto obj = QJsonDocument::fromJson(result).object();
|
||||
Backend::Utils::throwOnError(obj);
|
||||
return Backend::RpcResponse<QJsonObject>(result, obj);
|
||||
QJsonObject payload{{"accountID", id}, {"paths", Utils::toJsonArray(paths)}, {"password", hashedPassword}};
|
||||
auto result = MultiAccountStoreDerivedAccounts(Utils::jsonToStr(payload).toUtf8().data());
|
||||
auto obj = QJsonDocument::fromJson(result).object();
|
||||
Backend::Utils::throwOnError(obj);
|
||||
return Backend::RpcResponse<QJsonObject>(result, obj);
|
||||
}
|
||||
|
||||
Backend::RpcResponse<QJsonObject> Backend::Accounts::saveAccountAndLogin(
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig)
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig)
|
||||
{
|
||||
auto result = SaveAccountAndLogin(Utils::jsonToStr(account).toUtf8().data(),
|
||||
hashedPassword.toUtf8().data(),
|
||||
Utils::jsonToStr(settings).toUtf8().data(),
|
||||
Utils::jsonToStr(nodeConfig).toUtf8().data(),
|
||||
Utils::jsonToStr(subaccounts).toUtf8().data());
|
||||
auto obj = QJsonDocument::fromJson(result).object();
|
||||
Backend::Utils::throwOnError(obj);
|
||||
return Backend::RpcResponse<QJsonObject>(result, obj);
|
||||
auto result = SaveAccountAndLogin(Utils::jsonToStr(account).toUtf8().data(),
|
||||
hashedPassword.toUtf8().data(),
|
||||
Utils::jsonToStr(settings).toUtf8().data(),
|
||||
Utils::jsonToStr(nodeConfig).toUtf8().data(),
|
||||
Utils::jsonToStr(subaccounts).toUtf8().data());
|
||||
auto obj = QJsonDocument::fromJson(result).object();
|
||||
Backend::Utils::throwOnError(obj);
|
||||
return Backend::RpcResponse<QJsonObject>(result, obj);
|
||||
}
|
||||
|
||||
Backend::RpcResponse<QJsonArray> Backend::Accounts::openAccounts(QString path)
|
||||
{
|
||||
const char* result = OpenAccounts(path.toUtf8().data());
|
||||
auto resp = Backend::RpcResponse<QJsonArray>(result, QJsonDocument::fromJson(result).array());
|
||||
return resp;
|
||||
const char* result = OpenAccounts(path.toUtf8().data());
|
||||
auto resp = Backend::RpcResponse<QJsonArray>(result, QJsonDocument::fromJson(result).array());
|
||||
return resp;
|
||||
}
|
||||
|
||||
Backend::RpcResponse<QJsonObject> Backend::Accounts::login(
|
||||
QString name, QString keyUid, QString hashedPassword, QString identicon, QString thumbnail, QString large)
|
||||
QString name, QString keyUid, QString hashedPassword, QString identicon, QString thumbnail, QString large)
|
||||
{
|
||||
QJsonObject payload{{"name", name}, {"key-uid", keyUid}, {"identityImage", QJsonValue()}, {"identicon", identicon}};
|
||||
QJsonObject payload{{"name", name}, {"key-uid", keyUid}, {"identityImage", QJsonValue()}, {"identicon", identicon}};
|
||||
|
||||
if(!thumbnail.isEmpty() && !large.isEmpty())
|
||||
{
|
||||
payload["identityImage"] = QJsonObject{{"thumbnail", thumbnail}, {"large", large}};
|
||||
}
|
||||
if(!thumbnail.isEmpty() && !large.isEmpty())
|
||||
{
|
||||
payload["identityImage"] = QJsonObject{{"thumbnail", thumbnail}, {"large", large}};
|
||||
}
|
||||
|
||||
auto result = Login(Utils::jsonToStr(payload).toUtf8().data(), hashedPassword.toUtf8().data());
|
||||
auto obj = QJsonDocument::fromJson(result).object();
|
||||
Backend::Utils::throwOnError(obj);
|
||||
return Backend::RpcResponse<QJsonObject>(result, obj);
|
||||
}
|
||||
auto result = Login(Utils::jsonToStr(payload).toUtf8().data(), hashedPassword.toUtf8().data());
|
||||
auto obj = QJsonDocument::fromJson(result).object();
|
||||
Backend::Utils::throwOnError(obj);
|
||||
return Backend::RpcResponse<QJsonObject>(result, obj);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ RpcResponse<QString> generateAlias(QString publicKey);
|
|||
RpcResponse<QJsonObject> storeDerivedAccounts(QString accountId, QString hashedPassword, QVector<QString> paths);
|
||||
|
||||
RpcResponse<QJsonObject> saveAccountAndLogin(
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig);
|
||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig);
|
||||
|
||||
RpcResponse<QJsonArray> openAccounts(QString path);
|
||||
|
||||
|
@ -36,4 +36,4 @@ RpcResponse<QJsonObject>
|
|||
login(QString name, QString keyUid, QString hashedPassword, QString identicon, QString thumbnail, QString large);
|
||||
|
||||
} // namespace Accounts
|
||||
} // namespace Backend
|
||||
} // namespace Backend
|
||||
|
|
|
@ -16,18 +16,19 @@ struct RpcException : public std::exception
|
|||
{
|
||||
private:
|
||||
std::string m_message;
|
||||
|
||||
public:
|
||||
explicit RpcException(const std::string& message);
|
||||
const char* what() const throw();
|
||||
explicit RpcException(const std::string& message);
|
||||
const char* what() const throw();
|
||||
};
|
||||
|
||||
class RpcError
|
||||
{
|
||||
public:
|
||||
int m_code;
|
||||
QString m_message;
|
||||
int m_code;
|
||||
QString m_message;
|
||||
|
||||
friend ostream& operator<<(ostream& os, Backend::RpcError& r);
|
||||
friend ostream& operator<<(ostream& os, Backend::RpcError& r);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -35,16 +36,16 @@ template <typename T>
|
|||
class RpcResponse
|
||||
{
|
||||
public:
|
||||
QString m_jsonrpc;
|
||||
T m_result;
|
||||
int m_id;
|
||||
RpcError m_error;
|
||||
QString m_jsonrpc;
|
||||
T m_result;
|
||||
int m_id;
|
||||
RpcError m_error;
|
||||
|
||||
public:
|
||||
RpcResponse(QString jsonrpc, T result)
|
||||
: m_jsonrpc(jsonrpc)
|
||||
, m_result(result)
|
||||
{ }
|
||||
RpcResponse(QString jsonrpc, T result)
|
||||
: m_jsonrpc(jsonrpc)
|
||||
, m_result(result)
|
||||
{ }
|
||||
};
|
||||
|
||||
} // namespace Backend
|
||||
|
|
|
@ -10,11 +10,11 @@ namespace Backend
|
|||
class Utils
|
||||
{
|
||||
public:
|
||||
static QString hashString(QString str);
|
||||
static QString jsonToStr(QJsonObject obj);
|
||||
static QString jsonToStr(QJsonArray arr);
|
||||
static QJsonArray toJsonArray(const QVector<QString>& value);
|
||||
static QVector<QString> toStringVector(const QJsonArray& arr);
|
||||
static void throwOnError(QJsonObject response);
|
||||
static QString hashString(QString str);
|
||||
static QString jsonToStr(QJsonObject obj);
|
||||
static QString jsonToStr(QJsonArray arr);
|
||||
static QJsonArray toJsonArray(const QVector<QString>& value);
|
||||
static QVector<QString> toStringVector(const QJsonArray& arr);
|
||||
static void throwOnError(QJsonObject response);
|
||||
};
|
||||
} // namespace Backend
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
namespace Backend::Wallet::Accounts
|
||||
{
|
||||
Backend::RpcResponse<QJsonArray> getAccounts();
|
||||
} // Backend::Wallet::Accounts
|
||||
} // namespace Backend::Wallet::Accounts
|
||||
|
||||
#endif // WALLETACCOUNT_BACKEND_H
|
||||
|
|
|
@ -5,15 +5,15 @@ using namespace std;
|
|||
|
||||
ostream& operator<<(ostream& os, const Backend::RpcError& r)
|
||||
{
|
||||
return (os << "RpcError(\n code: " << r.m_code << "\n message: " << r.m_message.toStdString() << "\n)"
|
||||
<< std::endl);
|
||||
return (os << "RpcError(\n code: " << r.m_code << "\n message: " << r.m_message.toStdString() << "\n)"
|
||||
<< std::endl);
|
||||
}
|
||||
|
||||
Backend::RpcException::RpcException(const std::string& message)
|
||||
: m_message(message)
|
||||
: m_message(message)
|
||||
{ }
|
||||
|
||||
const char* Backend::RpcException::what() const throw()
|
||||
{
|
||||
return m_message.c_str();
|
||||
}
|
||||
return m_message.c_str();
|
||||
}
|
||||
|
|
|
@ -1,51 +1,53 @@
|
|||
#include "backend/utils.h"
|
||||
#include "backend/types.h"
|
||||
#include <QCryptographicHash>
|
||||
#include <QDebug>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QDebug>
|
||||
|
||||
QJsonArray Backend::Utils::toJsonArray(const QVector<QString>& value)
|
||||
{
|
||||
QJsonArray array;
|
||||
for(auto& v : value)
|
||||
array << v;
|
||||
return array;
|
||||
QJsonArray array;
|
||||
for(auto& v : value)
|
||||
array << v;
|
||||
return array;
|
||||
}
|
||||
|
||||
QString Backend::Utils::jsonToStr(QJsonObject obj)
|
||||
{
|
||||
QJsonDocument doc(obj);
|
||||
return QString::fromUtf8(doc.toJson());
|
||||
QJsonDocument doc(obj);
|
||||
return QString::fromUtf8(doc.toJson());
|
||||
}
|
||||
|
||||
QString Backend::Utils::jsonToStr(QJsonArray arr)
|
||||
{
|
||||
QJsonDocument doc(arr);
|
||||
return QString::fromUtf8(doc.toJson());
|
||||
QJsonDocument doc(arr);
|
||||
return QString::fromUtf8(doc.toJson());
|
||||
}
|
||||
|
||||
QVector<QString> Backend::Utils::toStringVector(const QJsonArray& arr)
|
||||
{
|
||||
QVector<QString> result;
|
||||
foreach(const QJsonValue& value, arr)
|
||||
{
|
||||
result << value.toString();
|
||||
}
|
||||
return result;
|
||||
QVector<QString> result;
|
||||
foreach(const QJsonValue& value, arr)
|
||||
{
|
||||
result << value.toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString Backend::Utils::hashString(QString str)
|
||||
{
|
||||
return "0x" + QString::fromUtf8(QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Keccak_256).toHex());
|
||||
return "0x" + QString::fromUtf8(QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Keccak_256).toHex());
|
||||
}
|
||||
|
||||
void Backend::Utils::throwOnError(QJsonObject response) {
|
||||
if(!response["error"].isUndefined() && !response["error"].toString().isEmpty()){
|
||||
qWarning() << "RpcException: " << response["error"].toString();
|
||||
throw Backend::RpcException(response["error"].toString().toStdString());
|
||||
}
|
||||
}
|
||||
void Backend::Utils::throwOnError(QJsonObject response)
|
||||
{
|
||||
if(!response["error"].isUndefined() && !response["error"].toString().isEmpty())
|
||||
{
|
||||
qWarning() << "RpcException: " << response["error"].toString();
|
||||
throw Backend::RpcException(response["error"].toString().toStdString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "backend/wallet_accounts.h"
|
||||
#include "backend/types.h"
|
||||
#include "backend/utils.h"
|
||||
#include "backend/wallet_accounts.h"
|
||||
#include "libstatus.h"
|
||||
|
||||
namespace Backend::Wallet::Accounts
|
||||
|
@ -16,6 +16,4 @@ RpcResponse<QJsonArray> getAccounts()
|
|||
return RpcResponse<QJsonArray>(result, QJsonDocument::fromJson(result)["result"].toArray());
|
||||
}
|
||||
|
||||
|
||||
} // namespace Backend::Wallet::Accounts
|
||||
|
||||
|
|
|
@ -7,35 +7,34 @@
|
|||
|
||||
// TODO: merge with constants from backend/
|
||||
|
||||
|
||||
QString Constants::applicationPath(QString path)
|
||||
{
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath();
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath();
|
||||
}
|
||||
|
||||
QString Constants::tmpPath(QString path)
|
||||
{
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath();
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath();
|
||||
}
|
||||
|
||||
QString Constants::cachePath(QString path)
|
||||
{
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath();
|
||||
return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath();
|
||||
}
|
||||
|
||||
bool Constants::ensureDirectories()
|
||||
{
|
||||
if(Constants::applicationPath().isEmpty())
|
||||
{
|
||||
QDir d{Constants::applicationPath()};
|
||||
if(!d.mkpath(d.absolutePath()))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Warning);
|
||||
msgBox.setText("Cannot determine storage location");
|
||||
msgBox.exec();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if(Constants::applicationPath().isEmpty())
|
||||
{
|
||||
QDir d{Constants::applicationPath()};
|
||||
if(!d.mkpath(d.absolutePath()))
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Warning);
|
||||
msgBox.setText("Cannot determine storage location");
|
||||
msgBox.exec();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
void DOtherSide::registerMetaTypes()
|
||||
{
|
||||
qRegisterMetaType<QVector<int>>();
|
||||
qmlRegisterType<StatusWindow>("DotherSide", 0, 1, "StatusWindow");
|
||||
qmlRegisterType<StatusSyntaxHighlighterHelper>("DotherSide", 0, 1, "StatusSyntaxHighlighter");
|
||||
qmlRegisterType<SpellChecker>("DotherSide", 0, 1, "SpellChecker");
|
||||
qRegisterMetaType<QVector<int>>();
|
||||
qmlRegisterType<StatusWindow>("DotherSide", 0, 1, "StatusWindow");
|
||||
qmlRegisterType<StatusSyntaxHighlighterHelper>("DotherSide", 0, 1, "StatusSyntaxHighlighter");
|
||||
qmlRegisterType<SpellChecker>("DotherSide", 0, 1, "SpellChecker");
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue