add route to matrix get all regs addresses, add links to connection btns, add in matrix section
This commit is contained in:
parent
68ef36c3bd
commit
0476376281
6 changed files with 113 additions and 35 deletions
|
|
@ -1166,7 +1166,58 @@ const requestsLimiter = rateLimit({
|
|||
} else {
|
||||
return res.json({ success: true, asset: dbAsset });
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
app.post('/api/get_assets_price_rates', exceptionHandler(async (req, res) => {
|
||||
const { assetsIds } = req.body;
|
||||
if (!assetsIds) {
|
||||
return res.json({ success: false, data: "Asset id not provided" });
|
||||
}
|
||||
const assetsPricesResponse = await axios({
|
||||
method: 'post',
|
||||
url: config.trade_api_url + '/dex/get-assets-price-rates',
|
||||
data: { assetsIds },
|
||||
});
|
||||
|
||||
const assetsPrices = assetsPricesResponse.data;
|
||||
|
||||
if (assetsPricesResponse?.data?.success) {
|
||||
return res.json({ success: true, priceRates: assetsPrices.priceRates });
|
||||
} else {
|
||||
return res.json({ success: false, data: "Assets not found" })
|
||||
}
|
||||
|
||||
}))
|
||||
|
||||
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) => {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export const config = {
|
|||
},
|
||||
"enableVisibilityInfo": process.env.ENABLE_VISIBILITY_INFO === "true",
|
||||
"maxDaemonRequestCount": parseInt(process.env.MAX_DAEMON_REQUEST_COUNT || "", 10) || 1000,
|
||||
"trade_api_url": process.env.TRADE_API_URL,
|
||||
"matrix_api_url": process.env.MATRIX_API_URL
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<SetStateAction<boolean>>;
|
||||
titles: string[];
|
||||
selectedTitleIdx: number;
|
||||
setSelectedTitleIdx: Dispatch<SetStateAction<number>>;
|
||||
}
|
||||
|
||||
export default function Switch({
|
||||
firstTitle,
|
||||
secondTitle,
|
||||
isFirstSelected,
|
||||
setIsFirstSelected
|
||||
titles,
|
||||
selectedTitleIdx,
|
||||
setSelectedTitleIdx
|
||||
}: SwitchProps) {
|
||||
return (
|
||||
<div className={styles["switch"]}>
|
||||
return (
|
||||
<div className={styles['switch']}>
|
||||
{titles.map((title, idx) => {
|
||||
|
||||
return (
|
||||
<Button
|
||||
key={idx}
|
||||
wrapper
|
||||
className={`${styles["switch__item"]} ${isFirstSelected ? styles["switch__item_selected"] : ""}`}
|
||||
onClick={() => setIsFirstSelected(true)}
|
||||
>
|
||||
<p>{firstTitle}</p>
|
||||
</Button>
|
||||
<Button
|
||||
wrapper
|
||||
className={`${styles["switch__item"]} ${!isFirstSelected ? styles["switch__item_selected"] : ""}`}
|
||||
onClick={() => setIsFirstSelected(false)}
|
||||
>
|
||||
<p>{secondTitle}</p>
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
className={`${styles["switch__item"]} ${(idx === selectedTitleIdx) && styles["switch__item_selected"] }`}
|
||||
onClick={() => setSelectedTitleIdx(idx)}
|
||||
>
|
||||
<p>{title}</p>
|
||||
</Button>
|
||||
)
|
||||
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -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<string>(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 || "",
|
||||
|
|
@ -63,10 +68,22 @@ function Aliases(props: AliasesPageProps) {
|
|||
);
|
||||
}, [itemsOnPage, page, searchState, isPremiumOnly]);
|
||||
|
||||
const fetchMatrixAliases = useCallback(async () => {
|
||||
const result = await Fetch.getMatrixAddresses(page, itemsOnPage);
|
||||
if(!result.success || !(result.addresses instanceof Array)) return;
|
||||
setAliases(result.addresses);
|
||||
},[itemsOnPage, page])
|
||||
|
||||
useEffect(() => {
|
||||
setPage("1");
|
||||
}, [isPremiumOnly, searchState]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isInMatrix) {
|
||||
fetchMatrixAliases();
|
||||
}
|
||||
}, [isInMatrix, fetchMatrixAliases])
|
||||
|
||||
useEffect(() => {
|
||||
fetchAliases();
|
||||
|
||||
|
|
@ -164,10 +181,9 @@ function Aliases(props: AliasesPageProps) {
|
|||
}}
|
||||
content={
|
||||
<Switch
|
||||
firstTitle="Premium"
|
||||
secondTitle="All Aliases"
|
||||
isFirstSelected={isPremiumOnly}
|
||||
setIsFirstSelected={setIsPremiumOnly}
|
||||
titles={["Premium", "All Aliases", "In Matrix"]}
|
||||
selectedTitleIdx={selectedTitleIdx}
|
||||
setSelectedTitleIdx={setSelectedTitleIdx}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -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<any[]>(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);
|
||||
|
|
@ -234,10 +236,9 @@ function Assets(props: AssetsPageProps) {
|
|||
}}
|
||||
content={
|
||||
<Switch
|
||||
firstTitle="Whitelisted"
|
||||
secondTitle="All Assets"
|
||||
isFirstSelected={isWhitelist}
|
||||
setIsFirstSelected={setIsWhitelist}
|
||||
titles={["Whitelisted", "All Assets"]}
|
||||
selectedTitleIdx={selectedTitleIdx}
|
||||
setSelectedTitleIdx={setSelectedTitleIdx}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -102,6 +102,17 @@ class Fetch {
|
|||
static async getTxPoolInfo(count: number) {
|
||||
return await fetch(this.proxyPath + `/get_tx_pool_details/${encodeURIComponent(count)}`).then(res => res.json());
|
||||
}
|
||||
|
||||
static async getAssetsPriceRates(assetsIds: string[]){
|
||||
return await postFetch(
|
||||
this.proxyPath + `/get_assets_price_rates`,
|
||||
{ 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;
|
||||
Loading…
Add table
Reference in a new issue