Skip to content

Commit

Permalink
fix: tx params prefix 0x (RabbyHub#1919)
Browse files Browse the repository at this point in the history
* fix: tx params prefix 0x

* fix: personal_sign message prefix 0x
  • Loading branch information
vvvvvv1vvvvvv authored Dec 15, 2023
1 parent 5ff2212 commit b6705aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/background/controller/provider/rpcFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { resemblesETHAddress } from '@/utils';
import { ProviderRequest } from './type';
import * as Sentry from '@sentry/browser';
import stats from '@/stats';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';

const isSignApproval = (type: string) => {
const SIGN_APPROVALS = ['SignText', 'SignTypedData', 'SignTx'];
Expand Down Expand Up @@ -174,6 +175,11 @@ const flowContext = flow
from = second;
message = first;
}
const hexReg = /^[0-9A-Fa-f]+$/gu;
const stripped = stripHexPrefix(message);
if (stripped.match(hexReg)) {
message = addHexPrefix(stripped);
}
ctx.request.data.params[0] = message;
ctx.request.data.params[1] = from;
}
Expand Down
10 changes: 10 additions & 0 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const normalizeHex = (value: string | number) => {

const normalizeTxParams = (tx) => {
const copy = tx;
console.log('copy', tx);
try {
if ('nonce' in copy && isStringOrNumber(copy.nonce)) {
copy.nonce = normalizeHex(copy.nonce);
Expand All @@ -112,6 +113,15 @@ const normalizeTxParams = (tx) => {
if ('gasPrice' in copy && isStringOrNumber(copy.gasPrice)) {
copy.gasPrice = normalizeHex(copy.gasPrice);
}
if ('maxFeePerGas' in copy && isStringOrNumber(copy.maxFeePerGas)) {
copy.maxFeePerGas = normalizeHex(copy.maxFeePerGas);
}
if (
'maxPriorityFeePerGas' in copy &&
isStringOrNumber(copy.maxPriorityFeePerGas)
) {
copy.maxPriorityFeePerGas = normalizeHex(copy.maxPriorityFeePerGas);
}
if ('value' in copy) {
if (!isStringOrNumber(copy.value)) {
copy.value = '0x0';
Expand Down

0 comments on commit b6705aa

Please sign in to comment.