Skip to content

Commit

Permalink
fix(@desktop/wallet): send modal not working with bridge hop (mainnet…
Browse files Browse the repository at this point in the history
… to optimism)

Fixes #12615
  • Loading branch information
saledjenic committed Nov 6, 2023
1 parent 52dd0ab commit 94953bb
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 30 deletions.
6 changes: 4 additions & 2 deletions src/app/modules/main/wallet_section/send/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ proc authenticate*(self: Controller, keyUid = "") =
keyUid: keyUid)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)

proc suggestedRoutes*(self: Controller, account: string, amount: Uint256, token: string, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): string =
let suggestedRoutes = self.transactionService.suggestedRoutes(account, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts)
proc suggestedRoutes*(self: Controller, accountFrom: string, accountTo: string, amount: Uint256, token: string, disabledFromChainIDs,
disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): string =
let suggestedRoutes = self.transactionService.suggestedRoutes(accountFrom, accountTo, amount, token, disabledFromChainIDs,
disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts)
return suggestedRoutes.toJson()

proc transfer*(self: Controller, from_addr: string, to_addr: string, tokenSymbol: string,
Expand Down
3 changes: 2 additions & 1 deletion src/app/modules/main/wallet_section/send/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ method refreshWalletAccounts*(self: AccessInterface) {.base.} =
method getTokenBalanceOnChain*(self: AccessInterface, address: string, chainId: int, symbol: string): CurrencyAmount {.base.} =
raise newException(ValueError, "No implementation available")

method suggestedRoutes*(self: AccessInterface, account: string, amount: UInt256, token: string, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): string {.base.} =
method suggestedRoutes*(self: AccessInterface, accountFrom: string, accountTo: string, amount: UInt256, token: string, disabledFromChainIDs,
disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): string {.base.} =
raise newException(ValueError, "No implementation available")

method suggestedRoutesReady*(self: AccessInterface, suggestedRoutes: SuggestedRoutesDto) {.base.} =
Expand Down
11 changes: 6 additions & 5 deletions src/app/modules/main/wallet_section/send/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export io_interface
logScope:
topics = "wallet-send-module"

const cancelledRequest* = "cancelled"
const authenticationCanceled* = "authenticationCanceled"

# Shouldn't be public ever, use only within this module.
type TmpSendTransactionDetails = object
Expand Down Expand Up @@ -279,7 +279,7 @@ method authenticateAndTransfer*(self: Module, fromAddr: string, toAddr: string,

method onUserAuthenticated*(self: Module, password: string, pin: string) =
if password.len == 0:
self.transactionWasSent()
self.transactionWasSent(chainId = 0, txHash = "", uuid = self.tmpSendTransactionDetails.uuid, error = authenticationCanceled)
else:
self.tmpPin = pin
let doHashing = self.tmpPin.len == 0
Expand Down Expand Up @@ -323,12 +323,13 @@ method onTransactionSigned*(self: Module, keycardFlowType: string, keycardEvent:

method transactionWasSent*(self: Module, chainId: int, txHash, uuid, error: string) =
if txHash.len == 0:
self.view.sendTransactionSentSignal(chainId = 0, txHash = "", uuid = self.tmpSendTransactionDetails.uuid, error = cancelledRequest)
self.view.sendTransactionSentSignal(chainId = 0, txHash = "", uuid = self.tmpSendTransactionDetails.uuid, error)
return
self.view.sendTransactionSentSignal(chainId, txHash, uuid, error)

method suggestedRoutes*(self: Module, account: string, amount: UInt256, token: string, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): string =
return self.controller.suggestedRoutes(account, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts)
method suggestedRoutes*(self: Module, accountFrom: string, accountTo: string, amount: UInt256, token: string, disabledFromChainIDs,
disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): string =
return self.controller.suggestedRoutes(accountFrom, accountTo, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, sendType, lockedInAmounts)

method suggestedRoutesReady*(self: Module, suggestedRoutes: SuggestedRoutesDto) =
self.tmpSendTransactionDetails.paths = suggestedRoutes.best
Expand Down
6 changes: 4 additions & 2 deletions src/app/modules/main/wallet_section/send/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,18 @@ QtObject:
proc setTransactionRoute*(self: View, routes: TransactionRoutes) =
self.transactionRoutes = routes
self.suggestedRoutesReady(newQVariant(self.transactionRoutes))

proc suggestedRoutes*(self: View, amount: string): string {.slot.} =
var parsedAmount = stint.u256(0)
try:
parsedAmount = amount.parse(Uint256)
except Exception as e:
discard

return self.delegate.suggestedRoutes(self.selectedSenderAccount.address(),
return self.delegate.suggestedRoutes(self.selectedSenderAccount.address(), self.selectedRecipient,
parsedAmount, self.selectedAssetSymbol, self.fromNetworksModel.getRouteDisabledNetworkChainIds(),
self.toNetworksModel.getRouteDisabledNetworkChainIds(), self.toNetworksModel.getRoutePreferredNetworkChainIds(), self.sendType, self.fromNetworksModel.getRouteLockedChainIds())
self.toNetworksModel.getRouteDisabledNetworkChainIds(), self.toNetworksModel.getRoutePreferredNetworkChainIds(),
self.sendType, self.fromNetworksModel.getRouteLockedChainIds())

proc switchSenderAccountByAddress*(self: View, address: string) =
let (account, index) = self.senderAccounts.getItemByAddress(address)
Expand Down
6 changes: 2 additions & 4 deletions src/app_service/service/keycard/internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ proc toTransactionSignature(jsonObj: JsonNode): TransactionSignature =
discard jsonObj.getProp(ResponseParamTxSignatureS, result.s)
var v: int
discard jsonObj.getProp(ResponseParamTxSignatureV, v)
## The signature must conform to the secp256k1 curve R, S and V values, where the V value must be 27 or 28 for legacy reasons.
## Transform V from 0/1 to 27/28 (1b/1c) according to the yellow paper https://ethereum.github.io/yellowpaper/paper.pdf
result.v = "1b"
result.v = "00"
if v == 1:
result.v = "1c"
result.v = "01"

proc toKeycardEvent(jsonObj: JsonNode): KeycardEvent =
discard jsonObj.getProp(ResponseParamErrorKey, result.error)
Expand Down
11 changes: 7 additions & 4 deletions src/app_service/service/transaction/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ proc sortAsc[T](t1, t2: T): int =

type
GetSuggestedRoutesTaskArg* = ref object of QObjectTaskArg
account: string
accountFrom: string
accountTo: string
amount: Uint256
token: string
disabledFromChainIDs: seq[int]
Expand Down Expand Up @@ -88,12 +89,14 @@ const getSuggestedRoutesTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall
except:
discard

let response = eth.suggestedRoutes(arg.account, amountAsHex, arg.token, arg.disabledFromChainIDs, arg.disabledToChainIDs, arg.preferredChainIDs, ord(arg.sendType), lockedInAmounts).result
let response = eth.suggestedRoutes(arg.accountFrom, arg.accountTo, amountAsHex, arg.token, arg.disabledFromChainIDs,
arg.disabledToChainIDs, arg.preferredChainIDs, ord(arg.sendType), lockedInAmounts).result
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, @[], ord(arg.sendType), lockedInAmounts).result
let response = eth.suggestedRoutes(arg.accountFrom, arg.accountTo, amountAsHex, arg.token, arg.disabledFromChainIDs,
arg.disabledToChainIDs, @[], ord(arg.sendType), lockedInAmounts).result
bestPaths = response["Best"].getElems().map(x => x.toTransactionPathDto())

bestPaths.sort(sortAsc[TransactionPathDto])
Expand Down Expand Up @@ -165,7 +168,7 @@ const getCryptoServicesTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.
error "Error fetching crypto services", message = e.msg
arg.finish(%* {
"result": @[],
})
})

type
FetchDecodedTxDataTaskArg* = ref object of QObjectTaskArg
Expand Down
11 changes: 4 additions & 7 deletions src/app_service/service/transaction/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,6 @@ QtObject:
try:
let response = transactions.proceedWithTransactionsSignatures(signatures)
self.sendTransactionSentSignal(fromAddr, toAddr, uuid, selectedRoutes, response)
if response.result{"hashes"} != nil:
for route in selectedRoutes:
for hash in response.result["hashes"][$route.fromNetwork.chainID]:
self.watchTransaction(hash.getStr, fromAddr, toAddr, $PendingTransactionTypeDto.WalletTransfer, " ", route.fromNetwork.chainID, track = false)
self.events.emit(SIGNAL_TRANSACTION_SENT, TransactionSentArgs(chainId: route.fromNetwork.chainID, txHash: hash.getStr, uuid: uuid , error: ""))
except Exception as e:
self.sendTransactionSentSignal(fromAddr, toAddr, uuid, @[], RpcResponse[JsonNode](), fmt"Error proceeding with transactions signatures: {e.msg}")

Expand All @@ -451,12 +446,14 @@ QtObject:
error "error handling suggestedRoutesReady response", errDesription=e.msg
self.events.emit(SIGNAL_SUGGESTED_ROUTES_READY, SuggestedRoutesArgs(suggestedRoutes: suggestedRoutesDto))

proc suggestedRoutes*(self: Service, account: string, amount: Uint256, token: string, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): SuggestedRoutesDto =
proc suggestedRoutes*(self: Service, accountFrom: string, accountTo: string, amount: Uint256, token: string, disabledFromChainIDs,
disabledToChainIDs, preferredChainIDs: seq[int], sendType: SendType, lockedInAmounts: string): SuggestedRoutesDto =
let arg = GetSuggestedRoutesTaskArg(
tptr: cast[ByteAddress](getSuggestedRoutesTask),
vptr: cast[ByteAddress](self.vptr),
slot: "suggestedRoutesReady",
account: account,
accountFrom: accountFrom,
accountTo: accountTo,
amount: amount,
token: token,
disabledFromChainIDs: disabledFromChainIDs,
Expand Down
5 changes: 3 additions & 2 deletions src/backend/eth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ proc suggestedFees*(chainId: int): RpcResponse[JsonNode] {.raises: [Exception].}
let payload = %* [chainId]
return core.callPrivateRPC("wallet_getSuggestedFees", payload)

proc suggestedRoutes*(account: string, amount: string, token: string, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs: seq[int], sendType: int, lockedInAmounts: var Table[string, string]): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [sendType, account, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, 1 , lockedInAmounts]
proc suggestedRoutes*(accountFrom: string, accountTo: string, amount: string, token: string, disabledFromChainIDs,
disabledToChainIDs, preferredChainIDs: seq[int], sendType: int, lockedInAmounts: var Table[string, string]): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* [sendType, accountFrom, accountTo, amount, token, disabledFromChainIDs, disabledToChainIDs, preferredChainIDs, 1, lockedInAmounts]
return core.callPrivateRPC("wallet_getSuggestedRoutes", payload)

rpc(getEstimatedLatestBlockNumber, "wallet"):
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/shared/popups/send/SendModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ StatusDialog {
d.isPendingTx = false
if (uuid !== d.uuid) return
if (!!error) {
if (error.includes(Constants.walletSection.cancelledMessage)) {
if (error.includes(Constants.walletSection.authenticationCanceled)) {
return
}
sendingError.text = error
Expand Down
2 changes: 1 addition & 1 deletion ui/imports/utils/Constants.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ QtObject {
}

readonly property QtObject walletSection: QtObject {
readonly property string cancelledMessage: "cancelled"
readonly property string authenticationCanceled: "authenticationCanceled"
}

// list of symbols for which pngs are stored to avoid
Expand Down

0 comments on commit 94953bb

Please sign in to comment.