chore(CPP): Align Saved Addresses with new changes

It adds favourite false and doesn't extend the implementation to support
these new features
Workaround to crash of chats whit a new account by lazy loading sections
and defaulting to wallet

Updates #7229
This commit is contained in:
Stefan 2022-10-10 12:13:34 +03:00 committed by Stefan Dunca
parent b348527edc
commit a157f688fd
7 changed files with 35 additions and 11 deletions

View File

@ -34,6 +34,7 @@ Item {
Layout.fillHeight: true
sections: appSections.sections
currentIndex: 1
}
ColumnLayout {
@ -59,6 +60,7 @@ Item {
delegate: Loader {
Layout.fillWidth: true
Layout.fillHeight: true
active: navBar.currentIndex === index
sourceComponent: modelData.content
}

View File

@ -2,6 +2,8 @@
#include "Helpers/conversions.h"
#include <QCommandLineParser>
#include <filesystem>
namespace fs = std::filesystem;
@ -40,8 +42,25 @@ void UserConfiguration::setUserDataFolder(const QString &newUserDataFolder)
void UserConfiguration::generateReleaseConfiguration()
{
m_userDataFolder = toPath(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation))/statusFolder/dataSubfolder;
if(!parseFromCommandLineAndReturnTrueIfSet())
m_userDataFolder = toPath(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation))/statusFolder/dataSubfolder;
emit userDataFolderChanged();
}
bool UserConfiguration::parseFromCommandLineAndReturnTrueIfSet()
{
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("dataDir", "Data folder");
parser.process(*QCoreApplication::instance());
auto args = parser.positionalArguments();
if (args.size() > 0) {
m_userDataFolder = toPath(args[0]);
emit userDataFolderChanged();
return true;
}
return false;
}
}

View File

@ -9,14 +9,13 @@ namespace Status::ApplicationCore {
namespace fs = std::filesystem;
/// Contains necessary data for each created account hence this will be the same path for all accounts
class UserConfiguration: public QObject
{
Q_OBJECT
QML_ELEMENT
// Not sure why `qmlUserDataFolder` is writable??? We should not change it from the qml side.
// Even from the backend side this will be set only on the app start, and it will contain
// necessary data for each created account, so even we're switching accounts, this will be the same path.
/// @note userFolder is writable in order to allow changing it in tests until a proper abstraction is in place
Q_PROPERTY(QString userDataFolder READ qmlUserDataFolder WRITE setUserDataFolder NOTIFY userDataFolderChanged)
public:
@ -31,6 +30,7 @@ signals:
private:
void generateReleaseConfiguration();
bool parseFromCommandLineAndReturnTrueIfSet();
fs::path m_userDataFolder;
};

View File

@ -20,10 +20,12 @@ struct SavedAddress
{
Accounts::EOAddress address;
QString name;
bool favourite;
ChainID chainId;
};
using SavedAddresses = std::vector<SavedAddress>;
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SavedAddress, address, name);
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SavedAddress, address, name, favourite, chainId);
}

View File

@ -46,7 +46,7 @@ SavedAddresses getSavedAddresses()
checkPrivateRpcCallResultAndReportError(resultJson);
const auto &data = resultJson.get<CallPrivateRpcResponse>().result;
return data.is_null() ? nlohmann::json() : data;
return data.is_null() ? json::array() : data;
}
void saveAddress(const SavedAddress &address)
@ -77,7 +77,7 @@ NetworkConfigurations getEthereumChains(bool onlyEnabled)
checkPrivateRpcCallResultAndReportError(resultJson);
const auto &data = resultJson.get<CallPrivateRpcResponse>().result;
return data.is_null() ? nlohmann::json() : data;
return data.is_null() ? json::array() : data;
}
Tokens getTokens(const ChainID &chainId)
@ -94,7 +94,7 @@ Tokens getTokens(const ChainID &chainId)
checkPrivateRpcCallResultAndReportError(resultJson);
const auto &data = resultJson.get<CallPrivateRpcResponse>().result;
return data.is_null() ? nlohmann::json() : data;
return data.is_null() ? json::array() : data;
}
TokenBalances getTokensBalancesForChainIDs(const std::vector<ChainID> &chainIds,

View File

@ -18,12 +18,13 @@ QAbstractListModel *SavedAddressesController::savedAddresses() const
return m_savedAddresses.get();
}
// TODO: extend with favourite and chain ID
void SavedAddressesController::saveAddress(const QString &address, const QString &name)
{
try
{
StatusGo::Wallet::saveAddress(StatusGo::Wallet::SavedAddress(
{ StatusGo::Accounts::EOAddress(address), name }));
{ StatusGo::Accounts::EOAddress(address), name, false, StatusGo::Wallet::ChainID(0) }));
}
catch(const StatusGo::CallPrivateRpcError& rpcError)
{

View File

@ -27,7 +27,7 @@
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": true
"enabled": false
},
{
"chainId": 4,
@ -57,7 +57,7 @@
"nativeCurrencyDecimals": 18,
"isTest": true,
"layer": 1,
"enabled": false
"enabled": true
},
{
"chainId": 10,