From 5b24faf1f371a2df21f836ad159a2cf1a6e64ec3 Mon Sep 17 00:00:00 2001 From: gregfromstl Date: Tue, 10 Dec 2024 23:56:35 +0000 Subject: [PATCH] [SDK] Fix: Pay not respecting ecosystem AA (#5682) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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}` --- .changeset/lazy-games-cheat.md | 5 ++ .../src/react/core/utils/wallet.test.ts | 77 +++++++++++++++++++ .../thirdweb/src/react/core/utils/wallet.ts | 3 +- 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .changeset/lazy-games-cheat.md create mode 100644 packages/thirdweb/src/react/core/utils/wallet.test.ts diff --git a/.changeset/lazy-games-cheat.md b/.changeset/lazy-games-cheat.md new file mode 100644 index 00000000000..544c3e0ac54 --- /dev/null +++ b/.changeset/lazy-games-cheat.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Fix ecosystem wallet AA detection in Pay modal diff --git a/packages/thirdweb/src/react/core/utils/wallet.test.ts b/packages/thirdweb/src/react/core/utils/wallet.test.ts new file mode 100644 index 00000000000..1afd6022943 --- /dev/null +++ b/packages/thirdweb/src/react/core/utils/wallet.test.ts @@ -0,0 +1,77 @@ +import { describe, expect, it } from "vitest"; +import type { Wallet } from "../../../wallets/interfaces/wallet"; +import { hasSponsoredTransactionsEnabled } from "./wallet"; + +describe("hasSponsoredTransactionsEnabled", () => { + it("should return false for undefined wallet", () => { + expect(hasSponsoredTransactionsEnabled(undefined)).toBe(false); + }); + + it("should handle smart wallet with sponsorGas config", () => { + const mockSmartWallet = { + id: "smart", + getConfig: () => ({ sponsorGas: true }), + } as Wallet; + expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true); + + const mockSmartWalletDisabled = { + id: "smart", + getConfig: () => ({ sponsorGas: false }), + } as Wallet; + expect(hasSponsoredTransactionsEnabled(mockSmartWalletDisabled)).toBe( + false, + ); + }); + + it("should handle smart wallet with gasless config", () => { + const mockSmartWallet = { + id: "smart", + getConfig: () => ({ gasless: true }), + } as Wallet; + expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true); + }); + + it("should handle inApp wallet with smartAccount config", () => { + const mockInAppWallet = { + id: "inApp", + getConfig: () => ({ + smartAccount: { + sponsorGas: true, + }, + }), + } as Wallet; + expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true); + + const mockInAppWalletDisabled = { + id: "inApp", + getConfig: () => ({ + smartAccount: { + sponsorGas: false, + }, + }), + } as Wallet; + expect(hasSponsoredTransactionsEnabled(mockInAppWalletDisabled)).toBe( + false, + ); + }); + + it("should handle inApp wallet with gasless config", () => { + const mockInAppWallet = { + id: "inApp", + getConfig: () => ({ + smartAccount: { + gasless: true, + }, + }), + } as Wallet; + expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true); + }); + + it("should return false for regular wallet without smart account config", () => { + const mockRegularWallet = { + id: "inApp", + getConfig: () => ({}), + } as Wallet; + expect(hasSponsoredTransactionsEnabled(mockRegularWallet)).toBe(false); + }); +}); diff --git a/packages/thirdweb/src/react/core/utils/wallet.ts b/packages/thirdweb/src/react/core/utils/wallet.ts index 0c96f7937ca..2689da5ced3 100644 --- a/packages/thirdweb/src/react/core/utils/wallet.ts +++ b/packages/thirdweb/src/react/core/utils/wallet.ts @@ -7,6 +7,7 @@ import { resolveName } from "../../../extensions/ens/resolve-name.js"; import { shortenAddress } from "../../../utils/address.js"; import { parseAvatarRecord } from "../../../utils/ens/avatar.js"; import { getWalletInfo } from "../../../wallets/__generated__/getWalletInfo.js"; +import { isEcosystemWallet } from "../../../wallets/ecosystem/is-ecosystem-wallet.js"; import type { Account, Wallet } from "../../../wallets/interfaces/wallet.js"; import type { WalletInfo } from "../../../wallets/wallet-info.js"; import type { WalletId } from "../../../wallets/wallet-types.js"; @@ -223,7 +224,7 @@ export function hasSponsoredTransactionsEnabled(wallet: Wallet | undefined) { sponsoredTransactionsEnabled = options.gasless; } } - if (wallet && wallet.id === "inApp") { + if (wallet && (wallet.id === "inApp" || isEcosystemWallet(wallet))) { const options = (wallet as Wallet<"inApp">).getConfig(); if (options && "smartAccount" in options && options.smartAccount) { const smartOptions = options.smartAccount;