thirdweb 5.102.3-nightly-f44d6ba2827d7d7391425a5ddb2d49cafdc934bb-20250531000435 → 5.102.4-nightly-283dc289fca1ad16a9296e610d293b73a7123709-20250602000433

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 (131) hide show
  1. package/dist/cjs/bridge/Token.js +153 -0
  2. package/dist/cjs/bridge/Token.js.map +1 -0
  3. package/dist/cjs/bridge/index.js +3 -1
  4. package/dist/cjs/bridge/index.js.map +1 -1
  5. package/dist/cjs/extensions/erc1155/read/getNFTs.js +9 -2
  6. package/dist/cjs/extensions/erc1155/read/getNFTs.js.map +1 -1
  7. package/dist/cjs/extensions/erc721/read/getNFTs.js +9 -2
  8. package/dist/cjs/extensions/erc721/read/getNFTs.js.map +1 -1
  9. package/dist/cjs/insight/get-tokens.js +5 -6
  10. package/dist/cjs/insight/get-tokens.js.map +1 -1
  11. package/dist/cjs/pay/convert/cryptoToFiat.js +6 -38
  12. package/dist/cjs/pay/convert/cryptoToFiat.js.map +1 -1
  13. package/dist/cjs/pay/convert/fiatToCrypto.js +6 -38
  14. package/dist/cjs/pay/convert/fiatToCrypto.js.map +1 -1
  15. package/dist/cjs/pay/convert/get-token.js +19 -0
  16. package/dist/cjs/pay/convert/get-token.js.map +1 -0
  17. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +2 -2
  18. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  19. package/dist/cjs/react/core/utils/wallet.js +0 -48
  20. package/dist/cjs/react/core/utils/wallet.js.map +1 -1
  21. package/dist/cjs/react/native/ui/connect/ConnectedModal.js +5 -5
  22. package/dist/cjs/react/native/ui/connect/ConnectedModal.js.map +1 -1
  23. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +7 -7
  24. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  25. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +2 -2
  26. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
  27. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +28 -8
  28. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
  29. package/dist/cjs/react/web/ui/TransactionButton/DepositScreen.js +2 -2
  30. package/dist/cjs/react/web/ui/TransactionButton/DepositScreen.js.map +1 -1
  31. package/dist/cjs/version.js +1 -1
  32. package/dist/cjs/wallets/manager/index.js +1 -2
  33. package/dist/cjs/wallets/manager/index.js.map +1 -1
  34. package/dist/cjs/wallets/smart/is-smart-wallet.js +62 -5
  35. package/dist/cjs/wallets/smart/is-smart-wallet.js.map +1 -1
  36. package/dist/esm/bridge/Token.js +150 -0
  37. package/dist/esm/bridge/Token.js.map +1 -0
  38. package/dist/esm/bridge/index.js +1 -0
  39. package/dist/esm/bridge/index.js.map +1 -1
  40. package/dist/esm/extensions/erc1155/read/getNFTs.js +9 -2
  41. package/dist/esm/extensions/erc1155/read/getNFTs.js.map +1 -1
  42. package/dist/esm/extensions/erc721/read/getNFTs.js +9 -2
  43. package/dist/esm/extensions/erc721/read/getNFTs.js.map +1 -1
  44. package/dist/esm/insight/get-tokens.js +5 -6
  45. package/dist/esm/insight/get-tokens.js.map +1 -1
  46. package/dist/esm/pay/convert/cryptoToFiat.js +6 -38
  47. package/dist/esm/pay/convert/cryptoToFiat.js.map +1 -1
  48. package/dist/esm/pay/convert/fiatToCrypto.js +6 -38
  49. package/dist/esm/pay/convert/fiatToCrypto.js.map +1 -1
  50. package/dist/esm/pay/convert/get-token.js +16 -0
  51. package/dist/esm/pay/convert/get-token.js.map +1 -0
  52. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +1 -1
  53. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  54. package/dist/esm/react/core/utils/wallet.js +0 -47
  55. package/dist/esm/react/core/utils/wallet.js.map +1 -1
  56. package/dist/esm/react/native/ui/connect/ConnectedModal.js +5 -5
  57. package/dist/esm/react/native/ui/connect/ConnectedModal.js.map +1 -1
  58. package/dist/esm/react/web/ui/ConnectWallet/Details.js +7 -7
  59. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  60. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +1 -1
  61. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
  62. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +28 -8
  63. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
  64. package/dist/esm/react/web/ui/TransactionButton/DepositScreen.js +1 -1
  65. package/dist/esm/react/web/ui/TransactionButton/DepositScreen.js.map +1 -1
  66. package/dist/esm/version.js +1 -1
  67. package/dist/esm/wallets/manager/index.js +1 -2
  68. package/dist/esm/wallets/manager/index.js.map +1 -1
  69. package/dist/esm/wallets/smart/is-smart-wallet.js +61 -5
  70. package/dist/esm/wallets/smart/is-smart-wallet.js.map +1 -1
  71. package/dist/types/bridge/Token.d.ts +140 -0
  72. package/dist/types/bridge/Token.d.ts.map +1 -0
  73. package/dist/types/bridge/index.d.ts +1 -0
  74. package/dist/types/bridge/index.d.ts.map +1 -1
  75. package/dist/types/extensions/erc1155/read/getNFTs.d.ts.map +1 -1
  76. package/dist/types/insight/get-tokens.d.ts +2 -2
  77. package/dist/types/insight/get-tokens.d.ts.map +1 -1
  78. package/dist/types/pay/convert/cryptoToFiat.d.ts.map +1 -1
  79. package/dist/types/pay/convert/fiatToCrypto.d.ts.map +1 -1
  80. package/dist/types/pay/convert/get-token.d.ts +3 -0
  81. package/dist/types/pay/convert/get-token.d.ts.map +1 -0
  82. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  83. package/dist/types/react/core/utils/wallet.d.ts +1 -5
  84. package/dist/types/react/core/utils/wallet.d.ts.map +1 -1
  85. package/dist/types/react/native/ui/connect/ConnectedModal.d.ts.map +1 -1
  86. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  87. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.d.ts.map +1 -1
  88. package/dist/types/version.d.ts +1 -1
  89. package/dist/types/wallets/manager/index.d.ts.map +1 -1
  90. package/dist/types/wallets/smart/is-smart-wallet.d.ts +5 -1
  91. package/dist/types/wallets/smart/is-smart-wallet.d.ts.map +1 -1
  92. package/package.json +1 -1
  93. package/src/bridge/Token.test.ts +90 -0
  94. package/src/bridge/Token.ts +184 -0
  95. package/src/bridge/index.ts +1 -0
  96. package/src/extensions/erc1155/read/getNFTs.ts +8 -2
  97. package/src/extensions/erc721/read/getNFTs.ts +8 -2
  98. package/src/insight/get-tokens.ts +13 -11
  99. package/src/pay/convert/cryptoToFiat.test.ts +1 -18
  100. package/src/pay/convert/cryptoToFiat.ts +6 -52
  101. package/src/pay/convert/fiatToCrypto.test.ts +1 -18
  102. package/src/pay/convert/fiatToCrypto.ts +6 -51
  103. package/src/pay/convert/get-token.ts +24 -0
  104. package/src/react/core/hooks/transaction/useSendTransaction.ts +1 -1
  105. package/src/react/core/utils/wallet.ts +1 -49
  106. package/src/react/native/ui/connect/ConnectedModal.tsx +5 -5
  107. package/src/react/web/ui/ConnectWallet/Details.tsx +7 -7
  108. package/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx +1 -1
  109. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.tsx +32 -8
  110. package/src/react/web/ui/TransactionButton/DepositScreen.tsx +1 -1
  111. package/src/version.ts +1 -1
  112. package/src/wallets/manager/index.ts +1 -2
  113. package/src/wallets/smart/is-smart-wallet.test.ts +163 -1
  114. package/src/wallets/smart/is-smart-wallet.ts +62 -5
  115. package/dist/cjs/react/core/utils/isSmartWallet.js +0 -12
  116. package/dist/cjs/react/core/utils/isSmartWallet.js.map +0 -1
  117. package/dist/cjs/wallets/smart/get-smart-wallet-config.js +0 -23
  118. package/dist/cjs/wallets/smart/get-smart-wallet-config.js.map +0 -1
  119. package/dist/esm/react/core/utils/isSmartWallet.js +0 -9
  120. package/dist/esm/react/core/utils/isSmartWallet.js.map +0 -1
  121. package/dist/esm/wallets/smart/get-smart-wallet-config.js +0 -20
  122. package/dist/esm/wallets/smart/get-smart-wallet-config.js.map +0 -1
  123. package/dist/types/react/core/utils/isSmartWallet.d.ts +0 -3
  124. package/dist/types/react/core/utils/isSmartWallet.d.ts.map +0 -1
  125. package/dist/types/wallets/smart/get-smart-wallet-config.d.ts +0 -13
  126. package/dist/types/wallets/smart/get-smart-wallet-config.d.ts.map +0 -1
  127. package/src/react/core/utils/isSmartWallet.test.ts +0 -19
  128. package/src/react/core/utils/isSmartWallet.ts +0 -12
  129. package/src/react/core/utils/wallet.test.ts +0 -77
  130. package/src/wallets/smart/get-smart-wallet-config.test.ts +0 -67
  131. package/src/wallets/smart/get-smart-wallet-config.ts +0 -24
@@ -30,6 +30,7 @@ import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
30
30
  import { isEcosystemWallet } from "../../../../wallets/ecosystem/is-ecosystem-wallet.js";
31
31
  import type { Ecosystem } from "../../../../wallets/in-app/core/wallet/types.js";
32
32
  import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
33
+ import { isSmartWallet } from "../../../../wallets/smart/is-smart-wallet.js";
33
34
  import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
34
35
  import {
35
36
  type AppMetadata,
@@ -77,7 +78,6 @@ import type {
77
78
  SupportedNFTs,
78
79
  SupportedTokens,
79
80
  } from "../../../core/utils/defaultTokens.js";
80
- import { hasSmartAccount } from "../../../core/utils/isSmartWallet.js";
81
81
  import { useWalletInfo } from "../../../core/utils/wallet.js";
82
82
  import { WalletUIStatesProvider } from "../../providers/wallet-ui-states-provider.js";
83
83
  import { ChainActiveDot } from "../components/ChainActiveDot.js";
@@ -1186,14 +1186,14 @@ export function ConnectedToSmartWallet(props: {
1186
1186
  }) {
1187
1187
  const activeAccount = useActiveAccount();
1188
1188
  const activeWallet = useActiveWallet();
1189
- const isSmartWallet = hasSmartAccount(activeWallet);
1189
+ const isSW = isSmartWallet(activeWallet);
1190
1190
  const chain = useActiveWalletChain();
1191
1191
  const { client, connectLocale: locale } = props;
1192
1192
 
1193
1193
  const [isSmartWalletDeployed, setIsSmartWalletDeployed] = useState(false);
1194
1194
 
1195
1195
  useEffect(() => {
1196
- if (activeAccount && isSmartWallet && activeAccount.address && chain) {
1196
+ if (activeAccount && isSW && activeAccount.address && chain) {
1197
1197
  const contract = getContract({
1198
1198
  address: activeAccount.address,
1199
1199
  chain,
@@ -1206,7 +1206,7 @@ export function ConnectedToSmartWallet(props: {
1206
1206
  } else {
1207
1207
  setIsSmartWalletDeployed(false);
1208
1208
  }
1209
- }, [activeAccount, chain, client, isSmartWallet]);
1209
+ }, [activeAccount, chain, client, isSW]);
1210
1210
 
1211
1211
  const content = (
1212
1212
  <Container flex="row" gap="3xs" center="y">
@@ -1216,7 +1216,7 @@ export function ConnectedToSmartWallet(props: {
1216
1216
  </Container>
1217
1217
  );
1218
1218
 
1219
- if (chain && activeAccount && isSmartWallet) {
1219
+ if (chain && activeAccount && isSW) {
1220
1220
  return (
1221
1221
  <>
1222
1222
  {isSmartWalletDeployed ? (
@@ -1251,7 +1251,7 @@ export function InAppWalletUserInfo(props: {
1251
1251
  const activeWallet = useActiveWallet();
1252
1252
  const adminWallet = useAdminWallet();
1253
1253
  const { data: walletInfo } = useWalletInfo(activeWallet?.id);
1254
- const isSmartWallet = hasSmartAccount(activeWallet);
1254
+ const isSW = isSmartWallet(activeWallet);
1255
1255
  const { data: walletName } = useQuery({
1256
1256
  queryKey: [
1257
1257
  "wallet-name",
@@ -1317,7 +1317,7 @@ export function InAppWalletUserInfo(props: {
1317
1317
  enabled: !!adminWallet,
1318
1318
  });
1319
1319
 
1320
- if (!userInfoQuery.data && isSmartWallet) {
1320
+ if (!userInfoQuery.data && isSW) {
1321
1321
  return <ConnectedToSmartWallet client={client} connectLocale={locale} />;
1322
1322
  }
1323
1323
 
@@ -5,6 +5,7 @@ import { NATIVE_TOKEN_ADDRESS } from "../../../../../../constants/addresses.js";
5
5
  import { formatNumber } from "../../../../../../utils/formatNumber.js";
6
6
  import { toTokens } from "../../../../../../utils/units.js";
7
7
  import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
8
+ import { hasSponsoredTransactionsEnabled } from "../../../../../../wallets/smart/is-smart-wallet.js";
8
9
  import { useCustomTheme } from "../../../../../core/design-system/CustomThemeProvider.js";
9
10
  import {
10
11
  fontSize,
@@ -16,7 +17,6 @@ import { useChainMetadata } from "../../../../../core/hooks/others/useChainQuery
16
17
  import { useWalletBalance } from "../../../../../core/hooks/others/useWalletBalance.js";
17
18
  import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
18
19
  import { useActiveWallet } from "../../../../../core/hooks/wallets/useActiveWallet.js";
19
- import { hasSponsoredTransactionsEnabled } from "../../../../../core/utils/wallet.js";
20
20
  import { ErrorState } from "../../../../wallets/shared/ErrorState.js";
21
21
  import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js";
22
22
  import type { PayEmbedConnectOptions } from "../../../PayEmbed.js";
@@ -141,17 +141,37 @@ async function fetchBalancesForWallet({
141
141
  const insightChunks = chunkChains(insightEnabledChains);
142
142
  await Promise.all(
143
143
  insightChunks.map(async (chunk) => {
144
- const owned = await getOwnedTokens({
145
- ownerAddress: account.address,
146
- chains: chunk,
147
- client,
148
- });
144
+ let owned: GetWalletBalanceResult[] = [];
145
+ let page = 0;
146
+ const limit = 100;
147
+
148
+ while (true) {
149
+ const batch = await getOwnedTokens({
150
+ ownerAddress: account.address,
151
+ chains: chunk,
152
+ client,
153
+ queryOptions: {
154
+ limit,
155
+ page,
156
+ },
157
+ }).catch((err) => {
158
+ console.error("error fetching balances from insight", err);
159
+ return [];
160
+ });
161
+
162
+ if (batch.length === 0) {
163
+ break;
164
+ }
165
+
166
+ owned = [...owned, ...batch];
167
+ page += 1;
168
+ }
149
169
 
150
170
  for (const b of owned) {
151
171
  const matching = sourceSupportedTokens[b.chainId]?.find(
152
172
  (t) => t.address.toLowerCase() === b.tokenAddress.toLowerCase(),
153
173
  );
154
- if (matching) {
174
+ if (matching && b.value > 0n) {
155
175
  balances.push({
156
176
  balance: b,
157
177
  chain: getCachedChain(b.chainId),
@@ -187,6 +207,10 @@ async function fetchBalancesForWallet({
187
207
  const chainId = Number(chainIdStr);
188
208
  const chain = getCachedChain(chainId);
189
209
 
210
+ if (insightEnabledChains.some((c) => c.id === chainId)) {
211
+ continue;
212
+ }
213
+
190
214
  for (const token of tokens) {
191
215
  const isNative = isNativeToken(token);
192
216
  const isAlreadyFetched = balances.some(
@@ -194,7 +218,7 @@ async function fetchBalancesForWallet({
194
218
  b.chain.id === chainId &&
195
219
  b.token.address.toLowerCase() === token.address.toLowerCase(),
196
220
  );
197
- if (isAlreadyFetched && !isNative) {
221
+ if (isAlreadyFetched) {
198
222
  // ERC20 on insight-enabled chain already handled by insight call
199
223
  continue;
200
224
  }
@@ -222,7 +246,7 @@ async function fetchBalancesForWallet({
222
246
  }
223
247
  } catch (err) {
224
248
  console.warn(
225
- `Failed to fetch balance for ${token.symbol} on chain ${chainId}`,
249
+ `Failed to fetch RPC balance for ${token.symbol} on chain ${chainId}`,
226
250
  err,
227
251
  );
228
252
  }
@@ -4,6 +4,7 @@ import type { PreparedTransaction } from "../../../../transaction/prepare-transa
4
4
  import { shortenAddress } from "../../../../utils/address.js";
5
5
  import { formatNumber } from "../../../../utils/formatNumber.js";
6
6
  import { toTokens } from "../../../../utils/units.js";
7
+ import { hasSponsoredTransactionsEnabled } from "../../../../wallets/smart/is-smart-wallet.js";
7
8
  import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
8
9
  import {
9
10
  fontSize,
@@ -13,7 +14,6 @@ import {
13
14
  } from "../../../core/design-system/index.js";
14
15
  import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
15
16
  import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js";
16
- import { hasSponsoredTransactionsEnabled } from "../../../core/utils/wallet.js";
17
17
  import { ErrorState } from "../../wallets/shared/ErrorState.js";
18
18
  import { LoadingScreen } from "../../wallets/shared/LoadingScreen.js";
19
19
  import { CoinsIcon } from "../ConnectWallet/icons/CoinsIcon.js";
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.102.3-nightly-f44d6ba2827d7d7391425a5ddb2d49cafdc934bb-20250531000435";
1
+ export const version = "5.102.4-nightly-283dc289fca1ad16a9296e610d293b73a7123709-20250602000433";
@@ -1,7 +1,6 @@
1
1
  import type { Chain } from "../../chains/types.js";
2
2
  import { cacheChains } from "../../chains/utils.js";
3
3
  import type { ThirdwebClient } from "../../client/client.js";
4
- import { hasSmartAccount } from "../../react/core/utils/isSmartWallet.js";
5
4
  import { computedStore } from "../../reactive/computedStore.js";
6
5
  import { effect } from "../../reactive/effect.js";
7
6
  import { createStore } from "../../reactive/store.js";
@@ -135,7 +134,7 @@ export function createConnectionManager(storage: AsyncStorage) {
135
134
  }
136
135
 
137
136
  const activeWallet = await (async () => {
138
- if (options?.accountAbstraction && !hasSmartAccount(wallet)) {
137
+ if (options?.accountAbstraction && !isSmartWallet(wallet)) {
139
138
  return await handleSmartWalletConnection(
140
139
  wallet,
141
140
  options.client,
@@ -1,6 +1,9 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import type { Wallet } from "../interfaces/wallet.js";
3
- import { isSmartWallet } from "./is-smart-wallet.js";
3
+ import {
4
+ hasSponsoredTransactionsEnabled,
5
+ isSmartWallet,
6
+ } from "./is-smart-wallet.js";
4
7
 
5
8
  describe("isSmartWallet", () => {
6
9
  it("should return true for smart wallet ID", () => {
@@ -22,6 +25,34 @@ describe("isSmartWallet", () => {
22
25
  expect(isSmartWallet(wallet)).toBe(true);
23
26
  });
24
27
 
28
+ it("should return true for wallet with EIP7702 config", () => {
29
+ const wallet = {
30
+ id: "inApp",
31
+ getConfig: () => ({
32
+ executionMode: {
33
+ mode: "EIP7702",
34
+ },
35
+ }),
36
+ } as Wallet;
37
+ expect(isSmartWallet(wallet)).toBe(true);
38
+ });
39
+
40
+ it("should return true for wallet with EIP4337 config", () => {
41
+ const wallet = {
42
+ id: "inApp",
43
+ getConfig: () => ({
44
+ executionMode: {
45
+ mode: "EIP4337",
46
+ smartAccount: {
47
+ chain: { id: 1, name: "test", rpc: "test" },
48
+ sponsorGas: true,
49
+ },
50
+ },
51
+ }),
52
+ } as Wallet;
53
+ expect(isSmartWallet(wallet)).toBe(true);
54
+ });
55
+
25
56
  it("should return false for non-smart wallet", () => {
26
57
  const wallet = {
27
58
  id: "inApp",
@@ -56,3 +87,134 @@ describe("isSmartWallet", () => {
56
87
  expect(isSmartWallet(wallet)).toBe(false);
57
88
  });
58
89
  });
90
+
91
+ describe("hasSponsoredTransactionsEnabled", () => {
92
+ it("should return false for undefined wallet", () => {
93
+ expect(hasSponsoredTransactionsEnabled(undefined)).toBe(false);
94
+ });
95
+
96
+ it("should handle smart wallet with sponsorGas config", () => {
97
+ const mockSmartWallet = {
98
+ id: "smart",
99
+ getConfig: () => ({ sponsorGas: true }),
100
+ } as Wallet;
101
+ expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true);
102
+
103
+ const mockSmartWalletDisabled = {
104
+ id: "smart",
105
+ getConfig: () => ({ sponsorGas: false }),
106
+ } as Wallet;
107
+ expect(hasSponsoredTransactionsEnabled(mockSmartWalletDisabled)).toBe(
108
+ false,
109
+ );
110
+ });
111
+
112
+ it("should handle smart wallet with gasless config", () => {
113
+ const mockSmartWallet = {
114
+ id: "smart",
115
+ getConfig: () => ({ gasless: true }),
116
+ } as Wallet;
117
+ expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true);
118
+ });
119
+
120
+ it("should handle inApp wallet with smartAccount config", () => {
121
+ const mockInAppWallet = {
122
+ id: "inApp",
123
+ getConfig: () => ({
124
+ smartAccount: {
125
+ sponsorGas: true,
126
+ },
127
+ }),
128
+ } as Wallet;
129
+ expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
130
+
131
+ const mockInAppWalletDisabled = {
132
+ id: "inApp",
133
+ getConfig: () => ({
134
+ smartAccount: {
135
+ sponsorGas: false,
136
+ },
137
+ }),
138
+ } as Wallet;
139
+ expect(hasSponsoredTransactionsEnabled(mockInAppWalletDisabled)).toBe(
140
+ false,
141
+ );
142
+ });
143
+
144
+ it("should handle inApp wallet with EIP7702 config", () => {
145
+ const mockInAppWallet = {
146
+ id: "inApp",
147
+ getConfig: () => ({
148
+ executionMode: {
149
+ mode: "EIP7702",
150
+ sponsorGas: true,
151
+ },
152
+ }),
153
+ } as Wallet;
154
+ expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
155
+
156
+ const mockInAppWalletDisabled = {
157
+ id: "inApp",
158
+ getConfig: () => ({
159
+ executionMode: {
160
+ mode: "EIP7702",
161
+ },
162
+ }),
163
+ } as Wallet;
164
+ expect(hasSponsoredTransactionsEnabled(mockInAppWalletDisabled)).toBe(
165
+ false,
166
+ );
167
+ });
168
+
169
+ it("should handle inApp wallet with EIP4337 config", () => {
170
+ const mockInAppWallet = {
171
+ id: "inApp",
172
+ getConfig: () => ({
173
+ executionMode: {
174
+ mode: "EIP4337",
175
+ smartAccount: {
176
+ chain: { id: 1, name: "test", rpc: "test" },
177
+ sponsorGas: true,
178
+ },
179
+ },
180
+ }),
181
+ } as Wallet;
182
+ expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
183
+
184
+ const mockInAppWalletDisabled = {
185
+ id: "inApp",
186
+ getConfig: () => ({
187
+ executionMode: {
188
+ mode: "EIP4337",
189
+ smartAccount: {
190
+ chain: { id: 1, name: "test", rpc: "test" },
191
+ sponsorGas: false,
192
+ },
193
+ },
194
+ }),
195
+ } as Wallet;
196
+ expect(hasSponsoredTransactionsEnabled(mockInAppWalletDisabled)).toBe(
197
+ false,
198
+ );
199
+ });
200
+
201
+ it("should handle inApp wallet with gasless config", () => {
202
+ const mockInAppWallet = {
203
+ id: "inApp",
204
+ getConfig: () => ({
205
+ smartAccount: {
206
+ gasless: true,
207
+ },
208
+ }),
209
+ } as Wallet;
210
+ expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
211
+ });
212
+
213
+ it("should return false for regular wallet without smart account config", () => {
214
+ const mockRegularWallet = {
215
+ id: "inApp",
216
+ getConfig: () => ({}),
217
+ } as Wallet;
218
+ expect(hasSponsoredTransactionsEnabled(mockRegularWallet)).toBe(false);
219
+ });
220
+ });
@@ -1,3 +1,4 @@
1
+ import { isEcosystemWallet } from "../ecosystem/is-ecosystem-wallet.js";
1
2
  import type { Wallet } from "../interfaces/wallet.js";
2
3
 
3
4
  /**
@@ -7,15 +8,71 @@ import type { Wallet } from "../interfaces/wallet.js";
7
8
  * @returns {boolean} True if the wallet is a smart wallet, false otherwise.
8
9
  * @internal
9
10
  */
10
- export function isSmartWallet(wallet: Wallet): boolean {
11
- if (wallet.id === "smart") {
12
- return true;
11
+ export function isSmartWallet(activeWallet?: Wallet): boolean {
12
+ if (!activeWallet) {
13
+ return false;
13
14
  }
14
15
 
15
- const config = wallet.getConfig();
16
- if (!!config && "smartAccount" in config && !!config.smartAccount) {
16
+ if (activeWallet.id === "smart") {
17
17
  return true;
18
18
  }
19
19
 
20
+ if (activeWallet.id === "inApp" || isEcosystemWallet(activeWallet)) {
21
+ const options = (activeWallet as Wallet<"inApp">).getConfig();
22
+ if (options && "smartAccount" in options && options.smartAccount) {
23
+ return true;
24
+ }
25
+ if (options?.executionMode) {
26
+ const execMode = options.executionMode;
27
+ return execMode.mode === "EIP4337" || execMode.mode === "EIP7702";
28
+ }
29
+ }
20
30
  return false;
21
31
  }
32
+
33
+ /**
34
+ * @internal
35
+ */
36
+ export function hasSponsoredTransactionsEnabled(wallet: Wallet | undefined) {
37
+ if (!wallet) {
38
+ return false;
39
+ }
40
+ let sponsoredTransactionsEnabled = false;
41
+ if (wallet && wallet.id === "smart") {
42
+ const options = (wallet as Wallet<"smart">).getConfig();
43
+ if ("sponsorGas" in options) {
44
+ sponsoredTransactionsEnabled = options.sponsorGas;
45
+ }
46
+ if ("gasless" in options) {
47
+ sponsoredTransactionsEnabled = options.gasless;
48
+ }
49
+ }
50
+ if (wallet && (wallet.id === "inApp" || isEcosystemWallet(wallet))) {
51
+ const options = (wallet as Wallet<"inApp">).getConfig();
52
+ if (options && "smartAccount" in options && options.smartAccount) {
53
+ const smartOptions = options.smartAccount;
54
+ if ("sponsorGas" in smartOptions) {
55
+ sponsoredTransactionsEnabled = smartOptions.sponsorGas;
56
+ }
57
+ if ("gasless" in smartOptions) {
58
+ sponsoredTransactionsEnabled = smartOptions.gasless;
59
+ }
60
+ }
61
+ if (options?.executionMode) {
62
+ const execMode = options.executionMode;
63
+ if (execMode.mode === "EIP4337") {
64
+ const smartOptions = execMode.smartAccount;
65
+ if (smartOptions && "sponsorGas" in smartOptions) {
66
+ sponsoredTransactionsEnabled = smartOptions.sponsorGas;
67
+ }
68
+ if (smartOptions && "gasless" in smartOptions) {
69
+ sponsoredTransactionsEnabled = smartOptions.gasless;
70
+ }
71
+ }
72
+ if (execMode.mode === "EIP7702") {
73
+ sponsoredTransactionsEnabled = execMode.sponsorGas || false;
74
+ }
75
+ }
76
+ }
77
+ return sponsoredTransactionsEnabled;
78
+ }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasSmartAccount = hasSmartAccount;
4
- const is_ecosystem_wallet_js_1 = require("../../../wallets/ecosystem/is-ecosystem-wallet.js");
5
- function hasSmartAccount(activeWallet) {
6
- const config = activeWallet?.getConfig();
7
- return (activeWallet !== undefined &&
8
- (activeWallet.id === "smart" ||
9
- (activeWallet.id === "inApp" && !!config && "smartAccount" in config) ||
10
- ((0, is_ecosystem_wallet_js_1.isEcosystemWallet)(activeWallet) && !!config && "smartAccount" in config)));
11
- }
12
- //# sourceMappingURL=isSmartWallet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isSmartWallet.js","sourceRoot":"","sources":["../../../../../src/react/core/utils/isSmartWallet.ts"],"names":[],"mappings":";;AAGA,0CAQC;AAXD,8FAAsF;AAGtF,SAAgB,eAAe,CAAC,YAAqB;IACnD,MAAM,MAAM,GAAG,YAAY,EAAE,SAAS,EAAE,CAAC;IACzC,OAAO,CACL,YAAY,KAAK,SAAS;QAC1B,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO;YAC1B,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,IAAI,MAAM,CAAC;YACrE,CAAC,IAAA,0CAAiB,EAAC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,IAAI,MAAM,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSmartWallet = getSmartWallet;
4
- /**
5
- * Gets the smart wallet configuration for a given wallet.
6
- *
7
- * @param {Wallet} wallet - The wallet to check.
8
- * @returns {SmartWalletOptions} The smart wallet configuration.
9
- *
10
- * @throws {Error} If the wallet is not a smart wallet.
11
- * @internal
12
- */
13
- function getSmartWallet(wallet) {
14
- if (wallet.id === "smart") {
15
- return wallet.getConfig();
16
- }
17
- const config = wallet.getConfig();
18
- if (!!config && "smartAccount" in config && !!config?.smartAccount) {
19
- return config.smartAccount;
20
- }
21
- throw new Error("Wallet is not a smart wallet");
22
- }
23
- //# sourceMappingURL=get-smart-wallet-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-smart-wallet-config.js","sourceRoot":"","sources":["../../../../src/wallets/smart/get-smart-wallet-config.ts"],"names":[],"mappings":";;AAYA,wCAWC;AApBD;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,IAAI,MAAM,CAAC,EAAE,KAAK,OAAO,EAAE,CAAC;QAC1B,OAAQ,MAA0B,CAAC,SAAS,EAAE,CAAC;IACjD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,IAAI,MAAM,IAAI,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;QACnE,OAAO,MAAM,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAClD,CAAC"}
@@ -1,9 +0,0 @@
1
- import { isEcosystemWallet } from "../../../wallets/ecosystem/is-ecosystem-wallet.js";
2
- export function hasSmartAccount(activeWallet) {
3
- const config = activeWallet?.getConfig();
4
- return (activeWallet !== undefined &&
5
- (activeWallet.id === "smart" ||
6
- (activeWallet.id === "inApp" && !!config && "smartAccount" in config) ||
7
- (isEcosystemWallet(activeWallet) && !!config && "smartAccount" in config)));
8
- }
9
- //# sourceMappingURL=isSmartWallet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isSmartWallet.js","sourceRoot":"","sources":["../../../../../src/react/core/utils/isSmartWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AAGtF,MAAM,UAAU,eAAe,CAAC,YAAqB;IACnD,MAAM,MAAM,GAAG,YAAY,EAAE,SAAS,EAAE,CAAC;IACzC,OAAO,CACL,YAAY,KAAK,SAAS;QAC1B,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO;YAC1B,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,IAAI,MAAM,CAAC;YACrE,CAAC,iBAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,IAAI,MAAM,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Gets the smart wallet configuration for a given wallet.
3
- *
4
- * @param {Wallet} wallet - The wallet to check.
5
- * @returns {SmartWalletOptions} The smart wallet configuration.
6
- *
7
- * @throws {Error} If the wallet is not a smart wallet.
8
- * @internal
9
- */
10
- export function getSmartWallet(wallet) {
11
- if (wallet.id === "smart") {
12
- return wallet.getConfig();
13
- }
14
- const config = wallet.getConfig();
15
- if (!!config && "smartAccount" in config && !!config?.smartAccount) {
16
- return config.smartAccount;
17
- }
18
- throw new Error("Wallet is not a smart wallet");
19
- }
20
- //# sourceMappingURL=get-smart-wallet-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-smart-wallet-config.js","sourceRoot":"","sources":["../../../../src/wallets/smart/get-smart-wallet-config.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,MAAM,CAAC,EAAE,KAAK,OAAO,EAAE,CAAC;QAC1B,OAAQ,MAA0B,CAAC,SAAS,EAAE,CAAC;IACjD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,IAAI,CAAC,CAAC,MAAM,IAAI,cAAc,IAAI,MAAM,IAAI,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;QACnE,OAAO,MAAM,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAClD,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { Wallet } from "../../../wallets/interfaces/wallet.js";
2
- export declare function hasSmartAccount(activeWallet?: Wallet): boolean;
3
- //# sourceMappingURL=isSmartWallet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isSmartWallet.d.ts","sourceRoot":"","sources":["../../../../../src/react/core/utils/isSmartWallet.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAEpE,wBAAgB,eAAe,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAQ9D"}
@@ -1,13 +0,0 @@
1
- import type { Wallet } from "../interfaces/wallet.js";
2
- import type { SmartWalletOptions } from "./types.js";
3
- /**
4
- * Gets the smart wallet configuration for a given wallet.
5
- *
6
- * @param {Wallet} wallet - The wallet to check.
7
- * @returns {SmartWalletOptions} The smart wallet configuration.
8
- *
9
- * @throws {Error} If the wallet is not a smart wallet.
10
- * @internal
11
- */
12
- export declare function getSmartWallet(wallet: Wallet): SmartWalletOptions;
13
- //# sourceMappingURL=get-smart-wallet-config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-smart-wallet-config.d.ts","sourceRoot":"","sources":["../../../../src/wallets/smart/get-smart-wallet-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAWjE"}
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ANVIL_CHAIN } from "~test/chains.js";
3
- import { createWallet } from "../../../wallets/create-wallet.js";
4
- import { hasSmartAccount } from "./isSmartWallet.js";
5
-
6
- describe("isSmartWallet", () => {
7
- it("should work if id is inApp and has smartAccount in wallet config", () => {
8
- const wallet = createWallet("inApp", {
9
- smartAccount: {
10
- chain: ANVIL_CHAIN,
11
- sponsorGas: true,
12
- overrides: {
13
- bundlerUrl: "your-bundler-url",
14
- },
15
- },
16
- });
17
- expect(hasSmartAccount(wallet)).toBe(true);
18
- });
19
- });
@@ -1,12 +0,0 @@
1
- import { isEcosystemWallet } from "../../../wallets/ecosystem/is-ecosystem-wallet.js";
2
- import type { Wallet } from "../../../wallets/interfaces/wallet.js";
3
-
4
- export function hasSmartAccount(activeWallet?: Wallet): boolean {
5
- const config = activeWallet?.getConfig();
6
- return (
7
- activeWallet !== undefined &&
8
- (activeWallet.id === "smart" ||
9
- (activeWallet.id === "inApp" && !!config && "smartAccount" in config) ||
10
- (isEcosystemWallet(activeWallet) && !!config && "smartAccount" in config))
11
- );
12
- }