2022-09-05 15:22:18 +00:00
|
|
|
#include "Status/Wallet/SavedAddressesController.h"
|
2022-09-06 15:26:06 +00:00
|
|
|
#include "Helpers/helpers.h"
|
2022-09-07 11:33:37 +00:00
|
|
|
#include "Metadata/api_response.h"
|
|
|
|
|
|
|
|
#include <StatusGo/Wallet/WalletApi.h>
|
2022-09-05 15:22:18 +00:00
|
|
|
|
|
|
|
namespace Status::Wallet
|
|
|
|
{
|
|
|
|
|
|
|
|
SavedAddressesController::SavedAddressesController(QObject* parent)
|
|
|
|
: QObject(parent)
|
2022-09-07 11:33:37 +00:00
|
|
|
, m_savedAddresses(Helpers::makeSharedQObject<SavedAddressesModel>("savedAddress"))
|
2022-09-06 15:26:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractListModel* SavedAddressesController::savedAddresses() const
|
|
|
|
{
|
|
|
|
return m_savedAddresses.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SavedAddressesController::saveAddress(const QString &address, const QString &name)
|
|
|
|
{
|
2022-09-07 11:33:37 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
StatusGo::Wallet::saveAddress(StatusGo::Accounts::EOAddress(address), name);
|
|
|
|
}
|
|
|
|
catch(const StatusGo::CallPrivateRpcError& rpcError)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
for (const StatusGo::Wallet::SavedAddress& address: StatusGo::Wallet::getSavedAddresses())
|
|
|
|
{
|
|
|
|
savedAddresses.push_back(std::make_shared<SavedAddress>(address.address.get(), address.name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const StatusGo::CallPrivateRpcError& rpcError)
|
|
|
|
{
|
|
|
|
qWarning() << "StatusGoQt.getSavedAddresses error: " <<
|
|
|
|
rpcError.errorResponse().error.message.c_str();
|
|
|
|
emit error(RetrieveSavedAddressesError);
|
|
|
|
}
|
|
|
|
m_savedAddresses->reset(savedAddresses);
|
2022-09-06 15:26:06 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 15:22:18 +00:00
|
|
|
} // namespace Status::Wallet
|