-
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.
- Loading branch information
Showing
12 changed files
with
321 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 ISlotRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The slot index to get the details for. | ||
*/ | ||
slotIndex: 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 @@ | ||
import { SlotCommitment } from "@iota/sdk-nova"; | ||
|
||
export interface ISlotResponse { | ||
/** | ||
* The deserialized slot. | ||
*/ | ||
slot?: SlotCommitment; | ||
} |
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 { ISlotRequest } from "../../../models/api/nova/ISlotRequest"; | ||
import { ISlotResponse } from "../../../models/api/nova/ISlotResponse"; | ||
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 block from the network. | ||
* @param _ The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function get(_: IConfiguration, request: ISlotRequest): Promise<ISlotResponse> { | ||
const networkService = ServiceFactory.get<NetworkService>("network"); | ||
const networks = networkService.networkNames(); | ||
ValidationHelper.oneOf(request.network, networks, "network"); | ||
ValidationHelper.numberFromString(request.slotIndex, "slotIndex"); | ||
|
||
const networkConfig = networkService.get(request.network); | ||
|
||
if (networkConfig.protocolVersion !== NOVA) { | ||
return {}; | ||
} | ||
|
||
const novaApiService = ServiceFactory.get<NovaApiService>(`api-service-${networkConfig.network}`); | ||
return novaApiService.getSlotCommitment(Number(request.slotIndex)); | ||
} |
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,86 @@ | ||
@import "../../../scss/fonts"; | ||
@import "../../../scss/mixins"; | ||
@import "../../../scss/media-queries"; | ||
@import "../../../scss/variables"; | ||
|
||
.slot-page { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
.wrapper { | ||
display: flex; | ||
justify-content: center; | ||
|
||
.inner { | ||
display: flex; | ||
flex: 1; | ||
flex-direction: column; | ||
max-width: $desktop-width; | ||
margin: 40px 25px; | ||
|
||
@include desktop-down { | ||
flex: unset; | ||
width: 100%; | ||
max-width: 100%; | ||
margin: 40px 24px; | ||
padding-right: 24px; | ||
padding-left: 24px; | ||
|
||
> .row { | ||
flex-direction: column; | ||
} | ||
} | ||
|
||
@include tablet-down { | ||
margin: 28px 0; | ||
} | ||
|
||
.slot-page--header { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
|
||
.section { | ||
padding-top: 44px; | ||
|
||
.section--header { | ||
margin-top: 44px; | ||
} | ||
|
||
.card--content__output { | ||
margin-top: 20px; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.tooltip { | ||
.children { | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
} | ||
.tooltip__special { | ||
background-color: #fff4df; | ||
border-radius: 4px; | ||
padding: 0 4px; | ||
font-weight: 400; | ||
} | ||
|
||
.wrap { | ||
left: 0; | ||
right: 0; | ||
margin-left: auto; | ||
margin-right: auto; | ||
width: 170px; | ||
|
||
.arrow { | ||
left: 0; | ||
right: 0; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
} | ||
} | ||
} |
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,90 @@ | ||
import React from "react"; | ||
import Modal from "~/app/components/Modal"; | ||
import { ModalData } from "~/app/components/ModalProps"; | ||
import { RouteComponentProps } from "react-router-dom"; | ||
import TruncatedId from "~/app/components/stardust/TruncatedId"; | ||
import classNames from "classnames"; | ||
import useSlotData from "~/helpers/nova/hooks/useSlot"; | ||
import "./SlotPage.scss"; | ||
|
||
interface SlotPageProps { | ||
network: string; | ||
slotIndex: string; | ||
} | ||
|
||
export default function SlotPage({ | ||
match: { | ||
params: { network, slotIndex }, | ||
}, | ||
}: RouteComponentProps<SlotPageProps>): React.JSX.Element { | ||
const { slotCommitment } = useSlotData(network, slotIndex); | ||
|
||
const message: ModalData = { | ||
title: "Slot Page", | ||
description: "<p>Slot Information here</p>", | ||
}; | ||
|
||
const dataRows: IDataRow[] = [ | ||
{ | ||
label: "Slot Index", | ||
value: slotCommitment?.slot, | ||
highlighted: true, | ||
}, | ||
{ | ||
label: "RMC", | ||
value: slotCommitment?.referenceManaCost.toString(), | ||
}, | ||
]; | ||
|
||
return ( | ||
<section className="slot-page"> | ||
<div className="wrapper"> | ||
<div className="inner"> | ||
<div className="slot-page--header"> | ||
<div className="row middle"> | ||
<h1>Slot</h1> | ||
<Modal icon="info" data={message} /> | ||
</div> | ||
</div> | ||
<div className="section"> | ||
<div className="section--header row row--tablet-responsive middle space-between"> | ||
<div className="row middle"> | ||
<h2>General</h2> | ||
</div> | ||
</div> | ||
{dataRows.map((dataRow, index) => { | ||
if (dataRow.value || dataRow.truncatedId) { | ||
return <DataRow key={index} {...dataRow} />; | ||
} | ||
})} | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
interface IDataRow { | ||
label: string; | ||
value?: string | number; | ||
highlighted?: boolean; | ||
truncatedId?: { | ||
id: string; | ||
link?: string; | ||
showCopyButton?: boolean; | ||
}; | ||
} | ||
const DataRow = ({ label, value, truncatedId, highlighted }: IDataRow) => { | ||
return ( | ||
<div className="section--data"> | ||
<div className="label">{label}</div> | ||
<div className={classNames("value code", { highlighted })}> | ||
{truncatedId ? ( | ||
<TruncatedId id={truncatedId.id} link={truncatedId.link} showCopyButton={truncatedId.showCopyButton} /> | ||
) : ( | ||
value | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; |
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,54 @@ | ||
import { SlotCommitment } from "@iota/sdk-wasm-nova/web"; | ||
import { plainToInstance } from "class-transformer"; | ||
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 IUseSlotData { | ||
slotCommitment: SlotCommitment | null; | ||
error: string | undefined; | ||
isLoading: boolean; | ||
} | ||
|
||
export default function useSlotData(network: string, slotIndex: string): IUseSlotData { | ||
const isMounted = useIsMounted(); | ||
const [apiClient] = useState(ServiceFactory.get<NovaApiClient>(`api-client-${NOVA}`)); | ||
const [slotCommitment, setSlotCommitment] = useState<SlotCommitment | null>(null); | ||
const [error, setError] = useState<string | undefined>(); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
setSlotCommitment(null); | ||
if (!slotCommitment) { | ||
// eslint-disable-next-line no-void | ||
void (async () => { | ||
apiClient | ||
.getSlotCommitment({ | ||
network, | ||
slotIndex, | ||
}) | ||
.then((response) => { | ||
if (isMounted) { | ||
const slot = plainToInstance(SlotCommitment, response.slot) as unknown as SlotCommitment; | ||
setSlotCommitment(slot); | ||
setError(response.error); | ||
} | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
})(); | ||
} else { | ||
setIsLoading(false); | ||
} | ||
}, [network, slotIndex]); | ||
|
||
return { | ||
slotCommitment, | ||
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 ISlotRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The slot index to get the commitment for. | ||
*/ | ||
slotIndex: 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 { SlotCommitment } from "@iota/sdk-wasm-nova/web"; | ||
import { IResponse } from "../IResponse"; | ||
|
||
export interface ISlotResponse extends IResponse { | ||
slot: SlotCommitment; | ||
} |
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