2024-05-28 17:39:41 +00:00
|
|
|
import QtQuick 2.15
|
2024-05-13 17:23:01 +00:00
|
|
|
import QtQuick.Layouts 1.15
|
2024-06-04 11:58:37 +00:00
|
|
|
import QtQml.Models 2.15
|
2024-05-13 17:23:01 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
2024-06-10 12:51:33 +00:00
|
|
|
import StatusQ.Controls 0.1
|
2024-05-13 17:23:01 +00:00
|
|
|
import StatusQ.Core 0.1
|
2024-07-12 09:46:43 +00:00
|
|
|
import StatusQ.Core.Backpressure 0.1
|
2024-05-13 17:23:01 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2024-06-10 12:51:33 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
2024-05-13 17:23:01 +00:00
|
|
|
import StatusQ.Popups.Dialog 0.1
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
import shared.popups.send.controls 1.0
|
2024-06-06 14:05:31 +00:00
|
|
|
import shared.controls 1.0
|
2024-05-15 21:22:13 +00:00
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
import AppLayouts.Wallet.controls 1.0
|
2024-06-13 00:45:33 +00:00
|
|
|
import AppLayouts.Wallet.panels 1.0
|
2024-08-06 16:04:22 +00:00
|
|
|
import AppLayouts.Wallet.popups.buy 1.0
|
2024-05-29 15:42:26 +00:00
|
|
|
|
2024-05-13 17:23:01 +00:00
|
|
|
StatusDialog {
|
|
|
|
id: root
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
/* This should be the only property which should be used to input
|
|
|
|
parameters to the modal when being launched from elsewhere */
|
|
|
|
required property SwapInputParamsForm swapInputParamsForm
|
|
|
|
required property SwapModalAdaptor swapAdaptor
|
2024-07-10 18:35:24 +00:00
|
|
|
required property int loginType
|
2024-05-15 21:22:13 +00:00
|
|
|
|
|
|
|
objectName: "swapModal"
|
2024-05-13 17:23:01 +00:00
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
implicitWidth: 556
|
2024-06-25 11:17:13 +00:00
|
|
|
padding: 0
|
2024-05-29 15:42:26 +00:00
|
|
|
backgroundColor: Theme.palette.baseColor3
|
2024-05-13 17:23:01 +00:00
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
2024-06-25 11:17:13 +00:00
|
|
|
property var debounceFetchSuggestedRoutes: Backpressure.debounce(root, 1000, function() {
|
|
|
|
root.swapAdaptor.fetchSuggestedRoutes(payPanel.rawValue)
|
|
|
|
})
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-07-03 22:08:03 +00:00
|
|
|
property Timer autoRefreshTimer: Timer {
|
|
|
|
interval: root.swapInputParamsForm.autoRefreshTime
|
|
|
|
running: false
|
|
|
|
repeat: false
|
2024-07-25 10:23:00 +00:00
|
|
|
onTriggered: {
|
|
|
|
if(!root.swapAdaptor.swapProposalLoading && !root.swapAdaptor.approvalPending) {
|
|
|
|
d.fetchSuggestedRoutes()
|
|
|
|
}
|
|
|
|
}
|
2024-07-03 22:08:03 +00:00
|
|
|
}
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
function fetchSuggestedRoutes() {
|
2024-07-10 19:30:42 +00:00
|
|
|
if (root.swapInputParamsForm.isFormFilledCorrectly()) {
|
2024-06-14 11:34:20 +00:00
|
|
|
root.swapAdaptor.swapProposalLoading = true
|
|
|
|
}
|
2024-07-16 15:19:56 +00:00
|
|
|
root.swapAdaptor.validSwapProposalReceived = false
|
|
|
|
root.swapAdaptor.approvalPending = false
|
|
|
|
root.swapAdaptor.approvalSuccessful = false
|
|
|
|
root.swapAdaptor.swapOutputData.resetPathInfoAndError()
|
|
|
|
debounceFetchSuggestedRoutes()
|
2024-06-13 00:45:33 +00:00
|
|
|
}
|
2024-07-19 03:36:36 +00:00
|
|
|
|
|
|
|
readonly property bool isError: root.swapAdaptor.errorMessage !== ""
|
2024-08-06 16:04:22 +00:00
|
|
|
|
|
|
|
readonly property BuyCryptoParamsForm buyFormData: BuyCryptoParamsForm {
|
|
|
|
selectedWalletAddress: root.swapInputParamsForm.selectedAccountAddress
|
|
|
|
selectedNetworkChainId: root.swapInputParamsForm.selectedNetworkChainId
|
|
|
|
selectedTokenKey: root.swapInputParamsForm.fromTokensKey
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.swapInputParamsForm
|
|
|
|
function onFormValuesChanged() {
|
|
|
|
d.fetchSuggestedRoutes()
|
|
|
|
}
|
2024-08-14 13:04:28 +00:00
|
|
|
|
|
|
|
// FIXME drop after SwapInputPanel uses ModelEntry to track the currently selected token
|
2024-06-13 00:45:33 +00:00
|
|
|
// refresh the selected asset in payPanel when account/network changes
|
|
|
|
function onSelectedAccountAddressChanged() {
|
|
|
|
payPanel.reevaluateSelectedId()
|
|
|
|
}
|
|
|
|
function onSelectedNetworkChainIdChanged() {
|
2024-06-18 22:51:49 +00:00
|
|
|
networkFilter.selection = [root.swapInputParamsForm.selectedNetworkChainId]
|
2024-06-13 00:45:33 +00:00
|
|
|
payPanel.reevaluateSelectedId()
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 13:52:10 +00:00
|
|
|
Connections {
|
|
|
|
target: root.swapAdaptor
|
|
|
|
function onApprovalSuccessfulChanged() {
|
|
|
|
// perform a recalculation to make sure expected outcome shown is accurate
|
|
|
|
if(root.swapAdaptor.approvalSuccessful) {
|
|
|
|
d.fetchSuggestedRoutes()
|
|
|
|
}
|
|
|
|
}
|
2024-07-03 22:08:03 +00:00
|
|
|
function onSuggestedRoutesReady() {
|
2024-07-25 10:23:00 +00:00
|
|
|
d.autoRefreshTimer.restart()
|
2024-07-03 22:08:03 +00:00
|
|
|
}
|
2024-07-24 20:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// needed as the first time the value not loaded correctly without this Binding
|
|
|
|
Binding {
|
|
|
|
target: root.swapAdaptor
|
|
|
|
property: "amountEnteredGreaterThanBalance"
|
|
|
|
value: payPanel.amountEnteredGreaterThanBalance
|
2024-06-24 13:52:10 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 11:58:37 +00:00
|
|
|
Behavior on implicitHeight {
|
|
|
|
NumberAnimation { duration: 1000; easing.type: Easing.OutExpo; alwaysRunToEnd: true}
|
|
|
|
}
|
2024-06-18 22:51:49 +00:00
|
|
|
|
2024-07-15 17:09:21 +00:00
|
|
|
onOpened: payPanel.forceActiveFocus()
|
2024-08-30 09:16:40 +00:00
|
|
|
onClosed: {
|
|
|
|
root.swapAdaptor.stopUpdatesForSuggestedRoute()
|
|
|
|
root.swapAdaptor.reset()
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
header: Item {
|
2024-06-20 14:32:56 +00:00
|
|
|
implicitHeight: selector.implicitHeight
|
|
|
|
implicitWidth: selector.implicitWidth
|
2024-05-15 21:22:13 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: -height - 18
|
2024-06-07 12:27:56 +00:00
|
|
|
AccountSelectorHeader {
|
|
|
|
id: selector
|
|
|
|
control.popup.width: 512
|
|
|
|
model: root.swapAdaptor.nonWatchAccounts
|
|
|
|
selectedAddress: root.swapInputParamsForm.selectedAccountAddress
|
|
|
|
onCurrentAccountAddressChanged: {
|
|
|
|
if (currentAccountAddress !== "" && currentAccountAddress !== root.swapInputParamsForm.selectedAccountAddress) {
|
|
|
|
root.swapInputParamsForm.selectedAccountAddress = currentAccountAddress
|
|
|
|
}
|
|
|
|
}
|
2024-07-15 17:09:21 +00:00
|
|
|
control.popup.onClosed: payPanel.forceActiveFocus()
|
2024-05-15 21:22:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
StatusScrollView {
|
|
|
|
anchors.fill: parent
|
|
|
|
contentWidth: availableWidth
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: Style.current.xlPadding
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.halfPadding
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.halfPadding
|
|
|
|
spacing: Style.current.padding
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
// without this Column, the whole popup resizing when the network selector popup is clicked
|
|
|
|
Column {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
spacing: 0
|
|
|
|
RowLayout {
|
|
|
|
width: parent.width
|
|
|
|
spacing: 12
|
|
|
|
HeaderTitleText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
|
|
|
|
text: qsTr("Swap")
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
|
|
|
text: qsTr("On:")
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: 13
|
|
|
|
lineHeight: 38
|
|
|
|
lineHeightMode: Text.FixedHeight
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
}
|
|
|
|
NetworkFilter {
|
|
|
|
id: networkFilter
|
|
|
|
objectName: "networkFilter"
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
multiSelection: false
|
|
|
|
showSelectionIndicator: false
|
|
|
|
showTitle: false
|
|
|
|
flatNetworks: root.swapAdaptor.filteredFlatNetworksModel
|
|
|
|
selection: [root.swapInputParamsForm.selectedNetworkChainId]
|
|
|
|
onSelectionChanged: {
|
|
|
|
if (root.swapInputParamsForm.selectedNetworkChainId !== selection[0]) {
|
|
|
|
root.swapInputParamsForm.selectedNetworkChainId = selection[0]
|
2024-07-03 16:29:30 +00:00
|
|
|
if(!!root.swapAdaptor.fromToken && !!root.swapAdaptor.fromToken.addressPerChain) {
|
|
|
|
let fromTokenAddressOnSelectedChain = SQUtils.ModelUtils.getByKey(
|
|
|
|
root.swapAdaptor.fromToken.addressPerChain, "chainId",
|
|
|
|
root.swapInputParamsForm.selectedNetworkChainId, "address")
|
|
|
|
if(!fromTokenAddressOnSelectedChain) {
|
|
|
|
// reset from token as it doesnt exist on selected network
|
|
|
|
root.swapInputParamsForm.resetFromTokenValues()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!!root.swapAdaptor.toToken && !!root.swapAdaptor.toToken.addressPerChain) {
|
|
|
|
let toTokenAddressOnSelectedChain = SQUtils.ModelUtils.getByKey(
|
|
|
|
root.swapAdaptor.toToken.addressPerChain, "chainId",
|
|
|
|
root.swapInputParamsForm.selectedNetworkChainId, "address")
|
|
|
|
if(!toTokenAddressOnSelectedChain) {
|
|
|
|
// reset to token as it doesnt exist on selected network
|
|
|
|
root.swapInputParamsForm.resetToTokenValues(false)
|
|
|
|
}
|
|
|
|
}
|
2024-06-25 11:17:13 +00:00
|
|
|
}
|
2024-07-15 17:09:21 +00:00
|
|
|
payPanel.forceActiveFocus()
|
2024-06-15 21:33:12 +00:00
|
|
|
}
|
2024-06-07 12:27:56 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-29 15:42:26 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.margins: 2
|
|
|
|
Layout.preferredHeight: payPanel.height + receivePanel.height + 4
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
SwapInputPanel {
|
|
|
|
id: payPanel
|
|
|
|
objectName: "payPanel"
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
top: parent.top
|
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
currencyStore: root.swapAdaptor.currencyStore
|
|
|
|
flatNetworksModel: root.swapAdaptor.swapStore.flatNetworks
|
|
|
|
processedAssetsModel: root.swapAdaptor.walletAssetsStore.groupedAccountAssetsModel
|
2024-07-03 16:29:30 +00:00
|
|
|
plainTokensBySymbolModel: root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
tokenKey: root.swapInputParamsForm.fromTokensKey
|
|
|
|
tokenAmount: root.swapInputParamsForm.fromTokenAmount
|
2024-06-18 22:51:49 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
selectedNetworkChainId: root.swapInputParamsForm.selectedNetworkChainId
|
|
|
|
selectedAccountAddress: root.swapInputParamsForm.selectedAccountAddress
|
|
|
|
nonInteractiveTokensKey: receivePanel.selectedHoldingId
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
swapSide: SwapInputPanel.SwapSide.Pay
|
|
|
|
swapExchangeButtonWidth: swapExchangeButton.width
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-08-30 09:16:40 +00:00
|
|
|
bottomTextLoading: root.swapAdaptor.swapProposalLoading
|
|
|
|
|
2024-07-24 00:33:26 +00:00
|
|
|
onSelectedHoldingIdChanged: root.swapInputParamsForm.fromTokensKey = selectedHoldingId
|
|
|
|
|
2024-06-25 13:37:42 +00:00
|
|
|
onRawValueChanged: {
|
2024-06-25 11:17:13 +00:00
|
|
|
if(root.swapInputParamsForm.fromTokensKey === selectedHoldingId) {
|
2024-06-25 13:37:42 +00:00
|
|
|
const amount = !tokenAmount && value === 0 ? "" :
|
|
|
|
SQUtils.AmountsArithmetic.div(SQUtils.AmountsArithmetic.fromString(rawValue),
|
|
|
|
SQUtils.AmountsArithmetic.fromNumber(1, rawValueMultiplierIndex)).toString()
|
|
|
|
root.swapInputParamsForm.fromTokenAmount = amount
|
2024-06-25 11:17:13 +00:00
|
|
|
}
|
2024-06-18 17:24:07 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
SwapInputPanel {
|
|
|
|
id: receivePanel
|
|
|
|
objectName: "receivePanel"
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
bottom: parent.bottom
|
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
currencyStore: root.swapAdaptor.currencyStore
|
|
|
|
flatNetworksModel: root.swapAdaptor.swapStore.flatNetworks
|
|
|
|
processedAssetsModel: root.swapAdaptor.walletAssetsStore.groupedAccountAssetsModel
|
2024-07-03 16:29:30 +00:00
|
|
|
plainTokensBySymbolModel: root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
tokenKey: root.swapInputParamsForm.toTokenKey
|
|
|
|
tokenAmount: root.swapAdaptor.validSwapProposalReceived && root.swapAdaptor.toToken ? root.swapAdaptor.swapOutputData.toTokenAmount: root.swapInputParamsForm.toTokenAmount
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
selectedNetworkChainId: root.swapInputParamsForm.selectedNetworkChainId
|
|
|
|
selectedAccountAddress: root.swapInputParamsForm.selectedAccountAddress
|
|
|
|
nonInteractiveTokensKey: payPanel.selectedHoldingId
|
2024-06-18 22:51:49 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
swapSide: SwapInputPanel.SwapSide.Receive
|
|
|
|
swapExchangeButtonWidth: swapExchangeButton.width
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
mainInputLoading: root.swapAdaptor.swapProposalLoading
|
|
|
|
bottomTextLoading: root.swapAdaptor.swapProposalLoading
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-07-24 00:33:26 +00:00
|
|
|
onSelectedHoldingIdChanged: root.swapInputParamsForm.toTokenKey = selectedHoldingId
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
/* TODO: keep this input as disabled until the work for adding a param to handle to
|
|
|
|
and from tokens inputed is supported by backend under
|
|
|
|
https://github.com/status-im/status-desktop/issues/15095 */
|
|
|
|
interactive: false
|
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
SwapExchangeButton {
|
|
|
|
id: swapExchangeButton
|
|
|
|
objectName: "swapExchangeButton"
|
|
|
|
anchors.centerIn: parent
|
2024-07-24 00:33:26 +00:00
|
|
|
enabled: !!root.swapInputParamsForm.fromTokensKey || !!root.swapInputParamsForm.toTokenKey
|
2024-06-25 11:17:13 +00:00
|
|
|
onClicked: {
|
|
|
|
const tempPayToken = root.swapInputParamsForm.fromTokensKey
|
|
|
|
const tempPayAmount = root.swapInputParamsForm.fromTokenAmount
|
|
|
|
root.swapInputParamsForm.fromTokensKey = root.swapInputParamsForm.toTokenKey
|
|
|
|
root.swapInputParamsForm.fromTokenAmount = !!root.swapAdaptor.swapOutputData.toTokenAmount ? root.swapAdaptor.swapOutputData.toTokenAmount : root.swapInputParamsForm.toTokenAmount
|
|
|
|
root.swapInputParamsForm.toTokenKey = tempPayToken
|
|
|
|
root.swapInputParamsForm.toTokenAmount = tempPayAmount
|
2024-07-03 22:08:03 +00:00
|
|
|
payPanel.forceActiveFocus()
|
2024-06-25 11:17:13 +00:00
|
|
|
}
|
2024-06-18 17:24:07 +00:00
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
EditSlippagePanel {
|
|
|
|
id: editSlippagePanel
|
|
|
|
objectName: "editSlippagePanel"
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: Style.current.padding
|
|
|
|
visible: editSlippageButton.checked
|
|
|
|
selectedToToken: root.swapAdaptor.toToken
|
|
|
|
toTokenAmount: root.swapAdaptor.swapOutputData.toTokenAmount
|
|
|
|
loading: root.swapAdaptor.swapProposalLoading
|
|
|
|
onSlippageValueChanged: {
|
|
|
|
root.swapInputParamsForm.selectedSlippage = slippageValue
|
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
|
2024-06-25 11:17:13 +00:00
|
|
|
ErrorTag {
|
|
|
|
objectName: "errorTag"
|
2024-07-19 03:36:36 +00:00
|
|
|
visible: d.isError
|
2024-07-23 22:38:10 +00:00
|
|
|
Layout.maximumWidth: parent.width
|
2024-06-25 11:17:13 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.topMargin: Style.current.smallPadding
|
2024-07-19 03:36:36 +00:00
|
|
|
text: root.swapAdaptor.errorMessage
|
|
|
|
buttonText: root.swapAdaptor.isTokenBalanceInsufficient ? qsTr("Buy crypto") : qsTr("Buy ETH")
|
|
|
|
buttonVisible: visible && (root.swapAdaptor.isTokenBalanceInsufficient || root.swapAdaptor.isEthBalanceInsufficient)
|
2024-08-06 16:04:22 +00:00
|
|
|
onButtonClicked: {
|
|
|
|
// value dont update correctly if not done from here
|
|
|
|
d.buyFormData.selectedWalletAddress = root.swapInputParamsForm.selectedAccountAddress
|
|
|
|
d.buyFormData.selectedNetworkChainId = root.swapInputParamsForm.selectedNetworkChainId
|
|
|
|
d.buyFormData.selectedTokenKey =root.swapInputParamsForm.fromTokensKey
|
|
|
|
Global.openBuyCryptoModalRequested(d.buyFormData)
|
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
footer: StatusDialogFooter {
|
|
|
|
color: Theme.palette.baseColor3
|
|
|
|
dropShadowEnabled: true
|
|
|
|
leftButtons: ObjectModel {
|
|
|
|
ColumnLayout {
|
|
|
|
Layout.leftMargin: Style.current.padding
|
|
|
|
spacing: 0
|
|
|
|
StatusBaseText {
|
|
|
|
objectName: "maxSlippageText"
|
|
|
|
text: qsTr("Max slippage:")
|
|
|
|
color: Theme.palette.directColor5
|
|
|
|
font.weight: Font.Medium
|
|
|
|
}
|
|
|
|
RowLayout {
|
|
|
|
StatusBaseText {
|
|
|
|
objectName: "maxSlippageValue"
|
2024-09-25 10:40:25 +00:00
|
|
|
text: editSlippagePanel.valid ? "%1%".arg(LocaleUtils.numberToLocaleString(root.swapInputParamsForm.selectedSlippage))
|
|
|
|
: qsTr("N/A")
|
2024-06-04 11:58:37 +00:00
|
|
|
color: Theme.palette.directColor4
|
|
|
|
font.weight: Font.Medium
|
|
|
|
}
|
|
|
|
StatusFlatButton {
|
|
|
|
id: editSlippageButton
|
|
|
|
objectName: "editSlippageButton"
|
|
|
|
checkable: true
|
|
|
|
checked: false
|
|
|
|
icon.name: "edit_pencil"
|
|
|
|
textColor: editSlippageButton.hovered ? Theme.palette.directColor1 : Theme.palette.directColor5
|
|
|
|
size: StatusBaseButton.Size.Tiny
|
|
|
|
hoverColor: Theme.palette.transparent
|
|
|
|
visible: !checked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rightButtons: ObjectModel {
|
|
|
|
RowLayout {
|
|
|
|
Layout.rightMargin: Style.current.padding
|
|
|
|
spacing: Style.current.bigPadding
|
|
|
|
ColumnLayout {
|
|
|
|
StatusBaseText {
|
2024-06-06 14:05:31 +00:00
|
|
|
objectName: "maxFeesText"
|
|
|
|
text: qsTr("Max fees:")
|
2024-06-04 11:58:37 +00:00
|
|
|
color: Theme.palette.directColor5
|
|
|
|
font.weight: Font.Medium
|
|
|
|
}
|
|
|
|
StatusTextWithLoadingState {
|
2024-06-06 14:05:31 +00:00
|
|
|
objectName: "maxFeesValue"
|
2024-06-24 13:52:10 +00:00
|
|
|
text: {
|
|
|
|
if(root.swapAdaptor.swapProposalLoading) {
|
|
|
|
return Constants.dummyText
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root.swapAdaptor.validSwapProposalReceived) {
|
2024-07-10 22:03:37 +00:00
|
|
|
return root.swapAdaptor.currencyStore.formatCurrencyAmount(
|
|
|
|
root.swapAdaptor.swapOutputData.totalFees,
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency)
|
2024-06-24 13:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "--"
|
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
customColor: Theme.palette.directColor4
|
|
|
|
font.weight: Font.Medium
|
|
|
|
loading: root.swapAdaptor.swapProposalLoading
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatusButton {
|
|
|
|
objectName: "signButton"
|
2024-06-24 13:52:10 +00:00
|
|
|
readonly property string fromTokenSymbol: !!root.swapAdaptor.fromToken ? root.swapAdaptor.fromToken.symbol ?? "" : ""
|
2024-08-19 09:00:35 +00:00
|
|
|
loadingWithText: root.swapAdaptor.approvalPending
|
2024-07-10 18:35:24 +00:00
|
|
|
icon.name: root.swapAdaptor.selectedAccount.migratedToKeycard ? Constants.authenticationIconByType[Constants.LoginType.Keycard]
|
|
|
|
: Constants.authenticationIconByType[root.loginType]
|
2024-06-24 13:52:10 +00:00
|
|
|
text: {
|
|
|
|
if(root.swapAdaptor.validSwapProposalReceived) {
|
|
|
|
if (root.swapAdaptor.approvalPending) {
|
|
|
|
return qsTr("Approving %1").arg(fromTokenSymbol)
|
|
|
|
} else if(root.swapAdaptor.swapOutputData.approvalNeeded) {
|
|
|
|
return qsTr("Approve %1").arg(fromTokenSymbol)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return qsTr("Swap")
|
|
|
|
}
|
|
|
|
tooltip.text: root.swapAdaptor.validSwapProposalReceived &&
|
|
|
|
root.swapAdaptor.swapOutputData.approvalNeeded ?
|
|
|
|
qsTr("Approve %1 spending cap to Swap").arg(fromTokenSymbol) : ""
|
2024-06-04 11:58:37 +00:00
|
|
|
disabledColor: Theme.palette.directColor8
|
2024-08-19 09:00:35 +00:00
|
|
|
interactive: root.swapAdaptor.validSwapProposalReceived &&
|
|
|
|
editSlippagePanel.valid &&
|
|
|
|
!d.isError &&
|
|
|
|
!root.swapAdaptor.approvalPending
|
2024-06-06 14:05:31 +00:00
|
|
|
onClicked: {
|
2024-07-01 22:35:10 +00:00
|
|
|
if (root.swapAdaptor.validSwapProposalReceived) {
|
2024-07-10 18:35:24 +00:00
|
|
|
if (root.swapAdaptor.swapOutputData.approvalNeeded)
|
|
|
|
Global.openPopup(swapApproveModalComponent)
|
|
|
|
else
|
|
|
|
Global.openPopup(swapSignModalComponent)
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-06 09:49:13 +00:00
|
|
|
}
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|
2024-06-24 13:52:10 +00:00
|
|
|
|
|
|
|
Component {
|
2024-07-10 18:35:24 +00:00
|
|
|
id: swapApproveModalComponent
|
|
|
|
SwapApproveCapModal {
|
2024-06-24 13:52:10 +00:00
|
|
|
destroyOnClose: true
|
2024-07-10 18:35:24 +00:00
|
|
|
|
2024-07-31 10:04:51 +00:00
|
|
|
formatBigNumber: (number, symbol, noSymbolOption) => root.swapAdaptor.currencyStore.formatBigNumber(number, symbol, noSymbolOption)
|
|
|
|
|
2024-07-10 18:35:24 +00:00
|
|
|
loginType: root.swapAdaptor.selectedAccount.migratedToKeycard ? Constants.LoginType.Keycard : root.loginType
|
|
|
|
feesLoading: root.swapAdaptor.swapProposalLoading
|
|
|
|
|
|
|
|
fromTokenSymbol: root.swapAdaptor.fromToken.symbol
|
|
|
|
fromTokenAmount: SQUtils.AmountsArithmetic.div(
|
|
|
|
SQUtils.AmountsArithmetic.fromString(root.swapAdaptor.swapOutputData.approvalAmountRequired),
|
|
|
|
SQUtils.AmountsArithmetic.fromNumber(1, root.swapAdaptor.fromToken.decimals ?? 18)).toFixed()
|
|
|
|
fromTokenContractAddress: SQUtils.ModelUtils.getByKey(root.swapAdaptor.fromToken.addressPerChain,
|
|
|
|
"chainId", root.swapInputParamsForm.selectedNetworkChainId,
|
|
|
|
"address")
|
|
|
|
|
|
|
|
accountName: root.swapAdaptor.selectedAccount.name
|
|
|
|
accountAddress: root.swapAdaptor.selectedAccount.address
|
|
|
|
accountEmoji: root.swapAdaptor.selectedAccount.emoji
|
|
|
|
accountColor: Utils.getColorForId(root.swapAdaptor.selectedAccount.colorId)
|
2024-07-15 11:17:42 +00:00
|
|
|
accountBalanceFormatted: root.swapAdaptor.selectedAccount.accountBalance.formattedBalance
|
2024-07-10 18:35:24 +00:00
|
|
|
|
|
|
|
networkShortName: networkFilter.singleSelectionItemData.shortName
|
|
|
|
networkName: networkFilter.singleSelectionItemData.chainName
|
|
|
|
networkIconPath: Style.svg(networkFilter.singleSelectionItemData.iconUrl)
|
|
|
|
networkBlockExplorerUrl: networkFilter.singleSelectionItemData.blockExplorerURL
|
|
|
|
|
|
|
|
fiatFees: {
|
|
|
|
const feesInFloat = root.swapAdaptor.currencyStore.getFiatValue(root.swapAdaptor.swapOutputData.approvalGasFees, Constants.ethToken)
|
|
|
|
return root.swapAdaptor.currencyStore.formatCurrencyAmount(feesInFloat, root.swapAdaptor.currencyStore.currentCurrency)
|
2024-06-24 13:52:10 +00:00
|
|
|
}
|
2024-07-31 10:04:51 +00:00
|
|
|
cryptoFees: root.swapAdaptor.currencyStore.formatCurrencyAmount(parseFloat(root.swapAdaptor.swapOutputData.approvalGasFees), Constants.ethToken)
|
2024-07-10 18:35:24 +00:00
|
|
|
estimatedTime: root.swapAdaptor.swapOutputData.estimatedTime
|
|
|
|
|
|
|
|
serviceProviderName: root.swapAdaptor.swapOutputData.txProviderName
|
2024-07-17 08:16:02 +00:00
|
|
|
serviceProviderURL: Constants.swap.paraswapUrl // TODO https://github.com/status-im/status-desktop/issues/15329
|
2024-08-08 13:52:19 +00:00
|
|
|
serviceProviderTandCUrl: Constants.swap.paraswapTermsAndConditionUrl // TODO https://github.com/status-im/status-desktop/issues/15329
|
2024-07-17 08:16:02 +00:00
|
|
|
serviceProviderIcon: Style.png("swap/%1".arg(Constants.swap.paraswapIcon)) // FIXME svg
|
2024-07-10 18:35:24 +00:00
|
|
|
serviceProviderContractAddress: root.swapAdaptor.swapOutputData.approvalContractAddress
|
2024-08-08 13:52:19 +00:00
|
|
|
serviceProviderHostname: Constants.swap.paraswapHostname
|
2024-07-10 18:35:24 +00:00
|
|
|
|
|
|
|
onAccepted: {
|
|
|
|
root.swapAdaptor.sendApproveTx()
|
2024-06-24 13:52:10 +00:00
|
|
|
}
|
2024-07-10 18:35:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: swapSignModalComponent
|
|
|
|
SwapSignModal {
|
|
|
|
destroyOnClose: true
|
|
|
|
|
2024-07-31 10:04:51 +00:00
|
|
|
formatBigNumber: (number, symbol, noSymbolOption) => root.swapAdaptor.currencyStore.formatBigNumber(number, symbol, noSymbolOption)
|
2024-07-17 16:03:36 +00:00
|
|
|
|
2024-07-10 18:35:24 +00:00
|
|
|
loginType: root.swapAdaptor.selectedAccount.migratedToKeycard ? Constants.LoginType.Keycard : root.loginType
|
|
|
|
feesLoading: root.swapAdaptor.swapProposalLoading
|
|
|
|
|
|
|
|
fromTokenSymbol: root.swapAdaptor.fromToken.symbol
|
|
|
|
fromTokenAmount: root.swapInputParamsForm.fromTokenAmount
|
|
|
|
fromTokenContractAddress: SQUtils.ModelUtils.getByKey(root.swapAdaptor.fromToken.addressPerChain,
|
|
|
|
"chainId", root.swapInputParamsForm.selectedNetworkChainId,
|
|
|
|
"address")
|
|
|
|
|
|
|
|
toTokenSymbol: root.swapAdaptor.toToken.symbol
|
|
|
|
toTokenAmount: root.swapAdaptor.swapOutputData.toTokenAmount
|
|
|
|
toTokenContractAddress: SQUtils.ModelUtils.getByKey(root.swapAdaptor.toToken.addressPerChain,
|
|
|
|
"chainId", root.swapInputParamsForm.selectedNetworkChainId,
|
|
|
|
"address")
|
|
|
|
|
|
|
|
accountName: root.swapAdaptor.selectedAccount.name
|
|
|
|
accountAddress: root.swapAdaptor.selectedAccount.address
|
|
|
|
accountEmoji: root.swapAdaptor.selectedAccount.emoji
|
|
|
|
accountColor: Utils.getColorForId(root.swapAdaptor.selectedAccount.colorId)
|
|
|
|
|
|
|
|
networkShortName: networkFilter.singleSelectionItemData.shortName
|
|
|
|
networkName: networkFilter.singleSelectionItemData.chainName
|
|
|
|
networkIconPath: Style.svg(networkFilter.singleSelectionItemData.iconUrl)
|
|
|
|
networkBlockExplorerUrl: networkFilter.singleSelectionItemData.blockExplorerURL
|
|
|
|
|
|
|
|
fiatFees: root.swapAdaptor.currencyStore.formatCurrencyAmount(root.swapAdaptor.swapOutputData.totalFees,
|
|
|
|
root.swapAdaptor.currencyStore.currentCurrency)
|
|
|
|
cryptoFees: {
|
|
|
|
const cryptoValue = root.swapAdaptor.currencyStore.getCryptoValue(root.swapAdaptor.swapOutputData.totalFees, Constants.ethToken)
|
|
|
|
return root.swapAdaptor.currencyStore.formatCurrencyAmount(cryptoValue, Constants.ethToken)
|
|
|
|
}
|
|
|
|
slippage: root.swapInputParamsForm.selectedSlippage
|
|
|
|
|
|
|
|
serviceProviderName: root.swapAdaptor.swapOutputData.txProviderName
|
2024-08-08 13:52:19 +00:00
|
|
|
serviceProviderURL: Constants.swap.paraswapUrl // TODO https://github.com/status-im/status-desktop/issues/15329
|
|
|
|
serviceProviderTandCUrl: Constants.swap.paraswapTermsAndConditionUrl // TODO https://github.com/status-im/status-desktop/issues/15329
|
2024-07-10 18:35:24 +00:00
|
|
|
|
|
|
|
onAccepted: {
|
|
|
|
root.swapAdaptor.sendSwapTx()
|
|
|
|
root.close()
|
2024-06-24 13:52:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|