Skip to content

Commit 7710277

Browse files
committed
renamed types, fixed wallet connect
1 parent d3c3e35 commit 7710277

File tree

6 files changed

+60
-23
lines changed

6 files changed

+60
-23
lines changed

examples/foundry/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Block: 9624270
8383
Paid: 0.000000162718420767 ETH (156813 gas * 0.001037659 gwei)
8484
8585
✅ Sequence #1 on sepolia | Total Paid: 0.000000162718420767 ETH (156813 gas * avg 0.001037659 gwei)
86-
86+
8787
8888
==========================
8989
```

examples/with-sdk-js/src/app/layout.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ function RootLayout({ children }: RootLayoutProps) {
6262
],
6363
},
6464
},
65-
// walletConnect: {
66-
// projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID!,
67-
// appMetadata: {
68-
// name: "Turnkey Wallet",
69-
// description: "A wallet for Turnkey",
70-
// url: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_URL!,
71-
// icons: ["/favicon.svg"],
72-
// },
73-
// },
65+
walletConnect: {
66+
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID!,
67+
appMetadata: {
68+
name: "Turnkey Wallet",
69+
description: "A wallet for Turnkey",
70+
url: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_URL!,
71+
icons: ["/favicon.svg"],
72+
},
73+
},
7474
},
7575
}}
7676
>

examples/with-sdk-js/src/app/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,8 +1624,9 @@ export default function AuthPage() {
16241624
value: parseEther("0.001"),
16251625
nonce: 0,
16261626
gasLimit: BigInt("21000"),
1627-
maxFeePerGas: BigInt("1000000000"),
1628-
maxPriorityFeePerGas: BigInt("1000000000"),
1627+
gasPrice: BigInt("100000000000000"),
1628+
// maxFeePerGas: BigInt("1000000000"),
1629+
// maxPriorityFeePerGas: BigInt("1000000000"),
16291630
chainId: 1,
16301631
};
16311632

packages/core/src/__types__/external-wallets.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export interface ConnectedWallet extends v1Wallet {
219219
/** @internal */
220220
export type Wallet = EmbeddedWallet | ConnectedWallet;
221221

222-
export type BaseTransactionParams = {
222+
export type EvmTransactionParams = {
223223
from: `0x${string}`;
224224
to: `0x${string}`;
225225
value: `0x${string}`;
@@ -229,16 +229,16 @@ export type BaseTransactionParams = {
229229
data: `0x${string}`;
230230
};
231231

232-
export type EIP1559TransactionParams = BaseTransactionParams & {
232+
export type EIP1559TransactionParams = EvmTransactionParams & {
233233
maxFeePerGas: `0x${string}`;
234234
maxPriorityFeePerGas: `0x${string}`;
235235
};
236236

237-
export type LegacyTransactionParams = BaseTransactionParams & {
237+
export type LegacyEvmTransactionParams = EvmTransactionParams & {
238238
gasPrice: `0x${string}`;
239239
};
240240

241241
/** @internal */
242242
export type EthereumTxParams =
243243
| EIP1559TransactionParams
244-
| LegacyTransactionParams;
244+
| LegacyEvmTransactionParams;

packages/core/src/__wallet__/wallet-connect/base.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
WalletConnectProvider,
1616
WalletConnectInterface,
1717
SwitchableChain,
18+
EvmTransactionParams,
19+
EthereumTxParams,
1820
} from "../../__types__";
1921
import type { WalletConnectClient } from "./client";
2022
import type { SessionTypes } from "@walletconnect/types";
@@ -320,20 +322,52 @@ export class WalletConnectWallet implements WalletConnectInterface {
320322
address,
321323
])) as string;
322324
case SignIntent.SignAndSendTransaction:
323-
const account = provider.connectedAddresses[0];
325+
const account = provider.connectedAddresses[0] as Hex;
326+
if (!account) throw new Error("no connected address");
324327
const tx = Transaction.from(payload);
325-
const txParams = {
328+
329+
const base: EvmTransactionParams = {
326330
from: account,
327331
to: tx.to?.toString() as Hex,
328332
value: toHex(tx.value),
329333
gas: toHex(tx.gasLimit),
330-
maxFeePerGas: toHex(tx.maxFeePerGas ?? 0n),
331-
maxPriorityFeePerGas: toHex(tx.maxPriorityFeePerGas ?? 0n),
332334
nonce: toHex(tx.nonce),
333335
chainId: toHex(tx.chainId),
334336
data: (tx.data?.toString() as Hex) ?? "0x",
335337
};
336338

339+
// Some libs use undefined for legacy, so normalize
340+
const txType = (tx as any).type ?? 0;
341+
342+
let txParams: EthereumTxParams;
343+
344+
if (txType === undefined || txType === 0 || txType === 1) {
345+
// legacy or EIP-2930 (gasPrice-based)
346+
if (tx.gasPrice == null) {
347+
throw new Error(
348+
"Legacy or EIP-2930 transaction missing gasPrice",
349+
);
350+
}
351+
352+
txParams = {
353+
...base,
354+
gasPrice: toHex(tx.gasPrice),
355+
};
356+
} else {
357+
// EIP-1559 or future fee-market types
358+
if (tx.maxFeePerGas == null || tx.maxPriorityFeePerGas == null) {
359+
throw new Error(
360+
"EIP-1559-style transaction missing maxFeePerGas or maxPriorityFeePerGas",
361+
);
362+
}
363+
364+
txParams = {
365+
...base,
366+
maxFeePerGas: toHex(tx.maxFeePerGas),
367+
maxPriorityFeePerGas: toHex(tx.maxPriorityFeePerGas),
368+
};
369+
}
370+
337371
return (await this.client.request(
338372
this.ethChain,
339373
"eth_sendTransaction",

packages/core/src/__wallet__/web/native/ethereum.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { Transaction } from "ethers";
1010
import { compressRawPublicKey } from "@turnkey/crypto";
1111
import {
12-
BaseTransactionParams,
12+
EvmTransactionParams,
1313
Chain,
1414
EthereumTxParams,
1515
EthereumWalletInterface,
@@ -284,7 +284,7 @@ export class EthereumWallet extends BaseEthereumWallet {
284284
case SignIntent.SignAndSendTransaction: {
285285
const tx = Transaction.from(payload);
286286

287-
const base: BaseTransactionParams = {
287+
const base: EvmTransactionParams = {
288288
from: account,
289289
to: tx.to?.toString() as Hex,
290290
value: toHex(tx.value),
@@ -312,7 +312,9 @@ export class EthereumWallet extends BaseEthereumWallet {
312312
} else {
313313
// EIP-1559 or future fee-market types
314314
if (tx.maxFeePerGas == null || tx.maxPriorityFeePerGas == null) {
315-
throw new Error("EIP-1559-style transaction missing maxFeePerGas or maxPriorityFeePerGas");
315+
throw new Error(
316+
"EIP-1559-style transaction missing maxFeePerGas or maxPriorityFeePerGas",
317+
);
316318
}
317319

318320
txParams = {

0 commit comments

Comments
 (0)