Skip to content

Commit

Permalink
fix: borked walletconnect v2 send transaction confirmation (#4978)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Jul 25, 2023
1 parent b1cf0d0 commit 3c0feb8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/plugins/walletConnectToDapps/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ export const getGasData = (
fees: FeeDataEstimate<EvmChainId>,
) => {
const { speed, customFee } = customTransactionData
return speed === 'custom' && customFee?.baseFee && customFee?.baseFee
return speed === 'custom' &&
bnOrZero(customFee?.baseFee).gt(0) &&
bnOrZero(customFee?.priorityFee).gt(0)
? {
maxPriorityFeePerGas: convertNumberToHex(
bnOrZero(customFee.priorityFee).times(1e9).toString(), // to wei
bnOrZero(customFee!.priorityFee).times(1e9).toString(), // to wei
),
maxFeePerGas: convertNumberToHex(
bnOrZero(customFee.baseFee).times(1e9).toString(), // to wei
bnOrZero(customFee!.baseFee).times(1e9).toString(), // to wei
),
}
: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const EIP155TransactionConfirmation: FC<
WalletConnectRequestModalProps<EthSendTransactionCallRequest | EthSignTransactionCallRequest>
> = ({ onConfirm: handleConfirm, onReject: handleReject, state }) => {
const { address, transaction, isInteractingWithContract, method } = useWalletConnectState(state)
assertIsTransactionParams(transaction)

transaction && assertIsTransactionParams(transaction)

const { feeAsset, fees, feeAssetPrice } = useCallRequestEvmFees(state)

Expand All @@ -46,10 +47,11 @@ export const EIP155TransactionConfirmation: FC<

const form = useForm<CustomTransactionData>({
defaultValues: {
nonce: transaction.nonce ? convertHexToNumber(transaction.nonce).toString() : undefined,
gasLimit: transaction.gasLimit
? convertHexToNumber(transaction.gasLimit).toString()
: undefined,
nonce: transaction?.nonce ? convertHexToNumber(transaction.nonce).toString() : undefined,
gasLimit:
transaction?.gasLimit ?? transaction?.gas
? convertHexToNumber((transaction?.gasLimit ?? transaction?.gas)!).toString()
: undefined,
speed: FeeDataKey.Average,
customFee: {
baseFee: '0',
Expand All @@ -65,6 +67,7 @@ export const EIP155TransactionConfirmation: FC<
</Center>
)

if (!transaction) return null
return (
<FormProvider {...form}>
<ModalSection title='plugins.walletConnectToDapps.modal.sendTransaction.sendingFrom'>
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/walletConnectToDapps/v2/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ export const isTransactionParams = (
!!transaction?.from &&
!!transaction?.to &&
!!transaction?.data &&
!!transaction?.value &&
!!transaction?.gasLimit &&
!!transaction?.gasPrice &&
!!transaction?.nonce
((!!transaction?.gasLimit && !!transaction?.gasPrice) || !!transaction?.gas)

export const assertIsTransactionParams: (
transaction: TransactionParams | string | undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/walletConnectToDapps/v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export enum WalletConnectModal {

export type CustomTransactionData = {
nonce?: string
gas?: string
gasLimit?: string
speed: WalletConnectFeeDataKey
customFee?: {
Expand All @@ -100,6 +101,7 @@ export type TransactionParams = {
to: string
data: string
gasLimit?: string
gas?: string
gasPrice?: string
value?: string
nonce?: string
Expand Down

0 comments on commit 3c0feb8

Please sign in to comment.