Skip to content
Permalink
Browse files

fix decimal encoding for transaction data and chainId requests

  • Loading branch information...
pedrouid committed May 10, 2019
1 parent 95b9898 commit 7d0cda3b4014cdb4f0aa3555e94b4031a5336cee
Showing with 16 additions and 17 deletions.
  1. +2 −2 packages/core/src/index.ts
  2. +14 −15 packages/utils/src/index.ts
@@ -24,7 +24,7 @@ import {
uuid,
formatRpcError,
parseWalletConnectUri,
convertUtf8ToHex
convertNumberToHex
} from '@walletconnect/utils'
import SocketTransport from './socket'
import EventManager from './events'
@@ -612,7 +612,7 @@ class Connector {
case 'eth_accounts':
return this.accounts
case 'eth_chainId':
return convertUtf8ToHex(`${this.chainId}`)
return convertNumberToHex(this.chainId)
case 'eth_sendTransaction':
case 'eth_signTransaction':
if (request.params) {
@@ -451,11 +451,15 @@ export function parseTransactionData (
throw new Error(`Transaction object must include a valid 'from' value.`)
}

function parseHexValues (str: string) {
if (utils.isHexString(str)) {
return str
function parseHexValues (value: number | string) {
let result = value
if (!utils.isHexString(value)) {
if (typeof value === 'string') {
value = convertUtf8ToNumber(value)
}
result = convertNumberToHex(value)
}
return convertUtf8ToHex(str)
return result
}

const txDataRPC = {
@@ -464,23 +468,18 @@ export function parseTransactionData (
gasPrice:
typeof txData.gasPrice === 'undefined'
? ''
: parseHexValues(`${txData.gasPrice}`),
: parseHexValues(txData.gasPrice),
gasLimit:
typeof txData.gasLimit === 'undefined'
? typeof txData.gas === 'undefined'
? ''
: parseHexValues(`${txData.gas}`)
: parseHexValues(`${txData.gasLimit}`),
: parseHexValues(txData.gas)
: parseHexValues(txData.gasLimit),
value:
typeof txData.value === 'undefined'
? ''
: parseHexValues(`${txData.value}`),
typeof txData.value === 'undefined' ? '' : parseHexValues(txData.value),
nonce:
typeof txData.nonce === 'undefined'
? ''
: parseHexValues(`${txData.nonce}`),
data:
typeof txData.data === 'undefined' ? '' : parseHexValues(`${txData.data}`)
typeof txData.nonce === 'undefined' ? '' : parseHexValues(txData.nonce),
data: typeof txData.data === 'undefined' ? '' : sanitizeHex(txData.data)
}

const prunable = ['gasPrice', 'gasLimit', 'value', 'nonce']

0 comments on commit 7d0cda3

Please sign in to comment.
You can’t perform that action at this time.