Skip to content

Commit

Permalink
add getDapps simple endpoint for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
gluneau committed Jan 4, 2024
1 parent ed708e2 commit 6c6afd5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
35 changes: 33 additions & 2 deletions public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@
"type": "string",
"description": "The network name. Supported networks: astar",
"enum": [
"astar"
"astar",
"shiden",
"shibuya"
]
},
{
Expand Down Expand Up @@ -420,7 +422,9 @@
"type": "string",
"description": "The network name. Supported networks: astar",
"enum": [
"astar"
"astar",
"shiden",
"shibuya"
]
},
{
Expand Down Expand Up @@ -543,6 +547,33 @@
}
}
},
"/api/v3/{network}/dapps-staking/dappssimple": {
"get": {
"tags": [
"Dapps Staking"
],
"description": "Retrieves list of dapps (basic info) registered for dapps staking",
"parameters": [
{
"name": "network",
"in": "path",
"required": true,
"type": "string",
"description": "The network name. Supported networks: astar, shiden, shibuya",
"enum": [
"astar",
"shiden",
"shibuya"
]
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/{network}/dapps-staking/dapps/{address}": {
"get": {
"tags": [
Expand Down
18 changes: 16 additions & 2 deletions src/controllers/DappsStakingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class DappsStakingController extends ControllerBase implements IControlle
in: 'path',
description: 'The network name. Supported networks: astar',
required: true,
enum: ['astar']
enum: ['astar', 'shiden', 'shibuya']
}
#swagger.parameters['period'] = {
in: 'path',
Expand All @@ -147,7 +147,7 @@ export class DappsStakingController extends ControllerBase implements IControlle
in: 'path',
description: 'The network name. Supported networks: astar',
required: true,
enum: ['astar']
enum: ['astar', 'shiden', 'shibuya']
}
#swagger.parameters['contractAddress'] = {
in: 'path',
Expand Down Expand Up @@ -223,6 +223,20 @@ export class DappsStakingController extends ControllerBase implements IControlle
res.json(await this._firebaseService.getDapps(req.params.network as NetworkType));
});

app.route('/api/v3/:network/dapps-staking/dappssimple').get(async (req: Request, res: Response) => {
/*
#swagger.description = 'Retrieves list of dapps (basic info) registered for dapps staking'
#swagger.tags = ['Dapps Staking']
#swagger.parameters['network'] = {
in: 'path',
description: 'The network name. Supported networks: astar, shiden, shibuya',
required: true,
enum: ['astar', 'shiden', 'shibuya']
}
*/
res.json(await this._dappsStakingEvents.getDapps(req.params.network as NetworkType));
});

app.route('/api/v1/:network/dapps-staking/dapps/:address').get(async (req: Request, res: Response) => {
/*
#swagger.description = 'Retrieves dapp with the given address'
Expand Down
27 changes: 27 additions & 0 deletions src/services/DappsStakingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from './DappStaking/ResponseData';

export interface IDappsStakingEvents {
getDapps(network: NetworkType): Promise<[]>;
getStakingEvents(
network: NetworkType,
address: string,
Expand Down Expand Up @@ -174,6 +175,32 @@ export class DappsStakingEvents extends ServiceBase implements IDappsStakingEven
}
}

public async getDapps(network: NetworkType): Promise<[]> {
if (network !== 'astar' && network !== 'shiden' && network !== 'shibuya') {
return [];
}

try {
const result = await axios.post(this.getApiUrl(network), {
query: `query {
dapps (orderBy: registeredAt_ASC) {
contractAddress: id
stakersCount
registeredAt
registrationBlockNumber
unregisteredAt
unregistrationBlockNumber
}
}`,
});

return result.data.data.dapps;
} catch (e) {
console.error(e);
return [];
}
}

private getApiUrl(network: NetworkType): string {
// For local development: `http://localhost:4350/graphql`;
switch (network) {
Expand Down

0 comments on commit 6c6afd5

Please sign in to comment.