Skip to content

Commit

Permalink
feat(wallet) save/load collectibles user handled state in DB
Browse files Browse the repository at this point in the history
Add a separation layer for save/load/clear/reset to ManageTokensModel
so that we can save/load from external sources.
The layer uses JSON as protocol and forwards that to current QSettings
for storybook and NIM controllers for StatusQ.
- [ ] Separate the dynamic private user data from static state
  settings (ArrangeByCommunity, ArrangeByCollection)
- [ ] Handle HiddenCommunityGroups and HiddenCollectionGroups in DB

Updates #13313
  • Loading branch information
stefandunca committed Mar 8, 2024
1 parent a9b5d8f commit a725576
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 214 deletions.
10 changes: 5 additions & 5 deletions src/backend/collectibles_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ type
contractAddress*: string
owners*: seq[CollectibleOwner]

# see status-go/services/wallet/collectibles/service.go CollectibleDataType
# Mirrors status-go/multiaccounts/settings_wallet/database.go CollectiblePreferencesType
CollectiblePreferencesItemType* {.pure.} = enum
NonCommunityCollectible = 1,
CommunityCollectible,
Collection,
NonCommunityCollectible = 1,
CommunityCollectible,
Collection,
Community

# Mirrors services/wallet/thirdparty/collectible_types.go CollectibleContractOwnership
# Mirrors status-go/multiaccounts/settings_wallet/database.go CollectiblePreferences
CollectiblePreferences* = ref object of RootObj
itemType* {.serializedFieldName("type").}: CollectiblePreferencesItemType
key* {.serializedFieldName("key").}: string
Expand Down
4 changes: 4 additions & 0 deletions storybook/pages/AssetsViewPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ SplitView {
controller: ManageTokensController {
sourceModel: d.walletAssetStore.groupedAccountAssetsModel
settingsKey: "WalletAssets"

onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()

onTokenHidden: (symbol, name) => Global.displayToastMessage(
qsTr("%1 (%2) was successfully hidden").arg(name).arg(symbol), "", "checkmark-circle",
false, Constants.ephemeralNotificationType.success, "")
Expand Down
4 changes: 4 additions & 0 deletions storybook/pages/CollectiblesViewPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ SplitView {
controller: ManageTokensController {
sourceModel: renamedModel
settingsKey: "WalletCollectibles"

onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()

onTokenHidden: (symbol, name) => Global.displayToastMessage(
qsTr("%1 was successfully hidden").arg(name), "", "checkmark-circle",
false, Constants.ephemeralNotificationType.success, "")
Expand Down
3 changes: 3 additions & 0 deletions storybook/pages/ManageAssetsPanelPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ SplitView {
controller: ManageTokensController {
sourceModel: ctrlEmptyModel.checked ? null : walletAssetStore.groupedAccountAssetsModel
settingsKey: "WalletAssets"

onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
}
}

Expand Down
2 changes: 2 additions & 0 deletions storybook/pages/ManageCollectiblesPanelPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ SplitView {
controller: ManageTokensController {
sourceModel: renamedModel
settingsKey: "WalletCollectibles"

onRequestLoadSettings: loadFromQSettings()onRequestClearSettings: clearQSettings()
}
}

Expand Down
6 changes: 6 additions & 0 deletions storybook/pages/ManageHiddenPanelPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ SplitView {
id: assetsController
sourceModel: ctrlEmptyModel.checked ? null : walletAssetStore.groupedAccountAssetsModel
settingsKey: "WalletAssets"

onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
}

ManageTokensController {
id: collectiblesController
sourceModel: ctrlEmptyModel.checked ? null : renamedModel
settingsKey: "WalletCollectibles"

onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()
}

ManageHiddenPanel {
Expand Down
8 changes: 8 additions & 0 deletions storybook/qmlTests/tests/tst_ManageCollectiblesPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ Item {
controller: ManageTokensController {
sourceModel: renamedModel
settingsKey: "WalletCollectibles"

onRequestLoadSettings: loadFromQSettings()
onRequestClearSettings: clearQSettings()

onCommunityTokenGroupHidden: (communityName) => Global.displayToastMessage(
qsTr("%1 community collectibles successfully hidden").arg(communityName), "", "checkmark-circle",
false, Constants.ephemeralNotificationType.success, "")
}

function clearSettings() {
controller.clearQSettings()
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions ui/StatusQ/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ add_library(StatusQ SHARED
src/wallet/managetokenscontroller.h
src/wallet/managetokensmodel.cpp
src/wallet/managetokensmodel.h
src/wallet/tokendata.cpp
src/wallet/tokendata.h
)

set_target_properties(StatusQ PROPERTIES
Expand Down
27 changes: 27 additions & 0 deletions ui/StatusQ/src/wallet/TODO-externalize-data-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TODO for externalizing data storage for ManageTokensController

Task [#13313](https://github.com/status-im/status-desktop/issues/13313)

## Solution

Extend interface of `ManageTokensController` to allow bidirectional save and load of data. The in/out structure should be a mirror of the json struct in status-go provided through a RPC api call

### C++ integration

Only Nim is setup to use the RPC api, therefore the best way to connect `ManageTokensController` status-go backend is through two plain Nim calls (save and load) via QML signals and slots.

collectible_preferences_table

- [x] Which Nim module is best to provide save/load api?
- Collectible service already exposes `updateCollectiblePreferences`

### status-go

- [x] Which module should be used to provide the data? Settings? Wallet?
- Already done in `accounts` module that calls `messenger` module for storing the data
- [x] Which DB should store the table with the data
- We use `collectible_preferences` that is already setup

## Prev history

`ManageTokensController` serializes and saves the tokens using a `QSettings` app instance
Loading

0 comments on commit a725576

Please # to comment.