2022-10-17 10:17:25 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
|
2023-08-15 18:21:51 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
2022-10-17 10:17:25 +00:00
|
|
|
|
|
|
|
import shared.stores 1.0
|
2023-08-15 18:21:51 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2022-10-17 10:17:25 +00:00
|
|
|
|
2023-09-11 10:20:36 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
2022-10-17 10:17:25 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2022-12-29 16:44:51 +00:00
|
|
|
property CurrenciesStore currencyStore: CurrenciesStore {}
|
2022-10-17 10:17:25 +00:00
|
|
|
|
|
|
|
property var mainModuleInst: mainModule
|
2023-04-20 08:41:45 +00:00
|
|
|
property var walletSectionSendInst: walletSectionSend
|
2022-10-17 10:17:25 +00:00
|
|
|
|
2023-08-15 18:21:51 +00:00
|
|
|
property var fromNetworksModel: walletSectionSendInst.fromNetworksModel
|
|
|
|
property var toNetworksModel: walletSectionSendInst.toNetworksModel
|
2023-05-04 12:55:39 +00:00
|
|
|
property var senderAccounts: walletSectionSendInst.senderAccounts
|
|
|
|
property var selectedSenderAccount: walletSectionSendInst.selectedSenderAccount
|
2023-08-15 18:21:51 +00:00
|
|
|
property var accounts: walletSectionSendInst.accounts
|
2023-09-11 10:20:36 +00:00
|
|
|
property var collectiblesModel: walletSectionSendInst.collectiblesModel
|
|
|
|
property var nestedCollectiblesModel: walletSectionSendInst.nestedCollectiblesModel
|
2023-07-21 08:41:24 +00:00
|
|
|
property bool areTestNetworksEnabled: networksModule.areTestNetworksEnabled
|
2023-08-15 18:21:51 +00:00
|
|
|
property var tmpActivityController: walletSection.tmpActivityController
|
2023-04-18 16:05:24 +00:00
|
|
|
property var savedAddressesModel: SortFilterProxyModel {
|
|
|
|
sourceModel: walletSectionSavedAddresses.model
|
|
|
|
filters: [
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "isTest"
|
2023-07-21 08:41:24 +00:00
|
|
|
value: areTestNetworksEnabled
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-08-15 18:21:51 +00:00
|
|
|
property string selectedAssetSymbol: walletSectionSendInst.selectedAssetSymbol
|
|
|
|
property bool showUnPreferredChains: walletSectionSendInst.showUnPreferredChains
|
2022-10-17 10:17:25 +00:00
|
|
|
|
2022-12-08 15:56:02 +00:00
|
|
|
function getEtherscanLink(chainID) {
|
|
|
|
return networksModule.all.getBlockExplorerURL(chainID)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyToClipboard(text) {
|
|
|
|
globalUtils.copyToClipboard(text)
|
|
|
|
}
|
|
|
|
|
2023-08-15 18:21:51 +00:00
|
|
|
function authenticateAndTransfer(from, to, tokenSymbol, amount, uuid) {
|
|
|
|
walletSectionSendInst.authenticateAndTransfer(from, to, tokenSymbol, amount, uuid)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
2023-08-15 18:21:51 +00:00
|
|
|
function suggestedRoutes(amount, sendType) {
|
|
|
|
walletSectionSendInst.suggestedRoutes(amount, sendType)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function resolveENS(value) {
|
|
|
|
mainModuleInst.resolveENS(value, "")
|
|
|
|
}
|
|
|
|
|
2022-11-15 11:22:03 +00:00
|
|
|
function getWei2Eth(wei, decimals) {
|
|
|
|
return globalUtils.wei2Eth(wei, decimals)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function plainText(text) {
|
|
|
|
return globalUtils.plainText(text)
|
|
|
|
}
|
2022-12-01 15:48:44 +00:00
|
|
|
|
2022-11-30 12:59:21 +00:00
|
|
|
enum EstimatedTime {
|
|
|
|
Unknown = 0,
|
|
|
|
LessThanOneMin,
|
|
|
|
LessThanThreeMins,
|
|
|
|
LessThanFiveMins,
|
|
|
|
MoreThanFiveMins
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLabelForEstimatedTxTime(estimatedFlag) {
|
|
|
|
switch(estimatedFlag) {
|
|
|
|
case TransactionStore.EstimatedTime.Unknown:
|
|
|
|
return qsTr("~ Unknown")
|
|
|
|
case TransactionStore.EstimatedTime.LessThanOneMin :
|
|
|
|
return qsTr("< 1 minute")
|
|
|
|
case TransactionStore.EstimatedTime.LessThanThreeMins :
|
|
|
|
return qsTr("< 3 minutes")
|
|
|
|
case TransactionStore.EstimatedTime.LessThanFiveMins:
|
|
|
|
return qsTr("< 5 minutes")
|
|
|
|
default:
|
|
|
|
return qsTr("> 5 minutes")
|
|
|
|
}
|
|
|
|
}
|
2022-11-25 09:13:02 +00:00
|
|
|
|
2023-04-06 12:59:24 +00:00
|
|
|
function findTokenSymbolByAddress(address) {
|
|
|
|
if (Global.appIsReady)
|
|
|
|
return walletSectionAllTokens.findTokenSymbolByAddress(address)
|
|
|
|
return ""
|
|
|
|
}
|
2023-04-07 10:34:01 +00:00
|
|
|
|
|
|
|
function getAsset(assetsList, symbol) {
|
|
|
|
for(var i=0; i< assetsList.count;i++) {
|
|
|
|
if(symbol === assetsList.rowData(i, "symbol"))
|
|
|
|
return {
|
|
|
|
name: assetsList.rowData(i, "name"),
|
|
|
|
symbol: assetsList.rowData(i, "symbol"),
|
|
|
|
totalBalance: JSON.parse(assetsList.rowData(i, "totalBalance")),
|
|
|
|
totalCurrencyBalance: JSON.parse(assetsList.rowData(i, "totalCurrencyBalance")),
|
|
|
|
balances: assetsList.rowData(i, "balances"),
|
|
|
|
decimals: assetsList.rowData(i, "decimals")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {}
|
|
|
|
}
|
2023-04-18 16:05:24 +00:00
|
|
|
|
2023-09-11 10:20:36 +00:00
|
|
|
function getCollectible(uid) {
|
|
|
|
const idx = ModelUtils.indexOf(collectiblesModel, "uid", uid)
|
|
|
|
if (idx < 0) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
return ModelUtils.get(collectiblesModel, idx)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectorCollectible(uid) {
|
|
|
|
const idx = ModelUtils.indexOf(nestedCollectiblesModel, "uid", uid)
|
|
|
|
if (idx < 0) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
return ModelUtils.get(nestedCollectiblesModel, idx)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHolding(holdingId, holdingType) {
|
|
|
|
if (holdingType === Constants.HoldingType.Asset) {
|
|
|
|
return getAsset(selectedSenderAccount.assets, holdingId)
|
|
|
|
} else if (holdingType === Constants.HoldingType.Collectible) {
|
|
|
|
return getCollectible(holdingId)
|
|
|
|
} else {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectorHolding(holdingId, holdingType) {
|
|
|
|
if (holdingType === Constants.HoldingType.Asset) {
|
|
|
|
return getAsset(selectedSenderAccount.assets, holdingId)
|
|
|
|
} else if (holdingType === Constants.HoldingType.Collectible) {
|
|
|
|
return getSelectorCollectible(holdingId)
|
|
|
|
} else {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function assetToSelectorAsset(asset) {
|
|
|
|
return asset
|
|
|
|
}
|
|
|
|
|
|
|
|
function collectibleToSelectorCollectible(collectible) {
|
|
|
|
return {
|
|
|
|
uid: collectible.uid,
|
|
|
|
chainId: collectible.chainId,
|
|
|
|
name: collectible.name,
|
|
|
|
iconUrl: collectible.imageUrl,
|
|
|
|
collectionUid: collectible.collectionUid,
|
|
|
|
collectionName: collectible.collectionName,
|
|
|
|
isCollection: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function holdingToSelectorHolding(holding, holdingType) {
|
|
|
|
if (holdingType === Constants.HoldingType.Asset) {
|
|
|
|
return assetToSelectorAsset(holding)
|
|
|
|
} else if (holdingType === Constants.HoldingType.Collectible) {
|
|
|
|
return collectibleToSelectorCollectible(holding)
|
|
|
|
} else {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 12:55:39 +00:00
|
|
|
function switchSenderAccount(index) {
|
|
|
|
walletSectionSendInst.switchSenderAccount(index)
|
2023-04-24 18:35:34 +00:00
|
|
|
}
|
2023-07-21 08:41:24 +00:00
|
|
|
|
|
|
|
function getNetworkShortNames(chainIds) {
|
|
|
|
return networksModule.getNetworkShortNames(chainIds)
|
|
|
|
}
|
2023-08-15 18:21:51 +00:00
|
|
|
|
|
|
|
function toggleFromDisabledChains(chainId) {
|
|
|
|
fromNetworksModel.toggleDisabledChains(chainId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleToDisabledChains(chainId) {
|
|
|
|
toNetworksModel.toggleDisabledChains(chainId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDisabledChains(chainId, disabled) {
|
|
|
|
toNetworksModel.setDisabledChains(chainId, disabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSelectedAssetSymbol(symbol) {
|
|
|
|
walletSectionSendInst.setSelectedAssetSymbol(symbol)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNetworkName(chainId) {
|
|
|
|
return fromNetworksModel.getNetworkName(chainId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePreferredChains(chainIds) {
|
|
|
|
walletSectionSendInst.updatePreferredChains(chainIds)
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleShowUnPreferredChains() {
|
|
|
|
walletSectionSendInst.toggleShowUnPreferredChains()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAllNetworksAsPreferredChains() {
|
|
|
|
toNetworksModel.setAllNetworksAsPreferredChains()
|
|
|
|
}
|
|
|
|
|
|
|
|
function lockCard(chainId, amount, lock) {
|
|
|
|
fromNetworksModel.lockCard(chainId, amount, lock)
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetStoredProperties() {
|
|
|
|
walletSectionSendInst.resetStoredProperties()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: move to nim
|
|
|
|
function splitAndFormatAddressPrefix(text, isBridgeTx) {
|
|
|
|
let address = ""
|
|
|
|
let tempPreferredChains = []
|
|
|
|
let chainFound = false
|
|
|
|
let splitWords = plainText(text).split(':')
|
|
|
|
let editedText = ""
|
|
|
|
|
|
|
|
for(var i=0; i<splitWords.length; i++) {
|
|
|
|
const word = splitWords[i]
|
|
|
|
if(word.startsWith("0x")) {
|
|
|
|
address = word
|
|
|
|
editedText += word
|
|
|
|
} else {
|
|
|
|
let chainColor = fromNetworksModel.getNetworkColor(word)
|
|
|
|
if(!!chainColor) {
|
|
|
|
chainFound = true
|
|
|
|
if(!isBridgeTx)
|
|
|
|
tempPreferredChains.push(fromNetworksModel.getNetworkChainId(word))
|
|
|
|
editedText += `<span style='color: %1'>%2</span>`.arg(chainColor).arg(word)+':'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isBridgeTx) {
|
|
|
|
if(!chainFound)
|
|
|
|
updatePreferredChains(networksModule.getMainnetChainId())
|
|
|
|
else
|
|
|
|
updatePreferredChains(tempPreferredChains.join(":"))
|
|
|
|
}
|
|
|
|
|
|
|
|
editedText +="</a></p>"
|
|
|
|
return {
|
|
|
|
formattedText: editedText,
|
|
|
|
address: address
|
|
|
|
}
|
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|