fix(wallet): hidden groups are still loading from user local settings

Removed loading hidden groups from local settings and instead reload
them from the externally loaded settings.
Also move the local saving code from the controller to external,
therefore now it is implemented in storybook

Updates #14365
This commit is contained in:
Stefan 2024-04-09 23:26:15 +03:00 committed by Stefan Dunca
parent 55dd8e3065
commit d3f037f93b
8 changed files with 164 additions and 69 deletions

View File

@ -2,6 +2,8 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import Qt.labs.settings 1.0
import SortFilterProxyModel 0.2
import StatusQ 0.1
@ -99,9 +101,19 @@ SplitView {
settingsKey: "WalletAssets"
serializeAsCollectibles: false
onRequestSaveSettings: (jsonData) => saveToQSettings(jsonData)
onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
onRequestSaveSettings: (jsonData) => {
savingStarted()
settingsStore.setValue(settingsKey, jsonData)
savingFinished()
}
onRequestLoadSettings: {
loadingStarted()
const jsonData = settingsStore.value(settingsKey, null)
loadingFinished(jsonData)
}
onRequestClearSettings: {
settingsStore.setValue(settingsKey, null)
}
onTokenHidden: (symbol, name) => Global.displayToastMessage(
qsTr("%1 (%2) was successfully hidden").arg(name).arg(symbol), "", "checkmark-circle",
@ -132,6 +144,11 @@ SplitView {
onReceiveRequested: logs.logEvent("onReceiveRequested", ["symbol"], arguments)
onSwitchToCommunityRequested: logs.logEvent("onSwitchToCommunityRequested", ["communityId"], arguments)
onManageTokensRequested: logs.logEvent("onManageTokensRequested")
Settings {
id: settingsStore
category: "ManageTokens-" + assetsView.controller.settingsKey
}
}
ColumnLayout {

View File

@ -2,6 +2,8 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import Qt.labs.settings 1.0
import StatusQ 0.1
import StatusQ.Models 0.1
import StatusQ.Core 0.1
@ -84,9 +86,19 @@ SplitView {
settingsKey: "WalletCollectibles"
serializeAsCollectibles: true
onRequestSaveSettings: (jsonData) => saveToQSettings(jsonData)
onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
onRequestSaveSettings: (jsonData) => {
savingStarted()
settingsStore.setValue(settingsKey, jsonData)
savingFinished()
}
onRequestLoadSettings: {
loadingStarted()
const jsonData = settingsStore.value(settingsKey, null)
loadingFinished(jsonData)
}
onRequestClearSettings: {
settingsStore.setValue(settingsKey, null)
}
onTokenHidden: (symbol, name) => Global.displayToastMessage(
qsTr("%1 was successfully hidden").arg(name), "", "checkmark-circle",
@ -111,6 +123,11 @@ SplitView {
isUpdating: ctrlUpdatingCheckbox.checked
isFetching: ctrlFetchingCheckbox.checked
isError: ctrlErrorCheckbox.checked
Settings {
id: settingsStore
category: "ManageTokens-" + collectiblesView.controller.settingsKey
}
}
LogsAndControlsPanel {

View File

@ -2,6 +2,8 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import Qt.labs.settings 1.0
import StatusQ.Core 0.1
import StatusQ.Models 0.1
@ -52,9 +54,24 @@ SplitView {
settingsKey: "WalletAssets"
serializeAsCollectibles: false
onRequestSaveSettings: (jsonData) => saveToQSettings(jsonData)
onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
onRequestSaveSettings: (jsonData) => {
savingStarted()
settingsStore.setValue(settingsKey, jsonData)
savingFinished()
}
onRequestLoadSettings: {
loadingStarted()
const jsonData = settingsStore.value(settingsKey, null)
loadingFinished(jsonData)
}
onRequestClearSettings: {
settingsStore.setValue(settingsKey, null)
}
}
Settings {
id: settingsStore
category: "ManageTokens-" + showcasePanel.controller.settingsKey
}
}

View File

@ -2,6 +2,8 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import Qt.labs.settings 1.0
import StatusQ 0.1
import StatusQ.Models 0.1
import StatusQ.Core 0.1
@ -46,9 +48,24 @@ SplitView {
settingsKey: "WalletCollectibles"
serializeAsCollectibles: true
onRequestSaveSettings: (jsonData) => saveToQSettings(jsonData)
onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
onRequestSaveSettings: (jsonData) => {
savingStarted()
settingsStore.setValue(settingsKey, jsonData)
savingFinished()
}
onRequestLoadSettings: {
loadingStarted()
const jsonData = settingsStore.value(settingsKey, null)
loadingFinished(jsonData)
}
onRequestClearSettings: {
settingsStore.setValue(settingsKey, null)
}
}
Settings {
id: settingsStore
category: "ManageTokens-" + showcasePanel.controller.settingsKey
}
}

View File

@ -2,6 +2,8 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import Qt.labs.settings 1.0
import StatusQ 0.1
import StatusQ.Core 0.1
import StatusQ.Models 0.1
@ -46,9 +48,24 @@ SplitView {
settingsKey: "WalletAssets"
serializeAsCollectibles: false
onRequestSaveSettings: (jsonData) => saveToQSettings(jsonData)
onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
onRequestSaveSettings: (jsonData) => {
savingStarted()
assetsSettingsStore.setValue(settingsKey, jsonData)
savingFinished()
}
onRequestLoadSettings: {
loadingStarted()
const jsonData = assetsSettingsStore.value(settingsKey, null)
loadingFinished(jsonData)
}
onRequestClearSettings: {
assetsSettingsStore.setValue(settingsKey, null)
}
}
Settings {
id: assetsSettingsStore
category: "ManageTokens-" + assetsController.settingsKey
}
ManageTokensController {
@ -57,9 +74,24 @@ SplitView {
settingsKey: "WalletCollectibles"
serializeAsCollectibles: true
onRequestSaveSettings: (jsonData) => saveToQSettings(jsonData)
onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
onRequestSaveSettings: (jsonData) => {
savingStarted()
collectiblesSettingsStore.setValue(settingsKey, jsonData)
savingFinished()
}
onRequestLoadSettings: {
loadingStarted()
const jsonData = collectiblesSettingsStore.value(settingsKey, null)
loadingFinished(jsonData)
}
onRequestClearSettings: {
collectiblesSettingsStore.setValue(settingsKey, null)
}
}
Settings {
id: collectiblesSettingsStore
category: "ManageTokens-" + collectiblesController.settingsKey
}
ManageHiddenPanel {

View File

@ -1,6 +1,8 @@
import QtQuick 2.15
import QtTest 1.15
import Qt.labs.settings 1.0
import StatusQ 0.1
import StatusQ.Models 0.1
@ -32,6 +34,7 @@ Item {
Component {
id: componentUnderTest
ManageCollectiblesPanel {
id: panel
width: 500
height: contentHeight
controller: ManageTokensController {
@ -39,9 +42,17 @@ Item {
settingsKey: "WalletCollectibles"
serializeAsCollectibles: true
onRequestSaveSettings: (jsonData) => saveToQSettings(jsonData)
onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
onRequestSaveSettings: (jsonData) => {
savingStarted()
settingsStore.setValue(settingsKey, jsonData)
savingFinished()
}
onRequestLoadSettings: {
loadingStarted()
const jsonData = settingsStore.value(settingsKey, null)
loadingFinished(jsonData)
}
onRequestClearSettings: panel.clearSettings()
onCommunityTokenGroupHidden: (communityName) => Global.displayToastMessage(
qsTr("%1 community collectibles successfully hidden").arg(communityName), "", "checkmark-circle",
@ -50,6 +61,12 @@ Item {
function clearSettings() {
controller.clearQSettings()
settingsStore.setValue(panel.controller.settingsKey, null)
}
Settings {
id: settingsStore
category: "ManageTokens-" + panel.controller.settingsKey
}
}
}

View File

@ -165,24 +165,7 @@ void ManageTokensController::showHideCollectionGroup(const QString& groupId, boo
requestSaveSettings(serializeSettingsAsJson());
}
void ManageTokensController::saveToQSettings(const QString& json)
{
Q_ASSERT(!m_settingsKey.isEmpty());
savingStarted();
// save to QSettings
m_settings.beginGroup(settingsGroupName());
// data
m_settings.setValue(m_settingsKey, json);
m_settings.endGroup();
m_settings.sync();
savingFinished();
}
// Used in testing
void ManageTokensController::clearQSettings()
{
Q_ASSERT(!m_settingsKey.isEmpty());
@ -196,19 +179,6 @@ void ManageTokensController::clearQSettings()
emit settingsDirtyChanged(false);
}
void ManageTokensController::loadFromQSettings()
{
Q_ASSERT(!m_settingsKey.isEmpty());
loadingStarted();
// load from QSettings
m_settings.beginGroup(settingsGroupName());
const auto jsonData = m_settings.value(m_settingsKey).toString();
m_settings.endGroup();
loadingFinished(jsonData);
}
void ManageTokensController::setSettingsDirty(bool dirty)
{
@ -238,13 +208,14 @@ void ManageTokensController::revert() { requestLoadSettings(); }
void ManageTokensController::savingStarted()
{
setSettingsDirty(true); // save to QSettings
setSettingsDirty(true);
m_settings.beginGroup(settingsGroupName());
m_settings.setValue(QStringLiteral("ArrangeByCommunity"), m_arrangeByCommunity);
m_settings.setValue(QStringLiteral("ArrangeByCollection"), m_arrangeByCollection);
m_settings.endGroup();
m_settings.sync();
}
void ManageTokensController::savingFinished()
@ -265,19 +236,6 @@ void ManageTokensController::loadingStarted()
m_settings.beginGroup(settingsGroupName());
// hidden groups
const auto groups = m_settings.value(QStringLiteral("HiddenCommunityGroups")).toStringList();
if (!groups.isEmpty()) {
m_hiddenCommunityGroups = {groups.constBegin(), groups.constEnd()};
emit hiddenCommunityGroupsChanged();
}
const auto collections = m_settings.value(QStringLiteral("HiddenCollectionGroups")).toStringList();
if (!collections.isEmpty()) {
m_hiddenCollectionGroups = {collections.constBegin(), collections.constEnd()};
emit hiddenCollectionGroupsChanged();
}
// arrange by
setArrangeByCommunity(m_settings.value(QStringLiteral("ArrangeByCommunity"), false).toBool());
setArrangeByCollection(m_settings.value(QStringLiteral("ArrangeByCollection"), false).toBool());
@ -558,6 +516,16 @@ void ManageTokensController::rebuildCommunityTokenGroupsModel()
for (const auto& group : std::as_const(result))
m_communityTokenGroupsModel->addItem(group);
// rebuild hidden community groups
m_hiddenCommunityGroups.clear();
for (auto i = 0; i < m_communityTokenGroupsModel->rowCount(); i++) {
const auto& group = m_communityTokenGroupsModel->itemAt(i);
if (m_settingsData.contains(group.communityId) && !m_settingsData.value(group.communityId).visible) {
m_hiddenCommunityGroups.insert(group.communityId);
}
}
emit hiddenCommunityGroupsChanged();
qCDebug(manageTokens) << "!!! GROUPS MODEL REBUILT WITH GROUPS:" << communityIds;
}
@ -649,6 +617,17 @@ void ManageTokensController::rebuildCollectionGroupsModel()
for (const auto& group : std::as_const(result))
m_collectionGroupsModel->addItem(group);
// rebuild hidden collection groups
m_hiddenCollectionGroups.clear();
for (auto i = 0; i < m_collectionGroupsModel->rowCount(); i++) {
const auto& group = m_collectionGroupsModel->itemAt(i);
if (m_settingsData.contains(group.collectionUid) && !m_settingsData.value(group.collectionUid).visible) {
m_hiddenCollectionGroups.insert(group.collectionUid);
}
}
emit hiddenCollectionGroupsChanged();
qCDebug(manageTokens) << "!!! COLLECTION MODEL REBUILT WITH GROUPS:" << collectionIds;
}

View File

@ -52,14 +52,13 @@ public:
Q_INVOKABLE void showHideGroup(const QString& groupId, bool flag);
Q_INVOKABLE void showHideCollectionGroup(const QString& groupId, bool flag);
Q_INVOKABLE void loadFromQSettings();
Q_INVOKABLE void saveToQSettings(const QString& json);
Q_INVOKABLE void clearQSettings();
Q_INVOKABLE void revert();
/// required to be called before the saving is started
/// required to call and guard the saving process
Q_INVOKABLE void savingStarted();
Q_INVOKABLE void savingFinished();
/// required to call and guard the loading process
Q_INVOKABLE void loadingStarted();
Q_INVOKABLE void loadingFinished(const QString& jsonData);