From 2b07a9569c252f5cf932700c13f0f8983f4f6541 Mon Sep 17 00:00:00 2001 From: greenflame089 Date: Tue, 5 Aug 2025 01:27:15 -0400 Subject: [PATCH 1/2] Add multiple name support --- src/components/layout/Navbar/Navbar.tsx | 20 +++++++++++++++++ src/state/features/authSlice.ts | 18 ++++++++++----- src/utils/qortalRequestFunctions.ts | 29 +++++++++++++++++++++++++ src/wrappers/GlobalWrapper.tsx | 21 +++++++++++++++--- 4 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 src/utils/qortalRequestFunctions.ts diff --git a/src/components/layout/Navbar/Navbar.tsx b/src/components/layout/Navbar/Navbar.tsx index 6cb3030..bf668c7 100644 --- a/src/components/layout/Navbar/Navbar.tsx +++ b/src/components/layout/Navbar/Navbar.tsx @@ -50,6 +50,8 @@ interface Props { userAvatar: string; authenticate: () => void; setTheme: (val: string) => void; + accountNames: { name: string }[]; + setActiveName: (name: string) => void; } const NavBar: React.FC = ({ @@ -58,6 +60,8 @@ const NavBar: React.FC = ({ userAvatar, authenticate, setTheme, + accountNames, + setActiveName, }) => { const windowSize = useWindowSize(); const searchValRef = useRef(""); @@ -426,6 +430,22 @@ const NavBar: React.FC = ({ horizontal: "left", }} > + {accountNames + .filter(n => n.name) + .map(n => ( + { + setActiveName(n.name); + handleCloseUserDropdown(); + }} + > + + {n.name === userName ? "✔︎ " : ""} + {n.name} + + + ))} { setIsOpenBlockedNamesModal(true); diff --git a/src/state/features/authSlice.ts b/src/state/features/authSlice.ts index 8f5ee20..a3f20e8 100644 --- a/src/state/features/authSlice.ts +++ b/src/state/features/authSlice.ts @@ -1,13 +1,21 @@ import { createSlice } from '@reduxjs/toolkit'; +export interface NameRecord { + name: string + owner: string +} + +interface User { + address: string + publicKey: string + name?: string + names?: NameRecord[] +} interface AuthState { - user: { - address: string; - publicKey: string; - name?: string; - } | null; + user: User | null } + const initialState: AuthState = { user: null }; diff --git a/src/utils/qortalRequestFunctions.ts b/src/utils/qortalRequestFunctions.ts new file mode 100644 index 0000000..d4dc232 --- /dev/null +++ b/src/utils/qortalRequestFunctions.ts @@ -0,0 +1,29 @@ +export interface NameRecord { + name: string; + owner: string; +} + +export async function getAccountNames(address: string): Promise { + try { + const list = await qortalRequest({ + action: 'GET_ACCOUNT_NAMES', + address, + }); + if (Array.isArray(list) && list.length) return list; + return [{ name: '', owner: address }]; + } catch { + return [{ name: '', owner: address }]; + } +} + +export async function getPrimaryAccountName(address: string): Promise { + try { + const res = await qortalRequest({ + action: 'GET_PRIMARY_NAME', + address, + }); + return typeof res === 'string' ? res : ''; + } catch { + return ''; + } +} diff --git a/src/wrappers/GlobalWrapper.tsx b/src/wrappers/GlobalWrapper.tsx index 9cf1e3c..f03c49a 100644 --- a/src/wrappers/GlobalWrapper.tsx +++ b/src/wrappers/GlobalWrapper.tsx @@ -8,6 +8,11 @@ import React, { import { useDispatch, useSelector } from "react-redux"; import { addUser } from "../state/features/authSlice"; +import { + getAccountNames, + getPrimaryAccountName, + NameRecord, +} from "../utils/qortalRequestFunctions"; import NavBar from "../components/layout/Navbar/Navbar"; import PageLoader from "../components/common/PageLoader"; import { RootState } from "../state/store"; @@ -69,10 +74,17 @@ const GlobalWrapper: React.FC = ({ children, setTheme }) => { useEffect(() => { if (!username) return; - getAvatar(username); }, [username, getAvatar]); + const switchActiveName = useCallback( + (newName: string) => { + if (!user) return; + dispatch(addUser({ ...user, name: newName })); + }, + [user, dispatch] + ); + const { isLoadingGlobal } = useSelector((state: RootState) => state.global); async function getNameInfo(address: string) { @@ -95,8 +107,9 @@ const GlobalWrapper: React.FC = ({ children, setTheme }) => { action: "GET_USER_ACCOUNT", }); - const name = await getNameInfo(account.address); - dispatch(addUser({ ...account, name })); + const names = await getAccountNames(account.address); + const primary = await getPrimaryAccountName(account.address); + dispatch(addUser({ ...account, name: primary, names })); } catch (error) { console.error(error); } @@ -136,6 +149,8 @@ const GlobalWrapper: React.FC = ({ children, setTheme }) => { setTheme={(val: string) => setTheme(val)} isAuthenticated={!!user?.name} userName={user?.name || ""} + accountNames={user?.names || []} + setActiveName={switchActiveName} userAvatar={userAvatar} authenticate={askForAccountInformation} /> -- 2.43.0 From 60b7cd8d36fd39df20da5aa27f80d530a50ef815 Mon Sep 17 00:00:00 2001 From: greenflame089 Date: Tue, 5 Aug 2025 01:27:37 -0400 Subject: [PATCH 2/2] Fix individual profile page --- src/pages/Home/FileListComponentLevel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Home/FileListComponentLevel.tsx b/src/pages/Home/FileListComponentLevel.tsx index e32c7c0..73d3c82 100644 --- a/src/pages/Home/FileListComponentLevel.tsx +++ b/src/pages/Home/FileListComponentLevel.tsx @@ -46,7 +46,7 @@ export const FileListComponentLevel = ({ mode }: VideoListProps) => { const getVideos = React.useCallback(async () => { try { const offset = videos.length; - const url = `/arbitrary/resources/search?mode=ALL&service=DOCUMENT&query=${QSHARE_FILE_BASE}_&limit=50&includemetadata=false&reverse=true&excludeblocked=true&name=${paramName}&exactmatchnames=true&offset=${offset}`; + const url = `/arbitrary/resources/search?mode=ALL&service=DOCUMENT&query=${QSHARE_FILE_BASE}&limit=50&includemetadata=false&reverse=true&excludeblocked=true&name=${paramName}&exactmatchnames=true&offset=${offset}`; const response = await fetch(url, { method: "GET", headers: { -- 2.43.0