Skip to content

Commit

Permalink
fix: tx fails if the bonder fee is higher than the amount being sent (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
saledjenic authored Aug 9, 2024
1 parent 2f34654 commit e4ddfa4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/app_service/service/transaction/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion ui/app/AppLayouts/Wallet/WalletUtils.qml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ QtObject {


function getRouterErrorBasedOnCode(code) {
if (code === "") {
return ""
}

switch(code) {
case Constants.routerErrorCodes.processor.errFailedToParseBaseFee:
case Constants.routerErrorCodes.processor.errFailedToParsePercentageFee:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 ""
}
Expand Down
6 changes: 2 additions & 4 deletions ui/imports/shared/popups/send/SendModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,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)
Expand Down
1 change: 1 addition & 0 deletions ui/imports/utils/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,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"
}
}

Expand Down

0 comments on commit e4ddfa4

Please sign in to comment.