Skip to content

Commit

Permalink
Merge pull request #5405 from EdgeApp/matthew/wc-send-raw
Browse files Browse the repository at this point in the history
Fix WalletConnect eth_sendRawTransaction handling
  • Loading branch information
peachbits authored Dec 18, 2024
2 parents 9ca8702 + cad6122 commit bb069b1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- changed: Handle errors in StakeKit API responses
- fixed: Missing "Done" button when managing tokens for certain assets
- fixed: Only send successful import items to completion scene
- fixed: WalletConnect `eth_sendRawTransaction` event handling
- removed: Removed patch for usb and node-hid

## 4.19.0
Expand Down
37 changes: 32 additions & 5 deletions src/components/modals/WcSmartContractModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { abs, add, div, gt, mul } from 'biggystring'
import { asArray, asEither, asNumber, asObject, asOptional, asString, asTuple, asUnknown, asValue } from 'cleaners'
import { EdgeCurrencyWallet, EdgeSpendInfo } from 'edge-core-js'
import { EdgeCurrencyWallet, EdgeSpendInfo, EdgeTransaction } from 'edge-core-js'
import * as React from 'react'
import { Image, ScrollView, View } from 'react-native'
import { AirshipBridge } from 'react-native-airship'
Expand Down Expand Up @@ -116,8 +116,7 @@ export const WcSmartContractModal = (props: Props) => {
await wallet.saveTx(signTx)
break
}
case 'eth_sendTransaction':
case 'eth_sendRawTransaction': {
case 'eth_sendTransaction': {
const cleanPayload = asEvmTransactionPayload(payload)
const spendInfo: EdgeSpendInfo = await wallet.otherMethods.txRpcParamsToSpendInfo(cleanPayload.params[0])
const tx = await wallet.makeSpend(spendInfo)
Expand All @@ -127,6 +126,27 @@ export const WcSmartContractModal = (props: Props) => {
await wallet.saveTx(sentTx)
break
}
case 'eth_sendRawTransaction': {
const cleanPayload = asEvmSendRawTransactionPayload(payload)
const fakeEdgeTransaction: EdgeTransaction = {
blockHeight: 0,
currencyCode: wallet.currencyInfo.currencyCode,
date: 0,
isSend: false,
memos: [],
nativeAmount: '0',
networkFee: '0',
networkFees: [],
ourReceiveAddresses: [],
signedTx: cleanPayload.params[0],
tokenId: null,
txid: '',
walletId: wallet.id
}
const sentTx = await wallet.broadcastTx(fakeEdgeTransaction)
await walletConnect.approveRequest(topic, requestId, sentTx.txid)
break
}
case 'algo_signTxn': {
const cleanPayload = asAlgoWcRpcPayload(payload)
const signedTxs = await Promise.all(cleanPayload.params[0].map(async txnObj => await wallet.signMessage(txnObj.txn)))
Expand Down Expand Up @@ -229,7 +249,12 @@ const asEvmSignPayload = asObject({
params: asTuple(asString, asString)
})

const asEvmTransactionMethod = asValue('eth_sendTransaction', 'eth_signTransaction', 'eth_sendRawTransaction')
const asEvmSendRawTransactionMethod = asValue('eth_sendRawTransaction')
const asEvmSendRawTransactionPayload = asObject({
method: asEvmSendRawTransactionMethod,
params: asTuple(asString)
})
const asEvmTransactionMethod = asValue('eth_sendTransaction', 'eth_signTransaction')
const asEvmTransactionPayload = asObject({
method: asEvmTransactionMethod,
params: asTuple(
Expand Down Expand Up @@ -293,7 +318,9 @@ const asCosmosSignAminoPayload = asObject({
})
})

const asPayload = asObject({ method: asEither(asCosmosPayloadMethod, asAlgoPayloadMethod, asEvmSignMethod, asEvmTransactionMethod) }).withRest
const asPayload = asObject({
method: asEither(asCosmosPayloadMethod, asAlgoPayloadMethod, asEvmSignMethod, asEvmTransactionMethod, asEvmSendRawTransactionMethod)
}).withRest

export const asWcSmartContractModalProps = asObject({
dApp: asObject({
Expand Down

0 comments on commit bb069b1

Please sign in to comment.