Skip to content

Commit 6052378

Browse files
WIP connect params
1 parent 1d59753 commit 6052378

File tree

10 files changed

+246
-196
lines changed

10 files changed

+246
-196
lines changed

.changeset/strong-panthers-notice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"@thirdweb-dev/wagmi-adapter": major
2+
"@thirdweb-dev/wagmi-adapter": minor
33
---
44

55
Wagmi connector for in-app wallets

packages/thirdweb/src/exports/wallets.native.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ export type {
8989
* @deprecated use InAppWalletSocialAuth instead
9090
*/
9191
InAppWalletSocialAuth as EmbeddedWalletSocialAuth,
92+
InAppWalletCreationOptions,
9293
} from "../wallets/in-app/core/wallet/types.js";
9394

95+
export type {
96+
MultiStepAuthArgsType,
97+
SingleStepAuthArgsType,
98+
} from "../wallets/in-app/core/authentication/types.js";
99+
94100
export {
95101
preAuthenticate,
96102
authenticate,

packages/thirdweb/src/exports/wallets.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ export type {
9696
* @deprecated use InAppWalletSocialAuth instead
9797
*/
9898
InAppWalletSocialAuth as EmbeddedWalletSocialAuth,
99+
InAppWalletCreationOptions,
99100
} from "../wallets/in-app/core/wallet/types.js";
100101

102+
export type {
103+
MultiStepAuthArgsType,
104+
SingleStepAuthArgsType,
105+
} from "../wallets/in-app/core/authentication/types.js";
106+
101107
export {
102108
preAuthenticate,
103109
authenticate,

packages/thirdweb/src/exports/wallets/in-app.native.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export type {
1717
InAppWalletAuth,
1818
InAppWalletSocialAuth,
1919
InAppWalletConnectionOptions,
20+
InAppWalletAutoConnectOptions,
2021
} from "../../wallets/in-app/core/wallet/types.js";
2122

23+
export type {
24+
MultiStepAuthArgsType,
25+
SingleStepAuthArgsType,
26+
} from "../../wallets/in-app/core/authentication/types.js";
27+
2228
export { hasStoredPasskey } from "../../wallets/in-app/native/auth/passkeys.js";

packages/thirdweb/src/exports/wallets/in-app.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ export type {
1717
InAppWalletAuth,
1818
InAppWalletSocialAuth,
1919
InAppWalletConnectionOptions,
20+
InAppWalletAutoConnectOptions,
2021
} from "../../wallets/in-app/core/wallet/types.js";
2122

23+
export type {
24+
MultiStepAuthArgsType,
25+
SingleStepAuthArgsType,
26+
} from "../../wallets/in-app/core/authentication/types.js";
27+
2228
export { hasStoredPasskey } from "../../wallets/in-app/web/lib/auth/passkeys.js";
2329

2430
export {

packages/thirdweb/src/wallets/in-app/core/wallet/types.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Chain } from "../../../../chains/types.js";
22
import type { ThirdwebClient } from "../../../../client/client.js";
3+
import type { Prettify } from "../../../../utils/type-utils.js";
34
import type { SmartWalletOptions } from "../../../smart/types.js";
45
import type {
56
AuthOption,
@@ -19,14 +20,12 @@ export type Ecosystem = {
1920
partnerId?: string;
2021
};
2122

22-
export type InAppWalletConnectionOptions = (
23-
| MultiStepAuthArgsType
24-
| SingleStepAuthArgsType
25-
) & {
26-
client: ThirdwebClient;
27-
chain?: Chain;
28-
redirect?: boolean;
29-
};
23+
export type InAppWalletConnectionOptions = Prettify<
24+
(MultiStepAuthArgsType | SingleStepAuthArgsType) & {
25+
client: ThirdwebClient;
26+
chain?: Chain;
27+
}
28+
>;
3029

3130
export type InAppWalletAutoConnectOptions = {
3231
client: ThirdwebClient;

packages/thirdweb/src/wallets/manager/connection-manager.test.ts

Lines changed: 133 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -199,157 +199,157 @@ describe.runIf(process.env.TW_SECRET_KEY)("Connection Manager", () => {
199199
const definedChain = manager.activeWalletChainStore.getValue();
200200
expect(definedChain).toEqual(newChain);
201201
});
202-
});
203-
204-
describe("handleSmartWalletConnection", () => {
205-
let client: ThirdwebClient;
206-
let eoaWallet: Wallet;
207-
let smartWalletOptions: SmartWalletOptions;
208202

209-
beforeEach(() => {
210-
client = TEST_CLIENT;
211-
eoaWallet = {
212-
id: "eoa-wallet-id",
213-
getAccount: vi.fn().mockReturnValue(TEST_ACCOUNT_A),
214-
subscribe: vi.fn().mockReturnValue(vi.fn()),
215-
disconnect: vi.fn(),
216-
switchChain: vi.fn(),
217-
getChain: vi.fn().mockReturnValue(sepolia),
218-
getConfig: vi.fn(),
219-
} as unknown as Wallet;
220-
smartWalletOptions = {
221-
chain: sepolia,
222-
} as SmartWalletOptions;
223-
});
224-
225-
it("should connect a smart wallet and subscribe to disconnect event", async () => {
226-
const onWalletDisconnect = vi.fn();
227-
const smartWallet = await handleSmartWalletConnection(
228-
eoaWallet,
229-
client,
230-
smartWalletOptions,
231-
onWalletDisconnect,
232-
);
233-
234-
expect(smartWallet.getAccount()).toBeTruthy();
235-
236-
expect(eoaWallet.subscribe).toHaveBeenCalledWith(
237-
"disconnect",
238-
expect.any(Function),
239-
);
240-
});
241-
242-
it("should call onWalletDisconnect when EOA wallet disconnects", async () => {
243-
const onWalletDisconnect = vi.fn();
244-
const smartWallet = await handleSmartWalletConnection(
245-
eoaWallet,
246-
client,
247-
smartWalletOptions,
248-
onWalletDisconnect,
249-
);
203+
describe("handleSmartWalletConnection", () => {
204+
let client: ThirdwebClient;
205+
let eoaWallet: Wallet;
206+
let smartWalletOptions: SmartWalletOptions;
207+
208+
beforeEach(() => {
209+
client = TEST_CLIENT;
210+
eoaWallet = {
211+
id: "eoa-wallet-id",
212+
getAccount: vi.fn().mockReturnValue(TEST_ACCOUNT_A),
213+
subscribe: vi.fn().mockReturnValue(vi.fn()),
214+
disconnect: vi.fn(),
215+
switchChain: vi.fn(),
216+
getChain: vi.fn().mockReturnValue(sepolia),
217+
getConfig: vi.fn(),
218+
} as unknown as Wallet;
219+
smartWalletOptions = {
220+
chain: sepolia,
221+
} as SmartWalletOptions;
222+
});
250223

251-
// biome-ignore lint/suspicious/noExplicitAny: Mocked function
252-
const disconnectCallback = (eoaWallet.subscribe as any).mock.calls[0][1];
253-
disconnectCallback();
224+
it("should connect a smart wallet and subscribe to disconnect event", async () => {
225+
const onWalletDisconnect = vi.fn();
226+
const smartWallet = await handleSmartWalletConnection(
227+
eoaWallet,
228+
client,
229+
smartWalletOptions,
230+
onWalletDisconnect,
231+
);
254232

255-
expect(onWalletDisconnect).toHaveBeenCalledWith(smartWallet);
256-
});
233+
expect(smartWallet.getAccount()).toBeTruthy();
257234

258-
it("should throw an error if EOA wallet has no account", async () => {
259-
eoaWallet.getAccount = vi.fn().mockReturnValue(null);
235+
expect(eoaWallet.subscribe).toHaveBeenCalledWith(
236+
"disconnect",
237+
expect.any(Function),
238+
);
239+
});
260240

261-
await expect(
262-
handleSmartWalletConnection(
241+
it("should call onWalletDisconnect when EOA wallet disconnects", async () => {
242+
const onWalletDisconnect = vi.fn();
243+
const smartWallet = await handleSmartWalletConnection(
263244
eoaWallet,
264245
client,
265246
smartWalletOptions,
266-
vi.fn(),
267-
),
268-
).rejects.toThrow("Cannot set a wallet without an account as active");
269-
});
270-
});
247+
onWalletDisconnect,
248+
);
271249

272-
describe("Connection Manager Error Handling", () => {
273-
let storage: AsyncStorage;
274-
let client: ThirdwebClient;
275-
let wallet: Wallet;
250+
// biome-ignore lint/suspicious/noExplicitAny: Mocked function
251+
const disconnectCallback = (eoaWallet.subscribe as any).mock.calls[0][1];
252+
disconnectCallback();
276253

277-
beforeEach(() => {
278-
storage = {
279-
getItem: vi.fn(),
280-
setItem: vi.fn(),
281-
removeItem: vi.fn(),
282-
};
283-
client = TEST_CLIENT;
284-
wallet = {
285-
id: "wallet-id",
286-
getAccount: vi.fn().mockReturnValue(null), // Simulate wallet without an account
287-
subscribe: vi.fn(),
288-
disconnect: vi.fn(),
289-
switchChain: vi.fn(),
290-
getChain: vi.fn().mockReturnValue(sepolia),
291-
getConfig: vi.fn(),
292-
} as unknown as Wallet;
293-
});
294-
295-
it("should throw an error if trying to set a wallet without an account as active", async () => {
296-
const manager = createConnectionManager(storage);
254+
expect(onWalletDisconnect).toHaveBeenCalledWith(smartWallet);
255+
});
297256

298-
await expect(manager.setActiveWallet(wallet)).rejects.toThrow(
299-
"Cannot set a wallet without an account as active",
300-
);
257+
it("should throw an error if EOA wallet has no account", async () => {
258+
eoaWallet.getAccount = vi.fn().mockReturnValue(null);
259+
260+
await expect(
261+
handleSmartWalletConnection(
262+
eoaWallet,
263+
client,
264+
smartWalletOptions,
265+
vi.fn(),
266+
),
267+
).rejects.toThrow("Cannot set a wallet without an account as active");
268+
});
301269
});
302270

303-
it("should throw an error if handleConnection is called with a wallet without an account", async () => {
304-
const manager = createConnectionManager(storage);
271+
describe("Connection Manager Error Handling", () => {
272+
let storage: AsyncStorage;
273+
let client: ThirdwebClient;
274+
let wallet: Wallet;
275+
276+
beforeEach(() => {
277+
storage = {
278+
getItem: vi.fn(),
279+
setItem: vi.fn(),
280+
removeItem: vi.fn(),
281+
};
282+
client = TEST_CLIENT;
283+
wallet = {
284+
id: "wallet-id",
285+
getAccount: vi.fn().mockReturnValue(null), // Simulate wallet without an account
286+
subscribe: vi.fn(),
287+
disconnect: vi.fn(),
288+
switchChain: vi.fn(),
289+
getChain: vi.fn().mockReturnValue(sepolia),
290+
getConfig: vi.fn(),
291+
} as unknown as Wallet;
292+
});
305293

306-
await expect(manager.handleConnection(wallet, { client })).rejects.toThrow(
307-
"Cannot set a wallet without an account as active",
308-
);
309-
});
310-
});
294+
it("should throw an error if trying to set a wallet without an account as active", async () => {
295+
const manager = createConnectionManager(storage);
311296

312-
describe("Connection Manager Event Subscriptions", () => {
313-
let storage: AsyncStorage;
314-
let client: ThirdwebClient;
315-
let wallet: Wallet;
316-
let account: Account;
297+
await expect(manager.setActiveWallet(wallet)).rejects.toThrow(
298+
"Cannot set a wallet without an account as active",
299+
);
300+
});
317301

318-
beforeEach(() => {
319-
storage = {
320-
getItem: vi.fn(),
321-
setItem: vi.fn(),
322-
removeItem: vi.fn(),
323-
};
324-
client = TEST_CLIENT;
325-
account = TEST_ACCOUNT_A;
326-
wallet = {
327-
id: "wallet-id",
328-
getAccount: vi.fn().mockReturnValue(account),
329-
subscribe: vi.fn().mockReturnValue(vi.fn()),
330-
disconnect: vi.fn(),
331-
switchChain: vi.fn(),
332-
getChain: vi.fn().mockReturnValue(sepolia),
333-
getConfig: vi.fn(),
334-
} as unknown as Wallet;
335-
});
302+
it("should throw an error if handleConnection is called with a wallet without an account", async () => {
303+
const manager = createConnectionManager(storage);
336304

337-
it("should subscribe to accountChanged, chainChanged, and disconnect events", async () => {
338-
const manager = createConnectionManager(storage);
305+
await expect(
306+
manager.handleConnection(wallet, { client }),
307+
).rejects.toThrow("Cannot set a wallet without an account as active");
308+
});
309+
});
339310

340-
await manager.handleConnection(wallet, { client });
311+
describe("Connection Manager Event Subscriptions", () => {
312+
let storage: AsyncStorage;
313+
let client: ThirdwebClient;
314+
let wallet: Wallet;
315+
let account: Account;
316+
317+
beforeEach(() => {
318+
storage = {
319+
getItem: vi.fn(),
320+
setItem: vi.fn(),
321+
removeItem: vi.fn(),
322+
};
323+
client = TEST_CLIENT;
324+
account = TEST_ACCOUNT_A;
325+
wallet = {
326+
id: "wallet-id",
327+
getAccount: vi.fn().mockReturnValue(account),
328+
subscribe: vi.fn().mockReturnValue(vi.fn()),
329+
disconnect: vi.fn(),
330+
switchChain: vi.fn(),
331+
getChain: vi.fn().mockReturnValue(sepolia),
332+
getConfig: vi.fn(),
333+
} as unknown as Wallet;
334+
});
341335

342-
expect(wallet.subscribe).toHaveBeenCalledWith(
343-
"accountChanged",
344-
expect.any(Function),
345-
);
346-
expect(wallet.subscribe).toHaveBeenCalledWith(
347-
"chainChanged",
348-
expect.any(Function),
349-
);
350-
expect(wallet.subscribe).toHaveBeenCalledWith(
351-
"disconnect",
352-
expect.any(Function),
353-
);
336+
it("should subscribe to accountChanged, chainChanged, and disconnect events", async () => {
337+
const manager = createConnectionManager(storage);
338+
339+
await manager.handleConnection(wallet, { client });
340+
341+
expect(wallet.subscribe).toHaveBeenCalledWith(
342+
"accountChanged",
343+
expect.any(Function),
344+
);
345+
expect(wallet.subscribe).toHaveBeenCalledWith(
346+
"chainChanged",
347+
expect.any(Function),
348+
);
349+
expect(wallet.subscribe).toHaveBeenCalledWith(
350+
"disconnect",
351+
expect.any(Function),
352+
);
353+
});
354354
});
355355
});

0 commit comments

Comments
 (0)