diff --git a/server/server.ts b/server/server.ts index df7222b..46c3b91 100644 --- a/server/server.ts +++ b/server/server.ts @@ -1194,6 +1194,33 @@ const requestsLimiter = rateLimit({ })) + app.get('/api/get_matrix_addresses', exceptionHandler(async (req, res) => { + const {page, items} = req.query; + + if (!page || !items) { + return res.status(200).send({ + success: false, + data: "no page or items provided" + }) + } + + const matrixAddressesResponse = await fetch(`${config.matrix_api_url}/get-registered-addresses/?page=${page}&items=${items}`) + .then(res => res.json()) + + const {addresses} = matrixAddressesResponse; + + if (matrixAddressesResponse?.success && addresses) { + return res.status(200).send({ + success: true, + addresses + }) + } else { + return res.status(200).send({ + success: false, + }) + } + })) + io.on('connection', async (socket) => { diff --git a/src/components/UI/Switch/Switch.tsx b/src/components/UI/Switch/Switch.tsx index 9ac12b3..bf443ca 100644 --- a/src/components/UI/Switch/Switch.tsx +++ b/src/components/UI/Switch/Switch.tsx @@ -3,34 +3,32 @@ import styles from "./Switch.module.scss"; import { Dispatch, SetStateAction } from "react"; interface SwitchProps { - firstTitle: string; - secondTitle: string; - isFirstSelected: boolean; - setIsFirstSelected: Dispatch>; + titles: string[]; + selectedTitleIdx: number; + setSelectedTitleIdx: Dispatch>; } export default function Switch({ - firstTitle, - secondTitle, - isFirstSelected, - setIsFirstSelected + titles, + selectedTitleIdx, + setSelectedTitleIdx }: SwitchProps) { - return ( -
+ return ( +
+ {titles.map((title, idx) => { + + return ( - -
- ) + className={`${styles["switch__item"]} ${(idx === selectedTitleIdx) && styles["switch__item_selected"] }`} + onClick={() => setSelectedTitleIdx(idx)} + > +

{title}

+ + ) + + })} +
+ ) } \ No newline at end of file diff --git a/src/components/default/Table/Table.tsx b/src/components/default/Table/Table.tsx index 312d584..4fa33dc 100644 --- a/src/components/default/Table/Table.tsx +++ b/src/components/default/Table/Table.tsx @@ -68,57 +68,59 @@ function Table(props: TableProps) { - {pagination && -
-
-

Pages:

-
- - -
- onNumberInput(e, setPage)} - /> -
- {pagesTotal &&

Pages total: {pagesTotal}

} -
-
-

Items on page:

- onNumberInput(e, setItemsOnPage, 50)} - /> -
- {!hidePaginationBlock && -
-

Go to block:

- onNumberInput(e, setGoToBlock)} - onEnterPress={goToBlockEnter} - /> -
- } -
-
- } - + ) + + function Pagination ({pagination}:{pagination:boolean | undefined}) { + if (!pagination) return null + return
+
+

Pages:

+
+ + +
+ onNumberInput(e, setPage)} + /> +
+ {pagesTotal &&

Pages total: {pagesTotal}

} +
+
+

Items on page:

+ onNumberInput(e, setItemsOnPage, 50)} + /> +
+ {!hidePaginationBlock && +
+

Go to block:

+ onNumberInput(e, setGoToBlock)} + onEnterPress={goToBlockEnter} + /> +
+ } +
+
+ } } export default Table; \ No newline at end of file diff --git a/src/pages/aliases/index.tsx b/src/pages/aliases/index.tsx index 293e647..60d134c 100644 --- a/src/pages/aliases/index.tsx +++ b/src/pages/aliases/index.tsx @@ -30,7 +30,11 @@ function Aliases(props: AliasesPageProps) { aliasesAmount: props.aliasesAmount, premiumAliasesAmount: props.premiumAliasesAmount }); - const [isPremiumOnly, setIsPremiumOnly] = useState(false); + const [selectedTitleIdx, setSelectedTitleIdx] = useState(0); + + const isPremiumOnly = selectedTitleIdx === 0; + + const isInMatrix = selectedTitleIdx === 2; const fetchIdRef = useRef(nanoid()); @@ -54,6 +58,7 @@ function Aliases(props: AliasesPageProps) { if (result.sucess === false) return; if (!(result instanceof Array)) return; + if (isInMatrix) return; setAliases( result.map((e: any) => ({ alias: e.alias || "", @@ -61,12 +66,27 @@ function Aliases(props: AliasesPageProps) { hasMatrixConnection: e.hasMatrixConnection || false })) ); - }, [itemsOnPage, page, searchState, isPremiumOnly]); + }, [itemsOnPage, page, searchState, isPremiumOnly, isInMatrix]); + + const fetchMatrixAliases = useCallback(async () => { + const result = await Fetch.getMatrixAddresses(page, itemsOnPage); + if(!result.success || !(result.addresses instanceof Array)) return; + const aliases = result.addresses.map((e :any)=>{ + return {...e, hasMatrixConnection: true} + }) + setAliases(aliases); + },[itemsOnPage, page]) useEffect(() => { setPage("1"); }, [isPremiumOnly, searchState]); + useEffect(() => { + if (isInMatrix) { + fetchMatrixAliases(); + } + }, [isInMatrix, fetchMatrixAliases]) + useEffect(() => { fetchAliases(); @@ -104,23 +124,25 @@ function Aliases(props: AliasesPageProps) { - {hasMatrixConnection && } + {hasMatrixConnection && } :
<> {alias} - {hasMatrixConnection && } + {hasMatrixConnection && }
); } - function ConnectionIcon(){ + function ConnectionIcon({alias}:{alias: string}){ const [hovered, setHovered] = useState(false); + const link = `https://matrix.to/#/@${alias}:zano.org` return ( +
setHovered(true)} onMouseLeave={ ()=> setHovered(false)} > <> @@ -132,6 +154,7 @@ function Aliases(props: AliasesPageProps) {
} +
) } @@ -164,10 +187,9 @@ function Aliases(props: AliasesPageProps) { }} content={ } /> diff --git a/src/pages/assets/index.tsx b/src/pages/assets/index.tsx index d3800db..760b4ab 100644 --- a/src/pages/assets/index.tsx +++ b/src/pages/assets/index.tsx @@ -60,6 +60,8 @@ function Assets(props: AssetsPageProps) { const searchParams = useSearchParams(); const router = useRouter(); + const [selectedTitleIdx, setSelectedTitleIdx] = useState(0); + const [burgerOpened, setBurgerOpened] = useState(false); const [assets, setAssets] = useState(props.assets); @@ -72,7 +74,7 @@ function Assets(props: AssetsPageProps) { const [itemsOnPage, setItemsOnPage] = useState(DEFAULT_ASSETS_ON_PAGE); const [page, setPage] = useState("1"); - const [isWhitelist, setIsWhitelist] = useState(true); + const isWhitelist = selectedTitleIdx === 0; const [inputState, setInputState] = useState(""); const [initFetched, setInitFetched] = useState(false); @@ -250,10 +252,9 @@ function Assets(props: AssetsPageProps) { }} content={ } /> diff --git a/src/styles/Aliases.module.scss b/src/styles/Aliases.module.scss index 1d55a69..c7c392a 100644 --- a/src/styles/Aliases.module.scss +++ b/src/styles/Aliases.module.scss @@ -20,7 +20,7 @@ .connection_icon__tooltip__arrow { z-index: 1; position: absolute; - top:0px; + top: 0px; transform: rotate(45deg) translateY(-5px); height: 10px; width: 10px; diff --git a/src/utils/methods.ts b/src/utils/methods.ts index 7b176cb..88f2387 100644 --- a/src/utils/methods.ts +++ b/src/utils/methods.ts @@ -111,6 +111,10 @@ class Fetch { { assetsIds }, ).then(res => res.json()); } + + static async getMatrixAddresses(page: string, items:string){ + return await fetch(this.proxyPath + `/get_matrix_addresses/?page=${page}&items=${items}`,).then((res) => res.json()); + } } export default Fetch; \ No newline at end of file