status-desktop/libs/Wallet/src/SavedAddressesController.cpp

58 lines
1.7 KiB
C++
Raw Normal View History

2022-09-05 15:22:18 +00:00
#include "Status/Wallet/SavedAddressesController.h"
#include "Helpers/helpers.h"
#include "Metadata/api_response.h"
#include <StatusGo/Wallet/WalletApi.h>
2022-09-05 15:22:18 +00:00
namespace Status::Wallet
{
2022-10-19 13:41:53 +00:00
SavedAddressesController::SavedAddressesController(QObject* parent)
2022-09-05 15:22:18 +00:00
: QObject(parent)
, m_savedAddresses(Helpers::makeSharedQObject<SavedAddressesModel>("savedAddress"))
2022-10-19 13:41:53 +00:00
{ }
2022-10-19 13:41:53 +00:00
QAbstractListModel* SavedAddressesController::savedAddresses() const
{
return m_savedAddresses.get();
}
// TODO: extend with favourite and chain ID
2022-10-19 13:41:53 +00:00
void SavedAddressesController::saveAddress(const QString& address, const QString& name)
{
try
{
StatusGo::Wallet::saveAddress(StatusGo::Wallet::SavedAddress(
2022-10-19 13:41:53 +00:00
{StatusGo::Accounts::EOAddress(address), name, false, StatusGo::Wallet::ChainID(0)}));
}
catch(const StatusGo::CallPrivateRpcError& rpcError)
{
2022-10-19 13:41:53 +00:00
qWarning() << "StatusGoQt.saveAddress error: " << rpcError.errorResponse().error.message.c_str();
emit error(SaveAddressError);
}
// TODO: signal from wallet data_source
this->refresh();
}
void SavedAddressesController::refresh()
{
std::vector<SavedAddressPtr> savedAddresses;
try
{
2022-10-19 13:41:53 +00:00
for(const auto& address : StatusGo::Wallet::getSavedAddresses())
{
savedAddresses.push_back(std::make_shared<SavedAddress>(address.address.get(), address.name));
}
}
catch(const StatusGo::CallPrivateRpcError& rpcError)
{
2022-10-19 13:41:53 +00:00
qWarning() << "StatusGoQt.getSavedAddresses error: " << rpcError.errorResponse().error.message.c_str();
emit error(RetrieveSavedAddressesError);
}
m_savedAddresses->reset(savedAddresses);
}
2022-09-05 15:22:18 +00:00
} // namespace Status::Wallet