- Settings -> Trust section (?section=trust, TrustSettingsCard): a show/hide-marks toggle (useTrustDisplay; Flagged is never hidden) and the active provider + relay (useTrustProvider), linked to /trust. - TrustBadge respects the display preference. - Name AGPL-3.0 on the License page by updating its existing copy (licenseLabel + body) in en/es. - Settings + card i18n keys; /settings?section=trust added to the smoke list. Docs updated.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { useNostr } from '@nostrify/react';
|
|
|
|
import { useCurrentUser } from './useCurrentUser';
|
|
import { onlyVerified } from '@/lib/verifyEvents';
|
|
import {
|
|
HOUSE_TRUST_PROVIDER,
|
|
NIP85_PROVIDER_LIST_KIND,
|
|
NIP85_USER_ASSERTION_KIND,
|
|
parseProviderDesignation,
|
|
resolveProvider,
|
|
type TrustProvider,
|
|
} from '@/lib/nip85';
|
|
|
|
/**
|
|
* The trust provider currently in effect for the viewer: the one named in their
|
|
* own kind-10040 designation, or the house provider when there is no
|
|
* designation. Read-only — publishing a designation is a separate step.
|
|
*/
|
|
export function useTrustProvider() {
|
|
const { nostr } = useNostr();
|
|
const { user } = useCurrentUser();
|
|
const pubkey = user?.pubkey;
|
|
|
|
return useQuery({
|
|
queryKey: ['trust-provider', pubkey],
|
|
enabled: !!pubkey,
|
|
staleTime: 5 * 60 * 1000,
|
|
queryFn: async (c): Promise<TrustProvider> => {
|
|
if (!pubkey) return HOUSE_TRUST_PROVIDER;
|
|
const signal = AbortSignal.any([c.signal, AbortSignal.timeout(8000)]);
|
|
const events = onlyVerified(await nostr.query(
|
|
[{ kinds: [NIP85_PROVIDER_LIST_KIND], authors: [pubkey], limit: 1 }],
|
|
{ signal },
|
|
));
|
|
const designation = parseProviderDesignation(events[0]);
|
|
return resolveProvider(designation, NIP85_USER_ASSERTION_KIND, 'rank', HOUSE_TRUST_PROVIDER);
|
|
},
|
|
});
|
|
}
|