Skip to content

Commit

Permalink
fix: filter pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
apskhem committed May 16, 2024
1 parent af37b51 commit f4ac101
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion utilities/wallet-tester/src/common/helpers/getCardano.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { pickBy } from "lodash-es";
import type { WalletCollections } from "types/cardano";

export default function getCardano<T extends string | undefined>(
walletName?: T
): T extends string ? WalletCollections[string] : WalletCollections {
return (walletName ? globalThis.cardano[walletName] : globalThis.cardano) as T extends string
return (walletName ? globalThis.cardano[walletName] : filterPolluteObjects(globalThis.cardano)) as T extends string
? WalletCollections[string]
: WalletCollections;
}

function filterPolluteObjects(cardano: any): WalletCollections {
return pickBy(cardano, (v) => typeof v === "object" && "enable" in v)
}

0 comments on commit f4ac101

Please sign in to comment.