From a0a37b72964b07f5f7ed8af45151e0c74d30357b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 13 Feb 2024 20:22:56 -0600 Subject: [PATCH] Make accountLookup work with Nostr --- package.json | 2 +- src/api/hooks/accounts/useAccountLookup.ts | 2 +- .../modals/nostr-signin-modal/nostr-signin-modal.tsx | 2 +- .../modals/nostr-signin-modal/steps/account-step.tsx | 8 ++++++-- .../modals/nostr-signin-modal/steps/identity-step.tsx | 2 +- src/schemas/account.ts | 4 ++++ yarn.lock | 2 +- 7 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f86f62c0a..6c6ec2d82 100644 --- a/package.json +++ b/package.json @@ -185,7 +185,7 @@ "vite-plugin-require": "^1.1.10", "vite-plugin-static-copy": "^1.0.0", "wicg-inert": "^3.1.1", - "zod": "^3.21.4" + "zod": "^3.22.4" }, "devDependencies": { "@formatjs/cli": "^6.2.0", diff --git a/src/api/hooks/accounts/useAccountLookup.ts b/src/api/hooks/accounts/useAccountLookup.ts index 7aed05f98..0e88435b6 100644 --- a/src/api/hooks/accounts/useAccountLookup.ts +++ b/src/api/hooks/accounts/useAccountLookup.ts @@ -22,7 +22,7 @@ function useAccountLookup(acct: string | undefined, opts: UseAccountLookupOpts = const { entity: account, isUnauthorized, ...result } = useEntityLookup( Entities.ACCOUNTS, - (account) => account.acct.toLowerCase() === acct?.toLowerCase(), + (account) => account.acct.toLowerCase() === acct?.toLowerCase() || account.nostr.npub === acct, () => api.get(`/api/v1/accounts/lookup?acct=${acct}`), { schema: accountSchema, enabled: !!acct }, ); diff --git a/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx b/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx index ce4ffa76e..186d5169e 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/nostr-signin-modal.tsx @@ -31,7 +31,7 @@ const NostrSigninModal: React.FC = ({ onClose }) => { case 2: return ; case 3: - return ; + return ; case 4: return ; } diff --git a/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx b/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx index 5bf641eba..1a01cc77d 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/steps/account-step.tsx @@ -1,14 +1,18 @@ import React from 'react'; +import { useAccountLookup } from 'soapbox/api/hooks'; import Stack from 'soapbox/components/ui/stack/stack'; interface IAccountStep { + username: string; } -const AccountStep: React.FC = () => { +const AccountStep: React.FC = ({ username }) => { + const { account } = useAccountLookup(username); + return ( - account step + {JSON.stringify(account, null, 2)} ); }; diff --git a/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx b/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx index ac7c409a9..853e57dc8 100644 --- a/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx +++ b/src/features/ui/components/modals/nostr-signin-modal/steps/identity-step.tsx @@ -30,7 +30,7 @@ const IdentityStep: React.FC = ({ username, setUsername, setStep - + ); diff --git a/src/schemas/account.ts b/src/schemas/account.ts index b419b13cf..40a5e5537 100644 --- a/src/schemas/account.ts +++ b/src/schemas/account.ts @@ -1,5 +1,6 @@ import escapeTextContentForBrowser from 'escape-html'; import DOMPurify from 'isomorphic-dompurify'; +import { NSchema as n } from 'nspec'; import z from 'zod'; import emojify from 'soapbox/features/emoji'; @@ -50,6 +51,9 @@ const baseAccountSchema = z.object({ z.string(), z.null(), ]).catch(null), + nostr: coerceObject({ + npub: n.bech32().optional().catch(undefined), + }), note: contentSchema, /** Fedibird extra settings. */ other_settings: z.object({ diff --git a/yarn.lock b/yarn.lock index 6a49d2e0a..5a9ae368e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9698,7 +9698,7 @@ yocto-queue@^1.0.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251" integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g== -zod@^3.21.0, zod@^3.21.4: +zod@^3.21.0: version "3.22.3" resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.3.tgz#2fbc96118b174290d94e8896371c95629e87a060" integrity sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug==