thirdweb 5.98.1 → 5.98.2

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.
Files changed (57) hide show
  1. package/dist/cjs/extensions/erc20/read/getCurrencyMetadata.js +2 -2
  2. package/dist/cjs/extensions/erc20/read/getCurrencyMetadata.js.map +1 -1
  3. package/dist/cjs/react/native/ui/connect/ConnectButton.js +4 -1
  4. package/dist/cjs/react/native/ui/connect/ConnectButton.js.map +1 -1
  5. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +6 -4
  6. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  7. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +1 -1
  8. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  9. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js +5 -15
  10. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js.map +1 -1
  11. package/dist/cjs/react/web/ui/PayEmbed.js +8 -1
  12. package/dist/cjs/react/web/ui/PayEmbed.js.map +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/cjs/wallets/connection/autoConnectCore.js +29 -12
  15. package/dist/cjs/wallets/connection/autoConnectCore.js.map +1 -1
  16. package/dist/cjs/wallets/in-app/core/wallet/is-in-app-signer.js +15 -0
  17. package/dist/cjs/wallets/in-app/core/wallet/is-in-app-signer.js.map +1 -0
  18. package/dist/esm/extensions/erc20/read/getCurrencyMetadata.js +2 -2
  19. package/dist/esm/extensions/erc20/read/getCurrencyMetadata.js.map +1 -1
  20. package/dist/esm/react/native/ui/connect/ConnectButton.js +4 -1
  21. package/dist/esm/react/native/ui/connect/ConnectButton.js.map +1 -1
  22. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +6 -4
  23. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  24. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +1 -1
  25. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  26. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js +1 -11
  27. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js.map +1 -1
  28. package/dist/esm/react/web/ui/PayEmbed.js +8 -1
  29. package/dist/esm/react/web/ui/PayEmbed.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/dist/esm/wallets/connection/autoConnectCore.js +29 -12
  32. package/dist/esm/wallets/connection/autoConnectCore.js.map +1 -1
  33. package/dist/esm/wallets/in-app/core/wallet/is-in-app-signer.js +12 -0
  34. package/dist/esm/wallets/in-app/core/wallet/is-in-app-signer.js.map +1 -0
  35. package/dist/types/react/native/ui/connect/ConnectButton.d.ts.map +1 -1
  36. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
  37. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
  38. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.d.ts.map +1 -1
  39. package/dist/types/react/web/ui/PayEmbed.d.ts +1 -1
  40. package/dist/types/react/web/ui/PayEmbed.d.ts.map +1 -1
  41. package/dist/types/version.d.ts +1 -1
  42. package/dist/types/wallets/connection/autoConnectCore.d.ts.map +1 -1
  43. package/dist/types/wallets/connection/types.d.ts +9 -0
  44. package/dist/types/wallets/connection/types.d.ts.map +1 -1
  45. package/dist/types/wallets/in-app/core/wallet/is-in-app-signer.d.ts +6 -0
  46. package/dist/types/wallets/in-app/core/wallet/is-in-app-signer.d.ts.map +1 -0
  47. package/package.json +1 -1
  48. package/src/extensions/erc20/read/getCurrencyMetadata.ts +2 -2
  49. package/src/react/native/ui/connect/ConnectButton.tsx +4 -1
  50. package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +11 -3
  51. package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +1 -0
  52. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.tsx +1 -21
  53. package/src/react/web/ui/PayEmbed.tsx +15 -1
  54. package/src/version.ts +1 -1
  55. package/src/wallets/connection/autoConnectCore.ts +33 -12
  56. package/src/wallets/connection/types.ts +10 -0
  57. package/src/wallets/in-app/core/wallet/is-in-app-signer.ts +21 -0
@@ -297,6 +297,9 @@ export function ConnectButton(props: ConnectButtonProps) {
297
297
  );
298
298
  const localeQuery = useConnectLocale(props.locale || "en_US");
299
299
  const connectionManager = useConnectionManager();
300
+ const activeAccount = useActiveAccount();
301
+ const activeWallet = useActiveWallet();
302
+ const siweAuth = useSiweAuth(activeWallet, activeAccount, props.auth);
300
303
 
301
304
  usePreloadWalletProviders({
302
305
  wallets,
@@ -337,6 +340,7 @@ export function ConnectButton(props: ConnectButtonProps) {
337
340
  }
338
341
  accountAbstraction={props.accountAbstraction}
339
342
  onConnect={props.onConnect}
343
+ siweAuth={siweAuth}
340
344
  />
341
345
  );
342
346
 
@@ -362,7 +366,11 @@ export function ConnectButton(props: ConnectButtonProps) {
362
366
 
363
367
  return (
364
368
  <WalletUIStatesProvider theme={props.theme} isOpen={false}>
365
- <ConnectButtonInner {...props} connectLocale={localeQuery.data} />
369
+ <ConnectButtonInner
370
+ {...props}
371
+ siweAuth={siweAuth}
372
+ connectLocale={localeQuery.data}
373
+ />
366
374
  <ConnectModal
367
375
  shouldSetActive={true}
368
376
  accountAbstraction={props.accountAbstraction}
@@ -396,11 +404,11 @@ export function ConnectButton(props: ConnectButtonProps) {
396
404
  function ConnectButtonInner(
397
405
  props: ConnectButtonProps & {
398
406
  connectLocale: ConnectLocale;
407
+ siweAuth: ReturnType<typeof useSiweAuth>;
399
408
  },
400
409
  ) {
401
- const activeWallet = useActiveWallet();
410
+ const siweAuth = props.siweAuth;
402
411
  const activeAccount = useActiveAccount();
403
- const siweAuth = useSiweAuth(activeWallet, activeAccount, props.auth);
404
412
  const [showSignatureModal, setShowSignatureModal] = useState(false);
405
413
 
406
414
  // if wallet gets disconnected suddently, close the signature modal if it's open
@@ -247,6 +247,7 @@ export function ConnectEmbed(props: ConnectEmbedProps) {
247
247
  chain={preferredChain}
248
248
  appMetadata={props.appMetadata}
249
249
  client={props.client}
250
+ siweAuth={siweAuth}
250
251
  wallets={wallets}
251
252
  accountAbstraction={props.accountAbstraction}
252
253
  timeout={
@@ -23,10 +23,7 @@ import { sendTransaction } from "../../../../../../../transaction/actions/send-t
23
23
  import type { WaitForReceiptOptions } from "../../../../../../../transaction/actions/wait-for-tx-receipt.js";
24
24
  import { waitForReceipt } from "../../../../../../../transaction/actions/wait-for-tx-receipt.js";
25
25
  import { formatNumber } from "../../../../../../../utils/formatNumber.js";
26
- import { isEcosystemWallet } from "../../../../../../../wallets/ecosystem/is-ecosystem-wallet.js";
27
- import { isInAppWallet } from "../../../../../../../wallets/in-app/core/wallet/index.js";
28
- import type { Wallet } from "../../../../../../../wallets/interfaces/wallet.js";
29
- import { isSmartWallet } from "../../../../../../../wallets/smart/is-smart-wallet.js";
26
+ import { isInAppSigner } from "../../../../../../../wallets/in-app/core/wallet/is-in-app-signer.js";
30
27
  import { spacing } from "../../../../../../core/design-system/index.js";
31
28
  import { useChainName } from "../../../../../../core/hooks/others/useChainQuery.js";
32
29
  import { useBuyWithCryptoStatus } from "../../../../../../core/hooks/pay/useBuyWithCryptoStatus.js";
@@ -779,20 +776,3 @@ function useSwapMutation(props: {
779
776
  },
780
777
  });
781
778
  }
782
-
783
- function isInAppSigner(options: {
784
- wallet: Wallet;
785
- connectedWallets: Wallet[];
786
- }) {
787
- const isInAppOrEcosystem = (w: Wallet) =>
788
- isInAppWallet(w) || isEcosystemWallet(w);
789
- const isSmartWalletWithAdmin =
790
- isSmartWallet(options.wallet) &&
791
- options.connectedWallets.some(
792
- (w) =>
793
- isInAppOrEcosystem(w) &&
794
- w.getAccount()?.address?.toLowerCase() ===
795
- options.wallet.getAdminAccount?.()?.address?.toLowerCase(),
796
- );
797
- return isInAppOrEcosystem(options.wallet) || isSmartWalletWithAdmin;
798
- }
@@ -9,13 +9,19 @@ import type { AppMetadata } from "../../../wallets/types.js";
9
9
  import type { WalletId } from "../../../wallets/wallet-types.js";
10
10
  import { CustomThemeProvider } from "../../core/design-system/CustomThemeProvider.js";
11
11
  import type { Theme } from "../../core/design-system/index.js";
12
- import type { SiweAuthOptions } from "../../core/hooks/auth/useSiweAuth.js";
12
+ import {
13
+ type SiweAuthOptions,
14
+ useSiweAuth,
15
+ } from "../../core/hooks/auth/useSiweAuth.js";
13
16
  import type {
14
17
  ConnectButton_connectModalOptions,
15
18
  PayUIOptions,
16
19
  } from "../../core/hooks/connection/ConnectButtonProps.js";
20
+ import { useActiveAccount } from "../../core/hooks/wallets/useActiveAccount.js";
21
+ import { useActiveWallet } from "../../core/hooks/wallets/useActiveWallet.js";
17
22
  import { useConnectionManager } from "../../core/providers/connection-manager.js";
18
23
  import type { SupportedTokens } from "../../core/utils/defaultTokens.js";
24
+ import { AutoConnect } from "../../web/ui/AutoConnect/AutoConnect.js";
19
25
  import { EmbedContainer } from "./ConnectWallet/Modal/ConnectEmbed.js";
20
26
  import { useConnectLocale } from "./ConnectWallet/locale/getConnectLocale.js";
21
27
  import BuyScreen from "./ConnectWallet/screens/Buy/BuyScreen.js";
@@ -300,6 +306,13 @@ export function PayEmbed(props: PayEmbedProps) {
300
306
  const [screen, setScreen] = useState<"buy" | "execute-tx">("buy");
301
307
  const theme = props.theme || "dark";
302
308
  const connectionManager = useConnectionManager();
309
+ const activeAccount = useActiveAccount();
310
+ const activeWallet = useActiveWallet();
311
+ const siweAuth = useSiweAuth(
312
+ activeWallet,
313
+ activeAccount,
314
+ props.connectOptions?.auth,
315
+ );
303
316
 
304
317
  // Add props.chain and props.chains to defined chains store
305
318
  useEffect(() => {
@@ -342,6 +355,7 @@ export function PayEmbed(props: PayEmbedProps) {
342
355
  } else {
343
356
  content = (
344
357
  <>
358
+ <AutoConnect client={props.client} siweAuth={siweAuth} />
345
359
  {screen === "buy" && (
346
360
  <BuyScreen
347
361
  title={metadata?.name || "Buy"}
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.98.1";
1
+ export const version = "5.98.2";
@@ -8,6 +8,7 @@ import type {
8
8
  AuthArgsType,
9
9
  AuthStoredTokenWithCookieReturnType,
10
10
  } from "../in-app/core/authentication/types.js";
11
+ import { isInAppSigner } from "../in-app/core/wallet/is-in-app-signer.js";
11
12
  import { getUrlToken } from "../in-app/web/lib/get-url-token.js";
12
13
  import type { Wallet } from "../interfaces/wallet.js";
13
14
  import {
@@ -82,11 +83,11 @@ const _autoConnectCore = async ({
82
83
  getStoredActiveWalletId(storage),
83
84
  ]);
84
85
 
85
- const result = getUrlToken();
86
+ const urlToken = getUrlToken();
86
87
 
87
88
  // If an auth cookie is found and this site supports the wallet, we'll set the auth cookie in the client storage
88
- const wallet = wallets.find((w) => w.id === result?.walletId);
89
- if (result?.authCookie && wallet) {
89
+ const wallet = wallets.find((w) => w.id === urlToken?.walletId);
90
+ if (urlToken?.authCookie && wallet) {
90
91
  const clientStorage = new ClientScopedStorage({
91
92
  storage,
92
93
  clientId: props.client.clientId,
@@ -97,17 +98,17 @@ const _autoConnectCore = async ({
97
98
  }
98
99
  : undefined,
99
100
  });
100
- await clientStorage.saveAuthCookie(result.authCookie);
101
+ await clientStorage.saveAuthCookie(urlToken.authCookie);
101
102
  }
102
- if (result?.walletId) {
103
- lastActiveWalletId = result.walletId;
104
- lastConnectedWalletIds = lastConnectedWalletIds?.includes(result.walletId)
103
+ if (urlToken?.walletId) {
104
+ lastActiveWalletId = urlToken.walletId;
105
+ lastConnectedWalletIds = lastConnectedWalletIds?.includes(urlToken.walletId)
105
106
  ? lastConnectedWalletIds
106
- : [result.walletId, ...(lastConnectedWalletIds || [])];
107
+ : [urlToken.walletId, ...(lastConnectedWalletIds || [])];
107
108
  }
108
109
 
109
- if (result?.authProvider) {
110
- await setLastAuthProvider?.(result.authProvider, storage);
110
+ if (urlToken?.authProvider) {
111
+ await setLastAuthProvider?.(urlToken.authProvider, storage);
111
112
  }
112
113
 
113
114
  // if no wallets were last connected or we didn't receive an auth token
@@ -132,7 +133,7 @@ const _autoConnectCore = async ({
132
133
  wallet: activeWallet,
133
134
  client: props.client,
134
135
  lastConnectedChain,
135
- authResult: result?.authResult,
136
+ authResult: urlToken?.authResult,
136
137
  }),
137
138
  {
138
139
  ms: timeout,
@@ -183,13 +184,33 @@ const _autoConnectCore = async ({
183
184
  wallet,
184
185
  client: props.client,
185
186
  lastConnectedChain,
186
- authResult: result?.authResult,
187
+ authResult: urlToken?.authResult,
187
188
  });
188
189
  manager.addConnectedWallet(wallet);
189
190
  } catch {
190
191
  // no-op
191
192
  }
192
193
  }
194
+
195
+ // Auto-login with SIWE
196
+ const isIAW =
197
+ activeWallet &&
198
+ isInAppSigner({
199
+ wallet: activeWallet,
200
+ connectedWallets: activeWallet
201
+ ? [activeWallet, ...otherWallets]
202
+ : otherWallets,
203
+ });
204
+ if (
205
+ isIAW &&
206
+ props.siweAuth?.requiresAuth &&
207
+ !props.siweAuth?.isLoggedIn &&
208
+ !props.siweAuth?.isLoggingIn
209
+ ) {
210
+ await props.siweAuth?.doLogin().catch((err) => {
211
+ console.warn("Error signing in with SIWE:", err.message);
212
+ });
213
+ }
193
214
  manager.isAutoConnecting.setValue(false);
194
215
  return autoConnected; // useQuery needs a return value
195
216
  };
@@ -118,4 +118,14 @@ export type AutoConnectProps = {
118
118
  * Callback to be called when the connection is timeout-ed
119
119
  */
120
120
  onTimeout?: () => void;
121
+
122
+ /**
123
+ * @hidden
124
+ */
125
+ siweAuth?: {
126
+ requiresAuth: boolean;
127
+ doLogin: () => Promise<void>;
128
+ isLoggedIn: boolean | undefined;
129
+ isLoggingIn: boolean | undefined;
130
+ };
121
131
  };
@@ -0,0 +1,21 @@
1
+ import { isEcosystemWallet } from "../../../../wallets/ecosystem/is-ecosystem-wallet.js";
2
+ import type { Wallet } from "../../../interfaces/wallet.js";
3
+ import { isSmartWallet } from "../../../smart/index.js";
4
+ import { isInAppWallet } from "./index.js";
5
+
6
+ export function isInAppSigner(options: {
7
+ wallet: Wallet;
8
+ connectedWallets: Wallet[];
9
+ }) {
10
+ const isInAppOrEcosystem = (w: Wallet) =>
11
+ isInAppWallet(w) || isEcosystemWallet(w);
12
+ const isSmartWalletWithAdmin =
13
+ isSmartWallet(options.wallet) &&
14
+ options.connectedWallets.some(
15
+ (w) =>
16
+ isInAppOrEcosystem(w) &&
17
+ w.getAccount()?.address?.toLowerCase() ===
18
+ options.wallet.getAdminAccount?.()?.address?.toLowerCase(),
19
+ );
20
+ return isInAppOrEcosystem(options.wallet) || isSmartWalletWithAdmin;
21
+ }