thirdweb 5.98.0 → 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 (78) 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/storage/upload/web-node.js +2 -0
  14. package/dist/cjs/storage/upload/web-node.js.map +1 -1
  15. package/dist/cjs/utils/fetch.js +10 -7
  16. package/dist/cjs/utils/fetch.js.map +1 -1
  17. package/dist/cjs/version.js +1 -1
  18. package/dist/cjs/wallets/connection/autoConnectCore.js +29 -12
  19. package/dist/cjs/wallets/connection/autoConnectCore.js.map +1 -1
  20. package/dist/cjs/wallets/engine/index.js +2 -1
  21. package/dist/cjs/wallets/engine/index.js.map +1 -1
  22. package/dist/cjs/wallets/in-app/core/wallet/is-in-app-signer.js +15 -0
  23. package/dist/cjs/wallets/in-app/core/wallet/is-in-app-signer.js.map +1 -0
  24. package/dist/esm/extensions/erc20/read/getCurrencyMetadata.js +2 -2
  25. package/dist/esm/extensions/erc20/read/getCurrencyMetadata.js.map +1 -1
  26. package/dist/esm/react/native/ui/connect/ConnectButton.js +4 -1
  27. package/dist/esm/react/native/ui/connect/ConnectButton.js.map +1 -1
  28. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +6 -4
  29. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  30. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +1 -1
  31. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  32. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js +1 -11
  33. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js.map +1 -1
  34. package/dist/esm/react/web/ui/PayEmbed.js +8 -1
  35. package/dist/esm/react/web/ui/PayEmbed.js.map +1 -1
  36. package/dist/esm/storage/upload/web-node.js +2 -0
  37. package/dist/esm/storage/upload/web-node.js.map +1 -1
  38. package/dist/esm/utils/fetch.js +10 -7
  39. package/dist/esm/utils/fetch.js.map +1 -1
  40. package/dist/esm/version.js +1 -1
  41. package/dist/esm/wallets/connection/autoConnectCore.js +29 -12
  42. package/dist/esm/wallets/connection/autoConnectCore.js.map +1 -1
  43. package/dist/esm/wallets/engine/index.js +2 -1
  44. package/dist/esm/wallets/engine/index.js.map +1 -1
  45. package/dist/esm/wallets/in-app/core/wallet/is-in-app-signer.js +12 -0
  46. package/dist/esm/wallets/in-app/core/wallet/is-in-app-signer.js.map +1 -0
  47. package/dist/types/react/native/ui/connect/ConnectButton.d.ts.map +1 -1
  48. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
  49. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
  50. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.d.ts.map +1 -1
  51. package/dist/types/react/web/ui/PayEmbed.d.ts +1 -1
  52. package/dist/types/react/web/ui/PayEmbed.d.ts.map +1 -1
  53. package/dist/types/storage/upload/web-node.d.ts.map +1 -1
  54. package/dist/types/utils/fetch.d.ts +1 -0
  55. package/dist/types/utils/fetch.d.ts.map +1 -1
  56. package/dist/types/version.d.ts +1 -1
  57. package/dist/types/wallets/connection/autoConnectCore.d.ts.map +1 -1
  58. package/dist/types/wallets/connection/types.d.ts +9 -0
  59. package/dist/types/wallets/connection/types.d.ts.map +1 -1
  60. package/dist/types/wallets/engine/index.d.ts.map +1 -1
  61. package/dist/types/wallets/in-app/core/wallet/is-in-app-signer.d.ts +6 -0
  62. package/dist/types/wallets/in-app/core/wallet/is-in-app-signer.d.ts.map +1 -0
  63. package/package.json +2 -2
  64. package/src/auth/verify-typed-data.test.ts +4 -3
  65. package/src/extensions/erc20/read/getCurrencyMetadata.ts +2 -2
  66. package/src/react/native/ui/connect/ConnectButton.tsx +4 -1
  67. package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +11 -3
  68. package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +1 -0
  69. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.tsx +1 -21
  70. package/src/react/web/ui/PayEmbed.tsx +15 -1
  71. package/src/storage/upload/web-node.ts +2 -0
  72. package/src/utils/fetch.test.ts +23 -1
  73. package/src/utils/fetch.ts +18 -11
  74. package/src/version.ts +1 -1
  75. package/src/wallets/connection/autoConnectCore.ts +33 -12
  76. package/src/wallets/connection/types.ts +10 -0
  77. package/src/wallets/engine/index.ts +2 -1
  78. package/src/wallets/in-app/core/wallet/is-in-app-signer.ts +21 -0
@@ -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
  };
@@ -102,12 +102,13 @@ export function engineAccount(options: EngineAccountOptions): Account {
102
102
  // engine wants a hex string here so we serialize it
103
103
  data: transaction.data || "0x",
104
104
  // value is always required
105
- value: toHex(transaction.value ?? 0n),
105
+ value: transaction.value ?? 0n,
106
106
  // optional authorization list
107
107
  authorizationList: transaction.authorizationList,
108
108
 
109
109
  txOverrides: {
110
110
  gas: transaction.gas,
111
+ value: transaction.value,
111
112
  },
112
113
  };
113
114
 
@@ -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
+ }