2022-02-11 09:44:49 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
|
2023-02-14 09:20:53 +00:00
|
|
|
import utils 1.0
|
2022-04-01 10:30:55 +00:00
|
|
|
|
2024-03-13 11:10:36 +00:00
|
|
|
import StatusQ 0.1
|
2024-05-15 09:14:46 +00:00
|
|
|
import StatusQ.Models 0.1
|
2024-03-20 17:29:45 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
2024-03-13 11:10:36 +00:00
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2022-02-11 09:44:49 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2023-08-04 12:41:57 +00:00
|
|
|
property var walletModule
|
|
|
|
property var accountsModule: root.walletModule.accountsModule
|
2024-03-20 17:29:45 +00:00
|
|
|
property var networksModuleInst: networksModule
|
2024-05-15 09:14:46 +00:00
|
|
|
property var collectibles: _jointCollectiblesBySymbolModel
|
2023-04-17 11:36:40 +00:00
|
|
|
|
2023-02-14 09:20:53 +00:00
|
|
|
property var accountSensitiveSettings: Global.appIsReady? localAccountSensitiveSettings : null
|
2023-08-29 15:28:41 +00:00
|
|
|
property var dappList: Global.appIsReady? dappPermissionsModule.dapps : null
|
2022-03-09 14:24:46 +00:00
|
|
|
|
2024-03-20 17:29:45 +00:00
|
|
|
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
|
|
|
|
2023-07-18 09:10:48 +00:00
|
|
|
property var selectedAccount
|
2022-03-01 14:40:53 +00:00
|
|
|
|
2024-02-12 13:13:36 +00:00
|
|
|
property var networkRPCChanged: ({}) // add network id to the object if changed
|
|
|
|
|
2022-03-15 13:38:20 +00:00
|
|
|
function toggleTestNetworksEnabled(){
|
2024-03-20 17:29:45 +00:00
|
|
|
networksModuleInst.toggleTestNetworksEnabled()
|
2022-03-15 13:38:20 +00:00
|
|
|
}
|
2023-04-17 11:36:40 +00:00
|
|
|
// TODO(alaibe): there should be no access to wallet section, create collectible in profile
|
2023-04-25 16:54:50 +00:00
|
|
|
property var overview: walletSectionOverview
|
2023-04-17 11:36:40 +00:00
|
|
|
property var accounts: Global.appIsReady? accountsModule.accounts : null
|
2023-06-22 10:32:43 +00:00
|
|
|
property var originModel: accountsModule.keyPairModel
|
2024-03-13 11:10:36 +00:00
|
|
|
property var ownAccounts: SortFilterProxyModel {
|
|
|
|
sourceModel: root.accounts
|
|
|
|
proxyRoles: FastExpressionRole {
|
|
|
|
name: "preferredSharingChainShortNames"
|
|
|
|
expression: {
|
2024-03-20 17:29:45 +00:00
|
|
|
return root.networksModuleInst.getNetworkShortNames(model.preferredSharingChainIds)
|
2024-03-13 11:10:36 +00:00
|
|
|
}
|
|
|
|
expectedRoles: ["preferredSharingChainIds"]
|
|
|
|
}
|
|
|
|
filters: ValueFilter {
|
|
|
|
roleName: "walletType"
|
|
|
|
value: Constants.watchWalletType
|
|
|
|
inverted: true
|
|
|
|
}
|
|
|
|
}
|
2023-06-22 10:32:43 +00:00
|
|
|
|
2024-05-15 09:14:46 +00:00
|
|
|
/* 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"
|
|
|
|
}
|
|
|
|
|
2023-06-22 10:32:43 +00:00
|
|
|
property string userProfilePublicKey: userProfile.pubKey
|
2023-08-21 10:58:21 +00:00
|
|
|
|
2023-05-04 14:34:00 +00:00
|
|
|
function deleteAccount(address) {
|
|
|
|
return accountsModule.deleteAccount(address)
|
2022-03-07 09:33:38 +00:00
|
|
|
}
|
2022-03-04 09:09:58 +00:00
|
|
|
|
2023-07-28 13:12:46 +00:00
|
|
|
function deleteKeypair(keyUid) {
|
|
|
|
return accountsModule.deleteKeypair(keyUid)
|
|
|
|
}
|
|
|
|
|
2023-05-22 15:55:47 +00:00
|
|
|
function updateAccount(address, accountName, colorId, emoji) {
|
|
|
|
return accountsModule.updateAccount(address, accountName, colorId, emoji)
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
|
2023-07-18 14:25:42 +00:00
|
|
|
function moveAccount(from, to) {
|
|
|
|
root.accountsModule.moveAccount(from, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveAccountFinally(from, to) {
|
|
|
|
root.accountsModule.moveAccountFinally(from, to)
|
2023-06-20 11:59:15 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 15:49:12 +00:00
|
|
|
function setSelectedAccount(address) {
|
|
|
|
root.accountsModule.setSelectedAccount(address)
|
|
|
|
}
|
|
|
|
|
2023-07-21 08:41:24 +00:00
|
|
|
function getAllNetworksChainIds() {
|
2024-03-20 17:29:45 +00:00
|
|
|
let result = []
|
|
|
|
let chainIdsArray = ModelUtils.modelToFlatArray(root.filteredFlatModel, "chainId")
|
|
|
|
for(let i = 0; i< chainIdsArray.length; i++) {
|
|
|
|
result.push(chainIdsArray[i].toString())
|
|
|
|
}
|
|
|
|
return result
|
2023-06-22 10:32:43 +00:00
|
|
|
}
|
2023-06-27 07:13:55 +00:00
|
|
|
|
|
|
|
function runAddAccountPopup() {
|
2023-08-04 12:41:57 +00:00
|
|
|
// 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
|
2023-06-27 07:13:55 +00:00
|
|
|
walletSection.runAddAccountPopup(false)
|
|
|
|
}
|
2023-07-11 15:10:26 +00:00
|
|
|
|
2023-08-21 10:58:21 +00:00
|
|
|
function runKeypairImportPopup(keyUid, mode) {
|
|
|
|
root.walletModule.runKeypairImportPopup(keyUid, mode)
|
2023-08-04 12:41:57 +00:00
|
|
|
}
|
|
|
|
|
2023-09-04 15:36:28 +00:00
|
|
|
function evaluateRpcEndPoint(url, isMainUrl) {
|
2024-03-20 17:29:45 +00:00
|
|
|
return networksModuleInst.fetchChainIdForUrl(url, isMainUrl)
|
2023-07-11 15:10:26 +00:00
|
|
|
}
|
|
|
|
|
2024-05-13 10:06:05 +00:00
|
|
|
function updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) {
|
|
|
|
networksModuleInst.updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault)
|
2023-07-11 15:10:26 +00:00
|
|
|
}
|
2023-07-21 08:41:24 +00:00
|
|
|
|
|
|
|
function updateWalletAccountPreferredChains(address, preferredChainIds) {
|
|
|
|
if(areTestNetworksEnabled) {
|
|
|
|
accountsModule.updateWalletAccountTestPreferredChains(address, preferredChainIds)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
accountsModule.updateWalletAccountProdPreferredChains(address, preferredChainIds)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNetworkShortNames(chainIds) {
|
2024-03-20 17:29:45 +00:00
|
|
|
return networksModuleInst.getNetworkShortNames(chainIds)
|
2023-07-21 08:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function processPreferredSharingNetworkToggle(preferredSharingNetworks, toggledNetwork) {
|
|
|
|
let prefChains = preferredSharingNetworks
|
2024-03-20 17:29:45 +00:00
|
|
|
if(prefChains.length === root.flatNetworks.count) {
|
2023-07-21 08:41:24 +00:00
|
|
|
prefChains = [toggledNetwork.chainId.toString()]
|
|
|
|
}
|
|
|
|
else if(!prefChains.includes(toggledNetwork.chainId.toString())) {
|
|
|
|
prefChains.push(toggledNetwork.chainId.toString())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(prefChains.length === 1) {
|
2024-03-20 17:29:45 +00:00
|
|
|
prefChains = getAllNetworksChainIds()
|
2023-07-21 08:41:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(var i = 0; i < prefChains.length;i++) {
|
|
|
|
if(prefChains[i] === toggledNetwork.chainId.toString()) {
|
|
|
|
prefChains.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return prefChains
|
|
|
|
}
|
2023-07-28 07:57:58 +00:00
|
|
|
|
|
|
|
function copyToClipboard(textToCopy) {
|
|
|
|
globalUtils.copyToClipboard(textToCopy)
|
|
|
|
}
|
2023-08-07 18:47:16 +00:00
|
|
|
|
|
|
|
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,
|
2023-08-07 18:47:16 +00:00
|
|
|
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,
|
2023-08-07 18:47:16 +00:00
|
|
|
blockExplorerURL: combinedNetwork.test.blockExplorerURL,
|
|
|
|
nativeCurrencySymbol: combinedNetwork.test.nativeCurrencySymbol},
|
|
|
|
layer: combinedNetwork.layer
|
|
|
|
}
|
|
|
|
}
|
2023-10-10 15:46:43 +00:00
|
|
|
|
|
|
|
function updateWatchAccountHiddenFromTotalBalance(address, hideFromTotalBalance) {
|
|
|
|
accountsModule.updateWatchAccountHiddenFromTotalBalance(address, hideFromTotalBalance)
|
|
|
|
}
|
2024-02-07 13:47:28 +00:00
|
|
|
|
|
|
|
function getRpcStats() {
|
|
|
|
return root.walletModule.getRpcStats()
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetRpcStats() {
|
|
|
|
root.walletModule.resetRpcStats()
|
|
|
|
}
|
2022-03-02 14:24:39 +00:00
|
|
|
}
|