2022-07-15 07:30:16 +00:00
|
|
|
#include "Status/Wallet/WalletController.h"
|
2022-07-26 11:49:03 +00:00
|
|
|
|
2022-09-06 15:26:06 +00:00
|
|
|
#include <QJSEngine>
|
2022-10-19 13:41:53 +00:00
|
|
|
#include <QQmlEngine>
|
2022-07-15 07:30:16 +00:00
|
|
|
|
|
|
|
#include <StatusGo/Wallet/WalletApi.h>
|
|
|
|
|
|
|
|
#include <StatusGo/Accounts/Accounts.h>
|
2022-10-19 13:41:53 +00:00
|
|
|
#include <StatusGo/Accounts/AccountsAPI.h>
|
2022-07-15 07:30:16 +00:00
|
|
|
#include <StatusGo/Accounts/accounts_types.h>
|
|
|
|
#include <StatusGo/Metadata/api_response.h>
|
|
|
|
#include <StatusGo/Types.h>
|
2022-10-19 13:41:53 +00:00
|
|
|
#include <StatusGo/Utils.h>
|
2022-07-15 07:30:16 +00:00
|
|
|
|
|
|
|
#include <Onboarding/Common/Constants.h>
|
|
|
|
|
2022-09-06 15:26:06 +00:00
|
|
|
#include "AccountAssetsController.h"
|
2022-10-19 13:41:53 +00:00
|
|
|
#include "NewWalletAccountController.h"
|
2022-09-06 15:26:06 +00:00
|
|
|
#include "SavedAddressesController.h"
|
2022-07-15 07:30:16 +00:00
|
|
|
|
|
|
|
namespace GoAccounts = Status::StatusGo::Accounts;
|
2022-07-26 11:49:03 +00:00
|
|
|
namespace WalletGo = Status::StatusGo::Wallet;
|
2022-07-15 07:30:16 +00:00
|
|
|
namespace UtilsSG = Status::StatusGo::Utils;
|
|
|
|
namespace StatusGo = Status::StatusGo;
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
namespace Status::Wallet
|
|
|
|
{
|
2022-07-15 07:30:16 +00:00
|
|
|
|
|
|
|
WalletController::WalletController()
|
2022-07-26 11:49:03 +00:00
|
|
|
: m_accounts(Helpers::makeSharedQObject<AccountsModel>(std::move(getWalletAccounts()), "account"))
|
2022-07-15 07:30:16 +00:00
|
|
|
, m_currentAccount(m_accounts->get(0))
|
2022-10-19 13:41:53 +00:00
|
|
|
{ }
|
2022-07-15 07:30:16 +00:00
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
WalletController* WalletController::create(QQmlEngine* qmlEngine, QJSEngine* jsEngine)
|
2022-07-15 07:30:16 +00:00
|
|
|
{
|
|
|
|
return new WalletController();
|
|
|
|
}
|
|
|
|
|
|
|
|
NewWalletAccountController* WalletController::createNewWalletAccountController() const
|
|
|
|
{
|
|
|
|
return new NewWalletAccountController(m_accounts);
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
SavedAddressesController* WalletController::createSavedAddressesController() const
|
2022-09-06 15:26:06 +00:00
|
|
|
{
|
|
|
|
return new SavedAddressesController();
|
|
|
|
}
|
|
|
|
|
2022-07-15 07:30:16 +00:00
|
|
|
QAbstractListModel* WalletController::accountsModel() const
|
|
|
|
{
|
|
|
|
return m_accounts.get();
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
WalletAccount* WalletController::currentAccount() const
|
2022-07-15 07:30:16 +00:00
|
|
|
{
|
|
|
|
return m_currentAccount.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletController::setCurrentAccountIndex(int index)
|
|
|
|
{
|
|
|
|
assert(index >= 0 && index < m_accounts->size());
|
|
|
|
|
|
|
|
auto newCurrentAccount = m_accounts->get(index);
|
2022-10-19 13:41:53 +00:00
|
|
|
if(m_currentAccount == newCurrentAccount) return;
|
2022-07-15 07:30:16 +00:00
|
|
|
|
|
|
|
m_currentAccount = newCurrentAccount;
|
|
|
|
emit currentAccountChanged();
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
AccountAssetsController* WalletController::createAccountAssetsController(WalletAccount* account)
|
2022-07-26 11:49:03 +00:00
|
|
|
{
|
|
|
|
return new AccountAssetsController(account);
|
|
|
|
}
|
|
|
|
|
2022-07-15 07:30:16 +00:00
|
|
|
std::vector<WalletAccountPtr> WalletController::getWalletAccounts(bool rootWalletAccountsOnly) const
|
|
|
|
{
|
|
|
|
auto all = GoAccounts::getAccounts();
|
|
|
|
std::vector<WalletAccountPtr> result;
|
2022-10-19 13:41:53 +00:00
|
|
|
for(auto account : all)
|
|
|
|
{
|
2022-07-15 07:30:16 +00:00
|
|
|
if(!account.isChat && (!rootWalletAccountsOnly || account.isWallet))
|
2022-07-26 11:49:03 +00:00
|
|
|
result.push_back(Helpers::makeSharedQObject<WalletAccount>(std::move(account)));
|
2022-07-15 07:30:16 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
} // namespace Status::Wallet
|