thirdweb 5.73.0 → 5.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/adapters/eip1193/from-eip1193.js +2 -0
- package/dist/cjs/adapters/eip1193/from-eip1193.js.map +1 -1
- package/dist/cjs/adapters/eip1193/to-eip1193.js +2 -0
- package/dist/cjs/adapters/eip1193/to-eip1193.js.map +1 -1
- package/dist/cjs/exports/wallets/smart.js +2 -1
- package/dist/cjs/exports/wallets/smart.js.map +1 -1
- package/dist/cjs/extensions/erc20/read/isERC20.js +8 -1
- package/dist/cjs/extensions/erc20/read/isERC20.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/SignatureScreen.js +12 -10
- package/dist/cjs/react/web/ui/ConnectWallet/screens/SignatureScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/useConnectModal.js.map +1 -1
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +1 -1
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/cjs/utils/any-evm/zksync/isZkSyncChain.js +4 -1
- package/dist/cjs/utils/any-evm/zksync/isZkSyncChain.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/ecosystem/is-ecosystem-wallet.js +1 -1
- package/dist/cjs/wallets/in-app/core/users/getUser.js +6 -1
- package/dist/cjs/wallets/in-app/core/users/getUser.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js +8 -4
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/ecosystem.js +1 -1
- package/dist/cjs/wallets/in-app/web/in-app.js +2 -2
- package/dist/cjs/wallets/smart/index.js +19 -12
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/bundler.js +2 -1
- package/dist/cjs/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/constants.js +21 -1
- package/dist/cjs/wallets/smart/lib/constants.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/userop.js +19 -4
- package/dist/cjs/wallets/smart/lib/userop.js.map +1 -1
- package/dist/cjs/wallets/smart/smart-wallet.js +1 -1
- package/dist/cjs/wallets/smart/types.js.map +1 -1
- package/dist/esm/adapters/eip1193/from-eip1193.js +2 -0
- package/dist/esm/adapters/eip1193/from-eip1193.js.map +1 -1
- package/dist/esm/adapters/eip1193/to-eip1193.js +2 -0
- package/dist/esm/adapters/eip1193/to-eip1193.js.map +1 -1
- package/dist/esm/exports/wallets/smart.js +1 -1
- package/dist/esm/exports/wallets/smart.js.map +1 -1
- package/dist/esm/extensions/erc20/read/isERC20.js +8 -1
- package/dist/esm/extensions/erc20/read/isERC20.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/SignatureScreen.js +12 -10
- package/dist/esm/react/web/ui/ConnectWallet/screens/SignatureScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/useConnectModal.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +1 -1
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/esm/utils/any-evm/zksync/isZkSyncChain.js +4 -1
- package/dist/esm/utils/any-evm/zksync/isZkSyncChain.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/ecosystem/is-ecosystem-wallet.js +1 -1
- package/dist/esm/wallets/in-app/core/users/getUser.js +6 -1
- package/dist/esm/wallets/in-app/core/users/getUser.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js +9 -5
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/esm/wallets/in-app/web/ecosystem.js +1 -1
- package/dist/esm/wallets/in-app/web/in-app.js +2 -2
- package/dist/esm/wallets/smart/index.js +20 -13
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/esm/wallets/smart/lib/bundler.js +2 -1
- package/dist/esm/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/esm/wallets/smart/lib/constants.js +20 -0
- package/dist/esm/wallets/smart/lib/constants.js.map +1 -1
- package/dist/esm/wallets/smart/lib/userop.js +20 -5
- package/dist/esm/wallets/smart/lib/userop.js.map +1 -1
- package/dist/esm/wallets/smart/smart-wallet.js +1 -1
- package/dist/esm/wallets/smart/types.js.map +1 -1
- package/dist/types/adapters/eip1193/from-eip1193.d.ts +2 -0
- package/dist/types/adapters/eip1193/from-eip1193.d.ts.map +1 -1
- package/dist/types/adapters/eip1193/to-eip1193.d.ts +2 -0
- package/dist/types/adapters/eip1193/to-eip1193.d.ts.map +1 -1
- package/dist/types/exports/wallets/smart.d.ts +1 -1
- package/dist/types/exports/wallets/smart.d.ts.map +1 -1
- package/dist/types/extensions/erc20/read/isERC20.d.ts +8 -1
- package/dist/types/extensions/erc20/read/isERC20.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/SignatureScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/useConnectModal.d.ts +0 -8
- package/dist/types/react/web/ui/ConnectWallet/useConnectModal.d.ts.map +1 -1
- package/dist/types/utils/any-evm/zksync/isZkSyncChain.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/ecosystem/get-ecosystem-wallet-auth-options.d.ts +1 -1
- package/dist/types/wallets/ecosystem/get-ecosystem-wallet-auth-options.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/users/getUser.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/ecosystem.d.ts +1 -1
- package/dist/types/wallets/in-app/web/in-app.d.ts +2 -2
- package/dist/types/wallets/smart/index.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/bundler.d.ts +6 -0
- package/dist/types/wallets/smart/lib/bundler.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/constants.d.ts +4 -0
- package/dist/types/wallets/smart/lib/constants.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/userop.d.ts.map +1 -1
- package/dist/types/wallets/smart/smart-wallet.d.ts +1 -1
- package/dist/types/wallets/smart/types.d.ts +7 -4
- package/dist/types/wallets/smart/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/eip1193/from-eip1193.ts +2 -0
- package/src/adapters/eip1193/to-eip1193.ts +2 -0
- package/src/exports/wallets/smart.ts +1 -0
- package/src/extensions/erc20/read/isERC20.ts +8 -1
- package/src/react/web/ui/ConnectWallet/screens/SignatureScreen.test.tsx +287 -0
- package/src/react/web/ui/ConnectWallet/screens/SignatureScreen.tsx +13 -5
- package/src/react/web/ui/ConnectWallet/useConnectModal.tsx +0 -9
- package/src/react/web/wallets/shared/ConnectWalletSocialOptions.test.tsx +87 -0
- package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +1 -1
- package/src/utils/any-evm/zksync/isZkSyncChain.ts +4 -1
- package/src/version.ts +1 -1
- package/src/wallets/ecosystem/get-ecosystem-wallet-auth-options.ts +1 -1
- package/src/wallets/ecosystem/is-ecosystem-wallet.ts +1 -1
- package/src/wallets/in-app/core/users/getUser.test.ts +216 -0
- package/src/wallets/in-app/core/users/getUser.ts +6 -1
- package/src/wallets/in-app/core/wallet/in-app-core.test.ts +270 -0
- package/src/wallets/in-app/core/wallet/in-app-core.ts +16 -5
- package/src/wallets/in-app/web/ecosystem.ts +1 -1
- package/src/wallets/in-app/web/in-app.ts +2 -2
- package/src/wallets/smart/index.ts +37 -17
- package/src/wallets/smart/lib/bundler.ts +14 -4
- package/src/wallets/smart/lib/constants.ts +23 -0
- package/src/wallets/smart/lib/userop.ts +31 -8
- package/src/wallets/smart/smart-wallet-tokenpaymaster.test.ts +117 -0
- package/src/wallets/smart/smart-wallet.ts +1 -1
- package/src/wallets/smart/types.ts +8 -4
@@ -0,0 +1,216 @@
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
2
|
+
import { createThirdwebClient } from "../../../../client/client.js";
|
3
|
+
import { getClientFetch } from "../../../../utils/fetch.js";
|
4
|
+
import { getUser } from "./getUser.js";
|
5
|
+
|
6
|
+
vi.mock("../../../../utils/fetch.js", () => ({
|
7
|
+
getClientFetch: vi.fn(),
|
8
|
+
}));
|
9
|
+
|
10
|
+
describe("getUser", () => {
|
11
|
+
const mockClient = createThirdwebClient({
|
12
|
+
secretKey: "secret",
|
13
|
+
});
|
14
|
+
|
15
|
+
const mockFetch = vi.fn();
|
16
|
+
beforeEach(() => {
|
17
|
+
vi.clearAllMocks();
|
18
|
+
vi.mocked(getClientFetch).mockReturnValue(mockFetch);
|
19
|
+
});
|
20
|
+
|
21
|
+
it("should throw an error if no secret key is provided", async () => {
|
22
|
+
await expect(
|
23
|
+
getUser({
|
24
|
+
client: { ...mockClient, secretKey: undefined },
|
25
|
+
walletAddress: "0x123",
|
26
|
+
}),
|
27
|
+
).rejects.toThrow(
|
28
|
+
"A secret key is required to query for users. If you're making this request from the server, please add a secret key to your client.",
|
29
|
+
);
|
30
|
+
});
|
31
|
+
|
32
|
+
it("should throw an error if no query parameter is provided", async () => {
|
33
|
+
await expect(
|
34
|
+
getUser({
|
35
|
+
client: mockClient,
|
36
|
+
}),
|
37
|
+
).rejects.toThrow(
|
38
|
+
"Please provide a walletAddress, email, phone, id, or externalWalletAddress to query for users.",
|
39
|
+
);
|
40
|
+
});
|
41
|
+
|
42
|
+
it("should call the correct URL with email", async () => {
|
43
|
+
mockFetch.mockResolvedValueOnce({
|
44
|
+
ok: true,
|
45
|
+
json: async () => [
|
46
|
+
{
|
47
|
+
userId: "user1",
|
48
|
+
walletAddress: "0x123",
|
49
|
+
email: "test@test.com",
|
50
|
+
createdAt: "2023-01-01T00:00:00Z",
|
51
|
+
linkedAccounts: [],
|
52
|
+
},
|
53
|
+
],
|
54
|
+
});
|
55
|
+
|
56
|
+
const result = await getUser({
|
57
|
+
client: mockClient,
|
58
|
+
email: "test@test.com",
|
59
|
+
});
|
60
|
+
|
61
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
62
|
+
"https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details?queryBy=email&email=test%40test.com",
|
63
|
+
);
|
64
|
+
expect(result).toEqual({
|
65
|
+
userId: "user1",
|
66
|
+
walletAddress: "0x123",
|
67
|
+
email: "test@test.com",
|
68
|
+
createdAt: "2023-01-01T00:00:00Z",
|
69
|
+
profiles: [],
|
70
|
+
});
|
71
|
+
});
|
72
|
+
|
73
|
+
it("should call the correct URL with phone", async () => {
|
74
|
+
mockFetch.mockResolvedValueOnce({
|
75
|
+
ok: true,
|
76
|
+
json: async () => [
|
77
|
+
{
|
78
|
+
userId: "user1",
|
79
|
+
walletAddress: "0x123",
|
80
|
+
phone: "+1234567890",
|
81
|
+
createdAt: "2023-01-01T00:00:00Z",
|
82
|
+
linkedAccounts: [],
|
83
|
+
},
|
84
|
+
],
|
85
|
+
});
|
86
|
+
|
87
|
+
const result = await getUser({
|
88
|
+
client: mockClient,
|
89
|
+
phone: "+1234567890",
|
90
|
+
});
|
91
|
+
|
92
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
93
|
+
"https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details?queryBy=phone&phone=%2B1234567890",
|
94
|
+
);
|
95
|
+
expect(result).toEqual({
|
96
|
+
userId: "user1",
|
97
|
+
walletAddress: "0x123",
|
98
|
+
phone: "+1234567890",
|
99
|
+
createdAt: "2023-01-01T00:00:00Z",
|
100
|
+
profiles: [],
|
101
|
+
});
|
102
|
+
});
|
103
|
+
|
104
|
+
it("should call the correct URL with id", async () => {
|
105
|
+
mockFetch.mockResolvedValueOnce({
|
106
|
+
ok: true,
|
107
|
+
json: async () => [
|
108
|
+
{
|
109
|
+
userId: "user1",
|
110
|
+
walletAddress: "0x123",
|
111
|
+
createdAt: "2023-01-01T00:00:00Z",
|
112
|
+
linkedAccounts: [
|
113
|
+
{
|
114
|
+
type: "id",
|
115
|
+
details: {
|
116
|
+
id: "0x456",
|
117
|
+
},
|
118
|
+
},
|
119
|
+
],
|
120
|
+
},
|
121
|
+
],
|
122
|
+
});
|
123
|
+
|
124
|
+
const result = await getUser({
|
125
|
+
client: mockClient,
|
126
|
+
id: "user1",
|
127
|
+
});
|
128
|
+
|
129
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
130
|
+
"https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details?queryBy=id&id=user1",
|
131
|
+
);
|
132
|
+
expect(result).toEqual({
|
133
|
+
userId: "user1",
|
134
|
+
walletAddress: "0x123",
|
135
|
+
createdAt: "2023-01-01T00:00:00Z",
|
136
|
+
profiles: [
|
137
|
+
{
|
138
|
+
type: "id",
|
139
|
+
details: {
|
140
|
+
id: "0x456",
|
141
|
+
},
|
142
|
+
},
|
143
|
+
],
|
144
|
+
});
|
145
|
+
});
|
146
|
+
|
147
|
+
it("should call the correct URL with externalWalletAddress", async () => {
|
148
|
+
mockFetch.mockResolvedValueOnce({
|
149
|
+
ok: true,
|
150
|
+
json: async () => [
|
151
|
+
{
|
152
|
+
userId: "user1",
|
153
|
+
walletAddress: "0x123",
|
154
|
+
createdAt: "2023-01-01T00:00:00Z",
|
155
|
+
linkedAccounts: [
|
156
|
+
{
|
157
|
+
type: "siwe",
|
158
|
+
details: {
|
159
|
+
address: "0x456",
|
160
|
+
},
|
161
|
+
},
|
162
|
+
],
|
163
|
+
},
|
164
|
+
],
|
165
|
+
});
|
166
|
+
|
167
|
+
const result = await getUser({
|
168
|
+
client: mockClient,
|
169
|
+
externalWalletAddress: "0x456",
|
170
|
+
});
|
171
|
+
|
172
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
173
|
+
"https://embedded-wallet.thirdweb.com/api/2023-11-30/embedded-wallet/user-details?queryBy=externalWalletAddress&externalWalletAddress=0x456",
|
174
|
+
);
|
175
|
+
expect(result).toEqual({
|
176
|
+
userId: "user1",
|
177
|
+
walletAddress: "0x123",
|
178
|
+
createdAt: "2023-01-01T00:00:00Z",
|
179
|
+
profiles: [
|
180
|
+
{
|
181
|
+
type: "wallet",
|
182
|
+
details: {
|
183
|
+
address: "0x456",
|
184
|
+
},
|
185
|
+
},
|
186
|
+
],
|
187
|
+
});
|
188
|
+
});
|
189
|
+
|
190
|
+
it("should handle fetch errors", async () => {
|
191
|
+
mockFetch.mockResolvedValueOnce({
|
192
|
+
ok: false,
|
193
|
+
});
|
194
|
+
|
195
|
+
await expect(
|
196
|
+
getUser({
|
197
|
+
client: mockClient,
|
198
|
+
walletAddress: "0x123",
|
199
|
+
}),
|
200
|
+
).rejects.toThrow("Failed to get profiles");
|
201
|
+
});
|
202
|
+
|
203
|
+
it("should return null if no user is found", async () => {
|
204
|
+
mockFetch.mockResolvedValueOnce({
|
205
|
+
ok: true,
|
206
|
+
json: async () => [],
|
207
|
+
});
|
208
|
+
|
209
|
+
const result = await getUser({
|
210
|
+
client: mockClient,
|
211
|
+
walletAddress: "0x123",
|
212
|
+
});
|
213
|
+
|
214
|
+
expect(result).toBeNull();
|
215
|
+
});
|
216
|
+
});
|
@@ -113,7 +113,12 @@ export async function getUser({
|
|
113
113
|
email: item.email,
|
114
114
|
phone: item.phone,
|
115
115
|
createdAt: item.createdAt,
|
116
|
-
profiles: item.linkedAccounts
|
116
|
+
profiles: item.linkedAccounts.map((profile) => {
|
117
|
+
return {
|
118
|
+
type: (profile.type as string) === "siwe" ? "wallet" : profile.type,
|
119
|
+
details: profile.details,
|
120
|
+
};
|
121
|
+
}),
|
117
122
|
}))[0] || null
|
118
123
|
);
|
119
124
|
}
|
@@ -0,0 +1,270 @@
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
2
|
+
import { baseSepolia } from "../../../../chains/chain-definitions/base-sepolia.js";
|
3
|
+
import { createThirdwebClient } from "../../../../client/client.js";
|
4
|
+
import { getEcosystemInfo } from "../../../ecosystem/get-ecosystem-wallet-auth-options.js";
|
5
|
+
import type { Account } from "../../../interfaces/wallet.js";
|
6
|
+
import type { InAppConnector } from "../interfaces/connector.js";
|
7
|
+
import { createInAppWallet } from "./in-app-core.js";
|
8
|
+
import { autoConnectInAppWallet, connectInAppWallet } from "./index.js";
|
9
|
+
|
10
|
+
vi.mock("../../../../analytics/track/connect.js", () => ({
|
11
|
+
trackConnect: vi.fn(),
|
12
|
+
}));
|
13
|
+
|
14
|
+
vi.mock("./index.js", () => ({
|
15
|
+
autoConnectInAppWallet: vi.fn(),
|
16
|
+
connectInAppWallet: vi.fn(),
|
17
|
+
}));
|
18
|
+
|
19
|
+
vi.mock("../../../ecosystem/get-ecosystem-wallet-auth-options.js", () => ({
|
20
|
+
getEcosystemInfo: vi.fn(),
|
21
|
+
}));
|
22
|
+
|
23
|
+
describe("createInAppWallet", () => {
|
24
|
+
const mockClient = createThirdwebClient({
|
25
|
+
clientId: "test-client",
|
26
|
+
});
|
27
|
+
const mockChain = baseSepolia;
|
28
|
+
const mockAccount = { address: "0x123" } as Account;
|
29
|
+
|
30
|
+
const mockConnectorFactory = vi.fn(() =>
|
31
|
+
Promise.resolve({
|
32
|
+
connect: vi.fn(),
|
33
|
+
logout: vi.fn(() => Promise.resolve({ success: true })),
|
34
|
+
authenticate: vi.fn(),
|
35
|
+
getAccounts: vi.fn(),
|
36
|
+
getAccount: vi.fn(),
|
37
|
+
getProfiles: vi.fn(),
|
38
|
+
getUser: vi.fn(),
|
39
|
+
linkProfile: vi.fn(),
|
40
|
+
preAuthenticate: vi.fn(),
|
41
|
+
} as InAppConnector),
|
42
|
+
);
|
43
|
+
|
44
|
+
beforeEach(() => {
|
45
|
+
vi.clearAllMocks();
|
46
|
+
});
|
47
|
+
|
48
|
+
it("should connect successfully", async () => {
|
49
|
+
vi.mocked(connectInAppWallet).mockResolvedValue([mockAccount, mockChain]);
|
50
|
+
|
51
|
+
const wallet = createInAppWallet({
|
52
|
+
connectorFactory: mockConnectorFactory,
|
53
|
+
});
|
54
|
+
|
55
|
+
const result = await wallet.connect({
|
56
|
+
client: mockClient,
|
57
|
+
chain: mockChain,
|
58
|
+
strategy: "email",
|
59
|
+
email: "",
|
60
|
+
verificationCode: "",
|
61
|
+
});
|
62
|
+
|
63
|
+
expect(result).toBe(mockAccount);
|
64
|
+
expect(connectInAppWallet).toHaveBeenCalledWith(
|
65
|
+
expect.objectContaining({
|
66
|
+
client: mockClient,
|
67
|
+
chain: mockChain,
|
68
|
+
}),
|
69
|
+
undefined,
|
70
|
+
expect.any(Object),
|
71
|
+
);
|
72
|
+
});
|
73
|
+
|
74
|
+
it("should auto connect successfully", async () => {
|
75
|
+
vi.mocked(autoConnectInAppWallet).mockResolvedValue([
|
76
|
+
mockAccount,
|
77
|
+
mockChain,
|
78
|
+
]);
|
79
|
+
|
80
|
+
const wallet = createInAppWallet({
|
81
|
+
connectorFactory: mockConnectorFactory,
|
82
|
+
});
|
83
|
+
|
84
|
+
const result = await wallet.autoConnect({
|
85
|
+
client: mockClient,
|
86
|
+
chain: mockChain,
|
87
|
+
});
|
88
|
+
|
89
|
+
expect(result).toBe(mockAccount);
|
90
|
+
expect(autoConnectInAppWallet).toHaveBeenCalledWith(
|
91
|
+
expect.objectContaining({
|
92
|
+
client: mockClient,
|
93
|
+
chain: mockChain,
|
94
|
+
}),
|
95
|
+
undefined,
|
96
|
+
expect.any(Object),
|
97
|
+
);
|
98
|
+
});
|
99
|
+
|
100
|
+
it("should handle ecosystem wallet connection with smart account settings", async () => {
|
101
|
+
vi.mocked(getEcosystemInfo).mockResolvedValue({
|
102
|
+
smartAccountOptions: {
|
103
|
+
defaultChainId: mockChain.id,
|
104
|
+
sponsorGas: true,
|
105
|
+
accountFactoryAddress: "0x456",
|
106
|
+
},
|
107
|
+
authOptions: [],
|
108
|
+
name: "hello world",
|
109
|
+
slug: "test-ecosystem",
|
110
|
+
});
|
111
|
+
|
112
|
+
vi.mocked(connectInAppWallet).mockResolvedValue([mockAccount, mockChain]);
|
113
|
+
|
114
|
+
const wallet = createInAppWallet({
|
115
|
+
connectorFactory: mockConnectorFactory,
|
116
|
+
ecosystem: { id: "ecosystem.test-ecosystem" },
|
117
|
+
});
|
118
|
+
|
119
|
+
const result = await wallet.connect({
|
120
|
+
client: mockClient,
|
121
|
+
chain: mockChain,
|
122
|
+
strategy: "email",
|
123
|
+
email: "",
|
124
|
+
verificationCode: "",
|
125
|
+
});
|
126
|
+
|
127
|
+
expect(result).toBe(mockAccount);
|
128
|
+
expect(connectInAppWallet).toHaveBeenCalledWith(
|
129
|
+
expect.objectContaining({
|
130
|
+
client: mockClient,
|
131
|
+
chain: mockChain,
|
132
|
+
}),
|
133
|
+
expect.objectContaining({
|
134
|
+
smartAccount: expect.objectContaining({
|
135
|
+
chain: mockChain,
|
136
|
+
sponsorGas: true,
|
137
|
+
factoryAddress: "0x456",
|
138
|
+
}),
|
139
|
+
}),
|
140
|
+
expect.any(Object),
|
141
|
+
);
|
142
|
+
});
|
143
|
+
it("should handle ecosystem wallet connection with smart account settings even when no chain is set", async () => {
|
144
|
+
vi.mocked(getEcosystemInfo).mockResolvedValue({
|
145
|
+
smartAccountOptions: {
|
146
|
+
defaultChainId: mockChain.id,
|
147
|
+
sponsorGas: true,
|
148
|
+
accountFactoryAddress: "0x456",
|
149
|
+
},
|
150
|
+
authOptions: [],
|
151
|
+
name: "hello world",
|
152
|
+
slug: "test-ecosystem",
|
153
|
+
});
|
154
|
+
|
155
|
+
vi.mocked(connectInAppWallet).mockResolvedValue([mockAccount, mockChain]);
|
156
|
+
|
157
|
+
const wallet = createInAppWallet({
|
158
|
+
connectorFactory: mockConnectorFactory,
|
159
|
+
ecosystem: { id: "ecosystem.test-ecosystem" },
|
160
|
+
});
|
161
|
+
|
162
|
+
const result = await wallet.connect({
|
163
|
+
client: mockClient,
|
164
|
+
strategy: "email",
|
165
|
+
email: "",
|
166
|
+
verificationCode: "",
|
167
|
+
});
|
168
|
+
|
169
|
+
expect(result).toBe(mockAccount);
|
170
|
+
expect(connectInAppWallet).toHaveBeenCalledWith(
|
171
|
+
expect.objectContaining({
|
172
|
+
client: mockClient,
|
173
|
+
}),
|
174
|
+
expect.objectContaining({
|
175
|
+
smartAccount: expect.objectContaining({
|
176
|
+
chain: mockChain,
|
177
|
+
sponsorGas: true,
|
178
|
+
factoryAddress: "0x456",
|
179
|
+
}),
|
180
|
+
}),
|
181
|
+
expect.any(Object),
|
182
|
+
);
|
183
|
+
});
|
184
|
+
|
185
|
+
it("should handle ecosystem wallet auto connection with smart account settings", async () => {
|
186
|
+
vi.mocked(getEcosystemInfo).mockResolvedValue({
|
187
|
+
smartAccountOptions: {
|
188
|
+
defaultChainId: mockChain.id,
|
189
|
+
sponsorGas: true,
|
190
|
+
accountFactoryAddress: "0x456",
|
191
|
+
},
|
192
|
+
authOptions: [],
|
193
|
+
name: "hello world",
|
194
|
+
slug: "test-ecosystem",
|
195
|
+
});
|
196
|
+
|
197
|
+
vi.mocked(autoConnectInAppWallet).mockResolvedValue([
|
198
|
+
mockAccount,
|
199
|
+
mockChain,
|
200
|
+
]);
|
201
|
+
|
202
|
+
const wallet = createInAppWallet({
|
203
|
+
connectorFactory: mockConnectorFactory,
|
204
|
+
ecosystem: { id: "ecosystem.test-ecosystem" },
|
205
|
+
});
|
206
|
+
|
207
|
+
const result = await wallet.autoConnect({
|
208
|
+
client: mockClient,
|
209
|
+
chain: mockChain,
|
210
|
+
});
|
211
|
+
|
212
|
+
expect(result).toBe(mockAccount);
|
213
|
+
expect(autoConnectInAppWallet).toHaveBeenCalledWith(
|
214
|
+
expect.objectContaining({
|
215
|
+
client: mockClient,
|
216
|
+
chain: mockChain,
|
217
|
+
}),
|
218
|
+
expect.objectContaining({
|
219
|
+
smartAccount: expect.objectContaining({
|
220
|
+
chain: mockChain,
|
221
|
+
sponsorGas: true,
|
222
|
+
factoryAddress: "0x456",
|
223
|
+
}),
|
224
|
+
}),
|
225
|
+
expect.any(Object),
|
226
|
+
);
|
227
|
+
});
|
228
|
+
|
229
|
+
it("should handle ecosystem wallet auto connection with smart account settings even when no chain is set", async () => {
|
230
|
+
vi.mocked(getEcosystemInfo).mockResolvedValue({
|
231
|
+
smartAccountOptions: {
|
232
|
+
defaultChainId: mockChain.id,
|
233
|
+
sponsorGas: true,
|
234
|
+
accountFactoryAddress: "0x456",
|
235
|
+
},
|
236
|
+
authOptions: [],
|
237
|
+
name: "hello world",
|
238
|
+
slug: "test-ecosystem",
|
239
|
+
});
|
240
|
+
|
241
|
+
vi.mocked(autoConnectInAppWallet).mockResolvedValue([
|
242
|
+
mockAccount,
|
243
|
+
mockChain,
|
244
|
+
]);
|
245
|
+
|
246
|
+
const wallet = createInAppWallet({
|
247
|
+
connectorFactory: mockConnectorFactory,
|
248
|
+
ecosystem: { id: "ecosystem.test-ecosystem" },
|
249
|
+
});
|
250
|
+
|
251
|
+
const result = await wallet.autoConnect({
|
252
|
+
client: mockClient,
|
253
|
+
});
|
254
|
+
|
255
|
+
expect(result).toBe(mockAccount);
|
256
|
+
expect(autoConnectInAppWallet).toHaveBeenCalledWith(
|
257
|
+
expect.objectContaining({
|
258
|
+
client: mockClient,
|
259
|
+
}),
|
260
|
+
expect.objectContaining({
|
261
|
+
smartAccount: expect.objectContaining({
|
262
|
+
chain: mockChain,
|
263
|
+
sponsorGas: true,
|
264
|
+
factoryAddress: "0x456",
|
265
|
+
}),
|
266
|
+
}),
|
267
|
+
expect.any(Object),
|
268
|
+
);
|
269
|
+
});
|
270
|
+
});
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import { trackConnect } from "../../../../analytics/track/connect.js";
|
2
2
|
import type { Chain } from "../../../../chains/types.js";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
getCachedChain,
|
5
|
+
getCachedChainIfExists,
|
6
|
+
} from "../../../../chains/utils.js";
|
4
7
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
5
8
|
import { stringify } from "../../../../utils/json.js";
|
6
9
|
import { getEcosystemInfo } from "../../../ecosystem/get-ecosystem-wallet-auth-options.js";
|
@@ -74,12 +77,16 @@ export function createInAppWallet(args: {
|
|
74
77
|
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
|
75
78
|
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
|
76
79
|
if (smartAccountOptions) {
|
77
|
-
const
|
80
|
+
const { defaultChainId } = ecosystemOptions.smartAccountOptions;
|
81
|
+
const preferredChain =
|
82
|
+
options.chain ??
|
83
|
+
(defaultChainId ? getCachedChain(defaultChainId) : undefined);
|
78
84
|
if (!preferredChain) {
|
79
85
|
throw new Error(
|
80
|
-
|
86
|
+
`A chain must be provided either via 'chain' in connect options or 'defaultChainId' in ecosystem configuration. Please pass it via connect() or update the ecosystem configuration.`,
|
81
87
|
);
|
82
88
|
}
|
89
|
+
|
83
90
|
createOptions = {
|
84
91
|
...createOptions,
|
85
92
|
smartAccount: {
|
@@ -123,12 +130,16 @@ export function createInAppWallet(args: {
|
|
123
130
|
const ecosystemOptions = await getEcosystemInfo(ecosystem.id);
|
124
131
|
const smartAccountOptions = ecosystemOptions?.smartAccountOptions;
|
125
132
|
if (smartAccountOptions) {
|
126
|
-
const
|
133
|
+
const { defaultChainId } = ecosystemOptions.smartAccountOptions;
|
134
|
+
const preferredChain =
|
135
|
+
options.chain ??
|
136
|
+
(defaultChainId ? getCachedChain(defaultChainId) : undefined);
|
127
137
|
if (!preferredChain) {
|
128
138
|
throw new Error(
|
129
|
-
|
139
|
+
`A chain must be provided either via 'chain' in connect options or 'defaultChainId' in ecosystem configuration. Please pass it via connect() or update the ecosystem configuration.`,
|
130
140
|
);
|
131
141
|
}
|
142
|
+
|
132
143
|
createOptions = {
|
133
144
|
...createOptions,
|
134
145
|
smartAccount: {
|
@@ -7,7 +7,7 @@ import type {
|
|
7
7
|
import { createInAppWallet } from "../core/wallet/in-app-core.js";
|
8
8
|
|
9
9
|
/**
|
10
|
-
* Creates an [Ecosystem Wallet](https://portal.thirdweb.com/connect/
|
10
|
+
* Creates an [Ecosystem Wallet](https://portal.thirdweb.com/connect/wallet/overview) based on various authentication methods. Full list of available authentication methods [here](/connect/wallet/sign-in-methods/configure).
|
11
11
|
*
|
12
12
|
* Can also be configured to use Account Abstraction to directly connect to a ERC4337 smart account based on those authentication methods.
|
13
13
|
*
|
@@ -4,7 +4,7 @@ import type { CreateWalletArgs } from "../../wallet-types.js";
|
|
4
4
|
import { createInAppWallet } from "../core/wallet/in-app-core.js";
|
5
5
|
|
6
6
|
/**
|
7
|
-
* Creates an app scoped wallet for users based on various authentication methods. Full list of available authentication methods [here](https://portal.thirdweb.com/connect/wallet/sign-in-methods/
|
7
|
+
* Creates an app scoped wallet for users based on various authentication methods. Full list of available authentication methods [here](https://portal.thirdweb.com/connect/wallet/sign-in-methods/configure).
|
8
8
|
*
|
9
9
|
* Can also be configured to use Account Abstraction to directly connect to a ERC4337 smart account based on those authentication methods.
|
10
10
|
*
|
@@ -27,7 +27,7 @@ import { createInAppWallet } from "../core/wallet/in-app-core.js";
|
|
27
27
|
* });
|
28
28
|
* ```
|
29
29
|
*
|
30
|
-
* [View all available social auth methods](https://portal.thirdweb.com/connect/wallet/sign-in-methods/
|
30
|
+
* [View all available social auth methods](https://portal.thirdweb.com/connect/wallet/sign-in-methods/configure)
|
31
31
|
*
|
32
32
|
* ### Login with email
|
33
33
|
*
|