Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to the new dApp Radar API #128

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controllers/DappsStakingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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'
Expand Down
27 changes: 16 additions & 11 deletions src/services/DappRadarService.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {}
Expand All @@ -63,9 +63,7 @@ export class DappRadarService {
}/dapps?chain=${network.toLowerCase()}&page=${currentPage}&resultsPerPage=${this.RESULTS_PER_PAGE}`;

try {
const response = await axios.get<ApiResponse<Dapp>>(url, {
headers: { 'X-BLOBR-KEY': `${functions.config().dappradar.apikey}` },
});
const response = await axios.get<ApiResponse<Dapp>>(url, this.getOptions());

if (response.status !== 200 && !response.data.success) {
break;
Expand Down Expand Up @@ -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<ApiResponse<AggregatedMetrics>>(url, {
headers: { 'X-BLOBR-KEY': `${functions.config().dappradar.apikey}` },
});
const response = await axios.get<ApiResponse<AggregatedMetrics>>(url, this.getOptions());

if (response.data.success) {
// Add url to result.
Expand Down Expand Up @@ -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<ApiResponse<Metric>>(url, {
headers: { 'X-BLOBR-KEY': `${functions.config().dappradar.apikey}` },
});
const response = await axios.get<ApiResponse<Metric>>(url, this.getOptions());

if (response.data.success) {
result.push(...response.data.results);
Expand Down Expand Up @@ -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;
}
}
Loading