-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: add Epoch page * feat: Add committee to epoch page * feat: add api committee route * fix: hook request param
- Loading branch information
Showing
11 changed files
with
260 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface IEpochCommitteeRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The epoch index to get the committee for. | ||
*/ | ||
epochIndex: 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,8 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
import { CommitteeResponse } from "@iota/sdk-nova"; | ||
import { IResponse } from "./IResponse"; | ||
|
||
export interface IEpochCommitteeResponse extends IResponse { | ||
committeeResponse?: CommitteeResponse; | ||
} |
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,30 @@ | ||
import { ServiceFactory } from "../../../../factories/serviceFactory"; | ||
import { IEpochCommitteeRequest } from "../../../../models/api/nova/IEpochCommitteeRequest"; | ||
import { IEpochCommitteeResponse } from "../../../../models/api/nova/IEpochCommitteeResponse"; | ||
import { IConfiguration } from "../../../../models/configuration/IConfiguration"; | ||
import { NOVA } from "../../../../models/db/protocolVersion"; | ||
import { NetworkService } from "../../../../services/networkService"; | ||
import { NovaApiService } from "../../../../services/nova/novaApiService"; | ||
import { ValidationHelper } from "../../../../utils/validationHelper"; | ||
|
||
/** | ||
* Fetch the committee from the network. | ||
* @param _ The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function get(_: IConfiguration, request: IEpochCommitteeRequest): Promise<IEpochCommitteeResponse> { | ||
const networkService = ServiceFactory.get<NetworkService>("network"); | ||
const networks = networkService.networkNames(); | ||
ValidationHelper.oneOf(request.network, networks, "network"); | ||
ValidationHelper.numberFromString(request.epochIndex, "epochIndex"); | ||
|
||
const networkConfig = networkService.get(request.network); | ||
|
||
if (networkConfig.protocolVersion !== NOVA) { | ||
return {}; | ||
} | ||
|
||
const novaApiService = ServiceFactory.get<NovaApiService>(`api-service-${networkConfig.network}`); | ||
return novaApiService.getEpochCommittee(Number(request.epochIndex)); | ||
} |
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,67 @@ | ||
@import "../../../scss/fonts"; | ||
@import "../../../scss/mixins"; | ||
@import "../../../scss/media-queries"; | ||
@import "../../../scss/variables"; | ||
|
||
.epoch-page { | ||
.validators-page__header { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
|
||
.header__title { | ||
margin-bottom: 8px; | ||
} | ||
} | ||
|
||
.all-validators__section { | ||
font-family: $metropolis; | ||
margin-top: 40px; | ||
background-color: $gray-1; | ||
border-radius: 8px; | ||
|
||
.all-validators__header { | ||
width: fit-content; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
|
||
.all-validators__wrapper { | ||
margin: 0 20px 20px; | ||
|
||
.validator-item { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr 1fr 1fr; | ||
margin: 0px 12px; | ||
align-items: center; | ||
line-height: 32px; | ||
justify-content: center; | ||
background-color: $gray-3; | ||
border-radius: 4px; | ||
|
||
&.table-header { | ||
background-color: $gray-5; | ||
} | ||
|
||
&:not(:last-child) { | ||
margin-bottom: 12px; | ||
} | ||
|
||
.validator-item__address, | ||
.validator-item__state, | ||
.validator-item__fixed-cost, | ||
.validator-item__pool-stake, | ||
.validator-item__validator-stake, | ||
.validator-item__delegator-stake { | ||
display: flex; | ||
margin: 0 auto; | ||
justify-content: center; | ||
} | ||
|
||
.validator-item__address { | ||
width: 140px; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,52 @@ | ||
import { CommitteeResponse } from "@iota/sdk-wasm-nova/web"; | ||
import { useEffect, useState } from "react"; | ||
import { ServiceFactory } from "~/factories/serviceFactory"; | ||
import { useIsMounted } from "~/helpers/hooks/useIsMounted"; | ||
import { NOVA } from "~/models/config/protocolVersion"; | ||
import { NovaApiClient } from "~/services/nova/novaApiClient"; | ||
|
||
interface IUseEpochCommittee { | ||
epochCommittee: CommitteeResponse | null; | ||
error: string | undefined; | ||
isLoading: boolean; | ||
} | ||
|
||
export default function useEpochCommittee(network: string, epochIndex?: string): IUseEpochCommittee { | ||
const isMounted = useIsMounted(); | ||
const [apiClient] = useState(ServiceFactory.get<NovaApiClient>(`api-client-${NOVA}`)); | ||
const [epochCommittee, setEpochCommittee] = useState<CommitteeResponse | null>(null); | ||
const [error, setError] = useState<string | undefined>(); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
setEpochCommittee(null); | ||
if (epochIndex) { | ||
// eslint-disable-next-line no-void | ||
void (async () => { | ||
apiClient | ||
.getEpochCommittee({ | ||
network, | ||
epochIndex, | ||
}) | ||
.then((response) => { | ||
if (isMounted) { | ||
setEpochCommittee(response.committeeResponse); | ||
setError(response.error); | ||
} | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
})(); | ||
} else { | ||
setIsLoading(false); | ||
} | ||
}, [epochIndex]); | ||
|
||
return { | ||
epochCommittee, | ||
error, | ||
isLoading, | ||
}; | ||
} |
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,11 @@ | ||
export interface IEpochCommitteeRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The epoch index to get the committee for. | ||
*/ | ||
epochIndex: 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,6 @@ | ||
import { CommitteeResponse } from "@iota/sdk-wasm-nova/web"; | ||
import { IResponse } from "../IResponse"; | ||
|
||
export interface IEpochCommitteeResponse extends IResponse { | ||
committeeResponse: CommitteeResponse; | ||
} |
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