Skip to content

Commit 8eb45b7

Browse files
Handle smart account detection for inApp and ecosystem wallets
1 parent 4e93539 commit 8eb45b7

File tree

15 files changed

+247
-271
lines changed

15 files changed

+247
-271
lines changed

.changeset/two-bugs-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Handle smart account detection for inApp and ecosystem wallets

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import { getTransactionGasCost } from "../../../../transaction/utils.js";
1313
import type { Hex } from "../../../../utils/encoding/hex.js";
1414
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
1515
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
16+
import { hasSponsoredTransactionsEnabled } from "../../../../wallets/smart/is-smart-wallet.js";
1617
import { getTokenBalance } from "../../../../wallets/utils/getTokenBalance.js";
1718
import { getWalletBalance } from "../../../../wallets/utils/getWalletBalance.js";
1819
import type { LocaleId } from "../../../web/ui/types.js";
1920
import type { Theme } from "../../design-system/index.js";
2021
import type { SupportedTokens } from "../../utils/defaultTokens.js";
21-
import { hasSponsoredTransactionsEnabled } from "../../utils/wallet.js";
2222

2323
/**
2424
* Configuration for the "Pay Modal" that opens when the user doesn't have enough funds to send a transaction.

packages/thirdweb/src/react/core/utils/isSmartWallet.test.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/thirdweb/src/react/core/utils/isSmartWallet.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/thirdweb/src/react/core/utils/wallet.test.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

packages/thirdweb/src/react/core/utils/wallet.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { resolveName } from "../../../extensions/ens/resolve-name.js";
77
import { shortenAddress } from "../../../utils/address.js";
88
import { parseAvatarRecord } from "../../../utils/ens/avatar.js";
99
import { getWalletInfo } from "../../../wallets/__generated__/getWalletInfo.js";
10-
import { isEcosystemWallet } from "../../../wallets/ecosystem/is-ecosystem-wallet.js";
11-
import type { Account, Wallet } from "../../../wallets/interfaces/wallet.js";
10+
import type { Account } from "../../../wallets/interfaces/wallet.js";
1211
import type { WalletInfo } from "../../../wallets/wallet-info.js";
1312
import type { WalletId } from "../../../wallets/wallet-types.js";
1413
import { useWalletBalance } from "../hooks/others/useWalletBalance.js";
@@ -215,50 +214,3 @@ export function useWalletImage(id: WalletId | undefined) {
215214
enabled: !!id,
216215
});
217216
}
218-
219-
/**
220-
* @internal
221-
*/
222-
export function hasSponsoredTransactionsEnabled(wallet: Wallet | undefined) {
223-
if (!wallet) {
224-
return false;
225-
}
226-
let sponsoredTransactionsEnabled = false;
227-
if (wallet && wallet.id === "smart") {
228-
const options = (wallet as Wallet<"smart">).getConfig();
229-
if ("sponsorGas" in options) {
230-
sponsoredTransactionsEnabled = options.sponsorGas;
231-
}
232-
if ("gasless" in options) {
233-
sponsoredTransactionsEnabled = options.gasless;
234-
}
235-
}
236-
if (wallet && (wallet.id === "inApp" || isEcosystemWallet(wallet))) {
237-
const options = (wallet as Wallet<"inApp">).getConfig();
238-
if (options && "smartAccount" in options && options.smartAccount) {
239-
const smartOptions = options.smartAccount;
240-
if ("sponsorGas" in smartOptions) {
241-
sponsoredTransactionsEnabled = smartOptions.sponsorGas;
242-
}
243-
if ("gasless" in smartOptions) {
244-
sponsoredTransactionsEnabled = smartOptions.gasless;
245-
}
246-
}
247-
if (options?.executionMode) {
248-
const execMode = options.executionMode;
249-
if (execMode.mode === "EIP4337") {
250-
const smartOptions = execMode.smartAccount;
251-
if (smartOptions && "sponsorGas" in smartOptions) {
252-
sponsoredTransactionsEnabled = smartOptions.sponsorGas;
253-
}
254-
if (smartOptions && "gasless" in smartOptions) {
255-
sponsoredTransactionsEnabled = smartOptions.gasless;
256-
}
257-
}
258-
if (execMode.mode === "EIP7702") {
259-
sponsoredTransactionsEnabled = execMode.sponsorGas || false;
260-
}
261-
}
262-
}
263-
return sponsoredTransactionsEnabled;
264-
}

packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getContract } from "../../../../contract/contract.js";
55
import { isContractDeployed } from "../../../../utils/bytecode/is-contract-deployed.js";
66
import { formatNumber } from "../../../../utils/formatNumber.js";
77
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
8+
import { isSmartWallet } from "../../../../wallets/smart/is-smart-wallet.js";
89
import type { Theme } from "../../../core/design-system/index.js";
910
import { useSiweAuth } from "../../../core/hooks/auth/useSiweAuth.js";
1011
import type { ConnectButtonProps } from "../../../core/hooks/connection/ConnectButtonProps.js";
@@ -13,7 +14,6 @@ import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.j
1314
import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js";
1415
import { useActiveWalletChain } from "../../../core/hooks/wallets/useActiveWalletChain.js";
1516
import { useDisconnect } from "../../../core/hooks/wallets/useDisconnect.js";
16-
import { hasSmartAccount } from "../../../core/utils/isSmartWallet.js";
1717
import { useConnectedWalletDetails } from "../../../core/utils/wallet.js";
1818
import { fontSize, radius, spacing } from "../../design-system/index.js";
1919
import { Address } from "../components/Address.js";
@@ -326,14 +326,14 @@ function SmartAccountBadge(props: {
326326
}) {
327327
const activeAccount = useActiveAccount();
328328
const activeWallet = useActiveWallet();
329-
const isSmartWallet = hasSmartAccount(activeWallet);
329+
const isSW = isSmartWallet(activeWallet);
330330
const chain = useActiveWalletChain();
331331
const { client, theme } = props;
332332

333333
const [isSmartWalletDeployed, setIsSmartWalletDeployed] = useState(false);
334334

335335
useEffect(() => {
336-
if (activeAccount && isSmartWallet && activeAccount.address && chain) {
336+
if (activeAccount && isSW && activeAccount.address && chain) {
337337
const contract = getContract({
338338
address: activeAccount.address,
339339
chain,
@@ -346,7 +346,7 @@ function SmartAccountBadge(props: {
346346
} else {
347347
setIsSmartWalletDeployed(false);
348348
}
349-
}, [activeAccount, chain, client, isSmartWallet]);
349+
}, [activeAccount, chain, client, isSW]);
350350

351351
const content = (
352352
<View
@@ -377,7 +377,7 @@ function SmartAccountBadge(props: {
377377
</View>
378378
);
379379

380-
if (chain && activeAccount && isSmartWallet) {
380+
if (chain && activeAccount && isSW) {
381381
return (
382382
<>
383383
<Spacer size="smd" />

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
3030
import { isEcosystemWallet } from "../../../../wallets/ecosystem/is-ecosystem-wallet.js";
3131
import type { Ecosystem } from "../../../../wallets/in-app/core/wallet/types.js";
3232
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
33+
import { isSmartWallet } from "../../../../wallets/smart/is-smart-wallet.js";
3334
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
3435
import {
3536
type AppMetadata,
@@ -77,7 +78,6 @@ import type {
7778
SupportedNFTs,
7879
SupportedTokens,
7980
} from "../../../core/utils/defaultTokens.js";
80-
import { hasSmartAccount } from "../../../core/utils/isSmartWallet.js";
8181
import { useWalletInfo } from "../../../core/utils/wallet.js";
8282
import { WalletUIStatesProvider } from "../../providers/wallet-ui-states-provider.js";
8383
import { ChainActiveDot } from "../components/ChainActiveDot.js";
@@ -1186,14 +1186,14 @@ export function ConnectedToSmartWallet(props: {
11861186
}) {
11871187
const activeAccount = useActiveAccount();
11881188
const activeWallet = useActiveWallet();
1189-
const isSmartWallet = hasSmartAccount(activeWallet);
1189+
const isSW = isSmartWallet(activeWallet);
11901190
const chain = useActiveWalletChain();
11911191
const { client, connectLocale: locale } = props;
11921192

11931193
const [isSmartWalletDeployed, setIsSmartWalletDeployed] = useState(false);
11941194

11951195
useEffect(() => {
1196-
if (activeAccount && isSmartWallet && activeAccount.address && chain) {
1196+
if (activeAccount && isSW && activeAccount.address && chain) {
11971197
const contract = getContract({
11981198
address: activeAccount.address,
11991199
chain,
@@ -1206,7 +1206,7 @@ export function ConnectedToSmartWallet(props: {
12061206
} else {
12071207
setIsSmartWalletDeployed(false);
12081208
}
1209-
}, [activeAccount, chain, client, isSmartWallet]);
1209+
}, [activeAccount, chain, client, isSW]);
12101210

12111211
const content = (
12121212
<Container flex="row" gap="3xs" center="y">
@@ -1216,7 +1216,7 @@ export function ConnectedToSmartWallet(props: {
12161216
</Container>
12171217
);
12181218

1219-
if (chain && activeAccount && isSmartWallet) {
1219+
if (chain && activeAccount && isSW) {
12201220
return (
12211221
<>
12221222
{isSmartWalletDeployed ? (
@@ -1251,7 +1251,7 @@ export function InAppWalletUserInfo(props: {
12511251
const activeWallet = useActiveWallet();
12521252
const adminWallet = useAdminWallet();
12531253
const { data: walletInfo } = useWalletInfo(activeWallet?.id);
1254-
const isSmartWallet = hasSmartAccount(activeWallet);
1254+
const isSW = isSmartWallet(activeWallet);
12551255
const { data: walletName } = useQuery({
12561256
queryKey: [
12571257
"wallet-name",
@@ -1317,7 +1317,7 @@ export function InAppWalletUserInfo(props: {
13171317
enabled: !!adminWallet,
13181318
});
13191319

1320-
if (!userInfoQuery.data && isSmartWallet) {
1320+
if (!userInfoQuery.data && isSW) {
13211321
return <ConnectedToSmartWallet client={client} connectLocale={locale} />;
13221322
}
13231323

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NATIVE_TOKEN_ADDRESS } from "../../../../../../constants/addresses.js";
55
import { formatNumber } from "../../../../../../utils/formatNumber.js";
66
import { toTokens } from "../../../../../../utils/units.js";
77
import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
8+
import { hasSponsoredTransactionsEnabled } from "../../../../../../wallets/smart/is-smart-wallet.js";
89
import { useCustomTheme } from "../../../../../core/design-system/CustomThemeProvider.js";
910
import {
1011
fontSize,
@@ -16,7 +17,6 @@ import { useChainMetadata } from "../../../../../core/hooks/others/useChainQuery
1617
import { useWalletBalance } from "../../../../../core/hooks/others/useWalletBalance.js";
1718
import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
1819
import { useActiveWallet } from "../../../../../core/hooks/wallets/useActiveWallet.js";
19-
import { hasSponsoredTransactionsEnabled } from "../../../../../core/utils/wallet.js";
2020
import { ErrorState } from "../../../../wallets/shared/ErrorState.js";
2121
import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js";
2222
import type { PayEmbedConnectOptions } from "../../../PayEmbed.js";

packages/thirdweb/src/react/web/ui/TransactionButton/DepositScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { PreparedTransaction } from "../../../../transaction/prepare-transa
44
import { shortenAddress } from "../../../../utils/address.js";
55
import { formatNumber } from "../../../../utils/formatNumber.js";
66
import { toTokens } from "../../../../utils/units.js";
7+
import { hasSponsoredTransactionsEnabled } from "../../../../wallets/smart/is-smart-wallet.js";
78
import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
89
import {
910
fontSize,
@@ -13,7 +14,6 @@ import {
1314
} from "../../../core/design-system/index.js";
1415
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
1516
import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js";
16-
import { hasSponsoredTransactionsEnabled } from "../../../core/utils/wallet.js";
1717
import { ErrorState } from "../../wallets/shared/ErrorState.js";
1818
import { LoadingScreen } from "../../wallets/shared/LoadingScreen.js";
1919
import { CoinsIcon } from "../ConnectWallet/icons/CoinsIcon.js";

packages/thirdweb/src/wallets/manager/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Chain } from "../../chains/types.js";
22
import { cacheChains } from "../../chains/utils.js";
33
import type { ThirdwebClient } from "../../client/client.js";
4-
import { hasSmartAccount } from "../../react/core/utils/isSmartWallet.js";
54
import { computedStore } from "../../reactive/computedStore.js";
65
import { effect } from "../../reactive/effect.js";
76
import { createStore } from "../../reactive/store.js";
@@ -135,7 +134,7 @@ export function createConnectionManager(storage: AsyncStorage) {
135134
}
136135

137136
const activeWallet = await (async () => {
138-
if (options?.accountAbstraction && !hasSmartAccount(wallet)) {
137+
if (options?.accountAbstraction && !isSmartWallet(wallet)) {
139138
return await handleSmartWalletConnection(
140139
wallet,
141140
options.client,

0 commit comments

Comments
 (0)