fix(amber): stop global SasquatchGuide from decrypting the stash on every page
usePersonalContext (consumed by SasquatchGuide, mounted in the app-wide Layout)
eagerly called useStash(), firing the encrypted-stash NIP-44 decrypt on EVERY
page load — one Amber popup per navigation. useStash now accepts { enabled },
and usePersonalContext passes enabled:false so it only reads the stash from
cache (populated when the user actually opens the Stash page). The AI's
getMyStash tool degrades gracefully to cached data. No behaviour change for
silent signers.
Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
parent
b910141699
commit
28cd59916a
2 changed files with 20 additions and 3 deletions
|
|
@ -50,7 +50,13 @@ function dedupeAddressable<T extends { pubkey: string; kind: number; tags: strin
|
|||
export function usePersonalContext() {
|
||||
const { nostr } = useNostr();
|
||||
const { user } = useCurrentUser();
|
||||
const { stash } = useStash();
|
||||
// IMPORTANT: pass enabled:false. This hook is consumed by the Sasquatch guide,
|
||||
// which is mounted in the GLOBAL Layout — so eagerly running useStash() here
|
||||
// fired the encrypted-stash decrypt on EVERY page. With Amber that's a popup
|
||||
// per navigation (the "Amber flashes when I move around" bug). We only read
|
||||
// the stash from cache (populated when the user actually visits the Stash
|
||||
// page); the AI's getMyStash tool degrades gracefully to whatever is cached.
|
||||
const { stash } = useStash({ enabled: false });
|
||||
|
||||
const pubkey = user?.pubkey;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,13 +46,24 @@ const STASH_D_TAG = 'skatespots-stash';
|
|||
* Hook to manage user's private gear stash
|
||||
* Uses NIP-44 encryption to store items privately
|
||||
*/
|
||||
export function useStash() {
|
||||
/**
|
||||
* @param options.enabled When false, the stash is NOT fetched/decrypted. Used
|
||||
* by callers that mount this hook only for its data-access API (e.g. the
|
||||
* global Sasquatch assistant via usePersonalContext) but must NOT trigger a
|
||||
* decrypt — with Amber every decrypt is a popup, and this hook used to fire on
|
||||
* every page because Sasquatch is mounted in the app-wide Layout. Defaults to
|
||||
* true so the actual Stash page still loads normally. When disabled, `stash`
|
||||
* still resolves from any previously-cached decrypt (React Query cache).
|
||||
*/
|
||||
export function useStash(options?: { enabled?: boolean }) {
|
||||
const { nostr } = useNostr();
|
||||
const { user } = useCurrentUser();
|
||||
const { logins } = useNostrLogin();
|
||||
const queryClient = useQueryClient();
|
||||
const { mutateAsync: createEvent } = useNostrPublish();
|
||||
|
||||
const callerEnabled = options?.enabled ?? true;
|
||||
|
||||
// Determine if nip44 is safely available WITHOUT touching any throwing getter.
|
||||
const hasNip44 = useMemo(() => checkNip44(user, logins), [user, logins]);
|
||||
// Amber prompts on the stash decrypt — keep it from re-running on window focus
|
||||
|
|
@ -97,7 +108,7 @@ export function useStash() {
|
|||
return { items: [], updatedAt: 0 };
|
||||
}
|
||||
},
|
||||
enabled: !!user?.pubkey && hasNip44,
|
||||
enabled: callerEnabled && !!user?.pubkey && hasNip44,
|
||||
staleTime: interactive ? Infinity : 60000,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue