thirdweb 5.65.2 → 5.66.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/exports/react.js +4 -1
- package/dist/cjs/exports/react.js.map +1 -1
- package/dist/cjs/react/core/hooks/contract/useContractEvents.js +1 -1
- package/dist/cjs/react/core/hooks/contract/useContractEvents.js.map +1 -1
- package/dist/cjs/react/core/hooks/wallets/useAutoConnect.js +19 -2
- package/dist/cjs/react/core/hooks/wallets/useAutoConnect.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/ConnectModal.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/ConnectedModal.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/MediaRenderer/ModelViewer.js +3 -1
- package/dist/cjs/react/web/ui/MediaRenderer/ModelViewer.js.map +1 -1
- package/dist/cjs/react/web/ui/SiteEmbed.js +63 -0
- package/dist/cjs/react/web/ui/SiteEmbed.js.map +1 -0
- package/dist/cjs/react/web/wallets/in-app/WalletAuth.js +1 -1
- package/dist/cjs/react/web/wallets/in-app/WalletAuth.js.map +1 -1
- package/dist/cjs/react/web/wallets/shared/PassKeyLogin.js +2 -1
- package/dist/cjs/react/web/wallets/shared/PassKeyLogin.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/core/actions/generate-wallet.enclave.js +1 -1
- package/dist/cjs/wallets/in-app/core/actions/generate-wallet.enclave.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js +2 -2
- package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
- package/dist/cjs/wallets/in-app/native/native-connector.js +15 -15
- package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js +1 -1
- package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/get-url-token.js +10 -4
- package/dist/cjs/wallets/in-app/web/lib/get-url-token.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js +7 -9
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/esm/exports/react.js +2 -0
- package/dist/esm/exports/react.js.map +1 -1
- package/dist/esm/react/core/hooks/contract/useContractEvents.js +1 -1
- package/dist/esm/react/core/hooks/contract/useContractEvents.js.map +1 -1
- package/dist/esm/react/core/hooks/wallets/useAutoConnect.js +19 -2
- package/dist/esm/react/core/hooks/wallets/useAutoConnect.js.map +1 -1
- package/dist/esm/react/native/ui/connect/ConnectModal.js.map +1 -1
- package/dist/esm/react/native/ui/connect/ConnectedModal.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/MediaRenderer/ModelViewer.js +3 -1
- package/dist/esm/react/web/ui/MediaRenderer/ModelViewer.js.map +1 -1
- package/dist/esm/react/web/ui/SiteEmbed.js +60 -0
- package/dist/esm/react/web/ui/SiteEmbed.js.map +1 -0
- package/dist/esm/react/web/wallets/in-app/WalletAuth.js +1 -1
- package/dist/esm/react/web/wallets/in-app/WalletAuth.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/PassKeyLogin.js +2 -1
- package/dist/esm/react/web/wallets/shared/PassKeyLogin.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/core/actions/generate-wallet.enclave.js +1 -1
- package/dist/esm/wallets/in-app/core/actions/generate-wallet.enclave.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js +2 -2
- package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
- package/dist/esm/wallets/in-app/native/native-connector.js +15 -15
- package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js +1 -1
- package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/get-url-token.js +10 -4
- package/dist/esm/wallets/in-app/web/lib/get-url-token.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/web-connector.js +7 -9
- package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/types/exports/react.d.ts +1 -0
- package/dist/types/exports/react.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +1 -0
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
- package/dist/types/react/core/hooks/wallets/useAutoConnect.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +1 -0
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
- package/dist/types/react/web/ui/MediaRenderer/ModelViewer.d.ts +0 -8
- package/dist/types/react/web/ui/MediaRenderer/ModelViewer.d.ts.map +1 -1
- package/dist/types/react/web/ui/SiteEmbed.d.ts +27 -0
- package/dist/types/react/web/ui/SiteEmbed.d.ts.map +1 -0
- package/dist/types/react/web/ui/components/Drawer.d.ts +2 -2
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/actions/generate-wallet.enclave.d.ts +2 -2
- package/dist/types/wallets/in-app/core/actions/generate-wallet.enclave.d.ts.map +1 -1
- package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/lib/get-url-token.d.ts +1 -0
- package/dist/types/wallets/in-app/web/lib/get-url-token.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +2 -1
- package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
- package/package.json +29 -29
- package/src/exports/react.ts +3 -0
- package/src/react/core/hooks/connection/ConnectButtonProps.ts +1 -0
- package/src/react/core/hooks/contract/useContractEvents.ts +1 -1
- package/src/react/core/hooks/wallets/useAutoConnect.ts +21 -2
- package/src/react/native/ui/connect/ConnectModal.tsx +1 -1
- package/src/react/native/ui/connect/ConnectedModal.tsx +1 -1
- package/src/react/web/ui/ConnectWallet/Details.tsx +1 -1
- package/src/react/web/ui/MediaRenderer/ModelViewer.tsx +1 -9
- package/src/react/web/ui/SiteEmbed.test.tsx +39 -0
- package/src/react/web/ui/SiteEmbed.tsx +90 -0
- package/src/react/web/wallets/in-app/WalletAuth.tsx +1 -1
- package/src/react/web/wallets/shared/PassKeyLogin.tsx +2 -1
- package/src/version.ts +1 -1
- package/src/wallets/in-app/core/actions/generate-wallet.enclave.ts +2 -2
- package/src/wallets/in-app/core/wallet/enclave-wallet.ts +2 -2
- package/src/wallets/in-app/native/native-connector.ts +18 -19
- package/src/wallets/in-app/web/lib/auth/iframe-auth.ts +1 -1
- package/src/wallets/in-app/web/lib/get-url-token.ts +11 -4
- package/src/wallets/in-app/web/lib/web-connector.ts +13 -12
@@ -0,0 +1,90 @@
|
|
1
|
+
"use client";
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
3
|
+
import type { ThirdwebClient } from "../../../client/client.js";
|
4
|
+
import { getLastAuthProvider } from "../../../react/core/utils/storage.js";
|
5
|
+
import { webLocalStorage } from "../../../utils/storage/webStorage.js";
|
6
|
+
import { isEcosystemWallet } from "../../../wallets/ecosystem/is-ecosystem-wallet.js";
|
7
|
+
import { ClientScopedStorage } from "../../../wallets/in-app/core/authentication/client-scoped-storage.js";
|
8
|
+
import type { Ecosystem } from "../../../wallets/in-app/core/wallet/types.js";
|
9
|
+
import { useActiveWallet } from "../../core/hooks/wallets/useActiveWallet.js";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Embeds another thirdweb-supported site for seamless in-app and ecosystem wallet connection.
|
13
|
+
*
|
14
|
+
* @note Make sure the embedded site includes <AutoConnect /> and supports frame ancestors, see [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors) for more information.
|
15
|
+
*
|
16
|
+
* @note The embedded site must support the connected wallet (ecosystem or in-app).
|
17
|
+
*
|
18
|
+
* @param {Object} props - The props to pass to the iframe
|
19
|
+
* @param {String} props.src - The URL of the site to embed
|
20
|
+
* @param {ThirdwebClient} props.client - The client to use for the embedded site
|
21
|
+
* @param {Ecosystem} [props.ecosystem] - The ecosystem to use for the embedded site
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* ```tsx
|
25
|
+
* import { SiteEmbed } from "thirdweb/react";
|
26
|
+
*
|
27
|
+
* <SiteEmbed src="https://thirdweb.com" clientId="thirdweb-client-id" />
|
28
|
+
* ```
|
29
|
+
*/
|
30
|
+
export function SiteEmbed({
|
31
|
+
src,
|
32
|
+
client,
|
33
|
+
ecosystem,
|
34
|
+
...props
|
35
|
+
}: {
|
36
|
+
src: string;
|
37
|
+
client: ThirdwebClient;
|
38
|
+
ecosystem?: Ecosystem;
|
39
|
+
} & React.DetailedHTMLProps<
|
40
|
+
React.IframeHTMLAttributes<HTMLIFrameElement>,
|
41
|
+
HTMLIFrameElement
|
42
|
+
>) {
|
43
|
+
if (!client.clientId) {
|
44
|
+
throw new Error("The SiteEmbed client must have a clientId");
|
45
|
+
}
|
46
|
+
|
47
|
+
const activeWallet = useActiveWallet();
|
48
|
+
const walletId = activeWallet?.id;
|
49
|
+
|
50
|
+
const {
|
51
|
+
data: { authProvider, authCookie } = {},
|
52
|
+
} = useQuery({
|
53
|
+
queryKey: ["site-embed", walletId, src, client.clientId, ecosystem],
|
54
|
+
enabled:
|
55
|
+
activeWallet && (isEcosystemWallet(activeWallet) || walletId === "inApp"),
|
56
|
+
queryFn: async () => {
|
57
|
+
const storage = new ClientScopedStorage({
|
58
|
+
storage: webLocalStorage,
|
59
|
+
clientId: client.clientId,
|
60
|
+
ecosystem,
|
61
|
+
});
|
62
|
+
|
63
|
+
const authProvider = await getLastAuthProvider(webLocalStorage);
|
64
|
+
const authCookie = await storage.getAuthCookie();
|
65
|
+
|
66
|
+
return { authProvider, authCookie };
|
67
|
+
},
|
68
|
+
});
|
69
|
+
|
70
|
+
const url = new URL(src);
|
71
|
+
if (walletId) {
|
72
|
+
url.searchParams.set("walletId", walletId);
|
73
|
+
}
|
74
|
+
if (authProvider) {
|
75
|
+
url.searchParams.set("authProvider", authProvider);
|
76
|
+
}
|
77
|
+
if (authCookie) {
|
78
|
+
url.searchParams.set("authCookie", authCookie);
|
79
|
+
}
|
80
|
+
|
81
|
+
return (
|
82
|
+
<iframe
|
83
|
+
src={encodeURI(url.toString())}
|
84
|
+
width="100%"
|
85
|
+
height="100%"
|
86
|
+
allowFullScreen
|
87
|
+
{...props}
|
88
|
+
/>
|
89
|
+
);
|
90
|
+
}
|
@@ -39,7 +39,7 @@ export function WalletAuth(props: {
|
|
39
39
|
}) {
|
40
40
|
const { wallet, done } = props;
|
41
41
|
const addConnectedWallet = useAddConnectedWallet();
|
42
|
-
const walletToConnect = useRef<Wallet>();
|
42
|
+
const walletToConnect = useRef<Wallet>(undefined);
|
43
43
|
const [status, setStatus] = useState<"loading" | "error" | "selecting">(
|
44
44
|
"selecting",
|
45
45
|
);
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.
|
1
|
+
export const version = "5.66.0";
|
@@ -9,13 +9,13 @@ import type { Ecosystem } from "../wallet/types.js";
|
|
9
9
|
* @internal
|
10
10
|
*/
|
11
11
|
export async function generateWallet({
|
12
|
-
authToken,
|
13
12
|
client,
|
14
13
|
ecosystem,
|
14
|
+
authToken,
|
15
15
|
}: {
|
16
16
|
client: ThirdwebClient;
|
17
|
-
ecosystem: Ecosystem;
|
18
17
|
authToken: string;
|
18
|
+
ecosystem?: Ecosystem;
|
19
19
|
}) {
|
20
20
|
const clientFetch = getClientFetch(client, ecosystem);
|
21
21
|
const response = await clientFetch(
|
@@ -139,8 +139,8 @@ export class EnclaveWallet implements IWebWallet {
|
|
139
139
|
chain: getCachedChain(tx.chainId),
|
140
140
|
});
|
141
141
|
const transaction: Record<string, Hex | number | undefined> = {
|
142
|
-
to:
|
143
|
-
data: tx.data
|
142
|
+
to: tx.to ? getAddress(tx.to) : undefined,
|
143
|
+
data: tx.data,
|
144
144
|
value: tx.value ? toHex(tx.value) : undefined,
|
145
145
|
gas: tx.gas ? toHex(tx.gas + tx.gas / BigInt(10)) : undefined, // Add a 10% buffer to gas
|
146
146
|
nonce: tx.nonce
|
@@ -80,27 +80,26 @@ export class InAppNativeConnector implements InAppConnector {
|
|
80
80
|
}
|
81
81
|
let wallet = user.wallets[0];
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
83
|
+
if (authResult && wallet && wallet.type === "sharded") {
|
84
|
+
try {
|
85
|
+
const { migrateToEnclaveWallet } = await import(
|
86
|
+
"./helpers/wallet/migration.js"
|
87
|
+
);
|
88
|
+
wallet = await migrateToEnclaveWallet({
|
89
|
+
client: this.client,
|
90
|
+
storage: this.storage,
|
91
|
+
storedToken: authResult.storedToken,
|
92
|
+
encryptionKey,
|
93
|
+
});
|
94
|
+
} catch {
|
95
|
+
console.warn(
|
96
|
+
"Failed to migrate from sharded to enclave wallet, continuing with sharded wallet",
|
97
|
+
);
|
98
|
+
}
|
99
99
|
}
|
100
100
|
|
101
|
-
if (authResult &&
|
102
|
-
// new
|
103
|
-
// TODO (enclaves): same flow for in-app wallets
|
101
|
+
if (authResult && !wallet) {
|
102
|
+
// new user, generate enclave wallet
|
104
103
|
const { generateWallet } = await import(
|
105
104
|
"../core/actions/generate-wallet.enclave.js"
|
106
105
|
);
|
@@ -128,7 +128,7 @@ export class Auth {
|
|
128
128
|
});
|
129
129
|
}
|
130
130
|
|
131
|
-
if (user.wallets.length === 0
|
131
|
+
if (user.wallets.length === 0) {
|
132
132
|
// If this is a new ecosystem wallet without an enclave yet, we'll generate an enclave
|
133
133
|
const result = await generateWallet({
|
134
134
|
authToken: authToken.storedToken.cookieString,
|
@@ -9,6 +9,7 @@ export function getUrlToken(): {
|
|
9
9
|
walletId?: WalletId;
|
10
10
|
authResult?: AuthStoredTokenWithCookieReturnType;
|
11
11
|
authProvider?: AuthOption;
|
12
|
+
authCookie?: string;
|
12
13
|
} {
|
13
14
|
if (!window?.location) {
|
14
15
|
// Not in web
|
@@ -20,18 +21,24 @@ export function getUrlToken(): {
|
|
20
21
|
const authResultString = params.get("authResult");
|
21
22
|
const walletId = params.get("walletId") as WalletId | undefined;
|
22
23
|
const authProvider = params.get("authProvider") as AuthOption | undefined;
|
24
|
+
const authCookie = params.get("authCookie") as string | undefined;
|
23
25
|
|
24
|
-
if (authResultString && walletId) {
|
25
|
-
const authResult =
|
26
|
-
|
26
|
+
if ((authCookie || authResultString) && walletId) {
|
27
|
+
const authResult = (() => {
|
28
|
+
if (authResultString) {
|
29
|
+
params.delete("authResult");
|
30
|
+
return JSON.parse(decodeURIComponent(authResultString));
|
31
|
+
}
|
32
|
+
})();
|
27
33
|
params.delete("walletId");
|
28
34
|
params.delete("authProvider");
|
35
|
+
params.delete("authCookie");
|
29
36
|
window.history.pushState(
|
30
37
|
{},
|
31
38
|
"",
|
32
39
|
`${window.location.pathname}?${params.toString()}`,
|
33
40
|
);
|
34
|
-
return { walletId, authResult, authProvider };
|
41
|
+
return { walletId, authResult, authProvider, authCookie };
|
35
42
|
}
|
36
43
|
return {};
|
37
44
|
}
|
@@ -101,10 +101,7 @@ export class InAppWebConnector implements InAppConnector {
|
|
101
101
|
onAuthSuccess: async (authResult) => {
|
102
102
|
onAuthSuccess?.(authResult);
|
103
103
|
|
104
|
-
if (
|
105
|
-
this.ecosystem &&
|
106
|
-
authResult.storedToken.authDetails.walletType === "sharded"
|
107
|
-
) {
|
104
|
+
if (authResult.storedToken.authDetails.walletType === "sharded") {
|
108
105
|
// If this is an existing sharded ecosystem wallet, we'll need to migrate
|
109
106
|
const result = await this.querier.call<boolean>({
|
110
107
|
procedureName: "migrateFromShardToEnclave",
|
@@ -113,11 +110,15 @@ export class InAppWebConnector implements InAppConnector {
|
|
113
110
|
},
|
114
111
|
});
|
115
112
|
if (!result) {
|
116
|
-
|
113
|
+
console.warn(
|
114
|
+
"Failed to migrate from sharded to enclave wallet, continuing with sharded wallet",
|
115
|
+
);
|
117
116
|
}
|
118
117
|
}
|
119
118
|
|
120
|
-
await this.initializeWallet(
|
119
|
+
this.wallet = await this.initializeWallet(
|
120
|
+
authResult.storedToken.cookieString,
|
121
|
+
);
|
121
122
|
|
122
123
|
if (!this.wallet) {
|
123
124
|
throw new Error("Failed to initialize wallet");
|
@@ -133,7 +134,7 @@ export class InAppWebConnector implements InAppConnector {
|
|
133
134
|
deviceShareStored,
|
134
135
|
});
|
135
136
|
|
136
|
-
if (
|
137
|
+
if (this.wallet instanceof IFrameWallet) {
|
137
138
|
await this.querier.call({
|
138
139
|
procedureName: "initIframe",
|
139
140
|
params: {
|
@@ -163,7 +164,7 @@ export class InAppWebConnector implements InAppConnector {
|
|
163
164
|
});
|
164
165
|
}
|
165
166
|
|
166
|
-
async initializeWallet(authToken?: string) {
|
167
|
+
async initializeWallet(authToken?: string): Promise<IWebWallet> {
|
167
168
|
const storedAuthToken = await this.storage.getAuthCookie();
|
168
169
|
if (!authToken && storedAuthToken === null) {
|
169
170
|
throw new Error(
|
@@ -176,6 +177,7 @@ export class InAppWebConnector implements InAppConnector {
|
|
176
177
|
client: this.client,
|
177
178
|
ecosystem: this.ecosystem,
|
178
179
|
});
|
180
|
+
|
179
181
|
if (!user) {
|
180
182
|
throw new Error("Cannot initialize wallet, no user logged in");
|
181
183
|
}
|
@@ -186,16 +188,15 @@ export class InAppWebConnector implements InAppConnector {
|
|
186
188
|
}
|
187
189
|
|
188
190
|
if (user.wallets[0]?.type === "enclave") {
|
189
|
-
|
191
|
+
return new EnclaveWallet({
|
190
192
|
client: this.client,
|
191
193
|
ecosystem: this.ecosystem,
|
192
194
|
address: user.wallets[0].address,
|
193
195
|
storage: this.storage,
|
194
196
|
});
|
195
|
-
return;
|
196
197
|
}
|
197
198
|
|
198
|
-
|
199
|
+
return new IFrameWallet({
|
199
200
|
client: this.client,
|
200
201
|
ecosystem: this.ecosystem,
|
201
202
|
querier: this.querier,
|
@@ -233,7 +234,7 @@ export class InAppWebConnector implements InAppConnector {
|
|
233
234
|
if (!localAuthToken) {
|
234
235
|
return { status: "Logged Out" };
|
235
236
|
}
|
236
|
-
await this.initializeWallet(localAuthToken);
|
237
|
+
this.wallet = await this.initializeWallet(localAuthToken);
|
237
238
|
}
|
238
239
|
if (!this.wallet) {
|
239
240
|
throw new Error("Wallet not initialized");
|