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
|
|
|
|
{
|
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
SavedAddressesController::SavedAddressesController(QObject* parent)
|
2022-09-05 15:22:18 +00:00
|
|
|
: QObject(parent)
|
2022-09-07 11:33:37 +00:00
|
|
|
, m_savedAddresses(Helpers::makeSharedQObject<SavedAddressesModel>("savedAddress"))
|
2022-10-19 13:41:53 +00:00
|
|
|
{ }
|
2022-09-06 15:26:06 +00:00
|
|
|
|
2022-10-19 13:41:53 +00:00
|
|
|
QAbstractListModel* SavedAddressesController::savedAddresses() const
|
2022-09-06 15:26:06 +00:00
|
|
|
{
|
|
|
|
return m_savedAddresses.get();
|
|
|
|
}
|
|
|
|
|
2022-10-10 09:13:34 +00:00
|
|
|
// TODO: extend with favourite and chain ID
|
2022-10-19 13:41:53 +00:00
|
|
|
void SavedAddressesController::saveAddress(const QString& address, const QString& name)
|
2022-09-06 15:26:06 +00:00
|
|
|
{
|
2022-09-07 11:33:37 +00:00
|
|
|
try
|
|
|
|
{
|
2022-09-08 12:24:50 +00:00
|
|
|
StatusGo::Wallet::saveAddress(StatusGo::Wallet::SavedAddress(
|
2022-10-19 13:41:53 +00:00
|
|
|
{StatusGo::Accounts::EOAddress(address), name, false, StatusGo::Wallet::ChainID(0)}));
|
2022-09-07 11:33:37 +00:00
|
|
|
}
|
|
|
|
catch(const StatusGo::CallPrivateRpcError& rpcError)
|
|
|
|
{
|
2022-10-19 13:41:53 +00:00
|
|
|
qWarning() << "StatusGoQt.saveAddress error: " << rpcError.errorResponse().error.message.c_str();
|
2022-09-07 11:33:37 +00:00
|
|
|
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())
|
2022-09-07 11:33:37 +00:00
|
|
|
{
|
|
|
|
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();
|
2022-09-07 11:33:37 +00:00
|
|
|
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
|