parent
97190ce716
commit
26fcb8b99f
|
@ -176,3 +176,9 @@ QtObject:
|
||||||
if(item.getShortName() == toLowerAscii(shortName)):
|
if(item.getShortName() == toLowerAscii(shortName)):
|
||||||
return item.getChainId()
|
return item.getChainId()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
proc getLayer1Network*(self: Model, testNet: bool): int =
|
||||||
|
for item in self.items:
|
||||||
|
if item.getLayer() == 1 and item.getIsTest() == testNet:
|
||||||
|
return item.getChainId()
|
||||||
|
return 0
|
||||||
|
|
|
@ -146,3 +146,6 @@ QtObject:
|
||||||
QtProperty[QVariant] layer2Proxy:
|
QtProperty[QVariant] layer2Proxy:
|
||||||
read = getLayer2Proxy
|
read = getLayer2Proxy
|
||||||
notify = layer2ProxyChanged
|
notify = layer2ProxyChanged
|
||||||
|
|
||||||
|
proc getMainnetChainId*(self: View): int {.slot.} =
|
||||||
|
return self.layer1.getLayer1Network(self.areTestNetworksEnabled)
|
||||||
|
|
|
@ -83,6 +83,12 @@ const getSuggestedRoutesTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall
|
||||||
let response = eth.suggestedRoutes(arg.account, amountAsHex, arg.token, arg.disabledFromChainIDs, arg.disabledToChainIDs, arg.preferredChainIDs, arg.priority, arg.sendType).result
|
let response = eth.suggestedRoutes(arg.account, amountAsHex, arg.token, arg.disabledFromChainIDs, arg.disabledToChainIDs, arg.preferredChainIDs, arg.priority, arg.sendType).result
|
||||||
|
|
||||||
var bestPaths = response["Best"].getElems().map(x => x.toTransactionPathDto())
|
var bestPaths = response["Best"].getElems().map(x => x.toTransactionPathDto())
|
||||||
|
|
||||||
|
# retry along with unpreferred chains incase no route is possible with preferred chains
|
||||||
|
if(bestPaths.len == 0 and arg.preferredChainIDs.len > 0):
|
||||||
|
let response = eth.suggestedRoutes(arg.account, amountAsHex, arg.token, arg.disabledFromChainIDs, arg.disabledToChainIDs, @[], arg.priority, arg.sendType).result
|
||||||
|
bestPaths = response["Best"].getElems().map(x => x.toTransactionPathDto())
|
||||||
|
|
||||||
bestPaths.sort(sortAsc[TransactionPathDto])
|
bestPaths.sort(sortAsc[TransactionPathDto])
|
||||||
let output = %*{
|
let output = %*{
|
||||||
"suggestedRoutes": SuggestedRoutesDto(
|
"suggestedRoutes": SuggestedRoutesDto(
|
||||||
|
|
|
@ -162,7 +162,6 @@ type
|
||||||
tokenFees*: float
|
tokenFees*: float
|
||||||
bonderFees*: string
|
bonderFees*: string
|
||||||
cost*: float
|
cost*: float
|
||||||
preferred*: bool
|
|
||||||
estimatedTime*: int
|
estimatedTime*: int
|
||||||
|
|
||||||
proc `$`*(self: TransactionPathDto): string =
|
proc `$`*(self: TransactionPathDto): string =
|
||||||
|
@ -177,7 +176,6 @@ proc `$`*(self: TransactionPathDto): string =
|
||||||
tokenFees:{self.tokenFees},
|
tokenFees:{self.tokenFees},
|
||||||
bonderFees:{self.bonderFees},
|
bonderFees:{self.bonderFees},
|
||||||
cost:{self.cost},
|
cost:{self.cost},
|
||||||
preferred:{self.preferred},
|
|
||||||
estimatedTime:{self.estimatedTime}
|
estimatedTime:{self.estimatedTime}
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
|
@ -195,7 +193,6 @@ proc toTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
||||||
result.amountOut = stint.fromHex(UInt256, jsonObj{"AmountOut"}.getStr)
|
result.amountOut = stint.fromHex(UInt256, jsonObj{"AmountOut"}.getStr)
|
||||||
result.estimatedTime = jsonObj{"EstimatedTime"}.getInt
|
result.estimatedTime = jsonObj{"EstimatedTime"}.getInt
|
||||||
discard jsonObj.getProp("GasAmount", result.gasAmount)
|
discard jsonObj.getProp("GasAmount", result.gasAmount)
|
||||||
discard jsonObj.getProp("Preferred", result.preferred)
|
|
||||||
|
|
||||||
proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
||||||
result = TransactionPathDto()
|
result = TransactionPathDto()
|
||||||
|
@ -211,7 +208,6 @@ proc convertToTransactionPathDto*(jsonObj: JsonNode): TransactionPathDto =
|
||||||
result.amountOut = stint.u256(jsonObj{"amountOut"}.getStr)
|
result.amountOut = stint.u256(jsonObj{"amountOut"}.getStr)
|
||||||
result.estimatedTime = jsonObj{"estimatedTime"}.getInt
|
result.estimatedTime = jsonObj{"estimatedTime"}.getInt
|
||||||
discard jsonObj.getProp("gasAmount", result.gasAmount)
|
discard jsonObj.getProp("gasAmount", result.gasAmount)
|
||||||
discard jsonObj.getProp("preferred", result.preferred)
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Fees* = ref object
|
Fees* = ref object
|
||||||
|
|
|
@ -183,7 +183,7 @@ Rectangle {
|
||||||
id: basicInput
|
id: basicInput
|
||||||
StatusBaseText {
|
StatusBaseText {
|
||||||
id: secondaryLabel
|
id: secondaryLabel
|
||||||
Layout.maximumWidth: root.width - 12
|
Layout.maximumWidth: root.width - cardIcon.width - errorIcon.width - 24
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
font.pixelSize: 13
|
font.pixelSize: 13
|
||||||
font.weight: Font.Medium
|
font.weight: Font.Medium
|
||||||
|
|
|
@ -75,7 +75,7 @@ StatusDialog {
|
||||||
let amount = parseFloat(amountToSendInput.text) * Math.pow(10, assetSelector.selectedAsset.decimals)
|
let amount = parseFloat(amountToSendInput.text) * Math.pow(10, assetSelector.selectedAsset.decimals)
|
||||||
popup.store.suggestedRoutes(popup.selectedAccount.address, amount.toString(16), assetSelector.selectedAsset.symbol,
|
popup.store.suggestedRoutes(popup.selectedAccount.address, amount.toString(16), assetSelector.selectedAsset.symbol,
|
||||||
store.disabledChainIdsFromList, store.disabledChainIdsToList,
|
store.disabledChainIdsFromList, store.disabledChainIdsToList,
|
||||||
d.preferredChainIds, fees.selectedPriority, popup.sendType)
|
store.preferredChainIds, fees.selectedPriority, popup.sendType)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -102,7 +102,6 @@ StatusDialog {
|
||||||
property string resolvedENSAddress
|
property string resolvedENSAddress
|
||||||
readonly property string uuid: Utils.uuid()
|
readonly property string uuid: Utils.uuid()
|
||||||
property bool isPendingTx: false
|
property bool isPendingTx: false
|
||||||
property var preferredChainIds: []
|
|
||||||
property bool sendTxError: false
|
property bool sendTxError: false
|
||||||
property string sendTxErrorString
|
property string sendTxErrorString
|
||||||
|
|
||||||
|
@ -120,7 +119,7 @@ StatusDialog {
|
||||||
} else {
|
} else {
|
||||||
let chainColor = popup.store.allNetworks.getNetworkColor(splitWords[i])
|
let chainColor = popup.store.allNetworks.getNetworkColor(splitWords[i])
|
||||||
if(!!chainColor) {
|
if(!!chainColor) {
|
||||||
d.addPreferredChain(popup.store.allNetworks.getNetworkChainId(splitWords[i]))
|
store.addPreferredChain(popup.store.allNetworks.getNetworkChainId(splitWords[i]))
|
||||||
editedText += `<span style='color: %1'>%2</span>`.arg(chainColor).arg(splitWords[i])+':'
|
editedText += `<span style='color: %1'>%2</span>`.arg(chainColor).arg(splitWords[i])+':'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,16 +129,6 @@ StatusDialog {
|
||||||
popup.recalculateRoutesAndFees()
|
popup.recalculateRoutesAndFees()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPreferredChain(chainID) {
|
|
||||||
if(!chainID)
|
|
||||||
return
|
|
||||||
|
|
||||||
if(preferredChainIds.includes(chainID))
|
|
||||||
return
|
|
||||||
|
|
||||||
preferredChainIds.push(chainID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
width: 556
|
width: 556
|
||||||
|
@ -153,6 +142,9 @@ StatusDialog {
|
||||||
onSelectedAccountChanged: popup.recalculateRoutesAndFees()
|
onSelectedAccountChanged: popup.recalculateRoutesAndFees()
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
|
store.addPreferredChain(popup.store.getMainnetChainId())
|
||||||
|
store.addUnpreferredChainsToDisabledChains()
|
||||||
|
|
||||||
amountToSendInput.input.edit.forceActiveFocus()
|
amountToSendInput.input.edit.forceActiveFocus()
|
||||||
|
|
||||||
if(!!popup.preSelectedAsset) {
|
if(!!popup.preSelectedAsset) {
|
||||||
|
|
|
@ -121,4 +121,30 @@ QtObject {
|
||||||
function plainText(text) {
|
function plainText(text) {
|
||||||
return globalUtils.plainText(text)
|
return globalUtils.plainText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property var preferredChainIds: []
|
||||||
|
|
||||||
|
function addPreferredChain(chainID) {
|
||||||
|
if(!chainID)
|
||||||
|
return
|
||||||
|
|
||||||
|
if(preferredChainIds.includes(chainID))
|
||||||
|
return
|
||||||
|
|
||||||
|
preferredChainIds.push(chainID)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMainnetChainId() {
|
||||||
|
return networksModule.getMainnetChainId()
|
||||||
|
}
|
||||||
|
|
||||||
|
function addUnpreferredChainsToDisabledChains() {
|
||||||
|
let mainnetChainId = getMainnetChainId()
|
||||||
|
for(var i = 0; i < allNetworks.count; i++) {
|
||||||
|
let chainId = allNetworks.rowData(i, "chainId") * 1
|
||||||
|
if(mainnetChainId !== chainId) {
|
||||||
|
addRemoveDisabledToChain(chainId, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property bool interactive: true
|
property bool interactive: true
|
||||||
|
property bool showPreferredChains: false
|
||||||
property var weiToEth: function(wei) {}
|
property var weiToEth: function(wei) {}
|
||||||
|
|
||||||
property var reCalculateSuggestedRoute: function() {}
|
property var reCalculateSuggestedRoute: function() {}
|
||||||
|
@ -49,15 +50,18 @@ Item {
|
||||||
toNetworksRepeater.itemAt(i).routeOnNetwork = 0
|
toNetworksRepeater.itemAt(i).routeOnNetwork = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
width: 410
|
function draw() {
|
||||||
height: visible ? networkCardsLayout.height : 0
|
|
||||||
|
|
||||||
onBestRoutesChanged: {
|
|
||||||
canvas.clear()
|
canvas.clear()
|
||||||
canvas.requestPaint()
|
canvas.requestPaint()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onVisibleChanged: if(visible) d.draw()
|
||||||
|
onBestRoutesChanged: d.draw()
|
||||||
|
|
||||||
|
width: 410
|
||||||
|
height: visible ? networkCardsLayout.height : 0
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: networkCardsLayout
|
id: networkCardsLayout
|
||||||
|
@ -131,12 +135,12 @@ Item {
|
||||||
objectName: model.chainId
|
objectName: model.chainId
|
||||||
property int routeOnNetwork: 0
|
property int routeOnNetwork: 0
|
||||||
property double amountToReceive: 0
|
property double amountToReceive: 0
|
||||||
|
property bool preferred: store.preferredChainIds.includes(model.chainId)
|
||||||
primaryText: model.chainName
|
primaryText: model.chainName
|
||||||
secondaryText: LocaleUtils.numberToLocaleString(amountToReceive)
|
secondaryText: LocaleUtils.numberToLocaleString(amountToReceive)
|
||||||
tertiaryText: ""
|
tertiaryText: state === "unpreferred" ? qsTr("UNPREFERRED") : ""
|
||||||
// To-do preferred in not something that is supported yet
|
state: root.errorMode ? "error" : !preferred ? "unpreferred" : "default"
|
||||||
state: root.errorMode ? "error" : "default"
|
opacity: preferred || showPreferredChains ? 1 : 0
|
||||||
// opacity: preferred ? 1 : 0
|
|
||||||
cardIcon.source: Style.svg(model.iconUrl)
|
cardIcon.source: Style.svg(model.iconUrl)
|
||||||
disabledText: qsTr("Disabled")
|
disabledText: qsTr("Disabled")
|
||||||
advancedMode: root.customMode
|
advancedMode: root.customMode
|
||||||
|
@ -150,9 +154,20 @@ Item {
|
||||||
root.reCalculateSuggestedRoute()
|
root.reCalculateSuggestedRoute()
|
||||||
}
|
}
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if(visible)
|
if(visible) {
|
||||||
disabled = store.disabledChainIdsToList.includes(model.chainId)
|
disabled = store.disabledChainIdsToList.includes(model.chainId)
|
||||||
|
preferred = store.preferredChainIds.includes(model.chainId)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
onOpacityChanged: {
|
||||||
|
if(opacity === 1) {
|
||||||
|
disabled = store.disabledChainIdsToList.includes(model.chainId)
|
||||||
|
} else {
|
||||||
|
if(opacity === 0 && routeOnNetwork > 0)
|
||||||
|
root.reCalculateSuggestedRoute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// To-do needed for custom view
|
// To-do needed for custom view
|
||||||
// onAdvancedInputTextChanged: {
|
// onAdvancedInputTextChanged: {
|
||||||
// if(selectedNetwork && selectedNetwork.chainName === model.chainName)
|
// if(selectedNetwork && selectedNetwork.chainName === model.chainName)
|
||||||
|
@ -217,11 +232,12 @@ Item {
|
||||||
fromN.routeOnNetwork += 1
|
fromN.routeOnNetwork += 1
|
||||||
toN.routeOnNetwork += 1
|
toN.routeOnNetwork += 1
|
||||||
d.thereIsApossibleRoute = true
|
d.thereIsApossibleRoute = true
|
||||||
|
let routeColor = toN.preferred ? '#627EEA' : Theme.palette.pinColor1
|
||||||
StatusQUtils.Utils.drawArrow(ctx, fromN.x + fromN.width,
|
StatusQUtils.Utils.drawArrow(ctx, fromN.x + fromN.width,
|
||||||
fromN.y + fromN.cardIconPosition + yOffsetFrom,
|
fromN.y + fromN.cardIconPosition + yOffsetFrom,
|
||||||
toNetworksLayout.x + toN.x,
|
toNetworksLayout.x + toN.x,
|
||||||
toN.y + toN.cardIconPosition + yOffsetTo,
|
toN.y + toN.cardIconPosition + yOffsetTo,
|
||||||
'#627EEA', xOffset)
|
routeColor, xOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,17 @@ ColumnLayout {
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
}
|
}
|
||||||
StatusButton {
|
StatusButton {
|
||||||
|
id: preferredToggleButton
|
||||||
Layout.alignment: Qt.AlignRight
|
Layout.alignment: Qt.AlignRight
|
||||||
Layout.preferredHeight: 22
|
Layout.preferredHeight: 22
|
||||||
verticalPadding: 0
|
verticalPadding: -1
|
||||||
|
checkable: true
|
||||||
size: StatusBaseButton.Size.Small
|
size: StatusBaseButton.Size.Small
|
||||||
icon.name: "hide"
|
icon.name: checked ? "show" : "hide"
|
||||||
text: qsTr("Show Unpreferred Networks")
|
icon.height: 16
|
||||||
|
icon.width: 16
|
||||||
|
text: checked ? qsTr("Hide Unpreferred Networks"): qsTr("Show Unpreferred Networks")
|
||||||
|
onToggled: if(!checked) store.addUnpreferredChainsToDisabledChains()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StatusBaseText {
|
StatusBaseText {
|
||||||
|
@ -90,6 +95,7 @@ ColumnLayout {
|
||||||
reCalculateSuggestedRoute: function() {
|
reCalculateSuggestedRoute: function() {
|
||||||
root.reCalculateSuggestedRoute()
|
root.reCalculateSuggestedRoute()
|
||||||
}
|
}
|
||||||
|
showPreferredChains: preferredToggleButton.checked
|
||||||
bestRoutes: root.bestRoutes
|
bestRoutes: root.bestRoutes
|
||||||
weiToEth: root.weiToEth
|
weiToEth: root.weiToEth
|
||||||
interactive: root.interactive
|
interactive: root.interactive
|
||||||
|
|
Loading…
Reference in New Issue