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(connect): allow to: null in ethereumSignTransaction for contract deployment #16835

Merged
merged 2 commits into from
Feb 5, 2025
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
6 changes: 5 additions & 1 deletion packages/connect-explorer/src/components/ParamsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ const SingleParam = ({
{hasDescendants && (
<div style={{ marginLeft: 30 }}>
{/* eslint-disable-next-line @typescript-eslint/no-use-before-define */}
<ParamsTable schema={value} topLevelSchema={topLevelSchema} />
<ParamsTable
schema={value}
topLevelSchema={topLevelSchema}
descriptions={descriptions}
/>
</div>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const paramDescriptions = {
'type of [`EthereumTransactionEIP1559`](https://github.com/trezor/trezor-suite/blob/develop/packages/connect/src/types/api/ethereum/index.ts)`|`[`EthereumSignTransaction`](https://github.com/trezor/trezor-suite/blob/develop/packages/connect/src/types/api/ethereum/index.ts) "0x" prefix for each field is optional',
chunkify:
'determines if recipient address will be displayed in chunks of 4 characters. Default is set to `false`',
to: "recipient's address, contract address or `null` in case of contract creation",
};

## Ethereum: Sign transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export default class EthereumSignTransaction extends AbstractMethod<
const definitions = await getEthereumDefinitions({
chainId: this.params.tx.chainId,
slip44,
contractAddress: this.params.tx.data ? this.params.tx.to : undefined,
contractAddress:
this.params.tx.data && this.params.tx.to != null ? this.params.tx.to : undefined,
});
this.params.definitions = definitions;

Expand Down
9 changes: 5 additions & 4 deletions packages/connect/src/api/ethereum/ethereumSignTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const serializeEthereumTx = (
const txData = deepHexPrefix({
...tx,
...signature,
to: tx.to || undefined,
type: isLegacy ? 0 : 2, // 0 for legacy, 2 for EIP-1559
...(isLegacy
? {
Expand Down Expand Up @@ -123,7 +124,7 @@ export const ethereumSignTx = async (
// todo: don't we change parameters here to object?
typedCall: TypedCall,
address_n: number[],
to: string,
to: string | null,
value: string,
gas_limit: string,
gas_price: string,
Expand All @@ -144,7 +145,7 @@ export const ethereumSignTx = async (
nonce: stripLeadingZeroes(nonce),
gas_price: stripLeadingZeroes(gas_price),
gas_limit: stripLeadingZeroes(gas_limit),
to,
to: to || undefined,
value: stripLeadingZeroes(value),
definitions,
chunkify,
Expand Down Expand Up @@ -174,7 +175,7 @@ export const ethereumSignTxEIP1559 = async (
// todo: don't we change parameters here to object?
typedCall: TypedCall,
address_n: number[],
to: string,
to: string | null,
value: string,
gas_limit: string,
max_gas_fee: string,
Expand All @@ -196,7 +197,7 @@ export const ethereumSignTxEIP1559 = async (
max_gas_fee: stripLeadingZeroes(max_gas_fee),
max_priority_fee: stripLeadingZeroes(max_priority_fee),
gas_limit: stripLeadingZeroes(gas_limit),
to,
to: to || undefined,
value: stripLeadingZeroes(value),
data_length: length,
data_initial_chunk: first,
Expand Down
4 changes: 2 additions & 2 deletions packages/connect/src/types/api/ethereum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const EthereumSignMessage = Type.Object({

export type EthereumTransaction = Static<typeof EthereumTransaction>;
export const EthereumTransaction = Type.Object({
to: Type.String(),
to: Type.Union([Type.String(), Type.Null()]),
value: Type.String(),
gasPrice: Type.String(),
gasLimit: Type.String(),
Expand All @@ -35,7 +35,7 @@ export const EthereumAccessList = Type.Object({

export type EthereumTransactionEIP1559 = Static<typeof EthereumTransactionEIP1559>;
export const EthereumTransactionEIP1559 = Type.Object({
to: Type.String(),
to: Type.Union([Type.String(), Type.Null()]),
value: Type.String(),
gasLimit: Type.String(),
gasPrice: Type.Optional(Type.Undefined()),
Expand Down
Loading