2023-11-24 12:16:13 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
|
|
|
import StatusQ 0.1
|
2024-01-29 18:02:59 +00:00
|
|
|
import StatusQ.Models 0.1
|
2023-11-24 12:16:13 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
|
|
|
|
|
|
|
import shared.stores 1.0
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
2024-01-29 18:02:59 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2023-11-24 12:16:13 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property TokensStore walletTokensStore
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
/* this property represents the grouped_account_assets_model from backend*/
|
|
|
|
readonly property var baseGroupedAccountAssetModel: walletSectionAssets.groupedAccountAssetsModel
|
|
|
|
|
2024-01-31 18:09:44 +00:00
|
|
|
readonly property var assetsController: ManageTokensController {
|
|
|
|
sourceModel: groupedAccountAssetsModel
|
2024-01-29 18:02:59 +00:00
|
|
|
settingsKey: "WalletAssets"
|
2024-03-01 02:04:36 +00:00
|
|
|
serializeAsCollectibles: false
|
|
|
|
|
|
|
|
onRequestSaveSettings: (jsonData) => {
|
2024-04-05 16:39:08 +00:00
|
|
|
savingStarted()
|
|
|
|
walletTokensStore.updateTokenPreferences(jsonData)
|
|
|
|
savingFinished()
|
2024-03-01 02:04:36 +00:00
|
|
|
}
|
|
|
|
onRequestLoadSettings: {
|
2024-04-05 16:39:08 +00:00
|
|
|
loadingStarted()
|
|
|
|
let jsonData = walletTokensStore.getTokenPreferencesJson()
|
|
|
|
loadingFinished(jsonData)
|
2024-03-01 02:04:36 +00:00
|
|
|
}
|
|
|
|
|
2024-01-31 18:09:44 +00:00
|
|
|
onCommunityTokenGroupHidden: (communityName) => Global.displayToastMessage(
|
|
|
|
qsTr("%1 community assets successfully hidden").arg(communityName), "", "checkmark-circle",
|
|
|
|
false, Constants.ephemeralNotificationType.success, "")
|
|
|
|
onTokenShown: (symbol, name) => Global.displayToastMessage(qsTr("%1 is now visible").arg(name), "", "checkmark-circle",
|
|
|
|
false, Constants.ephemeralNotificationType.success, "")
|
|
|
|
onCommunityTokenGroupShown: (communityName) => Global.displayToastMessage(
|
|
|
|
qsTr("%1 community assets are now visible").arg(communityName), "", "checkmark-circle",
|
|
|
|
false, Constants.ephemeralNotificationType.success, "")
|
2024-01-29 18:02:59 +00:00
|
|
|
}
|
|
|
|
|
2024-12-04 16:19:27 +00:00
|
|
|
/* This model renames the role "key" to "tokensKey" in TokensBySymbolModel so that
|
2023-11-24 12:16:13 +00:00
|
|
|
it can be easily joined with the Account Assets model */
|
2024-12-04 16:19:27 +00:00
|
|
|
readonly property var renamedTokensBySymbolModel: RolesRenamingModel {
|
|
|
|
objectName: "renamedTokensBySymbolModel"
|
2023-11-24 12:16:13 +00:00
|
|
|
sourceModel: walletTokensStore.plainTokensBySymbolModel
|
|
|
|
mapping: [
|
|
|
|
RoleRename {
|
|
|
|
from: "key"
|
|
|
|
to: "tokensKey"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PRIVATE: This model renames the roles
|
|
|
|
1. "id" to "communityId"
|
|
|
|
2. "name" to "communityName"
|
|
|
|
3. "image" to "communityImage"
|
|
|
|
4. "description" to "communityDescription"
|
|
|
|
in communitiesModule.model so that it can be easily
|
|
|
|
joined with the Account Assets model */
|
|
|
|
readonly property var _renamedCommunitiesModel: RolesRenamingModel {
|
|
|
|
sourceModel: communitiesModule.model
|
|
|
|
mapping: [
|
|
|
|
RoleRename {
|
|
|
|
from: "id"
|
|
|
|
to: "communityId"
|
|
|
|
},
|
|
|
|
RoleRename {
|
|
|
|
from: "name"
|
|
|
|
to: "communityName"
|
|
|
|
},
|
|
|
|
RoleRename {
|
|
|
|
from: "image"
|
|
|
|
to: "communityImage"
|
|
|
|
},
|
|
|
|
RoleRename {
|
|
|
|
from: "description"
|
|
|
|
to: "communityDescription"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PRIVATE: This model joins the "Tokens By Symbol Model" and "Communities Model" by communityId */
|
|
|
|
property LeftJoinModel _jointTokensBySymbolModel: LeftJoinModel {
|
2024-12-04 16:19:27 +00:00
|
|
|
leftModel: renamedTokensBySymbolModel
|
2023-11-24 12:16:13 +00:00
|
|
|
rightModel: _renamedCommunitiesModel
|
|
|
|
joinRole: "communityId"
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This model joins the "Tokens by symbol model combined with Community details"
|
|
|
|
and "Grouped Account Assets Model" by tokenskey */
|
|
|
|
property LeftJoinModel groupedAccountAssetsModel: LeftJoinModel {
|
2024-06-13 12:17:33 +00:00
|
|
|
objectName: "groupedAccountAssetsModel"
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
leftModel: root.baseGroupedAccountAssetModel
|
2023-11-24 12:16:13 +00:00
|
|
|
rightModel: _jointTokensBySymbolModel
|
|
|
|
joinRole: "tokensKey"
|
|
|
|
}
|
2024-07-30 22:26:30 +00:00
|
|
|
|
|
|
|
// This is hard coded for now, and should be updated whenever Hop add new tokens for support
|
|
|
|
// This should be dynamically fetched somehow in the future
|
2024-08-08 07:51:28 +00:00
|
|
|
readonly property var tokensSupportedByHopBridge: ["USDC", "USDC.e", "USDT", "DAI", "HOP", "SNX", "sUSD", "rETH", "MAGIC", "ETH"]
|
2024-07-30 22:26:30 +00:00
|
|
|
|
|
|
|
readonly property SortFilterProxyModel bridgeableGroupedAccountAssetsModel: SortFilterProxyModel {
|
|
|
|
objectName: "bridgeableGroupedAccountAssetsModel"
|
|
|
|
sourceModel: root.groupedAccountAssetsModel
|
|
|
|
|
|
|
|
filters: [
|
|
|
|
FastExpressionFilter {
|
|
|
|
expression: root.tokensSupportedByHopBridge.includes(model.symbol)
|
|
|
|
expectedRoles: ["symbol"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-11-24 12:16:13 +00:00
|
|
|
}
|
2024-07-30 22:26:30 +00:00
|
|
|
|