2023-09-27 13:41:55 +00:00
|
|
|
pragma Singleton
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQml 2.15
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import shared.stores 1.0
|
|
|
|
import shared.stores.send 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
2024-07-02 11:19:37 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2023-09-27 13:41:55 +00:00
|
|
|
|
|
|
|
import "./controls"
|
|
|
|
import "./views"
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2024-07-02 11:19:37 +00:00
|
|
|
enum RecipientAddressObjectType {
|
|
|
|
Address, // Just a string with the address information / default
|
|
|
|
Account, // Wallet account object
|
|
|
|
SavedAddress, // Saved addresses object
|
|
|
|
RecentsAddress // Recent addresses object got from transactions history
|
|
|
|
}
|
|
|
|
|
2024-09-30 08:34:28 +00:00
|
|
|
function recipientAddressObjectTypeToString(type) {
|
|
|
|
switch (type) {
|
|
|
|
case RecipientAddressObjectType.Address:
|
|
|
|
return "Address"
|
|
|
|
case RecipientAddressObjectType.Account:
|
|
|
|
return "Account"
|
|
|
|
case RecipientAddressObjectType.SavedAddress:
|
|
|
|
return "SavedAddress"
|
|
|
|
case RecipientAddressObjectType.RecentsAddress:
|
|
|
|
return "RecentsAddress"
|
|
|
|
default:
|
|
|
|
return "Unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-27 13:41:55 +00:00
|
|
|
function createSendModalRequirements() {
|
|
|
|
return {
|
|
|
|
preSelectedAccount: null,
|
2024-07-02 11:19:37 +00:00
|
|
|
preSelectedRecipientType: Helpers.RecipientAddressObjectType.Address,
|
2023-09-27 13:41:55 +00:00
|
|
|
preSelectedRecipient: null,
|
2023-11-07 22:45:47 +00:00
|
|
|
preSelectedHoldingType: Constants.TokenType.Unknown,
|
2023-09-27 13:41:55 +00:00
|
|
|
preSelectedHoldingID: "",
|
|
|
|
preDefinedAmountToSend: "",
|
2024-07-31 11:58:05 +00:00
|
|
|
preSelectedChainId: 0,
|
2023-09-27 13:41:55 +00:00
|
|
|
preSelectedSendType: Constants.SendType.Transfer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// \c token is an collectible object in case of \c isCollectible == true otherwise a token code (e.g. "ETH")
|
2024-07-02 11:19:37 +00:00
|
|
|
function lookupAddressesForSendModal(accountsModel,
|
|
|
|
savedAddressesModel,
|
|
|
|
senderAddress,
|
|
|
|
recipientAddress,
|
|
|
|
token,
|
|
|
|
isCollectible,
|
2024-07-31 11:58:05 +00:00
|
|
|
amount,
|
|
|
|
chainId) {
|
2023-09-27 13:41:55 +00:00
|
|
|
let req = createSendModalRequirements()
|
|
|
|
|
|
|
|
req.preSelectedSendType = Constants.SendType.Transfer
|
2024-07-02 11:19:37 +00:00
|
|
|
|
|
|
|
// Sender properties:
|
2023-09-27 13:41:55 +00:00
|
|
|
let senderAccount = null
|
2024-07-02 11:19:37 +00:00
|
|
|
let resolvedAcc = SQUtils.ModelUtils.getByKey(accountsModel, "address", senderAddress)
|
|
|
|
if (resolvedAcc) {
|
|
|
|
req.preSelectedAccount = resolvedAcc
|
|
|
|
req.preSelectedRecipientType = Helpers.RecipientAddressObjectType.Account
|
2023-09-27 13:41:55 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 11:19:37 +00:00
|
|
|
// Recipients properties:
|
|
|
|
const resAcc = SQUtils.ModelUtils.getByKey(accountsModel, "address", recipientAddress)
|
|
|
|
let resSaved = SQUtils.ModelUtils.getByKey(savedAddressesModel, "address", recipientAddress)
|
|
|
|
if (resAcc) {
|
|
|
|
req.preSelectedRecipientType = Helpers.RecipientAddressObjectType.Account
|
|
|
|
req.preSelectedRecipient = resAcc
|
|
|
|
} else if (resSaved) {
|
|
|
|
req.preSelectedRecipientType = Helpers.RecipientAddressObjectType.SavedAddress
|
|
|
|
req.preSelectedRecipient = resSaved
|
2023-09-27 13:41:55 +00:00
|
|
|
} else {
|
2024-07-02 11:19:37 +00:00
|
|
|
req.preSelectedRecipientType = Helpers.RecipientAddressObjectType.Address
|
2023-09-27 13:41:55 +00:00
|
|
|
req.preSelectedRecipient = recipientAddress
|
|
|
|
}
|
|
|
|
|
2024-07-31 11:58:05 +00:00
|
|
|
req.preSelectedHoldingType = isCollectible ? Constants.TokenType.ERC721 : Constants.TokenType.ERC20
|
|
|
|
req.preSelectedHoldingID = token
|
|
|
|
req.preSelectedChainId = chainId
|
2023-09-27 13:41:55 +00:00
|
|
|
|
|
|
|
req.preDefinedAmountToSend = LocaleUtils.numberToLocaleString(amount)
|
|
|
|
|
|
|
|
return req
|
|
|
|
}
|
2024-02-20 07:43:31 +00:00
|
|
|
|
|
|
|
function assetsSectionTitle(sectionNeeded, hasCommunityTokens, isInsideCollection, isERC20List) {
|
|
|
|
let title = ""
|
|
|
|
if (!isInsideCollection) {
|
|
|
|
if (sectionNeeded) {
|
|
|
|
title = qsTr("Community minted")
|
|
|
|
} else {
|
|
|
|
if (!isERC20List) {
|
|
|
|
// Show "Other" only if there are "Community minted" tokens on the list
|
|
|
|
if (hasCommunityTokens) {
|
|
|
|
title = qsTr("Other")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return title
|
|
|
|
}
|
|
|
|
|
|
|
|
function modelHasCommunityTokens(model, isERC20List) {
|
|
|
|
if (model.count > 0) {
|
|
|
|
let item
|
|
|
|
if (isERC20List) {
|
|
|
|
item = model.get(model.count - 1)
|
|
|
|
} else {
|
|
|
|
item = model.get(0)
|
|
|
|
}
|
|
|
|
return item.isCommunityAsset
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2023-11-07 22:45:47 +00:00
|
|
|
}
|