Skip to content

Commit

Permalink
feat: add onMissingSigner callback to useFrame_unstable hook (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
normanzb authored Jan 28, 2025
1 parent b4aa15d commit 227fd9a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-spies-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frames.js/render": patch
---

feat: add onMissingSigner callback to useFrame_unstable
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev:utils-starter": "FJS_MONOREPO=true turbo dev --filter=template-next-utils-starter... --filter=debugger...",
"lint": "turbo lint --filter=!template-*",
"test:ci": "jest --ci",
"test": "cd ./packages/frames.js && npm run test:watch",
"test": "cd ./packages/frames.js && yarn test:watch",
"check:package-types": "turbo check:package-types",
"check:package-lint": "turbo check:package-lint",
"check:types": "turbo check:types",
Expand Down
2 changes: 2 additions & 0 deletions packages/render/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export type OnSignatureFunc = (
args: OnSignatureArgs
) => Promise<`0x${string}` | null>;

export type OnMissingSignerFunction = () => void;

type OnComposerFormActionFuncArgs = {
form: ComposerActionFormResponse;
cast: ComposerActionState;
Expand Down
3 changes: 3 additions & 0 deletions packages/render/src/unstable-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type {
FrameGETRequest,
FramePOSTRequest,
FrameRequest,
OnMissingSignerFunction,
OnMintArgs,
OnSignatureFunc,
OnTransactionFunc,
Expand Down Expand Up @@ -200,6 +201,8 @@ export type UseFrameOptions<
* Only for frames v2
*/
onLaunchFrameButtonPressed?: LaunchFrameButtonPressFunction;

onMissingSigner?: OnMissingSignerFunction;
} & Partial<
Pick<
UseFetchFrameOptions,
Expand Down
10 changes: 7 additions & 3 deletions packages/render/src/unstable-use-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
import { useFrameState } from "./unstable-use-frame-state";
import { useFetchFrame } from "./unstable-use-fetch-frame";
import { useFreshRef } from "./hooks/use-fresh-ref";
import { tryCallAsync } from "./helpers";
import { tryCall, tryCallAsync } from "./helpers";

function onErrorFallback(e: Error): void {
console.error("@frames.js/render", e);
Expand Down Expand Up @@ -192,6 +192,7 @@ export function useFrame_unstable<
onTransactionProcessingError,
onTransactionProcessingStart,
onTransactionProcessingSuccess,
onMissingSigner,
}: UseFrameOptions<
TExtraDataPending,
TExtraDataDone,
Expand Down Expand Up @@ -249,6 +250,7 @@ export function useFrame_unstable<

const fetchFrameRef = useFreshRef(fetchFrame);
const onErrorRef = useFreshRef(onError);
const onMissingSignerRef = useFreshRef(onMissingSigner);

useEffect(() => {
if (!homeframeUrl) {
Expand Down Expand Up @@ -318,6 +320,7 @@ export function useFrame_unstable<
}

if (!currentState.signerState.hasSigner) {
tryCall(() => onMissingSignerRef.current?.());
await currentState.signerState.onSignerlessFramePress();
return;
}
Expand All @@ -341,7 +344,7 @@ export function useFrame_unstable<
sourceFrame: currentFrame,
});
},
[fetchFrameRef, frameStateRef, onErrorRef]
[fetchFrameRef, frameStateRef, onErrorRef, onMissingSignerRef]
);

const resolveAddressRef = useFreshRef(resolveAddress);
Expand Down Expand Up @@ -370,6 +373,7 @@ export function useFrame_unstable<

// Send post request to get calldata
if (!currentState.signerState.hasSigner) {
tryCall(() => onMissingSignerRef.current?.());
await currentState.signerState.onSignerlessFramePress();
return;
}
Expand Down Expand Up @@ -417,7 +421,7 @@ export function useFrame_unstable<
sourceFrame: currentFrame,
});
},
[frameStateRef, fetchFrameRef, onErrorRef, resolveAddressRef]
[frameStateRef, fetchFrameRef, onErrorRef, onMissingSignerRef, resolveAddressRef]
);

const onLaunchFrameButtonPressRef = useFreshRef(onLaunchFrameButtonPressed);
Expand Down

0 comments on commit 227fd9a

Please sign in to comment.