2024-05-28 17:39:41 +00:00
|
|
|
import QtQml 2.15
|
2024-05-13 17:23:01 +00:00
|
|
|
|
2024-06-06 14:05:31 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
|
|
|
|
2024-05-13 17:23:01 +00:00
|
|
|
/* This is used so that there is an easy way to fill in the data
|
|
|
|
needed to launch the Swap Modal with pre-filled requisites. */
|
|
|
|
QtObject {
|
|
|
|
id: root
|
2024-06-06 14:05:31 +00:00
|
|
|
|
|
|
|
signal formValuesChanged()
|
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
property string selectedAccountAddress: ""
|
2024-05-13 17:23:01 +00:00
|
|
|
property int selectedNetworkChainId: -1
|
|
|
|
property string fromTokensKey: ""
|
2024-06-13 00:45:33 +00:00
|
|
|
property string fromTokenAmount: ""
|
2024-06-18 17:24:07 +00:00
|
|
|
property string toTokenKey: root.defaultToTokenKey
|
2024-06-13 00:45:33 +00:00
|
|
|
property string toTokenAmount: ""
|
2024-06-04 11:58:37 +00:00
|
|
|
property double selectedSlippage: 0.5
|
2024-06-06 14:05:31 +00:00
|
|
|
|
2024-06-18 17:24:07 +00:00
|
|
|
// default token key
|
|
|
|
property string defaultToTokenKey: ""
|
2024-07-03 22:08:03 +00:00
|
|
|
// 15 seconds
|
|
|
|
property int autoRefreshTime: 15000
|
2024-06-18 17:24:07 +00:00
|
|
|
|
2024-06-13 00:45:33 +00:00
|
|
|
onSelectedAccountAddressChanged: root.formValuesChanged()
|
2024-06-06 14:05:31 +00:00
|
|
|
onSelectedNetworkChainIdChanged: root.formValuesChanged()
|
|
|
|
onFromTokensKeyChanged: root.formValuesChanged()
|
|
|
|
onFromTokenAmountChanged: root.formValuesChanged()
|
|
|
|
onToTokenKeyChanged: root.formValuesChanged()
|
|
|
|
onToTokenAmountChanged: root.formValuesChanged()
|
|
|
|
|
|
|
|
function resetFormData() {
|
2024-06-13 00:45:33 +00:00
|
|
|
selectedAccountAddress = ""
|
2024-06-06 14:05:31 +00:00
|
|
|
selectedNetworkChainId = -1
|
2024-06-18 17:24:07 +00:00
|
|
|
selectedSlippage = 0.5
|
2024-07-03 16:29:30 +00:00
|
|
|
root.resetFromTokenValues()
|
|
|
|
root.resetToTokenValues()
|
2024-06-18 17:24:07 +00:00
|
|
|
}
|
|
|
|
|
2024-07-03 16:29:30 +00:00
|
|
|
function resetFromTokenValues() {
|
2024-06-06 14:05:31 +00:00
|
|
|
fromTokensKey = ""
|
2024-06-13 00:45:33 +00:00
|
|
|
fromTokenAmount = ""
|
2024-07-03 16:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function resetToTokenValues(keepDefault = true) {
|
|
|
|
if(keepDefault) {
|
|
|
|
toTokenKey = root.defaultToTokenKey
|
|
|
|
} else {
|
|
|
|
toTokenKey = ""
|
|
|
|
}
|
2024-06-13 00:45:33 +00:00
|
|
|
toTokenAmount = ""
|
2024-06-06 14:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isFormFilledCorrectly() {
|
2024-07-03 22:08:03 +00:00
|
|
|
let bigIntNumber = SQUtils.AmountsArithmetic.fromString(root.fromTokenAmount)
|
2024-06-13 00:45:33 +00:00
|
|
|
return !!root.selectedAccountAddress &&
|
2024-06-06 14:05:31 +00:00
|
|
|
root.selectedNetworkChainId !== -1 &&
|
|
|
|
!!root.fromTokensKey && !!root.toTokenKey &&
|
2024-07-10 18:35:24 +00:00
|
|
|
(!!root.fromTokenAmount && !isNaN(bigIntNumber) && bigIntNumber.gt(0)) &&
|
2024-06-06 14:05:31 +00:00
|
|
|
root.selectedSlippage > 0
|
|
|
|
}
|
2024-05-13 17:23:01 +00:00
|
|
|
}
|