Skip to content

Commit

Permalink
Removed more config items to env variables and introduced dynamic tok…
Browse files Browse the repository at this point in the history
…en lookup
  • Loading branch information
taha-abbasi committed Apr 1, 2023
1 parent 86be544 commit 64495d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
8 changes: 5 additions & 3 deletions build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion build/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChainIdToNetwork> {
const MONGODB_URI = process.env.MONGODB_URI;
Expand All @@ -21,14 +23,14 @@ async function getChainIdToNetworkMap(): Promise<ChainIdToNetwork> {
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 = {};
Expand Down Expand Up @@ -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) });

Expand Down

0 comments on commit 64495d4

Please sign in to comment.