-
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.
feat: Add delegation output to Validator tab of Account page (the out…
…put that are delegated to the address) (#1340) Co-authored-by: Begoña Alvarez <[email protected]>
- Loading branch information
1 parent
0c5eac5
commit b33071a
Showing
12 changed files
with
193 additions
and
6 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 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
import { OutputWithMetadataResponse } from "@iota/sdk-nova"; | ||
import { IResponse } from "./IResponse"; | ||
|
||
export interface IDelegationByValidatorResponse extends IResponse { | ||
/** | ||
* The delegation output by validator address. | ||
*/ | ||
outputs?: OutputWithMetadataResponse[]; | ||
} |
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,30 @@ | ||
import { ServiceFactory } from "../../../../../factories/serviceFactory"; | ||
import { IAddressDetailsRequest } from "../../../../../models/api/nova/IAddressDetailsRequest"; | ||
import { IDelegationByValidatorResponse } from "../../../../../models/api/nova/IDelegationByValidatorResponse"; | ||
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 delegation outputs by owning address. | ||
* @param _ The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function get(_: IConfiguration, request: IAddressDetailsRequest): Promise<IDelegationByValidatorResponse> { | ||
const networkService = ServiceFactory.get<NetworkService>("network"); | ||
const networks = networkService.networkNames(); | ||
ValidationHelper.oneOf(request.network, networks, "network"); | ||
ValidationHelper.string(request.address, "address"); | ||
|
||
const networkConfig = networkService.get(request.network); | ||
|
||
if (networkConfig.protocolVersion !== NOVA) { | ||
return {}; | ||
} | ||
|
||
const novaApiService = ServiceFactory.get<NovaApiService>(`api-service-${networkConfig.network}`); | ||
return novaApiService.delegationOutputDetailsByValidator(request.address); | ||
} |
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
46 changes: 46 additions & 0 deletions
46
client/src/helpers/nova/hooks/useValidatorDelegationOutputs.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,46 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useIsMounted } from "~helpers/hooks/useIsMounted"; | ||
import { ServiceFactory } from "~factories/serviceFactory"; | ||
import { NOVA } from "~models/config/protocolVersion"; | ||
import { NovaApiClient } from "~/services/nova/novaApiClient"; | ||
import { OutputWithMetadataResponse } from "@iota/sdk-wasm-nova/web"; | ||
|
||
/** | ||
* Fetch delegation outputs this address is delegated to (validator). | ||
* @param network The Network in context | ||
* @param addressBech32 The address in bech32 format | ||
* @returns The output responses and loading bool. | ||
*/ | ||
export function useValidatorDelegationOutputs( | ||
network: string, | ||
addressBech32: string | null, | ||
): [OutputWithMetadataResponse[] | null, boolean] { | ||
const isMounted = useIsMounted(); | ||
const [apiClient] = useState(ServiceFactory.get<NovaApiClient>(`api-client-${NOVA}`)); | ||
const [outputs, setOutputs] = useState<OutputWithMetadataResponse[] | null>(null); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
setOutputs(null); | ||
if (addressBech32) { | ||
// eslint-disable-next-line no-void | ||
void (async () => { | ||
apiClient | ||
.delegationOutputsByValidator({ network, address: addressBech32 }) | ||
.then((response) => { | ||
if (!response?.error && response.outputs && isMounted) { | ||
setOutputs(response.outputs); | ||
} | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
})(); | ||
} else { | ||
setIsLoading(false); | ||
} | ||
}, [network, addressBech32]); | ||
|
||
return [outputs, 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,9 @@ | ||
import { OutputWithMetadataResponse } from "@iota/sdk-wasm-nova/web"; | ||
import { IResponse } from "./IResponse"; | ||
|
||
export interface IDelegationByValidatorResponse extends IResponse { | ||
/** | ||
* The delegation output by validator address. | ||
*/ | ||
outputs?: OutputWithMetadataResponse[]; | ||
} |
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 |
---|---|---|
|
@@ -43,7 +43,7 @@ | |
], | ||
"~features/*": [ | ||
"src/features/*" | ||
], | ||
] | ||
} | ||
}, | ||
"include": [ | ||
|