Skip to content

Commit 5b24faf

Browse files
committed
[SDK] Fix: Pay not respecting ecosystem AA (#5682)
<!-- start pr-codex --> ## PR-Codex overview This PR focuses on enhancing the detection of ecosystem wallets in the `Pay` modal by modifying the logic in the `hasSponsoredTransactionsEnabled` function and adding comprehensive tests for various wallet configurations. ### Detailed summary - Updated the condition in `hasSponsoredTransactionsEnabled` to check for ecosystem wallets. - Added tests for `hasSponsoredTransactionsEnabled` covering: - Undefined wallet - Smart wallet with `sponsorGas` config - Smart wallet with `gasless` config - In-app wallet with `smartAccount` config - Regular wallet without smart account config > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 714602d commit 5b24faf

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

.changeset/lazy-games-cheat.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+
Fix ecosystem wallet AA detection in Pay modal
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { Wallet } from "../../../wallets/interfaces/wallet";
3+
import { hasSponsoredTransactionsEnabled } from "./wallet";
4+
5+
describe("hasSponsoredTransactionsEnabled", () => {
6+
it("should return false for undefined wallet", () => {
7+
expect(hasSponsoredTransactionsEnabled(undefined)).toBe(false);
8+
});
9+
10+
it("should handle smart wallet with sponsorGas config", () => {
11+
const mockSmartWallet = {
12+
id: "smart",
13+
getConfig: () => ({ sponsorGas: true }),
14+
} as Wallet;
15+
expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true);
16+
17+
const mockSmartWalletDisabled = {
18+
id: "smart",
19+
getConfig: () => ({ sponsorGas: false }),
20+
} as Wallet;
21+
expect(hasSponsoredTransactionsEnabled(mockSmartWalletDisabled)).toBe(
22+
false,
23+
);
24+
});
25+
26+
it("should handle smart wallet with gasless config", () => {
27+
const mockSmartWallet = {
28+
id: "smart",
29+
getConfig: () => ({ gasless: true }),
30+
} as Wallet;
31+
expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true);
32+
});
33+
34+
it("should handle inApp wallet with smartAccount config", () => {
35+
const mockInAppWallet = {
36+
id: "inApp",
37+
getConfig: () => ({
38+
smartAccount: {
39+
sponsorGas: true,
40+
},
41+
}),
42+
} as Wallet;
43+
expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
44+
45+
const mockInAppWalletDisabled = {
46+
id: "inApp",
47+
getConfig: () => ({
48+
smartAccount: {
49+
sponsorGas: false,
50+
},
51+
}),
52+
} as Wallet;
53+
expect(hasSponsoredTransactionsEnabled(mockInAppWalletDisabled)).toBe(
54+
false,
55+
);
56+
});
57+
58+
it("should handle inApp wallet with gasless config", () => {
59+
const mockInAppWallet = {
60+
id: "inApp",
61+
getConfig: () => ({
62+
smartAccount: {
63+
gasless: true,
64+
},
65+
}),
66+
} as Wallet;
67+
expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
68+
});
69+
70+
it("should return false for regular wallet without smart account config", () => {
71+
const mockRegularWallet = {
72+
id: "inApp",
73+
getConfig: () => ({}),
74+
} as Wallet;
75+
expect(hasSponsoredTransactionsEnabled(mockRegularWallet)).toBe(false);
76+
});
77+
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +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";
1011
import type { Account, Wallet } from "../../../wallets/interfaces/wallet.js";
1112
import type { WalletInfo } from "../../../wallets/wallet-info.js";
1213
import type { WalletId } from "../../../wallets/wallet-types.js";
@@ -223,7 +224,7 @@ export function hasSponsoredTransactionsEnabled(wallet: Wallet | undefined) {
223224
sponsoredTransactionsEnabled = options.gasless;
224225
}
225226
}
226-
if (wallet && wallet.id === "inApp") {
227+
if (wallet && (wallet.id === "inApp" || isEcosystemWallet(wallet))) {
227228
const options = (wallet as Wallet<"inApp">).getConfig();
228229
if (options && "smartAccount" in options && options.smartAccount) {
229230
const smartOptions = options.smartAccount;

0 commit comments

Comments
 (0)