feat(@desktop/wallet): Swap: Switch input/output params

fixes #14827
This commit is contained in:
Khushboo Mehta 2024-06-18 19:24:07 +02:00 committed by Khushboo-dev-cpp
parent 64efd47805
commit 5e8f7515cf
12 changed files with 237 additions and 88 deletions

View File

@ -36,6 +36,7 @@ SplitView {
fromTokenAmount: ctrlFromTokenAmount.text
toTokenKey: ctrlToTokenKey.text
toTokenAmount: ctrlToTokenAmount.text
defaultToTokenKey: "STT"
}
readonly property SwapModalAdaptor adaptor: SwapModalAdaptor {

View File

@ -96,11 +96,11 @@ SplitView {
closePolicy: Popup.CloseOnEscape
destroyOnClose: true
swapInputParamsForm: SwapInputParamsForm {
defaultToTokenKey: "STT"
onSelectedAccountAddressChanged: {
if (selectedAccountAddress !== accountComboBox.currentValue)
accountComboBox.currentIndex = accountComboBox.indexOfValue(selectedAccountAddress)
}
fromTokenAmount: swapInput.text
}
swapAdaptor: SwapModalAdaptor {
swapStore: dSwapStore

View File

@ -5,6 +5,7 @@ import StatusQ 0.1 // See #10218
import StatusQ.Core 0.1
import StatusQ.Core.Utils 0.1 as SQUtils
import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1
import QtQuick.Controls 2.15
@ -62,7 +63,9 @@ Item {
accountAddress: !!root.swapFormData && root.swapFormData.selectedAccountAddress
}
property SwapInputParamsForm swapFormData: SwapInputParamsForm { }
property SwapInputParamsForm swapFormData: SwapInputParamsForm {
defaultToTokenKey: "STT"
}
Component {
id: componentUnderTest
@ -108,6 +111,7 @@ Item {
controlUnderTest.close()
verify(!controlUnderTest.opened)
formValuesChanged.clear()
root.swapFormData.resetFormData()
}
function getAndVerifyAccountsModalHeader() {
@ -386,8 +390,6 @@ Item {
}
function test_network_and_account_header_items() {
root.swapFormData.fromTokensKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(0).key
// Launch popup
launchAndVerfyModal()
@ -415,6 +417,8 @@ Item {
mouseClick(delegateUnderTest)
}
root.swapFormData.fromTokensKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(0).key
// verify values in accouns modal header dropdown
const accountsModalHeader = getAndVerifyAccountsModalHeader()
launchAccountSelectionPopup(accountsModalHeader)
@ -544,13 +548,12 @@ Item {
root.swapFormData.fromTokensKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(0).key
compare(formValuesChanged.count, 1)
root.swapFormData.toTokenKey = root.swapAdaptor.walletAssetsStore.walletTokensStore.plainTokensBySymbolModel.get(1).key
compare(formValuesChanged.count, 2)
root.swapFormData.fromTokenAmount = "0.001"
compare(formValuesChanged.count, 3)
compare(formValuesChanged.count, 2)
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
compare(formValuesChanged.count, 4)
compare(formValuesChanged.count, 3)
root.swapFormData.selectedAccountAddress = root.swapAdaptor.nonWatchAccounts.get(0).address
compare(formValuesChanged.count, 5)
compare(formValuesChanged.count, 4)
// wait for fetchSuggestedRoutes function to be called
wait(1000)
@ -587,7 +590,7 @@ Item {
// edit some params to retry swap
root.swapFormData.fromTokenAmount = "0.00011"
compare(formValuesChanged.count, 6)
compare(formValuesChanged.count, 5)
// wait for fetchSuggestedRoutes function to be called
wait(1000)
@ -636,7 +639,7 @@ Item {
// edit some params to retry swap
root.swapFormData.fromTokenAmount = "0.012"
compare(formValuesChanged.count, 7)
compare(formValuesChanged.count, 6)
// wait for fetchSuggestedRoutes function to be called
wait(1000)
@ -696,8 +699,8 @@ Item {
verify(!!holdingSelector)
const maxTagButton = findChild(payPanel, "maxTagButton")
verify(!!maxTagButton)
const holdingSelectorsContentItemText = findChild(payPanel, "holdingSelectorsContentItemText")
verify(!!holdingSelectorsContentItemText)
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
verify(!!tokenSelectorContentItemText)
waitForRendering(payPanel)
@ -709,7 +712,7 @@ Item {
compare(amountToSendInput.input.placeholderText, LocaleUtils.numberToLocaleString(0))
compare(bottomItemText.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(0, root.swapAdaptor.currencyStore.currentCurrency))
compare(holdingSelector.currentTokensKey, "")
compare(holdingSelectorsContentItemText.text, qsTr("Select asset"))
compare(tokenSelectorContentItemText.text, qsTr("Select asset"))
verify(!maxTagButton.visible)
compare(payPanel.selectedHoldingId, "")
compare(payPanel.value, 0)
@ -745,10 +748,10 @@ Item {
verify(!!holdingSelector)
const maxTagButton = findChild(payPanel, "maxTagButton")
verify(!!maxTagButton)
const holdingSelectorsContentItemText = findChild(payPanel, "holdingSelectorsContentItemText")
verify(!!holdingSelectorsContentItemText)
const holdingSelectorsTokenIcon = findChild(payPanel, "holdingSelectorsTokenIcon")
verify(!!holdingSelectorsTokenIcon)
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
verify(!!tokenSelectorContentItemText)
const tokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
verify(!!tokenSelectorIcon)
compare(amountToSendInput.caption, qsTr("Pay"))
verify(amountToSendInput.interactive)
@ -757,9 +760,9 @@ Item {
tryCompare(amountToSendInput.input.input.edit, "cursorVisible", true)
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(valueToExchange * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
compare(holdingSelector.currentTokensKey, expectedToken.tokensKey)
compare(holdingSelectorsContentItemText.text, expectedToken.symbol)
compare(holdingSelectorsTokenIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
verify(holdingSelectorsTokenIcon.visible)
compare(tokenSelectorContentItemText.text, expectedToken.symbol)
compare(tokenSelectorIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
verify(tokenSelectorIcon.visible)
verify(maxTagButton.visible)
compare(maxTagButton.text, qsTr("Max. %1").arg(root.swapAdaptor.currencyStore.formatCurrencyAmount(WalletUtils.calculateMaxSafeSendAmount(expectedToken.currentBalance, expectedToken.symbol), expectedToken.symbol, {noSymbol: true})))
compare(payPanel.selectedHoldingId, expectedToken.symbol)
@ -793,8 +796,8 @@ Item {
verify(!!holdingSelector)
const maxTagButton = findChild(payPanel, "maxTagButton")
verify(!!maxTagButton)
const holdingSelectorsContentItemText = findChild(payPanel, "holdingSelectorsContentItemText")
verify(!!holdingSelectorsContentItemText)
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
verify(!!tokenSelectorContentItemText)
waitForRendering(payPanel)
@ -804,7 +807,7 @@ Item {
verify(amountToSendInput.input.input.edit.cursorVisible)
compare(bottomItemText.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(0, root.swapAdaptor.currencyStore.currentCurrency))
compare(holdingSelector.currentTokensKey, "")
compare(holdingSelectorsContentItemText.text, "Select asset")
compare(tokenSelectorContentItemText.text, "Select asset")
verify(!maxTagButton.visible)
compare(payPanel.selectedHoldingId, "")
compare(payPanel.value, 0)
@ -841,10 +844,10 @@ Item {
verify(!!holdingSelector)
const maxTagButton = findChild(payPanel, "maxTagButton")
verify(!!maxTagButton)
const holdingSelectorsContentItemText = findChild(payPanel, "holdingSelectorsContentItemText")
verify(!!holdingSelectorsContentItemText)
const holdingSelectorsTokenIcon = findChild(payPanel, "holdingSelectorsTokenIcon")
verify(!!holdingSelectorsTokenIcon)
const tokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
verify(!!tokenSelectorContentItemText)
const tokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
verify(!!tokenSelectorIcon)
compare(amountToSendInput.caption, qsTr("Pay"))
verify(amountToSendInput.interactive)
@ -853,9 +856,9 @@ Item {
verify(amountToSendInput.input.input.edit.cursorVisible)
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(valueToExchange * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
compare(holdingSelector.currentTokensKey, expectedToken.tokensKey)
compare(holdingSelectorsContentItemText.text, expectedToken.symbol)
compare(holdingSelectorsTokenIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
verify(holdingSelectorsTokenIcon.visible)
compare(tokenSelectorContentItemText.text, expectedToken.symbol)
compare(tokenSelectorIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
verify(tokenSelectorIcon.visible)
verify(maxTagButton.visible)
compare(maxTagButton.text, qsTr("Max. %1").arg(root.swapAdaptor.currencyStore.formatCurrencyAmount(WalletUtils.calculateMaxSafeSendAmount(expectedToken.currentBalance, expectedToken.symbol), expectedToken.symbol, {noSymbol: true})))
compare(payPanel.selectedHoldingId, expectedToken.symbol)
@ -866,7 +869,7 @@ Item {
closeAndVerfyModal()
}
function test_modal_pay_input_switching_networks() {
function test_modal_switching_networks() {
// try setting value before popup is launched and check values
let valueToExchange = 0.3
let valueToExchangeString = valueToExchange.toString()
@ -914,8 +917,8 @@ Item {
verify(!!holdingSelector)
const maxTagButton = findChild(receivePanel, "maxTagButton")
verify(!!maxTagButton)
const holdingSelectorsContentItemText = findChild(receivePanel, "holdingSelectorsContentItemText")
verify(!!holdingSelectorsContentItemText)
const tokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
verify(!!tokenSelectorContentItemText)
// check default states for the from input selector
compare(amountToSendInput.caption, qsTr("Receive"))
@ -926,7 +929,7 @@ Item {
compare(amountToSendInput.input.placeholderText, LocaleUtils.numberToLocaleString(0))
compare(bottomItemText.text, root.swapAdaptor.currencyStore.formatCurrencyAmount(0, root.swapAdaptor.currencyStore.currentCurrency))
compare(holdingSelector.currentTokensKey, "")
compare(holdingSelectorsContentItemText.text, qsTr("Select asset"))
compare(tokenSelectorContentItemText.text, qsTr("Select asset"))
verify(!maxTagButton.visible)
compare(receivePanel.selectedHoldingId, "")
compare(receivePanel.value, 0)
@ -962,10 +965,10 @@ Item {
verify(!!holdingSelector)
const maxTagButton = findChild(receivePanel, "maxTagButton")
verify(!!maxTagButton)
const holdingSelectorsContentItemText = findChild(receivePanel, "holdingSelectorsContentItemText")
verify(!!holdingSelectorsContentItemText)
const holdingSelectorsTokenIcon = findChild(receivePanel, "holdingSelectorsTokenIcon")
verify(!!holdingSelectorsTokenIcon)
const tokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
verify(!!tokenSelectorContentItemText)
const tokenSelectorIcon = findChild(receivePanel, "tokenSelectorIcon")
verify(!!tokenSelectorIcon)
compare(amountToSendInput.caption, qsTr("Receive"))
// TODO: this should be come interactive under https://github.com/status-im/status-desktop/issues/15095
@ -975,9 +978,9 @@ Item {
compare(amountToSendInput.input.placeholderText, LocaleUtils.numberToLocaleString(0))
tryCompare(bottomItemText, "text", root.swapAdaptor.currencyStore.formatCurrencyAmount(valueToReceive * expectedToken.marketDetails.currencyPrice.amount, root.swapAdaptor.currencyStore.currentCurrency))
compare(holdingSelector.currentTokensKey, expectedToken.tokensKey)
compare(holdingSelectorsContentItemText.text, expectedToken.symbol)
compare(holdingSelectorsTokenIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
verify(holdingSelectorsTokenIcon.visible)
compare(tokenSelectorContentItemText.text, expectedToken.symbol)
compare(tokenSelectorIcon.image.source, Constants.tokenIcon(expectedToken.symbol))
verify(tokenSelectorIcon.visible)
verify(!maxTagButton.visible)
compare(receivePanel.selectedHoldingId, expectedToken.symbol)
compare(receivePanel.value, valueToReceive)
@ -997,7 +1000,7 @@ Item {
root.swapFormData.fromTokenAmount = valueToExchangeString
root.swapFormData.toTokenKey = "STT"
compare(formValuesChanged.count, 6)
compare(formValuesChanged.count, 4)
// Launch popup
launchAndVerfyModal()
@ -1034,9 +1037,6 @@ Item {
mouseClick(maxTagButton)
waitForItemPolished(payPanel)
// FIXME flaky; value is 2 in isolation, 3 in TestCase run
//tryCompare(formValuesChanged, "count", 3)
verify(amountToSendInput.interactive)
verify(amountToSendInput.input.input.edit.cursorVisible)
tryCompare(amountToSendInput.input, "text", maxPossibleValue === 0 ? "" : maxPossibleValue.toLocaleString(Qt.locale(), 'f', -128))
@ -1058,7 +1058,7 @@ Item {
root.swapFormData.fromTokensKey = "ETH"
root.swapFormData.toTokenKey = "STT"
compare(formValuesChanged.count, 4)
compare(formValuesChanged.count, 3)
const payPanel = findChild(controlUnderTest, "payPanel")
verify(!!payPanel)
@ -1087,7 +1087,7 @@ Item {
maxTagButton.clicked()
waitForItemPolished(payPanel)
tryCompare(formValuesChanged, "count", 5)
tryCompare(formValuesChanged, "count", 4)
verify(amountToSendInput.interactive)
verify(amountToSendInput.input.input.edit.cursorVisible)
@ -1153,5 +1153,130 @@ Item {
closeAndVerfyModal()
}
}
function test_modal_exchange_button_default_state() {
let default_test_data = [{fromToken: "", fromTokenAmount: "", toToken: "", toTokenAmount: ""},
{fromToken: "", fromTokenAmount: "", toToken: "STT", toTokenAmount: ""},
{fromToken: "ETH", fromTokenAmount: "", toToken: "", toTokenAmount: ""},
{fromToken: "ETH", fromTokenAmount: "", toToken: "STT", toTokenAmount: ""},
{fromToken: "ETH", fromTokenAmount: "100", toToken: "STT", toTokenAmount: ""},
{fromToken: "ETH", fromTokenAmount: "", toToken: "STT", toTokenAmount: "50"},
{fromToken: "ETH", fromTokenAmount: "100", toToken: "STT", toTokenAmount: "50"},
{fromToken: "", fromTokenAmount: "", toToken: "", toTokenAmount: "50"},
{fromToken: "", fromTokenAmount: "100", toToken: "", toTokenAmount: ""}]
const payPanel = findChild(controlUnderTest, "payPanel")
verify(!!payPanel)
const receivePanel = findChild(controlUnderTest, "receivePanel")
verify(!!receivePanel)
const swapExchangeButton = findChild(controlUnderTest, "swapExchangeButton")
verify(!!swapExchangeButton)
const payAmountToSendInput = findChild(payPanel, "amountToSendInput")
verify(!!payAmountToSendInput)
const payBottomItemText = findChild(payPanel, "bottomItemText")
verify(!!payBottomItemText)
const maxTagButton = findChild(payPanel, "maxTagButton")
verify(!!maxTagButton)
const receiveAmountToSendInput = findChild(receivePanel, "amountToSendInput")
verify(!!receiveAmountToSendInput)
const receiveBottomItemText = findChild(receivePanel, "bottomItemText")
verify(!!receiveBottomItemText)
for (let i =0; i< default_test_data.length; i++) {
root.swapAdaptor.reset()
// set network and address by default same
root.swapFormData.selectedNetworkChainId = root.swapAdaptor.filteredFlatNetworksModel.get(0).chainId
root.swapFormData.selectedAccountAddress = root.swapAdaptor.nonWatchAccounts.get(0).address
root.swapFormData.fromTokensKey = default_test_data[i].fromToken
root.swapFormData.fromTokenAmount = default_test_data[i].fromTokenAmount
root.swapFormData.toTokenKey = default_test_data[i].toToken
root.swapFormData.toTokenAmount = default_test_data[i].toTokenAmount
let expectedFromTokenIcon = !!root.swapAdaptor.fromToken && !!root.swapAdaptor.fromToken.symbol ?
Constants.tokenIcon(root.swapAdaptor.fromToken.symbol): ""
let expectedToTokenIcon = !!root.swapAdaptor.toToken && !!root.swapAdaptor.toToken.symbol ?
Constants.tokenIcon(root.swapAdaptor.toToken.symbol): ""
// Launch popup
launchAndVerfyModal()
waitForRendering(payPanel)
waitForRendering(receivePanel)
let paytokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
verify(!!paytokenSelectorContentItemText)
let paytokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
compare(!!default_test_data[i].fromToken , !!paytokenSelectorIcon)
let receivetokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
verify(!!receivetokenSelectorContentItemText)
let receivetokenSelectorIcon = findChild(receivePanel, "tokenSelectorIcon")
compare(!!default_test_data[i].toToken, !!receivetokenSelectorIcon)
// verify pay values
compare(payPanel.tokenKey, default_test_data[i].fromToken)
compare(payPanel.tokenAmount, default_test_data[i].fromTokenAmount)
verify(payAmountToSendInput.input.input.edit.cursorVisible)
compare(paytokenSelectorContentItemText.text, !!root.swapFormData.fromTokensKey ? root.swapFormData.fromTokensKey : qsTr("Select asset"))
compare(!!default_test_data[i].fromToken , !!paytokenSelectorIcon)
if(!!paytokenSelectorIcon) {
compare(paytokenSelectorIcon.image.source, expectedFromTokenIcon)
}
verify(!!default_test_data[i].fromToken ? maxTagButton.visible: !maxTagButton.visible)
// verify receive values
compare(receivePanel.tokenKey, default_test_data[i].toToken)
compare(receivePanel.tokenAmount, default_test_data[i].toTokenAmount)
verify(!receiveAmountToSendInput.input.input.edit.cursorVisible)
compare(receivetokenSelectorContentItemText.text, !!root.swapFormData.toTokenKey ? root.swapFormData.toTokenKey : qsTr("Select asset"))
if(!!receivetokenSelectorIcon) {
compare(receivetokenSelectorIcon.image.source, expectedToTokenIcon)
}
// click exchange button
swapExchangeButton.clicked()
waitForRendering(payPanel)
waitForRendering(receivePanel)
// verify form values
compare(root.swapFormData.fromTokensKey, default_test_data[i].toToken)
compare(root.swapFormData.fromTokenAmount, default_test_data[i].toTokenAmount)
compare(root.swapFormData.toTokenKey, default_test_data[i].fromToken)
compare(root.swapFormData.toTokenAmount, default_test_data[i].fromTokenAmount)
paytokenSelectorContentItemText = findChild(payPanel, "tokenSelectorContentItemText")
verify(!!paytokenSelectorContentItemText)
paytokenSelectorIcon = findChild(payPanel, "tokenSelectorIcon")
compare(!!root.swapFormData.fromTokensKey , !!paytokenSelectorIcon)
receivetokenSelectorContentItemText = findChild(receivePanel, "tokenSelectorContentItemText")
verify(!!receivetokenSelectorContentItemText)
receivetokenSelectorIcon = findChild(receivePanel, "tokenSelectorIcon")
compare(!!root.swapFormData.toTokenKey, !!receivetokenSelectorIcon)
// verify pay values
compare(payPanel.tokenKey, default_test_data[i].toToken)
compare(payPanel.tokenAmount, default_test_data[i].toTokenAmount)
verify(payAmountToSendInput.input.input.edit.cursorVisible)
compare(paytokenSelectorContentItemText.text, !!default_test_data[i].toToken ? default_test_data[i].toToken : qsTr("Select asset"))
if(!!paytokenSelectorIcon) {
compare(paytokenSelectorIcon.image.source, expectedToTokenIcon)
}
verify(!!default_test_data[i].toToken ? maxTagButton.visible: !maxTagButton.visible)
compare(maxTagButton.text, qsTr("Max. %1").arg(Qt.locale().zeroDigit))
compare(maxTagButton.type, (payAmountToSendInput.input.valid || !payAmountToSendInput.input.text) && maxTagButton.value > 0 ? StatusBaseButton.Type.Normal : StatusBaseButton.Type.Danger)
// verify receive values
compare(receivePanel.tokenKey, default_test_data[i].fromToken)
compare(receivePanel.tokenAmount, default_test_data[i].fromTokenAmount)
verify(!receiveAmountToSendInput.input.input.edit.cursorVisible)
compare(receivetokenSelectorContentItemText.text, !!default_test_data[i].fromToken ? default_test_data[i].fromToken : qsTr("Select asset"))
if(!!receivetokenSelectorIcon) {
compare(receivetokenSelectorIcon.image.source, expectedFromTokenIcon)
}
closeAndVerfyModal()
}
}
}
}

View File

@ -217,7 +217,7 @@ Item {
d.swapFormData.selectedAccountAddress = RootStore.selectedAddress
d.swapFormData.selectedNetworkChainId = StatusQUtils.ModelUtils.getByKey(RootStore.filteredFlatModel, "layer", 1, "chainId")
d.swapFormData.fromTokensKey = tokensKey
d.swapFormData.toTokenKey = RootStore.areTestNetworksEnabled ? Constants.swap.testStatusTokenKey : Constants.swap.mainnetStatusTokenKey
d.swapFormData.defaultToTokenKey = RootStore.areTestNetworksEnabled ? Constants.swap.testStatusTokenKey : Constants.swap.mainnetStatusTokenKey
Global.openSwapModalRequested(d.swapFormData)
}
}
@ -338,7 +338,7 @@ Item {
if(!!walletStore.currentViewedHoldingTokensKey && walletStore.currentViewedHoldingType === Constants.TokenType.ERC20) {
d.swapFormData.fromTokensKey = walletStore.currentViewedHoldingTokensKey
}
d.swapFormData.toTokenKey = RootStore.areTestNetworksEnabled ? Constants.swap.testStatusTokenKey : Constants.swap.mainnetStatusTokenKey
d.swapFormData.defaultToTokenKey = RootStore.areTestNetworksEnabled ? Constants.swap.testStatusTokenKey : Constants.swap.mainnetStatusTokenKey
Global.openSwapModalRequested(d.swapFormData)
}
}

View File

@ -181,7 +181,7 @@ ComboBox {
Component {
id: textContentItem
StatusBaseText {
objectName: "holdingSelectorsContentItemText"
objectName: "tokenSelectorContentItemText"
font.pixelSize: root.font.pixelSize
font.weight: Font.Medium
color: Theme.palette.primaryColor1
@ -196,13 +196,13 @@ ComboBox {
: ""
spacing: root.spacing
StatusRoundedImage {
objectName: "holdingSelectorsTokenIcon"
objectName: "tokenSelectorIcon"
Layout.preferredWidth: 20
Layout.preferredHeight: 20
image.source: Constants.tokenIcon(parent.currentSymbol)
}
StatusBaseText {
objectName: "holdingSelectorsContentItemText"
objectName: "tokenSelectorContentItemText"
font.pixelSize: 28
color: root.hovered ? Theme.palette.blue : Theme.palette.darkBlue
text: parent.currentSymbol

View File

@ -37,14 +37,7 @@ Control {
onTokenKeyChanged: Qt.callLater(reevaluateSelectedId)
property string tokenAmount
onTokenAmountChanged: {
if (tokenAmount === "") {
amountToSendInput.input.input.edit.clear()
return
}
Qt.callLater(() => amountToSendInput.input.text =
SQUtils.AmountsArithmetic.fromString(tokenAmount).toFixed().replace('.', LocaleUtils.userInputLocale.decimalPoint))
}
onTokenAmountChanged: Qt.callLater(d.updateInputText)
property int swapSide: SwapInputPanel.SwapSide.Pay
property bool fiatInputInteractive
@ -53,10 +46,8 @@ Control {
property bool interactive: true
function reevaluateSelectedId() {
if (!!tokenKey) {
holdingSelector.selectToken(tokenKey)
d.selectedHolding = SQUtils.ModelUtils.getByKey(holdingSelector.model, "tokensKey", holdingSelector.currentTokensKey)
}
holdingSelector.selectToken(tokenKey)
d.selectedHolding = SQUtils.ModelUtils.getByKey(holdingSelector.model, "tokensKey", holdingSelector.currentTokensKey)
}
// output API
@ -107,6 +98,17 @@ Control {
accountAddress: root.selectedAccountAddress || ""
searchString: holdingSelector.searchString
}
function updateInputText() {
if (!tokenAmount) {
amountToSendInput.input.input.edit.clear()
return
}
let amountToSet = SQUtils.AmountsArithmetic.fromString(tokenAmount).toFixed().replace('.', LocaleUtils.userInputLocale.decimalPoint)
if (amountToSendInput.input.text !== amountToSet) {
amountToSendInput.input.text = amountToSet
}
}
}
background: Shape {

View File

@ -13,10 +13,13 @@ QtObject {
property int selectedNetworkChainId: -1
property string fromTokensKey: ""
property string fromTokenAmount: ""
property string toTokenKey: ""
property string toTokenKey: root.defaultToTokenKey
property string toTokenAmount: ""
property double selectedSlippage: 0.5
// default token key
property string defaultToTokenKey: ""
onSelectedAccountAddressChanged: root.formValuesChanged()
onSelectedNetworkChainIdChanged: root.formValuesChanged()
onFromTokensKeyChanged: root.formValuesChanged()
@ -27,11 +30,15 @@ QtObject {
function resetFormData() {
selectedAccountAddress = ""
selectedNetworkChainId = -1
selectedSlippage = 0.5
root.resetToAndFromTokenValues()
}
function resetToAndFromTokenValues() {
fromTokensKey = ""
fromTokenAmount = ""
toTokenKey = ""
toTokenKey = root.defaultToTokenKey
toTokenAmount = ""
selectedSlippage = 0.5
}
function isFormFilledCorrectly() {

View File

@ -40,9 +40,10 @@ StatusDialog {
})
function fetchSuggestedRoutes() {
if (payPanel.valueValid && !!payPanel.selectedHoldingId) {
root.swapAdaptor.newFetchReset()
if (payPanel.valueValid && root.swapInputParamsForm.isFormFilledCorrectly()) {
root.swapAdaptor.validSwapProposalReceived = false
root.swapAdaptor.swapProposalLoading = true
root.swapAdaptor.swapOutputData.resetAllButReceivedTokenValuesForSwap()
debounceFetchSuggestedRoutes()
}
}
@ -157,10 +158,14 @@ StatusDialog {
nonInteractiveTokensKey: receivePanel.selectedHoldingId
swapSide: SwapInputPanel.SwapSide.Pay
swapExchangeButtonWidth: swapButton.width
swapExchangeButtonWidth: swapExchangeButton.width
onSelectedHoldingIdChanged: root.swapInputParamsForm.fromTokensKey = selectedHoldingId
onValueChanged: root.swapInputParamsForm.fromTokenAmount = value.toLocaleString(locale, 'f', -128)
onValueChanged: {
if(root.swapInputParamsForm.fromTokensKey === selectedHoldingId) {
root.swapInputParamsForm.fromTokenAmount = !tokenAmount && value === 0 ? "" : value.toLocaleString(locale, 'f', -128)
}
}
onValueValidChanged: d.fetchSuggestedRoutes()
}
@ -186,7 +191,7 @@ StatusDialog {
nonInteractiveTokensKey: payPanel.selectedHoldingId
swapSide: SwapInputPanel.SwapSide.Receive
swapExchangeButtonWidth: swapButton.width
swapExchangeButtonWidth: swapExchangeButton.width
mainInputLoading: root.swapAdaptor.swapProposalLoading
bottomTextLoading: root.swapAdaptor.swapProposalLoading
@ -200,8 +205,17 @@ StatusDialog {
}
SwapExchangeButton {
id: swapButton
id: swapExchangeButton
objectName: "swapExchangeButton"
anchors.centerIn: parent
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
}
}
}

View File

@ -168,13 +168,6 @@ QObject {
root.swapProposalLoading = false
}
// this function will not reset input params but only the output ones and loading states
function newFetchReset() {
root.swapOutputData.reset()
root.validSwapProposalReceived = false
root.swapProposalLoading = false
}
function getNetworkShortNames(chainIds) {
var networkString = ""
let chainIdsArray = chainIds.split(":")
@ -212,8 +205,8 @@ QObject {
function fetchSuggestedRoutes(cryptoValueRaw) {
if (root.swapFormData.isFormFilledCorrectly() && !!cryptoValueRaw) {
root.swapProposalLoading = true
root.swapOutputData.reset()
root.validSwapProposalReceived = false
// Identify new swap with a different uuid
d.uuid = Utils.uuid()
@ -228,7 +221,6 @@ QObject {
disabledChainIds, disabledChainIds, preferedChainIds,
Constants.SendType.Swap, "")
} else {
root.validSwapProposalReceived = false
root.swapProposalLoading = false
}
}

View File

@ -16,6 +16,10 @@ QtObject {
function reset() {
root.fromTokenAmount = ""
root.toTokenAmount = ""
root.resetAllButReceivedTokenValuesForSwap()
}
function resetAllButReceivedTokenValuesForSwap() {
root.totalFees = 0
root.bestRoutes = []
root.approvalNeeded = false

View File

@ -43,13 +43,17 @@ Item {
implicitHeight: comboBox.implicitHeight
onSelectedItemChanged: {
d.iconSource = itemIconSourceFn(selectedItem) ?? defaultIconSource
d.text = itemTextFn(selectedItem) ?? placeholderText
let iconSource = itemIconSourceFn(selectedItem)
d.iconSource = !selectedItem ? "" : !!iconSource ? iconSource : defaultIconSource
let itemText = itemTextFn(selectedItem)
d.text = !!itemText ? itemText : placeholderText
}
onHoveredItemChanged: {
d.iconSource = itemIconSourceFn(hoveredItem) ?? defaultIconSource
d.text = itemTextFn(hoveredItem) ?? placeholderText
let iconSource = itemIconSourceFn(hoveredItem)
d.iconSource = !!iconSource ? iconSource : defaultIconSource
let itemText = itemTextFn(hoveredItem)
d.text = !!itemText ? itemText : placeholderText
}
QtObject {
@ -105,7 +109,7 @@ Item {
StatusBaseText {
objectName: "holdingSelectorsContentItemText"
Layout.fillWidth: true
font.pixelSize: root.contentTextSize
font.pixelSize: !selectedItem && !hoveredItem ? Theme.primaryTextFontSize : root.contentTextSize
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
color: Theme.palette.primaryColor1

View File

@ -190,7 +190,7 @@ Item {
height: parent.height
defaultIconSource: Style.png("tokens/DEFAULT-TOKEN@3x")
placeholderText: d.isCurrentBrowsingTypeAsset ? qsTr("Select token") : qsTr("Select collectible")
placeholderText: d.isCurrentBrowsingTypeAsset ? qsTr("Select asset") : qsTr("Select collectible")
property bool hasCommunityTokens: false
comboBoxDelegate: Item {