Noelia 18e230bf91 refactor(Wallet/SendModal): Selected Recipients component review, backend dependencies cleanup
- Component name changed to be more precise with what it represents.
- Removed `RootStore` dependency from `Helpers.qml`.
- Removed unnecessary method `lookupAddressObject` from `RootStore`.
- Updated `SendModal` property bindings related to recipient.
- Some activity controller interaction details moved to transactions store instead of being directly in `SendModal`.
- Type enum living in `RecipientSelectorPanel` is moved to `Helpers`. Since it doesn't depends on the specific component and it's used in other global places.

Part of #15208
2024-07-11 14:05:55 +02:00

119 lines
4.0 KiB
QML

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
import StatusQ.Core.Utils 0.1 as SQUtils
import shared.popups.send.panels 1.0
import "./controls"
import "./views"
QtObject {
id: root
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
}
function createSendModalRequirements() {
return {
preSelectedAccount: null,
preSelectedRecipientType: Helpers.RecipientAddressObjectType.Address,
preSelectedRecipient: null,
preSelectedHoldingType: Constants.TokenType.Unknown,
preSelectedHolding: null,
preSelectedHoldingID: "",
preDefinedAmountToSend: "",
preSelectedSendType: Constants.SendType.Transfer
}
}
// \c token is an collectible object in case of \c isCollectible == true otherwise a token code (e.g. "ETH")
function lookupAddressesForSendModal(accountsModel,
savedAddressesModel,
senderAddress,
recipientAddress,
token,
isCollectible,
amount) {
let req = createSendModalRequirements()
req.preSelectedSendType = Constants.SendType.Transfer
// Sender properties:
let senderAccount = null
let resolvedAcc = SQUtils.ModelUtils.getByKey(accountsModel, "address", senderAddress)
if (resolvedAcc) {
req.preSelectedAccount = resolvedAcc
req.preSelectedRecipientType = Helpers.RecipientAddressObjectType.Account
}
// 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
} else {
req.preSelectedRecipientType = Helpers.RecipientAddressObjectType.Address
req.preSelectedRecipient = recipientAddress
}
// Holdings related properties:
if (isCollectible) {
req.preSelectedHoldingType = Constants.TokenType.ERC721
req.preSelectedHolding = token
} else {
req.preSelectedHoldingType = Constants.TokenType.ERC20
req.preSelectedHoldingID = token
}
req.preDefinedAmountToSend = LocaleUtils.numberToLocaleString(amount)
return req
}
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
}
}