2021-10-05 20:50:22 +00:00
|
|
|
pragma Singleton
|
|
|
|
|
|
|
|
import QtQuick 2.13
|
|
|
|
|
2022-02-21 17:07:16 +00:00
|
|
|
import utils 1.0
|
2023-10-12 17:45:25 +00:00
|
|
|
|
2023-02-20 10:57:45 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-10-12 17:45:25 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2023-02-20 10:57:45 +00:00
|
|
|
|
2021-10-05 20:50:22 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
2022-08-09 15:08:39 +00:00
|
|
|
|
2023-10-26 21:11:20 +00:00
|
|
|
readonly property TokensStore tokensStore: TokensStore {}
|
|
|
|
|
2022-10-27 09:26:34 +00:00
|
|
|
readonly property string defaultSelectedKeyUid: userProfile.keyUid
|
|
|
|
readonly property bool defaultSelectedKeyUidMigratedToKeycard: userProfile.isKeycardUser
|
|
|
|
|
2022-09-13 16:17:54 +00:00
|
|
|
property string backButtonName: ""
|
2023-04-13 09:59:17 +00:00
|
|
|
property var overview: walletSectionOverview
|
2023-04-25 16:54:50 +00:00
|
|
|
property var assets: walletSectionAssets.assets
|
|
|
|
property bool assetsLoading: walletSectionAssets.assetsLoading
|
2023-04-20 08:41:45 +00:00
|
|
|
property var accounts: walletSectionAccounts.accounts
|
2023-05-04 12:55:39 +00:00
|
|
|
property var receiveAccounts: walletSectionSend.accounts
|
|
|
|
property var selectedReceiveAccount: walletSectionSend.selectedReceiveAccount
|
2021-12-06 21:10:54 +00:00
|
|
|
property var appSettings: localAppSettings
|
|
|
|
property var accountSensitiveSettings: localAccountSensitiveSettings
|
|
|
|
property bool hideSignPhraseModal: accountSensitiveSettings.hideSignPhraseModal
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2023-10-27 16:18:24 +00:00
|
|
|
// "walletSection" is a context property slow to lookup, so we cache it here
|
2023-05-17 06:39:06 +00:00
|
|
|
property var walletSectionInst: walletSection
|
2023-10-27 16:18:24 +00:00
|
|
|
property var totalCurrencyBalance: walletSectionInst.totalCurrencyBalance
|
|
|
|
property var activityController: walletSectionInst.activityController
|
|
|
|
property var tmpActivityController: walletSectionInst.tmpActivityController
|
|
|
|
property string signingPhrase: walletSectionInst.signingPhrase
|
|
|
|
property string mnemonicBackedUp: walletSectionInst.isMnemonicBackedUp
|
|
|
|
property var walletConnectController: walletSectionInst.walletConnectController
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2023-07-17 23:56:40 +00:00
|
|
|
property CollectiblesStore collectiblesStore: CollectiblesStore {}
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2023-07-03 09:23:26 +00:00
|
|
|
property var areTestNetworksEnabled: networksModule.areTestNetworksEnabled
|
|
|
|
|
2023-02-20 10:57:45 +00:00
|
|
|
property var savedAddresses: SortFilterProxyModel {
|
|
|
|
sourceModel: walletSectionSavedAddresses.model
|
|
|
|
filters: [
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "isTest"
|
|
|
|
value: networksModule.areTestNetworksEnabled
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-08-29 15:28:41 +00:00
|
|
|
property var nonWatchAccounts: SortFilterProxyModel {
|
2023-08-09 12:31:58 +00:00
|
|
|
sourceModel: receiveAccounts
|
|
|
|
proxyRoles: [
|
|
|
|
ExpressionRole {
|
|
|
|
name: "color"
|
|
|
|
|
|
|
|
function getColor(colorId) {
|
|
|
|
return Utils.getColorForId(colorId)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Direct call for singleton function is not handled properly by
|
|
|
|
// SortFilterProxyModel that's why helper function is used instead.
|
|
|
|
expression: { return getColor(model.colorId) }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
filters: ValueFilter {
|
|
|
|
roleName: "walletType"
|
|
|
|
value: Constants.watchWalletType
|
|
|
|
inverted: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-19 14:16:45 +00:00
|
|
|
readonly property var currentActivityFiltersStore: {
|
|
|
|
const address = root.overview.mixedcaseAddress
|
|
|
|
if (address in d.activityFiltersStoreDictionary) {
|
|
|
|
return d.activityFiltersStoreDictionary[address]
|
|
|
|
}
|
|
|
|
let store = d.activityFilterStoreComponent.createObject(root)
|
|
|
|
d.activityFiltersStoreDictionary[address] = store
|
|
|
|
return store
|
|
|
|
}
|
|
|
|
|
2023-02-20 10:57:45 +00:00
|
|
|
property QtObject _d: QtObject {
|
|
|
|
id: d
|
2023-07-19 14:16:45 +00:00
|
|
|
|
|
|
|
property var activityFiltersStoreDictionary: ({})
|
|
|
|
readonly property Component activityFilterStoreComponent: ActivityFiltersStore{}
|
|
|
|
|
2023-02-20 10:57:45 +00:00
|
|
|
property var chainColors: ({})
|
|
|
|
|
|
|
|
function initChainColors(model) {
|
|
|
|
for (let i = 0; i < model.count; i++) {
|
|
|
|
chainColors[model.rowData(i, "shortName")] = model.rowData(i, "chainColor")
|
|
|
|
}
|
|
|
|
}
|
2023-07-19 14:16:45 +00:00
|
|
|
|
|
|
|
readonly property Connections walletSectionConnections: Connections {
|
|
|
|
target: root.walletSectionInst
|
|
|
|
function onWalletAccountRemoved(address) {
|
|
|
|
address = address.toLowerCase();
|
|
|
|
for (var addressKey in d.activityFiltersStoreDictionary){
|
|
|
|
if (address === addressKey.toLowerCase()){
|
|
|
|
delete d.activityFiltersStoreDictionary[addressKey]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-20 10:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function colorForChainShortName(chainShortName) {
|
|
|
|
return d.chainColors[chainShortName]
|
|
|
|
}
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2022-02-17 09:15:37 +00:00
|
|
|
property var layer1Networks: networksModule.layer1
|
|
|
|
property var layer2Networks: networksModule.layer2
|
|
|
|
property var enabledNetworks: networksModule.enabled
|
2022-07-19 09:25:13 +00:00
|
|
|
property var allNetworks: networksModule.all
|
2023-02-20 10:57:45 +00:00
|
|
|
onAllNetworksChanged: {
|
|
|
|
d.initChainColors(allNetworks)
|
|
|
|
}
|
2022-02-17 09:15:37 +00:00
|
|
|
|
2022-03-01 14:54:41 +00:00
|
|
|
property var cryptoRampServicesModel: walletSectionBuySellCrypto.model
|
|
|
|
|
2023-11-07 22:45:47 +00:00
|
|
|
function resetCurrentViewedHolding(type) {
|
2023-09-11 10:20:36 +00:00
|
|
|
currentViewedHoldingID = ""
|
2023-11-07 22:45:47 +00:00
|
|
|
currentViewedHoldingType = type
|
2023-09-11 10:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setCurrentViewedHoldingType(type) {
|
|
|
|
currentViewedHoldingID = ""
|
|
|
|
currentViewedHoldingType = type
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCurrentViewedHolding(id, type) {
|
|
|
|
currentViewedHoldingID = id
|
|
|
|
currentViewedHoldingType = type
|
|
|
|
}
|
|
|
|
|
|
|
|
property string currentViewedHoldingID: ""
|
2023-09-12 14:26:38 +00:00
|
|
|
property int currentViewedHoldingType
|
2023-09-20 13:01:37 +00:00
|
|
|
readonly property var currentViewedCollectible: collectiblesStore.detailedCollectible
|
2023-09-11 10:20:36 +00:00
|
|
|
|
2021-10-14 08:04:15 +00:00
|
|
|
// This should be exposed to the UI via "walletModule", WalletModule should use
|
2021-10-17 11:41:12 +00:00
|
|
|
// Accounts Service which keeps the info about that (isFirstTimeAccountLogin).
|
|
|
|
// Then in the View of WalletModule we may have either QtProperty or
|
|
|
|
// Q_INVOKABLE function (proc marked as slot) depends on logic/need.
|
|
|
|
// The only need for onboardingModel here is actually to check if an account
|
|
|
|
// has been just created or an old one.
|
2021-10-14 08:04:15 +00:00
|
|
|
|
2021-10-17 11:41:12 +00:00
|
|
|
//property bool firstTimeLogin: onboardingModel.isFirstTimeLogin
|
2021-10-05 20:50:22 +00:00
|
|
|
|
|
|
|
// example wallet model
|
|
|
|
property ListModel exampleWalletModel: ListModel {
|
|
|
|
ListElement {
|
|
|
|
name: "Status account"
|
|
|
|
address: "0xcfc9f08bbcbcb80760e8cb9a3c1232d19662fc6f"
|
|
|
|
balance: "12.00 USD"
|
2021-10-21 08:22:05 +00:00
|
|
|
color: "#7CDA00"
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ListElement {
|
|
|
|
name: "Test account 1"
|
|
|
|
address: "0x2Ef1...E0Ba"
|
|
|
|
balance: "12.00 USD"
|
2021-10-21 08:22:05 +00:00
|
|
|
color: "#FA6565"
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
name: "Status account"
|
|
|
|
address: "0x2Ef1...E0Ba"
|
|
|
|
balance: "12.00 USD"
|
2021-10-21 08:22:05 +00:00
|
|
|
color: "#7CDA00"
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property ListModel exampleAssetModel: ListModel {
|
|
|
|
ListElement {
|
2021-12-06 21:10:54 +00:00
|
|
|
name: "Ethereum"
|
2021-10-05 20:50:22 +00:00
|
|
|
symbol: "ETH"
|
2021-12-06 21:10:54 +00:00
|
|
|
balance: "3423 ETH"
|
|
|
|
address: "token-icons/eth"
|
|
|
|
currencyBalance: "123 USD"
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-21 14:18:43 +00:00
|
|
|
function setHideSignPhraseModal(value) {
|
2021-12-06 21:10:54 +00:00
|
|
|
localAccountSensitiveSettings.hideSignPhraseModal = value;
|
|
|
|
}
|
|
|
|
|
2023-05-24 06:22:29 +00:00
|
|
|
function getLatestBlockNumber(chainId) {
|
2023-09-11 08:08:53 +00:00
|
|
|
// NOTE returns hex
|
2023-06-29 17:35:18 +00:00
|
|
|
return walletSection.getLatestBlockNumber(chainId)
|
2021-12-13 14:24:21 +00:00
|
|
|
}
|
|
|
|
|
2023-09-11 08:08:53 +00:00
|
|
|
function getEstimatedLatestBlockNumber(chainId) {
|
|
|
|
// NOTE returns decimal
|
|
|
|
return walletSection.getEstimatedLatestBlockNumber(chainId)
|
|
|
|
}
|
|
|
|
|
2023-04-27 13:22:27 +00:00
|
|
|
function setFilterAddress(address) {
|
|
|
|
walletSection.setFilterAddress(address)
|
2023-02-28 15:00:10 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 07:11:44 +00:00
|
|
|
function setFillterAllAddresses() {
|
|
|
|
walletSection.setFillterAllAddresses()
|
|
|
|
}
|
|
|
|
|
2023-05-04 14:34:00 +00:00
|
|
|
function deleteAccount(address) {
|
|
|
|
return walletSectionAccounts.deleteAccount(address)
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-22 15:55:47 +00:00
|
|
|
function updateCurrentAccount(address, accountName, colorId, emoji) {
|
|
|
|
return walletSectionAccounts.updateAccount(address, accountName, colorId, emoji)
|
2021-10-21 08:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateCurrency(newCurrency) {
|
|
|
|
walletSection.updateCurrency(newCurrency)
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getQrCode(address) {
|
2022-01-24 11:41:55 +00:00
|
|
|
return globalUtils.qrCode(address)
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hex2Dec(value) {
|
2021-12-14 16:11:31 +00:00
|
|
|
return globalUtils.hex2Dec(value)
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:00:10 +00:00
|
|
|
function getNameForSavedWalletAddress(address) {
|
|
|
|
return walletSectionSavedAddresses.getNameByAddress(address)
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:44:35 +00:00
|
|
|
function getNameForWalletAddress(address) {
|
|
|
|
return walletSectionAccounts.getNameByAddress(address)
|
|
|
|
}
|
|
|
|
|
2023-05-10 11:54:06 +00:00
|
|
|
function getNameForAddress(address) {
|
2023-07-18 15:59:35 +00:00
|
|
|
var name = getNameForWalletAddress(address)
|
2023-05-10 11:54:06 +00:00
|
|
|
if (name.length === 0) {
|
2023-05-23 08:44:35 +00:00
|
|
|
name = getNameForSavedWalletAddress(address)
|
2023-05-10 11:54:06 +00:00
|
|
|
}
|
|
|
|
return name
|
2023-05-22 10:16:39 +00:00
|
|
|
}
|
|
|
|
|
2023-09-27 13:41:55 +00:00
|
|
|
enum LookupType {
|
|
|
|
Account = 0,
|
|
|
|
SavedAddress = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns object of type {type: null, object: null} or null if lookup didn't find anything
|
|
|
|
function lookupAddressObject(address) {
|
|
|
|
let res = null
|
2023-10-12 17:45:25 +00:00
|
|
|
let acc = SQUtils.ModelUtils.getByKey(root.accounts, "address", address)
|
2023-09-27 13:41:55 +00:00
|
|
|
if (acc) {
|
|
|
|
res = {type: RootStore.LookupType.Account, object: acc}
|
|
|
|
} else {
|
2023-10-12 17:45:25 +00:00
|
|
|
let sa = SQUtils.ModelUtils.getByKey(walletSectionSavedAddresses.model, "address", address)
|
2023-09-27 13:41:55 +00:00
|
|
|
if (sa) {
|
|
|
|
res = {type: RootStore.LookupType.SavedAddress, object: sa}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAssetForSendTx(tx) {
|
|
|
|
if (tx.isNFT) {
|
|
|
|
return {
|
|
|
|
uid: tx.tokenID,
|
|
|
|
chainId: tx.chainId,
|
|
|
|
name: tx.nftName,
|
|
|
|
imageUrl: tx.nftImageUrl,
|
|
|
|
collectionUid: "",
|
|
|
|
collectionName: ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return tx.symbol
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isTxRepeatable(tx) {
|
2023-10-03 12:15:11 +00:00
|
|
|
if (!tx || tx.txType !== Constants.TransactionType.Send)
|
2023-09-27 13:41:55 +00:00
|
|
|
return false
|
|
|
|
|
|
|
|
let res = root.lookupAddressObject(tx.sender)
|
|
|
|
if (!res || res.type !== RootStore.LookupType.Account || res.object.walletType == Constants.watchWalletType)
|
|
|
|
return false
|
|
|
|
|
|
|
|
if (tx.isNFT) {
|
|
|
|
// TODO #12275: check if account owns enough NFT
|
|
|
|
} else {
|
|
|
|
// TODO #12275: Check if account owns enough tokens
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-08-02 04:36:54 +00:00
|
|
|
function isOwnedAccount(address) {
|
|
|
|
return walletSectionAccounts.isOwnedAccount(address)
|
|
|
|
}
|
|
|
|
|
2023-05-22 10:16:39 +00:00
|
|
|
function getEmojiForWalletAddress(address) {
|
|
|
|
return walletSectionAccounts.getEmojiByAddress(address)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getColorForWalletAddress(address) {
|
|
|
|
return walletSectionAccounts.getColorByAddress(address)
|
2023-05-10 11:54:06 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 10:57:45 +00:00
|
|
|
function createOrUpdateSavedAddress(name, address, favourite, chainShortNames, ens) {
|
|
|
|
return walletSectionSavedAddresses.createOrUpdateSavedAddress(name, address, favourite, chainShortNames, ens)
|
2021-12-15 10:08:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 10:57:45 +00:00
|
|
|
function deleteSavedAddress(address, ens) {
|
|
|
|
return walletSectionSavedAddresses.deleteSavedAddress(address, ens)
|
2021-12-15 10:08:47 +00:00
|
|
|
}
|
2022-02-17 09:15:37 +00:00
|
|
|
|
|
|
|
function toggleNetwork(chainId) {
|
|
|
|
networksModule.toggleNetwork(chainId)
|
|
|
|
}
|
2022-03-15 19:34:28 +00:00
|
|
|
|
|
|
|
function copyToClipboard(text) {
|
|
|
|
globalUtils.copyToClipboard(text)
|
|
|
|
}
|
2023-03-22 15:48:44 +00:00
|
|
|
|
|
|
|
function runAddAccountPopup() {
|
2023-03-27 12:49:32 +00:00
|
|
|
walletSection.runAddAccountPopup(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
function runAddWatchOnlyAccountPopup() {
|
|
|
|
walletSection.runAddAccountPopup(true)
|
2023-03-22 15:48:44 +00:00
|
|
|
}
|
2023-03-30 13:00:55 +00:00
|
|
|
|
|
|
|
function runEditAccountPopup(address) {
|
|
|
|
walletSection.runEditAccountPopup(address)
|
|
|
|
}
|
2023-04-24 18:35:34 +00:00
|
|
|
|
2023-05-04 12:55:39 +00:00
|
|
|
function switchReceiveAccount(index) {
|
|
|
|
walletSectionSend.switchReceiveAccount(index)
|
2023-04-24 18:35:34 +00:00
|
|
|
}
|
2023-05-12 07:11:44 +00:00
|
|
|
|
|
|
|
function toggleWatchOnlyAccounts() {
|
|
|
|
walletSection.toggleWatchOnlyAccounts()
|
|
|
|
}
|
2023-07-21 08:41:24 +00:00
|
|
|
|
|
|
|
function getAllNetworksChainIds() {
|
|
|
|
return networksModule.getAllNetworksChainIds()
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNetworkShortNames(chainIds) {
|
2023-09-20 13:01:37 +00:00
|
|
|
return networksModule.getNetworkShortNames(chainIds)
|
2023-07-21 08:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateWalletAccountPreferredChains(address, preferredChainIds) {
|
|
|
|
if(areTestNetworksEnabled) {
|
|
|
|
walletSectionAccounts.updateWalletAccountTestPreferredChains(address, preferredChainIds)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
walletSectionAccounts.updateWalletAccountProdPreferredChains(address, preferredChainIds)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function processPreferredSharingNetworkToggle(preferredSharingNetworks, toggledNetwork) {
|
|
|
|
let prefChains = preferredSharingNetworks
|
|
|
|
if(prefChains.length === allNetworks.count) {
|
|
|
|
prefChains = [toggledNetwork.chainId.toString()]
|
|
|
|
}
|
|
|
|
else if(!prefChains.includes(toggledNetwork.chainId.toString())) {
|
|
|
|
prefChains.push(toggledNetwork.chainId.toString())
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(prefChains.length === 1) {
|
|
|
|
prefChains = getAllNetworksChainIds().split(":")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(var i = 0; i < prefChains.length;i++) {
|
|
|
|
if(prefChains[i] === toggledNetwork.chainId.toString()) {
|
|
|
|
prefChains.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return prefChains
|
|
|
|
}
|
2023-10-10 15:46:43 +00:00
|
|
|
|
|
|
|
function updateWatchAccountHiddenFromTotalBalance(address, hideFromTotalBalance) {
|
|
|
|
walletSectionAccounts.updateWatchAccountHiddenFromTotalBalance(address, hideFromTotalBalance)
|
|
|
|
}
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|