From 64495d4a472c1baacb0a80af955a36da3ea7aede Mon Sep 17 00:00:00 2001 From: Taha Abbasi Date: Fri, 31 Mar 2023 18:28:55 -0600 Subject: [PATCH] Removed more config items to env variables and introduced dynamic token lookup --- build/config.js | 8 +++++--- build/server.js | 18 +++++++++++++++++- src/config.ts | 8 +++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/build/config.js b/build/config.js index fd2f430..f15008b 100644 --- a/build/config.js +++ b/build/config.js @@ -20,6 +20,8 @@ const dotenv_1 = require("dotenv"); (0, dotenv_1.config)(); const API_URL = process.env.API_URL; const DATABASE_NAME = process.env.DATABASE_NAME; +const DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS = process.env.DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS; +const DB_COLLECTION_NAME_CHAIN_NETWORK_MAP = process.env.DB_COLLECTION_NAME_CHAIN_NETWORK_MAP; function getChainIdToNetworkMap() { return __awaiter(this, void 0, void 0, function* () { const MONGODB_URI = process.env.MONGODB_URI; @@ -29,11 +31,11 @@ function getChainIdToNetworkMap() { const client = new mongodb_1.MongoClient(MONGODB_URI); yield client.connect(); const database = client.db(DATABASE_NAME); - const chainIdToNetworkMapCollection = database.collection("chainIdToNetworkMap"); + const chainIdToNetworkMapCollection = database.collection(DB_COLLECTION_NAME_CHAIN_NETWORK_MAP); const result = yield chainIdToNetworkMapCollection.findOne({ appName: "tokenSupply" }); yield client.close(); if (!result) { - throw new Error("chainIdToNetworkMap not found in the database."); + throw new Error(`${DB_COLLECTION_NAME_CHAIN_NETWORK_MAP} not found in the database.`); } const chainIdToNetworkMap = {}; for (const item of result.chainIdToNetworkMap) { @@ -77,7 +79,7 @@ function getNonCirculatingSupplyAddressesConfigInput(currencyId) { const client = new mongodb_1.MongoClient(MONGODB_URI); yield client.connect(); const database = client.db(DATABASE_NAME); - const collection = database.collection("nonCirculatingSupplyAddressesConfig"); + const collection = database.collection(DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS); const result = yield collection.findOne({ currency: new mongodb_1.ObjectId(currencyId) }); yield client.close(); if (!result) { diff --git a/build/server.js b/build/server.js index 1569852..1fcfab2 100644 --- a/build/server.js +++ b/build/server.js @@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -64,7 +75,12 @@ app.get("/nonCirculatingSupplyAddresses", (0, cacheMiddleware_1.default)(cacheDu } const { networks, currencyId } = yield (0, config_1.getNetworkConfigurations)(tokenContractAddress, Number(chainId)); const nonCirculatingSupplyAddressConfigurations = yield (0, config_1.getNonCirculatingSupplyAddressConfigurations)(tokenContractAddress, Number(chainId), currencyId); - res.json(nonCirculatingSupplyAddressConfigurations); + // Remove jsonRpcUrl from the response + const filteredResponse = nonCirculatingSupplyAddressConfigurations.map((_a) => { + var { jsonRpcUrl } = _a, rest = __rest(_a, ["jsonRpcUrl"]); + return rest; + }); + res.json(filteredResponse); })); app.get('/nonCirculatingSupplyBalancesByAddress', (0, cacheMiddleware_1.default)(cacheDuration), (req, res) => __awaiter(void 0, void 0, void 0, function* () { try { diff --git a/src/config.ts b/src/config.ts index 7a5d40a..7c2407b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,6 +12,8 @@ config(); const API_URL = process.env.API_URL; const DATABASE_NAME = process.env.DATABASE_NAME; +const DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS = process.env.DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS as string; +const DB_COLLECTION_NAME_CHAIN_NETWORK_MAP = process.env.DB_COLLECTION_NAME_CHAIN_NETWORK_MAP as string; async function getChainIdToNetworkMap(): Promise { const MONGODB_URI = process.env.MONGODB_URI; @@ -21,14 +23,14 @@ async function getChainIdToNetworkMap(): Promise { const client = new MongoClient(MONGODB_URI); await client.connect(); const database = client.db(DATABASE_NAME); - const chainIdToNetworkMapCollection = database.collection("chainIdToNetworkMap"); + const chainIdToNetworkMapCollection = database.collection(DB_COLLECTION_NAME_CHAIN_NETWORK_MAP); const result = await chainIdToNetworkMapCollection.findOne({ appName: "tokenSupply" }); await client.close(); if (!result) { - throw new Error("chainIdToNetworkMap not found in the database."); + throw new Error(`${DB_COLLECTION_NAME_CHAIN_NETWORK_MAP} not found in the database.`); } const chainIdToNetworkMap: ChainIdToNetwork = {}; @@ -77,7 +79,7 @@ export async function getNonCirculatingSupplyAddressesConfigInput(currencyId: st const client = new MongoClient(MONGODB_URI); await client.connect(); const database = client.db(DATABASE_NAME); - const collection = database.collection("nonCirculatingSupplyAddressesConfig"); + const collection = database.collection(DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS); const result = await collection.findOne({ currency: new ObjectId(currencyId) });