Merge branch 'feature_add_asset_price_view' of https://github.com/jejolare-dev/zano-explorer into feature_add_asset_price_view
This commit is contained in:
commit
d96e26414d
4 changed files with 57 additions and 6 deletions
|
|
@ -24,6 +24,8 @@ import { ITransaction } from "./schemes/Transaction";
|
|||
import BigNumber from "bignumber.js";
|
||||
import next from "next";
|
||||
import { rateLimit } from 'express-rate-limit';
|
||||
import bodyParser from 'body-parser';
|
||||
|
||||
import fs from "fs";
|
||||
// @ts-ignore
|
||||
const __dirname = import.meta.dirname;
|
||||
|
|
@ -73,6 +75,8 @@ const requestsLimiter = rateLimit({
|
|||
})
|
||||
app.use(express.static(path.resolve(__dirname, "../build/")));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.use([
|
||||
"/api/find_outs_in_recent_blocks"
|
||||
], requestsLimiter);
|
||||
|
|
@ -1122,7 +1126,6 @@ const requestsLimiter = rateLimit({
|
|||
return res.json(responseData);
|
||||
}));
|
||||
|
||||
|
||||
app.get('/api/get_asset_details/:asset_id', exceptionHandler(async (req, res) => {
|
||||
const { asset_id } = req.params;
|
||||
|
||||
|
|
@ -1166,7 +1169,31 @@ 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" })
|
||||
}
|
||||
|
||||
}))
|
||||
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,23 @@ function Assets(props: AssetsPageProps) {
|
|||
|
||||
if (newFetchId !== fetchIdRef.current) return;
|
||||
|
||||
const resultAssets = result;
|
||||
const assetsIds = result.map((asset: any) => asset.asset_id);
|
||||
|
||||
const assetsPriceRatesResponse = await Fetch.getAssetsPriceRates(assetsIds);
|
||||
|
||||
const assetsPriceRates = assetsPriceRatesResponse?.priceRates;
|
||||
|
||||
const zanoPrice = await Utils.getZanoPrice();
|
||||
|
||||
const resultAssets = result.map((resultAsset:any) => {
|
||||
if (assetsPriceRatesResponse?.success && zanoPrice) {
|
||||
const targetAsset = assetsPriceRates.find((asset: any)=> asset.asset_id === resultAsset.asset_id);
|
||||
if (!targetAsset) return resultAsset;
|
||||
resultAsset.price = (targetAsset.rate * zanoPrice).toFixed(2);
|
||||
}
|
||||
return resultAsset
|
||||
})
|
||||
|
||||
if (!resultAssets || !(resultAssets instanceof Array)) return;
|
||||
|
||||
fetchZanoPrice(resultAssets);
|
||||
|
|
@ -196,7 +212,7 @@ function Assets(props: AssetsPageProps) {
|
|||
}
|
||||
|
||||
const tableHeaders = [ "NAME", "TICKER", "ASSET ID", "PRICE (POWERED BY COINGECKO)" ];
|
||||
|
||||
|
||||
const tableElements = assets.map(e => [
|
||||
e?.full_name || "",
|
||||
e?.ticker || "",
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ import { chartRequestNames } from "./constants";
|
|||
const PORT = process.env.SERVER_PORT;
|
||||
|
||||
async function postFetch(path: string, body: Object) {
|
||||
return await fetch("/api/user/set-theme", {
|
||||
return await fetch(path, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
}).then(res => res.json());
|
||||
});
|
||||
}
|
||||
|
||||
class Fetch {
|
||||
|
|
@ -104,6 +104,13 @@ 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());
|
||||
}
|
||||
}
|
||||
|
||||
export default Fetch;
|
||||
Loading…
Add table
Reference in a new issue