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
|
|
|
|
2024-01-30 13:15:58 +00:00
|
|
|
import StatusQ 0.1
|
2023-09-11 10:20:36 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
2023-11-28 19:16:18 +00:00
|
|
|
import AppLayouts.Wallet.stores 1.0
|
|
|
|
|
2022-10-17 10:17:25 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2024-05-28 17:39:41 +00:00
|
|
|
property CurrenciesStore currencyStore
|
2023-11-28 19:16:18 +00:00
|
|
|
property WalletAssetsStore walletAssetStore
|
2024-01-30 13:15:58 +00:00
|
|
|
property TokensStore tokensStore
|
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
|
2024-03-13 17:38:16 +00:00
|
|
|
property var flatNetworksModel: networksModule.flatNetworks
|
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
|
2024-02-26 02:32:59 +00:00
|
|
|
property var tmpActivityController0: walletSection.tmpActivityController0
|
|
|
|
property var tmpActivityController1: walletSection.tmpActivityController1
|
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
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2024-02-05 16:44:49 +00:00
|
|
|
property string selectedAssetKey: walletSectionSendInst.selectedAssetKey
|
2023-08-15 18:21:51 +00:00
|
|
|
property bool showUnPreferredChains: walletSectionSendInst.showUnPreferredChains
|
2023-09-20 16:07:09 +00:00
|
|
|
property int sendType: walletSectionSendInst.sendType
|
|
|
|
property string selectedRecipient: walletSectionSendInst.selectedRecipient
|
|
|
|
|
|
|
|
function setSendType(sendType) {
|
|
|
|
walletSectionSendInst.setSendType(sendType)
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSelectedRecipient(recipientAddress) {
|
|
|
|
walletSectionSendInst.setSelectedRecipient(recipientAddress)
|
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
|
2022-12-08 15:56:02 +00:00
|
|
|
function getEtherscanLink(chainID) {
|
2024-03-13 17:38:16 +00:00
|
|
|
return networksModule.getBlockExplorerURL(chainID)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyToClipboard(text) {
|
|
|
|
globalUtils.copyToClipboard(text)
|
|
|
|
}
|
|
|
|
|
2024-03-05 14:08:49 +00:00
|
|
|
function authenticateAndTransfer(uuid) {
|
|
|
|
walletSectionSendInst.authenticateAndTransfer(uuid)
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-20 16:07:09 +00:00
|
|
|
function suggestedRoutes(amount) {
|
2023-10-25 08:36:55 +00:00
|
|
|
const value = AmountsArithmetic.fromNumber(amount)
|
|
|
|
walletSectionSendInst.suggestedRoutes(value.toFixed())
|
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-07 10:34:01 +00:00
|
|
|
function getAsset(assetsList, symbol) {
|
2023-11-28 19:16:18 +00:00
|
|
|
for(var i=0; i< assetsList.rowCount();i++) {
|
2024-01-30 13:15:58 +00:00
|
|
|
let asset = assetsList.get(i)
|
2023-11-28 19:16:18 +00:00
|
|
|
if(symbol === asset.symbol) {
|
2024-01-30 13:15:58 +00:00
|
|
|
return asset
|
2023-09-12 14:26:38 +00:00
|
|
|
}
|
2023-04-07 10:34:01 +00:00
|
|
|
}
|
|
|
|
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) {
|
2023-11-07 22:45:47 +00:00
|
|
|
if (holdingType === Constants.TokenType.ERC20) {
|
2024-01-30 13:15:58 +00:00
|
|
|
return getAsset(processedAssetsModel, holdingId)
|
2024-03-05 09:27:40 +00:00
|
|
|
} else if (holdingType === Constants.TokenType.ERC721 || holdingType === Constants.TokenType.ERC1155) {
|
2023-09-11 10:20:36 +00:00
|
|
|
return getCollectible(holdingId)
|
|
|
|
} else {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectorHolding(holdingId, holdingType) {
|
2023-11-07 22:45:47 +00:00
|
|
|
if (holdingType === Constants.TokenType.ERC20) {
|
2024-01-30 13:15:58 +00:00
|
|
|
return getAsset(processedAssetsModel, holdingId)
|
2024-03-05 09:27:40 +00:00
|
|
|
} else if (holdingType === Constants.TokenType.ERC721 || holdingType === Constants.TokenType.ERC1155) {
|
2023-09-11 10:20:36 +00:00
|
|
|
return getSelectorCollectible(holdingId)
|
|
|
|
} else {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function assetToSelectorAsset(asset) {
|
|
|
|
return asset
|
|
|
|
}
|
2024-03-05 14:08:49 +00:00
|
|
|
|
2023-09-11 10:20:36 +00:00
|
|
|
function collectibleToSelectorCollectible(collectible) {
|
2024-03-27 16:18:45 +00:00
|
|
|
var groupId = collectible.collectionUid
|
|
|
|
var groupName = collectible.collectionName
|
|
|
|
var itemType = Constants.CollectiblesNestedItemType.Collectible
|
|
|
|
if (collectible.communityId !== "") {
|
|
|
|
groupId = collectible.communityId
|
|
|
|
groupName = collectible.communityName
|
|
|
|
itemType = Constants.CollectiblesNestedItemType.CommunityCollectible
|
|
|
|
}
|
2023-09-11 10:20:36 +00:00
|
|
|
return {
|
|
|
|
uid: collectible.uid,
|
|
|
|
chainId: collectible.chainId,
|
|
|
|
name: collectible.name,
|
|
|
|
iconUrl: collectible.imageUrl,
|
2024-03-27 16:18:45 +00:00
|
|
|
groupId: groupId,
|
|
|
|
groupName: groupName,
|
|
|
|
tokenType: collectible.tokenType,
|
|
|
|
itemType: itemType,
|
|
|
|
count: 1 // TODO: Properly handle count
|
2023-09-11 10:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function holdingToSelectorHolding(holding, holdingType) {
|
2023-11-07 22:45:47 +00:00
|
|
|
if (holdingType === Constants.TokenType.ERC20) {
|
2023-09-11 10:20:36 +00:00
|
|
|
return assetToSelectorAsset(holding)
|
2024-03-05 09:27:40 +00:00
|
|
|
} else if (holdingType === Constants.TokenType.ERC721 || holdingType === Constants.TokenType.ERC1155) {
|
2023-09-11 10:20:36 +00:00
|
|
|
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) {
|
2023-08-31 10:27:15 +00:00
|
|
|
fromNetworksModel.toggleRouteDisabledChains(chainId)
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleToDisabledChains(chainId) {
|
2023-08-31 10:27:15 +00:00
|
|
|
toNetworksModel.toggleRouteDisabledChains(chainId)
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 10:27:15 +00:00
|
|
|
function setRouteDisabledChains(chainId, disabled) {
|
|
|
|
toNetworksModel.setRouteDisabledChains(chainId, disabled)
|
|
|
|
}
|
|
|
|
|
2023-11-24 08:48:50 +00:00
|
|
|
function setSelectedTokenName(tokenName) {
|
|
|
|
walletSectionSendInst.setSelectedTokenName(tokenName)
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSelectedTokenIsOwnerToken(isOwnerToken) {
|
|
|
|
walletSectionSendInst.setSelectedTokenIsOwnerToken(isOwnerToken)
|
|
|
|
}
|
|
|
|
|
2023-08-31 10:27:15 +00:00
|
|
|
function setRouteEnabledFromChains(chainId) {
|
|
|
|
fromNetworksModel.setRouteEnabledFromChains(chainId)
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 16:44:49 +00:00
|
|
|
function setSelectedAssetKey(assetsKey) {
|
|
|
|
walletSectionSendInst.setSelectedAssetKey(assetsKey)
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNetworkName(chainId) {
|
|
|
|
return fromNetworksModel.getNetworkName(chainId)
|
|
|
|
}
|
|
|
|
|
2023-08-31 10:27:15 +00:00
|
|
|
function updateRoutePreferredChains(chainIds) {
|
|
|
|
walletSectionSendInst.updateRoutePreferredChains(chainIds)
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleShowUnPreferredChains() {
|
|
|
|
walletSectionSendInst.toggleShowUnPreferredChains()
|
|
|
|
}
|
|
|
|
|
2023-08-31 10:27:15 +00:00
|
|
|
function setAllNetworksAsRoutePreferredChains() {
|
|
|
|
toNetworksModel.setAllNetworksAsRoutePreferredChains()
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function lockCard(chainId, amount, lock) {
|
|
|
|
fromNetworksModel.lockCard(chainId, amount, lock)
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetStoredProperties() {
|
2024-01-30 13:15:58 +00:00
|
|
|
assetSearchString = ""
|
2023-08-15 18:21:51 +00:00
|
|
|
walletSectionSendInst.resetStoredProperties()
|
2023-09-12 14:26:38 +00:00
|
|
|
nestedCollectiblesModel.currentCollectionUid = ""
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 10:27:15 +00:00
|
|
|
function splitAndFormatAddressPrefix(text, updateInStore) {
|
2023-08-15 18:21:51 +00:00
|
|
|
return {
|
2023-09-19 15:06:57 +00:00
|
|
|
formattedText: walletSectionSendInst.splitAndFormatAddressPrefix(text, updateInStore),
|
|
|
|
address: walletSectionSendInst.getAddressFromFormattedString(text)
|
2023-08-15 18:21:51 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-19 15:06:57 +00:00
|
|
|
|
|
|
|
function getShortChainIds(chainShortNames) {
|
|
|
|
return walletSectionSendInst.getShortChainIds(chainShortNames)
|
|
|
|
}
|
2023-11-28 19:16:18 +00:00
|
|
|
|
2024-01-30 13:15:58 +00:00
|
|
|
function formatCurrencyAmountFromBigInt(balance, symbol, decimals) {
|
2023-11-28 19:16:18 +00:00
|
|
|
let bigIntBalance = AmountsArithmetic.fromString(balance)
|
|
|
|
let decimalBalance = AmountsArithmetic.toNumber(bigIntBalance, decimals)
|
2024-01-30 13:15:58 +00:00
|
|
|
return currencyStore.formatCurrencyAmount(decimalBalance, symbol)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Property set from TokenLIstView and HoldingSelector to search token by name, symbol or contract address
|
|
|
|
property string assetSearchString
|
|
|
|
|
|
|
|
// Internal model filtering balances by the account selected on the SendModalPage
|
|
|
|
property SubmodelProxyModel __assetsWithFilteredBalances: SubmodelProxyModel {
|
|
|
|
sourceModel: walletAssetStore.groupedAccountAssetsModel
|
|
|
|
submodelRoleName: "balances"
|
|
|
|
delegateModel: SortFilterProxyModel {
|
|
|
|
sourceModel: submodel
|
2024-05-28 17:39:41 +00:00
|
|
|
filters: [
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "account"
|
|
|
|
value: root.selectedSenderAccount.address
|
|
|
|
}
|
|
|
|
]
|
2024-01-30 13:15:58 +00:00
|
|
|
}
|
2023-11-28 19:16:18 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 12:09:07 +00:00
|
|
|
readonly property Connections tokensStoreConnections: Connections {
|
|
|
|
target: tokensStore
|
|
|
|
function onDisplayAssetsBelowBalanceThresholdChanged() {
|
|
|
|
processedAssetsModel.displayAssetsBelowBalanceThresholdAmount = tokensStore.getDisplayAssetsBelowBalanceThresholdDisplayAmount()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:15:58 +00:00
|
|
|
// Model prepared to provide filtered and sorted assets as per the advanced Settings in token management
|
|
|
|
property var processedAssetsModel: SortFilterProxyModel {
|
2024-02-19 12:09:07 +00:00
|
|
|
property real displayAssetsBelowBalanceThresholdAmount: tokensStore.getDisplayAssetsBelowBalanceThresholdDisplayAmount()
|
2024-01-30 13:15:58 +00:00
|
|
|
sourceModel: __assetsWithFilteredBalances
|
|
|
|
proxyRoles: [
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "isCommunityAsset"
|
|
|
|
expression: !!model.communityId
|
|
|
|
expectedRoles: ["communityId"]
|
|
|
|
},
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "currentBalance"
|
2024-05-28 17:39:41 +00:00
|
|
|
expression: __getTotalBalance(model.balances, model.decimals)
|
2024-01-30 13:15:58 +00:00
|
|
|
expectedRoles: ["balances", "decimals"]
|
|
|
|
},
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "currentCurrencyBalance"
|
|
|
|
expression: {
|
|
|
|
if (!!model.marketDetails) {
|
|
|
|
return model.currentBalance * model.marketDetails.currencyPrice.amount
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
2024-03-19 23:34:25 +00:00
|
|
|
expectedRoles: ["marketDetails", "currentBalance"]
|
2024-01-30 13:15:58 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
filters: [
|
|
|
|
FastExpressionFilter {
|
|
|
|
function search(symbol, name, addressPerChain, searchString) {
|
|
|
|
return (
|
|
|
|
symbol.toUpperCase().startsWith(searchString.toUpperCase()) ||
|
|
|
|
name.toUpperCase().startsWith(searchString.toUpperCase()) || __searchAddressInList(addressPerChain, searchString)
|
|
|
|
)
|
|
|
|
}
|
2024-05-28 17:39:41 +00:00
|
|
|
expression: search(symbol, name, addressPerChain, root.assetSearchString)
|
2024-01-30 13:15:58 +00:00
|
|
|
expectedRoles: ["symbol", "name", "addressPerChain"]
|
|
|
|
},
|
|
|
|
ValueFilter {
|
|
|
|
roleName: "isCommunityAsset"
|
|
|
|
value: false
|
|
|
|
enabled: !tokensStore.showCommunityAssetsInSend
|
|
|
|
},
|
|
|
|
FastExpressionFilter {
|
|
|
|
expression: {
|
2024-03-19 23:34:25 +00:00
|
|
|
root.walletAssetStore.assetsController.revision
|
|
|
|
|
|
|
|
if (!root.walletAssetStore.assetsController.filterAcceptsSymbol(model.symbol)) // explicitely hidden
|
|
|
|
return false
|
2024-01-30 13:15:58 +00:00
|
|
|
if (model.isCommunityAsset)
|
|
|
|
return true
|
2024-03-19 23:34:25 +00:00
|
|
|
if (tokensStore.displayAssetsBelowBalance)
|
|
|
|
return model.currentCurrencyBalance > processedAssetsModel.displayAssetsBelowBalanceThresholdAmount
|
|
|
|
return true
|
2024-01-30 13:15:58 +00:00
|
|
|
}
|
2024-03-19 23:34:25 +00:00
|
|
|
expectedRoles: ["symbol", "isCommunityAsset", "currentCurrencyBalance"]
|
2024-01-30 13:15:58 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
sorters: RoleSorter {
|
|
|
|
roleName: "isCommunityAsset"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Internal function to search token address */
|
|
|
|
function __searchAddressInList(addressPerChain, searchString) {
|
|
|
|
let addressFound = false
|
|
|
|
let tokenAddresses = ModelUtils.modelToFlatArray(addressPerChain, "address")
|
|
|
|
for (let i =0; i< tokenAddresses.length; i++){
|
|
|
|
if(tokenAddresses[i].toUpperCase().startsWith(searchString.toUpperCase())) {
|
|
|
|
addressFound = true
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addressFound
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Internal function to calculate total balance */
|
|
|
|
function __getTotalBalance(balances, decimals) {
|
|
|
|
let totalBalance = 0
|
|
|
|
for(let i=0; i<balances.count; i++) {
|
|
|
|
let balancePerAddressPerChain = ModelUtils.get(balances, i)
|
|
|
|
totalBalance+=AmountsArithmetic.toNumber(balancePerAddressPerChain.balance, decimals)
|
|
|
|
}
|
|
|
|
return totalBalance
|
2023-11-28 19:16:18 +00:00
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
}
|