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 #312 from NodeFactoryIo/beacon-assign
Beacon assign
- Loading branch information
Showing
17 changed files
with
229 additions
and
27 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
49 changes: 49 additions & 0 deletions
49
src/renderer/containers/AssignBeaconNode/AssignBeaconNode.tsx
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,49 @@ | ||
import React, {useState} from "react"; | ||
import OnBoardModal from "../Onboard/OnBoardModal"; | ||
import {Background} from "../../components/Background/Background"; | ||
import {useHistory} from "react-router-dom"; | ||
import {ButtonPrimary} from "../../components/Button/ButtonStandard"; | ||
import {Dropdown} from "../../components/Dropdown/Dropdown"; | ||
import {useDispatch, useSelector} from "react-redux"; | ||
import {getBeaconKeys} from "../../ducks/beacon/selectors"; | ||
import {setValidatorBeaconNode} from "../../ducks/validator/actions"; | ||
import {useParams} from "react-router"; | ||
import {Routes} from "../../constants/routes"; | ||
|
||
export const AssignBeaconNode: React.FC = () => { | ||
const {validatorKey} = useParams(); | ||
const history = useHistory(); | ||
|
||
const [beaconIndex, setBeaconIndex] = useState<number>(0); | ||
const beaconNodes = useSelector(getBeaconKeys); | ||
const dispatch = useDispatch(); | ||
|
||
const onChange = (selected: number): void => { | ||
setBeaconIndex(selected); | ||
}; | ||
|
||
const onSubmit = (): void => { | ||
dispatch(setValidatorBeaconNode(validatorKey, beaconNodes[beaconIndex])); | ||
history.push(Routes.DASHBOARD_ROUTE); | ||
}; | ||
|
||
return ( | ||
<Background> | ||
<OnBoardModal history={history} currentStep={0}> | ||
<h1>Validator Beacon Node</h1> | ||
<p>Assigns Beacon Node to Validator.</p> | ||
<br /> | ||
|
||
<div className='dropdown-input-container'> | ||
<Dropdown options={beaconNodes} current={beaconIndex} onChange={onChange} /> | ||
</div> | ||
|
||
<span className='submit-button-container'> | ||
<ButtonPrimary buttonId='assign' onClick={onSubmit}> | ||
ASSIGN | ||
</ButtonPrimary> | ||
</span> | ||
</OnBoardModal> | ||
</Background> | ||
); | ||
}; |
10 changes: 10 additions & 0 deletions
10
src/renderer/containers/AssignBeaconNode/assignBeaconNode.scss
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 @@ | ||
.dropdown-input-container { | ||
display: flex; | ||
flex-direction: column; | ||
align-self: flex-start; | ||
width: 100%; | ||
|
||
h3 { | ||
margin-right: 0.2rem; | ||
} | ||
} |
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,6 +1,10 @@ | ||
import {IRootState} from "../reducers"; | ||
import {IBeaconState} from "./slice"; | ||
import {IBeaconState, IBeaconDictionary} from "./slice"; | ||
|
||
export const getBeacons = (state: IRootState): IBeaconState => state.beacons; | ||
|
||
export const getBeaconDictionary = (state: IRootState): IBeaconDictionary => state.beacons.beacons; | ||
|
||
export const getBeaconKeys = (state: IRootState): string[] => state.beacons.keys; | ||
|
||
export const getHasBeacons = (state: IRootState): boolean => !!state.beacons.keys.length; |
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
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 {ContainerType, ListType} from "@chainsafe/ssz"; | ||
import {StringType} from "./basic"; | ||
import {ValidatorBeaconNodes} from "../validatorBeaconNodes"; | ||
|
||
export const ValidatorBeaconNodesType = new ContainerType<ValidatorBeaconNodes>({ | ||
fields: { | ||
nodes: new ListType({elementType: new StringType(), limit: 1}), | ||
}, | ||
}); |
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 @@ | ||
interface IValidatorBeaconNodes { | ||
nodes: string[]; | ||
} | ||
|
||
export class ValidatorBeaconNodes implements IValidatorBeaconNodes { | ||
public nodes: string[] = []; | ||
|
||
public static createNodes(nodes: string[]): ValidatorBeaconNodes | null { | ||
const list = new ValidatorBeaconNodes(); | ||
nodes.forEach((url) => list.addNode(url)); | ||
|
||
return list; | ||
} | ||
|
||
// Add new node to the list that has unique values | ||
public addNode(url: string): void { | ||
if (!this.nodes.some((beaconUrl) => beaconUrl === url)) { | ||
this.nodes.push(url); | ||
} | ||
} | ||
|
||
public removeNode(url: string): boolean { | ||
const index = this.nodes.findIndex((beaconUrl) => beaconUrl !== url); | ||
if (index !== -1) { | ||
this.nodes.splice(index, 1); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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.