From b9719ecb38d5c52ae2fbbe4a613e2f22e420dbe4 Mon Sep 17 00:00:00 2001 From: Bobo Date: Wed, 17 Jan 2024 16:25:01 +0100 Subject: [PATCH 1/2] Switched to the new dApp Radar API --- src/services/DappRadarService.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/services/DappRadarService.ts b/src/services/DappRadarService.ts index a7dc07e..d5c81eb 100644 --- a/src/services/DappRadarService.ts +++ b/src/services/DappRadarService.ts @@ -1,5 +1,5 @@ import { inject, injectable } from 'inversify'; -import axios from 'axios'; +import axios, { AxiosRequestConfig } from 'axios'; import * as functions from 'firebase-functions'; import { Dapp, Metric } from '../models/DappRadar'; import { NetworkType } from '../networks'; @@ -44,7 +44,7 @@ enum DappRadarMetricType { @injectable() export class DappRadarService { - public static BaseUrl = 'https://api.dappradar.com/97c1ov0nxxr0jjh8/'; + public static BaseUrl = 'https://apis.dappradar.com/v2/'; readonly RESULTS_PER_PAGE = 50; constructor(@inject(ContainerTypes.FirebaseService) private firebase: IFirebaseService) {} @@ -63,9 +63,7 @@ export class DappRadarService { }/dapps?chain=${network.toLowerCase()}&page=${currentPage}&resultsPerPage=${this.RESULTS_PER_PAGE}`; try { - const response = await axios.get>(url, { - headers: { 'X-BLOBR-KEY': `${functions.config().dappradar.apikey}` }, - }); + const response = await axios.get>(url, this.getOptions()); if (response.status !== 200 && !response.data.success) { break; @@ -152,9 +150,7 @@ export class DappRadarService { }/dapps/aggregated/metrics?chain=${network.toLowerCase()}&range=${period}&resultsPerPage=${ this.RESULTS_PER_PAGE }&page=${currentPage}`; - const response = await axios.get>(url, { - headers: { 'X-BLOBR-KEY': `${functions.config().dappradar.apikey}` }, - }); + const response = await axios.get>(url, this.getOptions()); if (response.data.success) { // Add url to result. @@ -191,9 +187,7 @@ export class DappRadarService { if (dappId) { const url = `${DappRadarService.BaseUrl}/dapps/${dappId}/history/${metric}?chain=${network.toLowerCase()}`; - const response = await axios.get>(url, { - headers: { 'X-BLOBR-KEY': `${functions.config().dappradar.apikey}` }, - }); + const response = await axios.get>(url, this.getOptions()); if (response.data.success) { result.push(...response.data.results); @@ -238,4 +232,15 @@ export class DappRadarService { throw new Error(`Network ${network} is not supported.`); } } + + public getOptions(): AxiosRequestConfig { + // dappradar.apikey is deprecated, use dappradar.apikey2 instead. + const apiKey = this.firebase.getEnvVariable('dappradar', 'apikey2'); + const options: AxiosRequestConfig = {}; + if (apiKey) { + options.headers = { 'x-api-key': apiKey }; + } + + return options; + } } From 466d3e254bd4fb02d5bc165fe78a9b3e66a2bb49 Mon Sep 17 00:00:00 2001 From: Bobo Date: Thu, 18 Jan 2024 09:24:26 +0100 Subject: [PATCH 2/2] Minor data validation change for a dapp registration. --- src/controllers/DappsStakingController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DappsStakingController.ts b/src/controllers/DappsStakingController.ts index 5329959..6b6e374 100644 --- a/src/controllers/DappsStakingController.ts +++ b/src/controllers/DappsStakingController.ts @@ -199,7 +199,7 @@ export class DappsStakingController extends ControllerBase implements IControlle body('description').notEmpty().trim().escape(), body('shortDescription').optional().trim().escape(), body('url').isURL(), - body('license').notEmpty().trim().isIn(['GPL-3.0', 'MIT', 'GNU']), + body('license').optional().trim().escape(), body('address').notEmpty().trim().escape(), body('iconFile').notEmpty(), body('iconFile.name').notEmpty().isString(), @@ -229,7 +229,7 @@ export class DappsStakingController extends ControllerBase implements IControlle ]), body('communities.*.handle').notEmpty().isURL(), body('contractType').notEmpty().isIn(['wasm+evm', 'wasm', 'evm']), - body('mainCategory').notEmpty().isIn(['defi', 'nft', 'tooling', 'utility', 'others']), + body('mainCategory').notEmpty().isIn(['defi', 'nft', 'tooling', 'utility', 'others', 'unstoppable-grants']), async (req: Request, res: Response) => { /* #swagger.description = 'Registers a new dapp'