generated from axone-protocol/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from axone-protocol/feat/single-validator-page
feat: added info for single validator page
- Loading branch information
Showing
24 changed files
with
381 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { BadRequestException, Injectable } from "@nestjs/common"; | ||
import { HttpService } from "../http.service"; | ||
import { config } from "@core/config/config"; | ||
import { GSFResponse } from "./responses/generic-success-failed.response"; | ||
import { FailedResponse } from "./responses/failed.response"; | ||
import { createUrlParams } from "@utils/create-url-params"; | ||
import { UserLookupResponse } from "./responses/user-lookup.response"; | ||
|
||
@Injectable() | ||
export class KeybaseService { | ||
private BASE_URL = config.keybase.url; | ||
|
||
constructor(private readonly httpService: HttpService) {} | ||
|
||
private constructUrl(endpoint: string, params?: string): string { | ||
return `${this.BASE_URL}/${endpoint}${params ? `?${params}` : ''}`; | ||
} | ||
|
||
private getWithErrorHandling<T>(url: string): Promise<T> { | ||
return this.errorHandleWrapper( | ||
this.httpService.get.bind( | ||
null, | ||
url, | ||
), | ||
); | ||
} | ||
|
||
async getUserLookup(key: string): Promise<UserLookupResponse> { | ||
return this.getWithErrorHandling( | ||
this.constructUrl( | ||
'user/lookup.json', | ||
createUrlParams({ | ||
fields: 'pictures', | ||
key_suffix: key | ||
}) | ||
) | ||
) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
private async errorHandleWrapper<T>(fn: any): Promise<T> { | ||
try { | ||
const response: GSFResponse<T> = await fn(); | ||
|
||
if (this.isFailedResponse(response)) { | ||
throw new BadRequestException(response.status.name); | ||
} | ||
|
||
return response as T; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} catch (e: any) { | ||
throw new BadRequestException(e.message); | ||
} | ||
} | ||
|
||
private isFailedResponse<T>(response: GSFResponse<T>): response is FailedResponse { | ||
return (response as FailedResponse).status.code !== 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface FailedResponse { | ||
status: { | ||
code: number; | ||
desc: string; | ||
fields: { | ||
key_suffix: string; | ||
}; | ||
name: string; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/core/lib/keybase/responses/generic-success-failed.response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { FailedResponse } from './failed.response'; | ||
|
||
export type GSFResponse<T> = T | FailedResponse; // Generic Success / Failed Response for Osmosis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface UserLookupResponse { | ||
status: { | ||
code: number; | ||
name: string; | ||
}, | ||
them: [ | ||
{ | ||
id: string; | ||
pictures: { | ||
primary: { | ||
url: string; | ||
source: string; | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum RouteParam { | ||
DELEGATOR_ADDRES = ':delegator_addr', | ||
VALIDATOR_ADDRES = ':validator_addr', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/core/lib/okp4/responses/validator-delegations.response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { WithPaginationResponse } from "./with-pagination.response"; | ||
|
||
export type ValidatorDelegationsResponse = WithPaginationResponse<{ delegation_responses: Delegation[] }>; | ||
|
||
export interface Delegation { | ||
delegation: { | ||
delegator_address: string; | ||
validator_address: string; | ||
shares: string | ||
}; | ||
balance: { | ||
denom: string; | ||
amount: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface MyValidatorDelegationDto { | ||
address: string; | ||
validatorAddress: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ValidatorDelegationsDto { | ||
address: string; | ||
limit?: number; | ||
offset?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
export interface ValidatorsViewDto { | ||
logo: string; | ||
description: { | ||
moniker: string; | ||
identity: string; | ||
website: string; | ||
securityContact: string; | ||
details: string; | ||
}; | ||
commission: { | ||
rate: string; | ||
maxRate: string; | ||
maxChangeRate: string; | ||
updateTime: string; | ||
}; | ||
address: string; | ||
name: string; | ||
status: string; | ||
jailed: boolean; | ||
stakedAmount: string; | ||
commission: string; | ||
uptime: number; | ||
votingPower: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum QueryParam { | ||
ADDRESS = 'address', | ||
VALIDATOR_ADDRESS = 'validatorAddress', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum StakingCachePrefix { | ||
STAKING = 'staking', | ||
GLOBAL_OVERVIEW = 'global_overview', | ||
VALIDATORS = 'validators', | ||
VALIDATOR_IMG = 'validator_img', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export enum StakingEndpoints { | ||
MY_OVERVIEW = '/my/overview', | ||
MY_VALIDATOR_DELEGATION = '/my/validator-delegation', | ||
VALIDATOR_DELEGATIONS = '/validator-delegations', | ||
OVERVIEW = '/overview', | ||
VALIDATORS = '/validators', | ||
} |
6 changes: 6 additions & 0 deletions
6
src/modules/staking/schemas/my-validator-delegation.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as Joi from 'joi'; | ||
|
||
export const MyValidatorDelegationSchema = Joi.object({ | ||
address: Joi.string().required(), | ||
validatorAddress: Joi.string().required(), | ||
}).required() |
10 changes: 10 additions & 0 deletions
10
src/modules/staking/schemas/validator-delegations.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as Joi from 'joi'; | ||
|
||
export const ValidatorDelegationsSchema = Joi.object({ | ||
address: Joi.string().required(), | ||
limit: Joi.number().optional(), | ||
offset: Joi.number().optional(), | ||
}) | ||
.keys() | ||
.and('limit', 'offset') | ||
.required(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.