fix: tx fails if the bonder fee is higher than the amount being sent

Closes #15922
This commit is contained in:
Sale Djenic 2024-07-31 14:33:56 +02:00 committed by saledjenic
parent 74bc695f10
commit 0c4b7e92a0
5 changed files with 23 additions and 8 deletions

View File

@ -152,6 +152,7 @@ QtObject:
networkService: network_service.Service
settingsService: settings_service.Service
tokenService: token_service.Service
uuidOfTheLastRequestForSuggestedRoutes: string
## Forward declarations
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, errCode: string, errDescription: string)
@ -508,7 +509,7 @@ QtObject:
if not asset.isNil:
var foundAddress = false
for addressPerChain in asset.addressPerChainId:
if addressPerChain.chainId == route.toNetwork.chainId:
if addressPerChain.chainId == route.fromNetwork.chainId:
toContractAddress = parseAddress(addressPerChain.address)
foundAddress = true
break
@ -648,8 +649,10 @@ QtObject:
error "Error getting suggested fees", msg = e.msg
proc suggestedRoutesV2Ready(self: Service, uuid: string, route: seq[TransactionPathDtoV2], routeRaw: string, errCode: string, errDescription: string) =
# TODO: refactor sending modal part of the app, but for now since we're integrating the router v2 just map params to the old dto
if self.uuidOfTheLastRequestForSuggestedRoutes != uuid:
return
# TODO: refactor sending modal part of the app, but for now since we're integrating the router v2 just map params to the old dto
var oldRoute = convertToOldRoute(route)
let suggestedDto = SuggestedRoutesDto(
@ -680,6 +683,8 @@ QtObject:
lockedInAmounts: Table[string, string] = initTable[string, string](),
extraParamsTable: Table[string, string] = initTable[string, string]()) =
self.uuidOfTheLastRequestForSuggestedRoutes = uuid
let
bigAmountIn = common_utils.stringToUint256(amountIn)
bigAmountOut = common_utils.stringToUint256(amountOut)

View File

@ -134,6 +134,10 @@ QtObject {
function getRouterErrorBasedOnCode(code) {
if (code === "") {
return ""
}
switch(code) {
case Constants.routerErrorCodes.processor.errFailedToParseBaseFee:
case Constants.routerErrorCodes.processor.errFailedToParsePercentageFee:
@ -203,12 +207,18 @@ QtObject {
return qsTr("not enough token balance")
case Constants.routerErrorCodes.router.errNotEnoughNativeBalance:
return qsTr("not enough ETH")
case Constants.routerErrorCodes.router.errLowAmountInForHopBridge:
return qsTr("amount in too low")
default:
return qsTr("unknown processor error")
}
}
function getRouterErrorDetailsOnCode(code, details) {
if (code === "") {
return ""
}
switch(code) {
case Constants.routerErrorCodes.processor.errFailedToParseBaseFee:
return qsTr("failed to parse base fee")
@ -346,7 +356,8 @@ QtObject {
catch (e) {
return ""
}
case Constants.routerErrorCodes.router.errLowAmountInForHopBridge:
return qsTr("bonder fee greater than estimated received, a higher amount is needed to cover fees")
default:
return ""
}

View File

@ -680,10 +680,8 @@ StatusDialog {
function onSuggestedRoutesReady(txRoutes, errCode, errDescription) {
popup.bestRoutes = txRoutes.suggestedRoutes
if (errCode !== "") {
d.routerError = WalletUtils.getRouterErrorBasedOnCode(errCode)
d.routerErrorDetails = "%1 - %2".arg(errCode).arg(WalletUtils.getRouterErrorDetailsOnCode(errCode, errDescription))
}
d.routerError = WalletUtils.getRouterErrorBasedOnCode(errCode)
d.routerErrorDetails = "%1 - %2".arg(errCode).arg(WalletUtils.getRouterErrorDetailsOnCode(errCode, errDescription))
let gasTimeEstimate = txRoutes.gasTimeEstimate
d.totalTimeEstimate = WalletUtils.getLabelForEstimatedTxTime(gasTimeEstimate.totalTime)

View File

@ -1125,6 +1125,7 @@ QtObject {
readonly property string errNoBestRouteFound : "WR-023"
readonly property string errCannotCheckReceiverBalance : "WR-024"
readonly property string errCannotCheckLockedAmounts : "WR-025"
readonly property string errLowAmountInForHopBridge : "WR-026"
}
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 791ff9a0edef77a1cac7e35580a2464bba7f3d51
Subproject commit 8787da1b899d25a65332b0aee2440b8453062343