Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-rice-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@phantom/react-sdk": patch
---

make isInstalled a memoized value
2 changes: 1 addition & 1 deletion packages/react-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,4 @@ useAccountEffect({

### useIsInstalled

The `useIsInstalled` hook provides a function to check whether the phantom extension is installed
The `useIsInstalled` hook provides a variable `isInstalled` to check whether the phantom extension is installed
16 changes: 16 additions & 0 deletions packages/react-sdk/src/extension/assertions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Phantom } from "@phantom/browser-sdk";

/**
* Asserts that the Phantom instance has Solana configured and narrows the type.
* After calling this function, TypeScript will know that phantom.solana is defined.
*/
export function assertExtensionConfigured(
phantom: Phantom | undefined,
): asserts phantom is Phantom & { extension: NonNullable<Phantom["extension"]> } {
if (!phantom?.extension) {
throw new Error(
"Phantom extension plugin not found. Please ensure the extension plugin is installed and configured properly.",
);
}
}
bd1d166dff7c53e5d5295aba03b8b3ac37090677
14 changes: 7 additions & 7 deletions packages/react-sdk/src/extension/useIsInstalled.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as React from "react";
import { usePhantom } from "../PhantomContext";
import { assertExtensionConfigured } from "./assertions";

export function useIsInstalled() {
const { phantom } = usePhantom();
const { phantom, isReady } = usePhantom();

const isInstalled = React.useCallback(async () => {
if (!phantom?.extension) {
throw new Error("Phantom extension plugin not found.");
}
const isInstalled = React.useMemo(() => {
if (!isReady) return;
assertExtensionConfigured(phantom);

return await phantom.extension.isInstalled();
}, [phantom]);
return phantom.extension.isInstalled();
}, [phantom, isReady]);

return { isInstalled };
}