Skip to content

Commit

Permalink
🥅 server: handle panda check for undeployed accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Jan 31, 2025
1 parent 538107a commit 68d034f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-brooms-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/server": patch
---

🥅 handle panda check for undeployed accounts
17 changes: 13 additions & 4 deletions server/utils/panda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
pipe,
string,
} from "valibot";
import { BaseError, ContractFunctionZeroDataError } from "viem";

import { upgradeableModularAccountAbi } from "../generated/contracts";
import publicClient from "../utils/publicClient";
Expand Down Expand Up @@ -153,10 +154,18 @@ const CardResponse = object({
expirationYear: pipe(string(), length(4)),
});

export async function isPanda(account: Address): Promise<boolean> {
return await publicClient
.readContract({ address: account, functionName: "getInstalledPlugins", abi: upgradeableModularAccountAbi })
.then((ps) => ps.map((p) => parse(Hex, p.toLowerCase())).some((addr) => plugins.has(addr)));
export async function isPanda(account: Address) {
try {
const installedPlugins = await publicClient.readContract({
address: account,
functionName: "getInstalledPlugins",
abi: upgradeableModularAccountAbi,
});
return installedPlugins.some((addr) => plugins.has(addr.toLowerCase() as Hex));
} catch (error) {
if (error instanceof BaseError && error.cause instanceof ContractFunctionZeroDataError) return true;
throw error;
}
}

export function headerValidator() {
Expand Down

0 comments on commit 68d034f

Please sign in to comment.