Skip to content

Commit b1d9e4a

Browse files
authored
chore: Remove unused code from LocalWallet (#2798)
1 parent 5398d68 commit b1d9e4a

File tree

16 files changed

+75
-1097
lines changed

16 files changed

+75
-1097
lines changed

.changeset/perfect-ducks-walk.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44

55
Open "Buy Modal" UI when sending transaction using the `useSendTransaction` hook if the user does not have enough funds to execute the transaction to prompt the user to buy tokens
66

7-
`useSendTransaction` now takes an optional `config` option to customize the "Buy Modal" UI
7+
`useSendTransaction` now takes an optional `config` option to customize the "Pay Modal" UI
88

99
```tsx
1010
const sendTransaction = useSendTransaction({
11-
buyModal: {
11+
payModal: {
1212
locale: 'en_US',
1313
theme: 'light'
1414
}
1515
});
16+
```
17+
18+
You may also explicitly disable the "Pay Modal" UI by setting the `payModal` option to `false`
19+
20+
```tsx
21+
const sendTransaction = useSendTransaction({
22+
payModal: false
23+
});
1624
```

packages/thirdweb/benchmarks/send-transaction.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { run, bench, group } from "mitata";
1+
import { bench, group, run } from "mitata";
22

3-
import { prepareTransaction } from "../src/transaction/prepare-transaction";
4-
import { createThirdwebClient } from "../src/client/client";
53
import { defineChain } from "../src/chains/utils";
6-
import { privateKeyAccount } from "../src/wallets/private-key";
4+
import { createThirdwebClient } from "../src/client/client";
75
import { sendTransaction } from "../src/transaction/actions/send-transaction";
6+
import { prepareTransaction } from "../src/transaction/prepare-transaction";
7+
import { privateKeyToAccount } from "../src/wallets/private-key";
88

9+
import * as ethers from "ethers6";
910
import * as viem from "viem";
10-
import { privateKeyToAccount } from "viem/accounts";
11+
import { privateKeyToAccount as viemPrivateKeyToAccount } from "viem/accounts";
1112
import { mainnet } from "viem/chains";
12-
import * as ethers from "ethers6";
1313

1414
const LOCAL_RPC = "http://127.0.0.1:8545";
1515
const VITALIK_WALLET = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B";
@@ -27,13 +27,13 @@ const TEST_CHAIN = defineChain({
2727
const PKEY =
2828
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
2929

30-
const account = privateKeyAccount({
30+
const account = privateKeyToAccount({
3131
privateKey: PKEY,
3232
client,
3333
});
3434

3535
// viem setup
36-
const privateKeyAccountViem = privateKeyToAccount(PKEY);
36+
const privateKeyAccountViem = viemPrivateKeyToAccount(PKEY);
3737
const walletClient = viem.createWalletClient({
3838
account: privateKeyAccountViem,
3939
transport: viem.http(LOCAL_RPC),

packages/thirdweb/src/adapters/ethers5.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { describe, expect, test } from "vitest";
33
import { ANVIL_CHAIN } from "../../test/src/chains.js";
44
import { TEST_CLIENT } from "../../test/src/test-clients.js";
55
import { ANVIL_PKEY_A, TEST_ACCOUNT_B } from "../../test/src/test-wallets.js";
6-
import { privateKeyAccount } from "../wallets/private-key.js";
6+
import { privateKeyToAccount } from "../wallets/private-key.js";
77
import { toEthersSigner } from "./ethers5.js";
88

9-
const account = privateKeyAccount({
9+
const account = privateKeyToAccount({
1010
privateKey: ANVIL_PKEY_A,
1111
client: TEST_CLIENT,
1212
});

packages/thirdweb/src/adapters/ethers6.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { describe, expect, test } from "vitest";
22
import { ANVIL_CHAIN } from "../../test/src/chains.js";
33
import { TEST_CLIENT } from "../../test/src/test-clients.js";
44
import { ANVIL_PKEY_A, TEST_ACCOUNT_B } from "../../test/src/test-wallets.js";
5-
import { privateKeyAccount } from "../wallets/private-key.js";
5+
import { privateKeyToAccount } from "../wallets/private-key.js";
66
import { ethers6Adapter } from "./ethers6.js";
77

8-
const account = privateKeyAccount({
8+
const account = privateKeyToAccount({
99
privateKey: ANVIL_PKEY_A,
1010
client: TEST_CLIENT,
1111
});

packages/thirdweb/src/adapters/viem.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { ANVIL_PKEY_A } from "~test/test-wallets.js";
44
import { typedData } from "~test/typed-data.js";
55
import { ANVIL_CHAIN, FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js";
66
import { TEST_CLIENT } from "../../test/src/test-clients.js";
7-
import { privateKeyAccount } from "../wallets/private-key.js";
7+
import { privateKeyToAccount } from "../wallets/private-key.js";
88
import { viemAdapter } from "./viem.js";
99

10-
const account = privateKeyAccount({
10+
const account = privateKeyToAccount({
1111
privateKey: ANVIL_PKEY_A,
1212
client: TEST_CLIENT,
1313
});

packages/thirdweb/src/exports/wallets.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ export {
2424

2525
// private-key
2626
export {
27-
privateKeyAccount,
2827
privateKeyToAccount,
29-
type PrivateKeyAccountOptions,
28+
/**
29+
* @internal
30+
* @deprecated - use {@link privateKeyToAccount} instead
31+
*/
32+
privateKeyToAccount as privateKeyAccount,
33+
type PrivateKeyToAccountOptions,
34+
/**
35+
* @internal
36+
* @deprecated - use {@link PrivateKeyToAccountOptions} instead
37+
*/
38+
type PrivateKeyToAccountOptions as PrivateKeyAccountOptions,
3039
} from "../wallets/private-key.js";
3140

3241
// injected
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
export {
2-
privateKeyAccount,
3-
type PrivateKeyAccountOptions,
2+
privateKeyToAccount,
3+
/**
4+
* @internal
5+
* @deprecated - use {@link privateKeyToAccount} instead
6+
*/
7+
privateKeyToAccount as privateKeyAccount,
8+
type PrivateKeyToAccountOptions,
9+
/**
10+
* @internal
11+
* @deprecated - use {@link PrivateKeyToAccountOptions} instead
12+
*/
13+
type PrivateKeyToAccountOptions as PrivateKeyAccountOptions,
414
} from "../../wallets/private-key.js";

packages/thirdweb/src/react/core/hooks/contract/useSendTransaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type ShowModalData = {
3131
* @internal
3232
*/
3333
export function useSendTransactionCore(
34-
showBuyModal?: (data: ShowModalData) => void,
34+
showPayModal?: (data: ShowModalData) => void,
3535
): UseMutationResult<WaitForReceiptOptions, Error, PreparedTransaction> {
3636
const account = useActiveAccount();
3737

@@ -41,7 +41,7 @@ export function useSendTransactionCore(
4141
throw new Error("No active account");
4242
}
4343

44-
if (!showBuyModal) {
44+
if (!showPayModal) {
4545
return sendTransaction({
4646
transaction: tx,
4747
account,
@@ -98,7 +98,7 @@ export function useSendTransactionCore(
9898
}
9999

100100
// if not enough balance - show modal
101-
showBuyModal({
101+
showPayModal({
102102
tx,
103103
sendTx,
104104
rejectTx: () => {

packages/thirdweb/src/react/web/hooks/useSendTransaction.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { LoadingScreen } from "../wallets/shared/LoadingScreen.js";
2222
export type SendTransactionConfig = {
2323
/**
2424
* Configuration for the "Buy Modal" that opens when the user doesn't have enough funds to send a transaction.
25-
* Set `buyModal: false` to disable the "Buy Modal" popup
25+
* Set `payModal: false` to disable the "Buy Modal" popup
2626
*
2727
* This configuration object includes the following properties to configure the "Buy Modal" UI:
2828
*
@@ -40,7 +40,7 @@ export type SendTransactionConfig = {
4040
* Refer to [`lightTheme`](https://portal.thirdweb.com/references/typescript/v5/lightTheme)
4141
* or [`darkTheme`](https://portal.thirdweb.com/references/typescript/v5/darkTheme) helper functions to use the default light or dark theme and customize it.
4242
*/
43-
buyModal?:
43+
payModal?:
4444
| {
4545
locale?: LocaleId;
4646
supportedTokens?: SupportedTokens;
@@ -66,11 +66,11 @@ export type SendTransactionConfig = {
6666
* @transaction
6767
*/
6868
export function useSendTransaction(config: SendTransactionConfig = {}) {
69-
const buyModal = config.buyModal;
69+
const payModal = config.payModal;
7070

7171
const setRootEl = useContext(SetRootElementContext);
7272
return useSendTransactionCore(
73-
typeof buyModal === "object"
73+
typeof payModal === "object"
7474
? (data) => {
7575
setRootEl(
7676
<TxModal
@@ -81,9 +81,9 @@ export function useSendTransaction(config: SendTransactionConfig = {}) {
8181
data.rejectTx();
8282
}}
8383
client={data.tx.client}
84-
localeId={buyModal?.locale || "en_US"}
85-
supportedTokens={buyModal?.supportedTokens || defaultTokens}
86-
theme={buyModal?.theme || "dark"}
84+
localeId={payModal?.locale || "en_US"}
85+
supportedTokens={payModal?.supportedTokens || defaultTokens}
86+
theme={payModal?.theme || "dark"}
8787
txCostWei={data.totalCostWei}
8888
walletBalanceWei={data.walletBalance.value}
8989
nativeTokenSymbol={data.walletBalance.symbol}

0 commit comments

Comments
 (0)