status-desktop/ui/app/AppLayouts/Profile/stores/WalletStore.qml

234 lines
8.5 KiB
QML
Raw Normal View History

import QtQuick 2.13
import utils 1.0
import StatusQ 0.1
import StatusQ.Models 0.1
import StatusQ.Core.Utils 0.1
import SortFilterProxyModel 0.2
QtObject {
id: root
property var walletModule
property var accountsModule: root.walletModule.accountsModule
property var networksModuleInst: networksModule
property var collectibles: _jointCollectiblesBySymbolModel
property var accountSensitiveSettings: Global.appIsReady? localAccountSensitiveSettings : null
property var dappList: Global.appIsReady? dappPermissionsModule.dapps : null
readonly property bool areTestNetworksEnabled: networksModuleInst.areTestNetworksEnabled
readonly property bool isGoerliEnabled: networksModuleInst.isGoerliEnabled
readonly property var combinedNetworks: networksModuleInst.combinedNetworks
property var flatNetworks: networksModuleInst.flatNetworks
property SortFilterProxyModel filteredFlatModel: SortFilterProxyModel {
sourceModel: root.flatNetworks
filters: ValueFilter { roleName: "isTest"; value: root.areTestNetworksEnabled }
}
2023-10-03 13:30:42 +00:00
property var selectedAccount
2022-03-01 14:40:53 +00:00
property var networkRPCChanged: ({}) // add network id to the object if changed
2022-03-15 13:38:20 +00:00
function toggleTestNetworksEnabled(){
networksModuleInst.toggleTestNetworksEnabled()
2022-03-15 13:38:20 +00:00
}
// TODO(alaibe): there should be no access to wallet section, create collectible in profile
property var overview: walletSectionOverview
property var accounts: Global.appIsReady? accountsModule.accounts : null
property var originModel: accountsModule.keyPairModel
property var ownAccounts: SortFilterProxyModel {
sourceModel: root.accounts
proxyRoles: FastExpressionRole {
name: "preferredSharingChainShortNames"
expression: {
return root.networksModuleInst.getNetworkShortNames(model.preferredSharingChainIds)
}
expectedRoles: ["preferredSharingChainIds"]
}
filters: ValueFilter {
roleName: "walletType"
value: Constants.watchWalletType
inverted: true
}
}
/* 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 Collectibles 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 _jointCollectiblesBySymbolModel: LeftJoinModel {
leftModel: root.walletModule.collectiblesModel
rightModel: _renamedCommunitiesModel
joinRole: "communityId"
}
property string userProfilePublicKey: userProfile.pubKey
function deleteAccount(address) {
return accountsModule.deleteAccount(address)
}
function deleteKeypair(keyUid) {
return accountsModule.deleteKeypair(keyUid)
}
function updateAccount(address, accountName, colorId, emoji) {
return accountsModule.updateAccount(address, accountName, colorId, emoji)
}
function moveAccount(from, to) {
root.accountsModule.moveAccount(from, to)
}
function moveAccountFinally(from, to) {
root.accountsModule.moveAccountFinally(from, to)
}
function setSelectedAccount(address) {
root.accountsModule.setSelectedAccount(address)
}
function getAllNetworksChainIds() {
let result = []
let chainIdsArray = ModelUtils.modelToFlatArray(root.filteredFlatModel, "chainId")
for(let i = 0; i< chainIdsArray.length; i++) {
result.push(chainIdsArray[i].toString())
}
return result
}
function runAddAccountPopup() {
// TODO:
// - `runAddAccountPopup` should be part of `root.walletModule`
// - `AddAccountPopup {}` should be moved from `MainView` to `WalletView`
// - `Edit account` popup opened from the wallet settings should be the same as one opened from the wallet section
// - `walletSection` should not be used in the context of wallet settings
walletSection.runAddAccountPopup(false)
}
function runKeypairImportPopup(keyUid, mode) {
root.walletModule.runKeypairImportPopup(keyUid, mode)
}
function evaluateRpcEndPoint(url, isMainUrl) {
return networksModuleInst.fetchChainIdForUrl(url, isMainUrl)
}
function updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) {
networksModuleInst.updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
}
function updateWalletAccountPreferredChains(address, preferredChainIds) {
if(areTestNetworksEnabled) {
accountsModule.updateWalletAccountTestPreferredChains(address, preferredChainIds)
}
else {
accountsModule.updateWalletAccountProdPreferredChains(address, preferredChainIds)
}
}
function getNetworkShortNames(chainIds) {
return networksModuleInst.getNetworkShortNames(chainIds)
}
function processPreferredSharingNetworkToggle(preferredSharingNetworks, toggledNetwork) {
let prefChains = preferredSharingNetworks
if(prefChains.length === root.flatNetworks.count) {
prefChains = [toggledNetwork.chainId.toString()]
}
else if(!prefChains.includes(toggledNetwork.chainId.toString())) {
prefChains.push(toggledNetwork.chainId.toString())
}
else {
if(prefChains.length === 1) {
prefChains = getAllNetworksChainIds()
}
else {
for(var i = 0; i < prefChains.length;i++) {
if(prefChains[i] === toggledNetwork.chainId.toString()) {
prefChains.splice(i, 1)
}
}
}
}
return prefChains
}
function copyToClipboard(textToCopy) {
globalUtils.copyToClipboard(textToCopy)
}
function getNetworkData(combinedNetwork) {
return {
prod: {chainId: combinedNetwork.prod.chainId,
layer: combinedNetwork.prod.layer,
chainName: combinedNetwork.prod.chainName,
iconUrl: combinedNetwork.prod.iconUrl,
shortName: combinedNetwork.prod.shortName,
chainColor: combinedNetwork.prod.chainColor,
rpcURL: combinedNetwork.prod.rpcURL,
fallbackURL: combinedNetwork.prod.fallbackURL,
2023-08-17 09:38:10 +00:00
originalRpcURL: combinedNetwork.prod.originalRpcURL,
originalFallbackURL: combinedNetwork.prod.originalFallbackURL,
blockExplorerURL: combinedNetwork.prod.blockExplorerURL,
nativeCurrencySymbol: combinedNetwork.prod.nativeCurrencySymbol},
test: {chainId: combinedNetwork.test.chainId,
layer: combinedNetwork.test.layer,
chainName: combinedNetwork.test.chainName,
iconUrl: combinedNetwork.test.iconUrl,
shortName: combinedNetwork.test.shortName,
chainColor: combinedNetwork.test.chainColor,
rpcURL: combinedNetwork.test.rpcURL,
fallbackURL: combinedNetwork.test.fallbackURL,
2023-08-17 09:38:10 +00:00
originalRpcURL: combinedNetwork.test.originalRpcURL,
originalFallbackURL: combinedNetwork.test.originalFallbackURL,
blockExplorerURL: combinedNetwork.test.blockExplorerURL,
nativeCurrencySymbol: combinedNetwork.test.nativeCurrencySymbol},
layer: combinedNetwork.layer
}
}
function updateWatchAccountHiddenFromTotalBalance(address, hideFromTotalBalance) {
accountsModule.updateWatchAccountHiddenFromTotalBalance(address, hideFromTotalBalance)
}
function getRpcStats() {
return root.walletModule.getRpcStats()
}
function resetRpcStats() {
root.walletModule.resetRpcStats()
}
}