Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: borked walletconnect v2 send transaction confirmation #4978

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
0xApotheosis marked this conversation as resolved.
Show resolved Hide resolved
? {
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)

0xApotheosis marked this conversation as resolved.
Show resolved Hide resolved
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
0xApotheosis marked this conversation as resolved.
Show resolved Hide resolved
? convertHexToNumber((transaction?.gasLimit ?? transaction?.gas)!).toString()
Copy link
Contributor

@0xApotheosis 0xApotheosis Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we guaranteed to have either a gas or a gasLimit?
If not we might want to fallback to 0 or something so we don't throw.

: 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)
0xApotheosis marked this conversation as resolved.
Show resolved Hide resolved

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