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

197 lines
7.3 KiB
QML

import QtQuick 2.13
import utils 1.0
import StatusQ 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: root.walletModule.collectiblesModel
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 }
}
property var selectedAccount
property var networkRPCChanged: ({}) // add network id to the object if changed
function toggleTestNetworksEnabled(){
networksModuleInst.toggleTestNetworksEnabled()
}
// 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
}
}
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, newMainRpcInput, newFailoverRpcUrl, revertToDefault) {
networksModuleInst.updateNetworkEndPointValues(chainId, 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,
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,
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()
}
}