Skip to content

Commit b38604c

Browse files
authored
[SDK] Fix: Do not remove chain listener on disconnect (#6011)
1 parent 59eda22 commit b38604c

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.changeset/fuzzy-ants-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fixes issue with chain switching breaking after disconnect

packages/thirdweb/src/extensions/erc1155/write/sigMint1155.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
type ThirdwebContract,
1212
getContract,
1313
} from "../../../contract/contract.js";
14-
import { sendTransaction } from "../../../transaction/actions/send-transaction.js";
14+
import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js";
1515
import { toHex } from "../../../utils/encoding/hex.js";
1616
import { deployERC20Contract } from "../../prebuilts/deploy-erc20.js";
1717
import { deployERC1155Contract } from "../../prebuilts/deploy-erc1155.js";
@@ -76,7 +76,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("generateMintSignature1155", () => {
7676
payload,
7777
signature,
7878
});
79-
const { transactionHash } = await sendTransaction({
79+
const { transactionHash } = await sendAndConfirmTransaction({
8080
transaction,
8181
account: TEST_ACCOUNT_A,
8282
});
@@ -107,7 +107,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("generateMintSignature1155", () => {
107107
payload,
108108
signature,
109109
});
110-
const { transactionHash } = await sendTransaction({
110+
const { transactionHash } = await sendAndConfirmTransaction({
111111
transaction,
112112
account: TEST_ACCOUNT_A,
113113
});
@@ -153,7 +153,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("generateMintSignature1155", () => {
153153
payload,
154154
signature,
155155
});
156-
const { transactionHash } = await sendTransaction({
156+
const { transactionHash } = await sendAndConfirmTransaction({
157157
transaction,
158158
account: TEST_ACCOUNT_A,
159159
});

packages/thirdweb/src/wallets/create-wallet.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,7 @@ export function createWallet<const ID extends WalletId>(
190190
const emitter = createWalletEmitter<ID>();
191191
let account: Account | undefined = undefined;
192192
let chain: Chain | undefined = undefined;
193-
194-
const unsubscribeChain = emitter.subscribe("chainChanged", (newChain) => {
195-
chain = newChain;
196-
});
193+
let unsubscribeChain: (() => void) | undefined = undefined;
197194

198195
function reset() {
199196
account = undefined;
@@ -204,7 +201,7 @@ export function createWallet<const ID extends WalletId>(
204201

205202
const unsubscribeDisconnect = emitter.subscribe("disconnect", () => {
206203
reset();
207-
unsubscribeChain();
204+
unsubscribeChain?.();
208205
unsubscribeDisconnect();
209206
});
210207

@@ -263,6 +260,9 @@ export function createWallet<const ID extends WalletId>(
263260
chain = connectedChain;
264261
handleDisconnect = doDisconnect;
265262
handleSwitchChain = doSwitchChain;
263+
unsubscribeChain = emitter.subscribe("chainChanged", (newChain) => {
264+
chain = newChain;
265+
});
266266
trackConnect({
267267
client: options.client,
268268
walletType: id,
@@ -377,6 +377,9 @@ export function createWallet<const ID extends WalletId>(
377377
chain = connectedChain;
378378
handleDisconnect = doDisconnect;
379379
handleSwitchChain = doSwitchChain;
380+
unsubscribeChain = emitter.subscribe("chainChanged", (newChain) => {
381+
chain = newChain;
382+
});
380383
trackConnect({
381384
client: options.client,
382385
walletType: id,

0 commit comments

Comments
 (0)