2024-05-13 17:23:01 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2024-05-15 21:22:13 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
2024-05-13 17:23:01 +00:00
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
import StatusQ 0.1
|
2024-05-13 17:23:01 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import Storybook 1.0
|
|
|
|
import Models 1.0
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
import shared.stores 1.0
|
2024-05-13 17:23:01 +00:00
|
|
|
import AppLayouts.Wallet.stores 1.0
|
|
|
|
import AppLayouts.Wallet.popups.swap 1.0
|
|
|
|
|
|
|
|
SplitView {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
Logs { id: logs }
|
|
|
|
|
|
|
|
orientation: Qt.Horizontal
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
readonly property var tokenBySymbolModel: TokensBySymbolModel {}
|
2024-06-25 13:37:42 +00:00
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
function launchPopup() {
|
|
|
|
swapModal.createObject(root)
|
|
|
|
}
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
readonly property SwapTransactionRoutes dummySwapTransactionRoutes: SwapTransactionRoutes{}
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PopupBackground {
|
|
|
|
id: popupBg
|
|
|
|
|
|
|
|
SplitView.fillWidth: true
|
|
|
|
SplitView.fillHeight: true
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id: reopenButton
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: "Reopen"
|
|
|
|
enabled: !swapModal.visible
|
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
onClicked: d.launchPopup()
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
Component.onCompleted: d.launchPopup()
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
SwapStore {
|
|
|
|
id: dSwapStore
|
|
|
|
signal suggestedRoutesReady(var txRoutes)
|
2024-06-25 13:37:42 +00:00
|
|
|
readonly property var accounts: WalletAccountsModel {}
|
|
|
|
readonly property var flatNetworks: NetworksModel.flatNetworks
|
2024-06-13 00:45:33 +00:00
|
|
|
readonly property bool areTestNetworksEnabled: areTestNetworksEnabledCheckbox.checked
|
|
|
|
|
2024-06-30 22:08:08 +00:00
|
|
|
function fetchSuggestedRoutes(uuid, accountFrom, accountTo, amount, tokenFrom, tokenTo,
|
2024-06-13 00:45:33 +00:00
|
|
|
disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts) {
|
2024-06-30 22:08:08 +00:00
|
|
|
console.debug("fetchSuggestedRoutes called >> uuid = ", uuid, " accountFrom = ", accountFrom, " accountTo =",
|
|
|
|
accountTo, "amount = ", amount, " tokenFrom = ", tokenFrom, " tokenTo = ", tokenTo,
|
|
|
|
" disabledFromChainIDs = ", disabledFromChainIDs, " disabledToChainIDs = ", disabledToChainIDs,
|
|
|
|
" preferredChainIDs = ", preferredChainIDs, " sendType =", sendType, " lockedInAmounts = ", lockedInAmounts)
|
2024-06-13 00:45:33 +00:00
|
|
|
}
|
|
|
|
function authenticateAndTransfer(uuid, accountFrom, accountTo, tokenFrom,
|
|
|
|
tokenTo, sendType, tokenName, tokenIsOwnerToken, paths) {
|
|
|
|
console.debug("authenticateAndTransfer called >> uuid ", uuid, " accountFrom = ",accountFrom, " accountTo =",
|
|
|
|
accountTo, "tokenFrom = ",tokenFrom, " tokenTo = ",tokenTo, " sendType = ", sendType,
|
|
|
|
" tokenName = ", tokenName, " tokenIsOwnerToken = ", tokenIsOwnerToken, " paths = ", paths)
|
|
|
|
}
|
|
|
|
function getWei2Eth(wei, decimals) {
|
|
|
|
return wei/(10**decimals)
|
|
|
|
}
|
2024-05-29 15:42:26 +00:00
|
|
|
}
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
TokensStore {
|
|
|
|
id: tokensStore
|
2024-06-25 13:37:42 +00:00
|
|
|
plainTokensBySymbolModel: TokensBySymbolModel {}
|
2024-06-13 00:45:33 +00:00
|
|
|
getDisplayAssetsBelowBalanceThresholdDisplayAmount: () => 0
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 13:37:42 +00:00
|
|
|
SwapModalAdaptor {
|
|
|
|
id: adaptor
|
|
|
|
swapStore: dSwapStore
|
|
|
|
walletAssetsStore: WalletAssetsStore {
|
|
|
|
id: thisWalletAssetStore
|
|
|
|
walletTokensStore: tokensStore
|
|
|
|
readonly property var baseGroupedAccountAssetModel: GroupedAccountsAssetsModel {}
|
|
|
|
assetsWithFilteredBalances: thisWalletAssetStore.groupedAccountsAssetsModel
|
|
|
|
}
|
|
|
|
currencyStore: CurrenciesStore {}
|
|
|
|
swapFormData: SwapInputParamsForm {
|
|
|
|
defaultToTokenKey: "STT"
|
|
|
|
onSelectedAccountAddressChanged: {
|
|
|
|
if (selectedAccountAddress !== accountComboBox.currentValue)
|
|
|
|
accountComboBox.currentIndex = accountComboBox.indexOfValue(selectedAccountAddress)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
swapOutputData: SwapOutputData{}
|
|
|
|
}
|
|
|
|
|
2024-05-29 15:42:26 +00:00
|
|
|
Component {
|
|
|
|
id: swapModal
|
|
|
|
SwapModal {
|
2024-06-13 00:45:33 +00:00
|
|
|
id: modal
|
2024-05-29 15:42:26 +00:00
|
|
|
visible: true
|
2024-06-04 11:58:37 +00:00
|
|
|
modal: false
|
|
|
|
closePolicy: Popup.CloseOnEscape
|
2024-06-12 20:43:08 +00:00
|
|
|
destroyOnClose: true
|
2024-06-25 13:37:42 +00:00
|
|
|
swapInputParamsForm: adaptor.swapFormData
|
|
|
|
swapAdaptor: adaptor
|
|
|
|
plainTokensBySymbolModel: ListModel {
|
|
|
|
ListElement {
|
|
|
|
key: "aave"
|
|
|
|
name: "Aave"
|
|
|
|
symbol: "AAVE"
|
|
|
|
image: "https://cryptologos.cc/logos/aave-aave-logo.png"
|
|
|
|
communityId: ""
|
|
|
|
decimals: 18
|
|
|
|
marketDetails: []
|
2024-06-07 12:27:56 +00:00
|
|
|
}
|
2024-06-25 13:37:42 +00:00
|
|
|
ListElement {
|
|
|
|
key: "usdc"
|
|
|
|
name: "USDC"
|
|
|
|
symbol: "USDC"
|
|
|
|
image: ""
|
|
|
|
communityId: ""
|
|
|
|
decimals: 18
|
|
|
|
marketDetails: []
|
|
|
|
}
|
|
|
|
ListElement {
|
|
|
|
key: "hst"
|
|
|
|
name: "Decision Token"
|
|
|
|
symbol: "HST"
|
|
|
|
image: ""
|
|
|
|
communityId: ""
|
|
|
|
decimals: 18
|
|
|
|
marketDetails: []
|
2024-06-13 00:45:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Binding {
|
|
|
|
target: swapInputParamsForm
|
|
|
|
property: "fromTokensKey"
|
2024-06-18 22:51:49 +00:00
|
|
|
value: fromTokenComboBox.currentValue ?? ""
|
2024-06-13 00:45:33 +00:00
|
|
|
}
|
|
|
|
Binding {
|
|
|
|
target: swapInputParamsForm
|
|
|
|
property: "toTokenKey"
|
2024-06-18 22:51:49 +00:00
|
|
|
value: toTokenComboBox.currentValue ?? ""
|
|
|
|
}
|
|
|
|
Binding {
|
|
|
|
target: swapInputParamsForm
|
|
|
|
property: "selectedNetworkChainId"
|
|
|
|
value: networksComboBox.currentValue ?? -1
|
|
|
|
}
|
|
|
|
Binding {
|
|
|
|
target: swapInputParamsForm
|
|
|
|
property: "selectedAccountAddress"
|
|
|
|
value: accountComboBox.currentValue ?? ""
|
|
|
|
}
|
|
|
|
Binding {
|
|
|
|
target: swapInputParamsForm
|
|
|
|
property: "fromTokenAmount"
|
|
|
|
value: swapInput.text
|
2024-06-13 00:45:33 +00:00
|
|
|
}
|
2024-05-15 21:22:13 +00:00
|
|
|
}
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pane {
|
|
|
|
id: rightPanel
|
|
|
|
SplitView.minimumWidth: 300
|
|
|
|
SplitView.preferredWidth: 300
|
|
|
|
SplitView.minimumHeight: 300
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
spacing: 10
|
|
|
|
|
2024-05-15 21:22:13 +00:00
|
|
|
CheckBox {
|
|
|
|
id: areTestNetworksEnabledCheckbox
|
|
|
|
text: "areTestNetworksEnabled"
|
|
|
|
checked: true
|
2024-06-12 20:43:08 +00:00
|
|
|
onToggled: networksComboBox.currentIndex = 0
|
2024-05-15 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
2024-05-13 17:23:01 +00:00
|
|
|
StatusBaseText {
|
|
|
|
text:"Selected Account"
|
|
|
|
}
|
|
|
|
ComboBox {
|
|
|
|
id: accountComboBox
|
|
|
|
textRole: "name"
|
2024-06-07 12:27:56 +00:00
|
|
|
valueRole: "address"
|
2024-06-25 13:37:42 +00:00
|
|
|
model: adaptor.nonWatchAccounts
|
2024-05-13 17:23:01 +00:00
|
|
|
currentIndex: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
text: "Selected Network"
|
|
|
|
}
|
|
|
|
ComboBox {
|
|
|
|
id: networksComboBox
|
|
|
|
textRole: "chainName"
|
2024-06-18 22:51:49 +00:00
|
|
|
valueRole: "chainId"
|
2024-06-25 13:37:42 +00:00
|
|
|
model: adaptor.filteredFlatNetworksModel
|
2024-05-13 17:23:01 +00:00
|
|
|
currentIndex: 0
|
2024-05-15 21:22:13 +00:00
|
|
|
onCountChanged: currentIndex = 0
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
text: "From Token"
|
|
|
|
}
|
|
|
|
ComboBox {
|
|
|
|
id: fromTokenComboBox
|
|
|
|
textRole: "name"
|
2024-06-12 20:43:08 +00:00
|
|
|
valueRole: "key"
|
2024-05-13 17:23:01 +00:00
|
|
|
model: d.tokenBySymbolModel
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
id: swapInput
|
2024-06-18 22:51:49 +00:00
|
|
|
Layout.preferredWidth: 250
|
2024-05-28 17:39:41 +00:00
|
|
|
label: "Token amount to swap"
|
2024-06-13 00:45:33 +00:00
|
|
|
text: ""
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
text: "To Token"
|
|
|
|
}
|
|
|
|
ComboBox {
|
|
|
|
id: toTokenComboBox
|
|
|
|
textRole: "name"
|
2024-06-12 20:43:08 +00:00
|
|
|
valueRole: "key"
|
2024-05-13 17:23:01 +00:00
|
|
|
model: d.tokenBySymbolModel
|
|
|
|
currentIndex: 1
|
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
Button {
|
|
|
|
text: "emit no routes found event"
|
|
|
|
onClicked: {
|
2024-06-13 00:45:33 +00:00
|
|
|
dSwapStore.suggestedRoutesReady(d.dummySwapTransactionRoutes.txNoRoutes)
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
}
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
Button {
|
|
|
|
text: "emit no approval needed route"
|
|
|
|
onClicked: {
|
2024-06-13 00:45:33 +00:00
|
|
|
dSwapStore.suggestedRoutesReady(d.dummySwapTransactionRoutes.txHasRouteNoApproval)
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
}
|
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
Button {
|
|
|
|
text: "emit approval needed route"
|
|
|
|
onClicked: {
|
2024-06-13 00:45:33 +00:00
|
|
|
dSwapStore.suggestedRoutesReady(d.dummySwapTransactionRoutes.txHasRoutesApprovalNeeded)
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
2024-06-04 11:58:37 +00:00
|
|
|
}
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// category: Popups
|