2024-09-18 08:04:59 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2023-04-18 16:05:24 +00:00
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core 0.1
|
2024-07-12 09:46:43 +00:00
|
|
|
import StatusQ.Core.Backpressure 0.1
|
2023-04-18 16:05:24 +00:00
|
|
|
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
|
|
|
|
2024-09-18 08:04:59 +00:00
|
|
|
readonly property bool ready: d.isAddressValid && !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-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
|
|
|
|
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-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
|
2024-09-17 17:41:04 +00:00
|
|
|
|
|
|
|
// Resolve before using
|
|
|
|
if (Utils.isValidEns(root.selectedRecipient)) {
|
|
|
|
d.isPending = true
|
|
|
|
d.resolveENS(root.selectedRecipient)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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
|
2024-10-04 15:23:26 +00:00
|
|
|
root.store.updateRoutePreferredChains([])
|
2023-09-19 15:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recalculateRoutesAndFees()
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
2024-09-18 08:04:59 +00:00
|
|
|
readonly 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() {
|
2024-10-08 11:20:50 +00:00
|
|
|
const plainText = StatusQUtils.StringUtils.plainText(root.item.input.text)
|
|
|
|
const address = !!root.item.input && !!plainText ? plainText: ""
|
|
|
|
const result = root.store.splitAndFormatAddressPrefix(address, !root.isBridgeTx && !root.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 {
|
|
|
|
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
|
2024-10-03 20:13:01 +00:00
|
|
|
return StatusQUtils.Utils.elideText(modelData.address,6,4)
|
2023-04-18 16:05:24 +00:00
|
|
|
}
|
|
|
|
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 : ""
|
|
|
|
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-10-04 15:23:26 +00:00
|
|
|
return StatusQUtils.Utils.elideAndFormatWalletAddress(modelData.address)
|
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
|
2024-07-09 22:10:13 +00:00
|
|
|
visible: !root.isBridgeTx
|
2024-06-27 10:57:52 +00:00
|
|
|
text: root.addressText
|
|
|
|
|
|
|
|
function validateInput() {
|
2024-10-08 11:20:50 +00:00
|
|
|
const plainText = StatusQUtils.StringUtils.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
|
2024-09-18 08:04:59 +00:00
|
|
|
loading: d.isPending || d.waitTimer.running
|
2024-07-05 13:42:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|