2023-04-18 16:05:24 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
|
|
|
|
|
|
|
import AppLayouts.Wallet 1.0
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
import shared.controls 1.0 as SharedControls
|
|
|
|
import shared.stores.send 1.0
|
2024-07-02 11:19:37 +00:00
|
|
|
import shared.popups.send.panels 1.0
|
|
|
|
import shared.popups.send 1.0
|
2024-06-07 12:27:56 +00:00
|
|
|
|
2023-04-18 16:05:24 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import "../controls"
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: root
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
property TransactionStore store
|
2024-03-05 09:27:40 +00:00
|
|
|
property bool isCollectiblesTransfer
|
2023-04-18 16:05:24 +00:00
|
|
|
property bool isBridgeTx: false
|
|
|
|
property bool interactive: true
|
|
|
|
property var selectedAsset
|
|
|
|
property var selectedRecipient: null
|
2024-07-02 11:19:37 +00:00
|
|
|
property int selectedRecipientType: Helpers.RecipientAddressObjectType.Address
|
2023-04-18 16:05:24 +00:00
|
|
|
|
2023-09-19 15:06:57 +00:00
|
|
|
readonly property bool ready: (d.isAddressValid || !!resolvedENSAddress) && !d.isPending
|
2023-04-18 16:05:24 +00:00
|
|
|
property string addressText
|
|
|
|
property string resolvedENSAddress
|
|
|
|
|
|
|
|
signal recalculateRoutesAndFees()
|
|
|
|
signal isLoading()
|
|
|
|
|
|
|
|
onAddressTextChanged: d.isPending = false
|
|
|
|
|
|
|
|
onSelectedRecipientChanged: {
|
|
|
|
root.isLoading()
|
2024-07-02 11:19:37 +00:00
|
|
|
if(!!root.selectedRecipient) {
|
2023-09-19 15:06:57 +00:00
|
|
|
let preferredChainIds = []
|
2023-04-18 16:05:24 +00:00
|
|
|
switch(root.selectedRecipientType) {
|
2024-07-02 11:19:37 +00:00
|
|
|
case Helpers.RecipientAddressObjectType.Account: {
|
2023-09-19 15:06:57 +00:00
|
|
|
root.addressText = root.selectedRecipient.address
|
|
|
|
preferredChainIds = root.selectedRecipient.preferredSharingChainIds
|
|
|
|
break
|
|
|
|
}
|
2024-07-02 11:19:37 +00:00
|
|
|
case Helpers.RecipientAddressObjectType.SavedAddress: {
|
2023-09-19 15:06:57 +00:00
|
|
|
root.addressText = root.selectedRecipient.address
|
2024-03-02 10:48:11 +00:00
|
|
|
|
|
|
|
// Resolve before using
|
2023-09-19 15:06:57 +00:00
|
|
|
if (!!root.selectedRecipient.ens && root.selectedRecipient.ens.length > 0) {
|
2024-03-02 10:48:11 +00:00
|
|
|
d.isPending = true
|
|
|
|
d.resolveENS(root.selectedRecipient.ens)
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
2023-09-19 15:06:57 +00:00
|
|
|
preferredChainIds = store.getShortChainIds(root.selectedRecipient.chainShortNames)
|
2023-07-05 19:32:02 +00:00
|
|
|
break
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
2024-07-02 11:19:37 +00:00
|
|
|
case Helpers.RecipientAddressObjectType.RecentsAddress: {
|
2023-06-29 17:35:18 +00:00
|
|
|
let isIncoming = root.selectedRecipient.txType === Constants.TransactionType.Receive
|
|
|
|
root.addressText = isIncoming ? root.selectedRecipient.sender : root.selectedRecipient.recipient
|
2023-04-18 16:05:24 +00:00
|
|
|
root.item.input.text = root.addressText
|
2023-09-19 15:06:57 +00:00
|
|
|
break
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
2024-07-02 11:19:37 +00:00
|
|
|
case Helpers.RecipientAddressObjectType.Address: {
|
|
|
|
root.addressText = root.selectedRecipient
|
|
|
|
root.item.input.text = root.addressText
|
2023-07-05 19:32:02 +00:00
|
|
|
break
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-19 15:06:57 +00:00
|
|
|
|
|
|
|
// set preferred chains
|
2024-03-05 09:27:40 +00:00
|
|
|
if(!isCollectiblesTransfer) {
|
2023-09-19 15:06:57 +00:00
|
|
|
if(root.isBridgeTx)
|
|
|
|
root.store.setAllNetworksAsRoutePreferredChains()
|
|
|
|
else
|
|
|
|
root.store.updateRoutePreferredChains(preferredChainIds)
|
|
|
|
}
|
|
|
|
|
|
|
|
recalculateRoutesAndFees()
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
property bool isAddressValid: Utils.isValidAddress(root.addressText)
|
2023-09-19 15:06:57 +00:00
|
|
|
readonly property var resolveENS: Backpressure.debounce(root, 1500, function (ensName) {
|
2023-04-18 16:05:24 +00:00
|
|
|
store.resolveENS(ensName)
|
|
|
|
})
|
|
|
|
property bool isPending: false
|
|
|
|
function clearValues() {
|
|
|
|
root.addressText = ""
|
|
|
|
root.resolvedENSAddress = ""
|
2024-07-02 11:19:37 +00:00
|
|
|
root.selectedRecipientType = Helpers.RecipientAddressObjectType.Address
|
2023-04-18 16:05:24 +00:00
|
|
|
root.selectedRecipient = null
|
|
|
|
}
|
|
|
|
property Timer waitTimer: Timer {
|
|
|
|
interval: 1500
|
2023-09-19 15:06:57 +00:00
|
|
|
onTriggered: d.evaluateAndSetPreferredChains()
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
|
2023-09-19 15:06:57 +00:00
|
|
|
function evaluateAndSetPreferredChains() {
|
|
|
|
let address = !!root.item.input && !!root.store.plainText(root.item.input.text) ? root.store.plainText(root.item.input.text): ""
|
2024-03-05 09:27:40 +00:00
|
|
|
let result = store.splitAndFormatAddressPrefix(address, !root.isBridgeTx && !isCollectiblesTransfer)
|
2023-09-19 15:06:57 +00:00
|
|
|
if(!!result.address) {
|
|
|
|
root.addressText = result.address
|
2024-06-27 10:57:52 +00:00
|
|
|
if(!!root.item.input) {
|
2023-09-19 15:06:57 +00:00
|
|
|
root.item.input.text = result.formattedText
|
2024-06-27 10:57:52 +00:00
|
|
|
root.item.input.edit.cursorPosition = root.item.input.edit.length
|
|
|
|
}
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
2023-09-19 15:06:57 +00:00
|
|
|
root.recalculateRoutesAndFees()
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 11:19:37 +00:00
|
|
|
sourceComponent: root.selectedRecipientType === Helpers.RecipientAddressObjectType.SavedAddress
|
2023-09-27 13:41:55 +00:00
|
|
|
? savedAddressRecipient
|
2024-07-02 11:19:37 +00:00
|
|
|
: root.selectedRecipientType === Helpers.RecipientAddressObjectType.Account
|
2023-09-27 13:41:55 +00:00
|
|
|
? myAccountRecipient : addressRecipient
|
2023-04-18 16:05:24 +00:00
|
|
|
|
|
|
|
Component {
|
|
|
|
id: savedAddressRecipient
|
|
|
|
SavedAddressListItem {
|
|
|
|
property string chainShortNames: !!modelData ? modelData.chainShortNames: ""
|
|
|
|
implicitWidth: parent.width
|
|
|
|
modelData: root.selectedRecipient
|
|
|
|
radius: 8
|
|
|
|
clearVisible: true
|
|
|
|
color: Theme.palette.indirectColor1
|
|
|
|
sensor.enabled: false
|
|
|
|
subTitle: {
|
|
|
|
if(!!modelData) {
|
|
|
|
if (!!modelData && !!modelData.ens && modelData.ens.length > 0)
|
|
|
|
return Utils.richColorText(modelData.ens, Theme.palette.directColor1)
|
|
|
|
else
|
|
|
|
return WalletUtils.colorizedChainPrefix(modelData.chainShortNames) + StatusQUtils.Utils.elideText(modelData.address,6,4)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
onCleared: d.clearValues()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: myAccountRecipient
|
2024-06-07 12:27:56 +00:00
|
|
|
SharedControls.WalletAccountListItem {
|
|
|
|
id: accountItem
|
|
|
|
readonly property var modelData: root.selectedRecipient
|
|
|
|
|
|
|
|
name: !!modelData ? modelData.name : ""
|
|
|
|
address: !!modelData ? modelData.address : ""
|
|
|
|
chainShortNames: !!modelData ? store.getNetworkShortNames(modelData.preferredSharingChainIds) : ""
|
|
|
|
emoji: !!modelData ? modelData.emoji : ""
|
|
|
|
walletColor: !!modelData ? Utils.getColorForId(modelData.colorId): ""
|
|
|
|
currencyBalance: !!modelData ? modelData.currencyBalance : ""
|
|
|
|
walletType: !!modelData ? modelData.walletType : ""
|
|
|
|
migratedToKeycard: !!modelData ? modelData.migratedToKeycard ?? false : false
|
|
|
|
accountBalance: !!modelData ? modelData.accountBalance : null
|
|
|
|
|
2023-04-18 16:05:24 +00:00
|
|
|
implicitWidth: parent.width
|
|
|
|
radius: 8
|
|
|
|
clearVisible: true
|
|
|
|
color: Theme.palette.indirectColor1
|
|
|
|
sensor.enabled: false
|
|
|
|
subTitle: {
|
|
|
|
if(!!modelData) {
|
2024-06-07 12:27:56 +00:00
|
|
|
const elidedAddress = StatusQUtils.Utils.elideAndFormatWalletAddress(modelData.address)
|
|
|
|
return WalletUtils.colorizedChainPrefix(accountItem.chainShortNames) + elidedAddress
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
onCleared: d.clearValues()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: addressRecipient
|
2024-07-05 13:42:42 +00:00
|
|
|
SendRecipientInput {
|
2023-04-18 16:05:24 +00:00
|
|
|
width: parent.width
|
|
|
|
height: visible ? implicitHeight: 0
|
|
|
|
visible: !root.isBridgeTx && !!root.selectedAsset
|
2024-06-27 10:57:52 +00:00
|
|
|
text: root.addressText
|
|
|
|
|
|
|
|
function validateInput() {
|
2024-07-05 13:42:42 +00:00
|
|
|
const plainText = store.plainText(text)
|
2024-06-27 10:57:52 +00:00
|
|
|
root.isLoading()
|
|
|
|
if (Utils.isValidEns(plainText)) {
|
|
|
|
d.isPending = true
|
|
|
|
d.resolveENS(plainText)
|
|
|
|
} else {
|
|
|
|
d.waitTimer.restart()
|
|
|
|
}
|
|
|
|
}
|
2023-04-18 16:05:24 +00:00
|
|
|
|
2024-07-05 13:42:42 +00:00
|
|
|
interactive: root.interactive
|
|
|
|
checkMarkVisible: root.ready
|
|
|
|
onClearClicked: d.clearValues()
|
|
|
|
onValidateInputRequested: validateInput()
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: store.mainModuleInst
|
|
|
|
function onResolvedENS(resolvedPubKey: string, resolvedAddress: string, uuid: string) {
|
|
|
|
d.isPending = false
|
|
|
|
if(Utils.isValidAddress(resolvedAddress)) {
|
|
|
|
root.resolvedENSAddress = resolvedAddress
|
2023-09-19 15:06:57 +00:00
|
|
|
root.addressText = root.resolvedENSAddress
|
|
|
|
if(!!root.item.input)
|
|
|
|
root.item.input.text = root.resolvedENSAddress
|
|
|
|
d.evaluateAndSetPreferredChains()
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|