|
1 | 1 | /* eslint-disable max-len */ |
2 | 2 | import { RECEIPT_MILESTONE_OPTION_TYPE, POW_MILESTONE_OPTION_TYPE } from "@iota/iota.js"; |
| 3 | +import classNames from "classnames"; |
3 | 4 | import React, { Component, ReactNode } from "react"; |
4 | 5 | import { Link } from "react-router-dom"; |
5 | 6 | import { ClipboardHelper } from "../../../utils/clipboardHelper"; |
6 | 7 | import { FormatHelper } from "../../../utils/formatHelper"; |
7 | 8 | import MessageButton from "../layout/MessageButton"; |
| 9 | +import { ReactComponent as DropdownIcon } from "./../../../assets/dropdown-arrow.svg"; |
8 | 10 | import { MilestonePayloadProps } from "./MilestonePayloadProps"; |
9 | | -import ReceiptPayload from "./ReceiptMilestoneOption"; |
| 11 | +import { MilestonePayloadState } from "./MilestonePayloadState"; |
| 12 | +import PoWMilestoneOption from "./PoWMilestoneOption"; |
| 13 | +import ReceiptMilestoneOption from "./ReceiptMilestoneOption"; |
10 | 14 |
|
11 | 15 | /** |
12 | 16 | * Component which will display a milestone payload. |
13 | 17 | */ |
14 | | -class MilestonePayload extends Component<MilestonePayloadProps> { |
| 18 | +class MilestonePayload extends Component<MilestonePayloadProps, MilestonePayloadState> { |
| 19 | + /** |
| 20 | + * Create a new instance of Milestone payload. |
| 21 | + * @param props The props. |
| 22 | + */ |
| 23 | + constructor(props: MilestonePayloadProps) { |
| 24 | + super(props); |
| 25 | + |
| 26 | + this.state = { |
| 27 | + showSignatures: false, |
| 28 | + showOptions: false |
| 29 | + }; |
| 30 | + } |
| 31 | + |
15 | 32 | /** |
16 | 33 | * Render the component. |
17 | 34 | * @returns The node to render. |
18 | 35 | */ |
19 | 36 | public render(): ReactNode { |
20 | 37 | return ( |
21 | | - <div className="milestone-payload"> |
| 38 | + <div className="milestone-payload card--content padding-0"> |
22 | 39 | <h2>Milestone Payload</h2> |
23 | 40 | <div className="card--label"> |
24 | 41 | Index |
@@ -93,72 +110,77 @@ class MilestonePayload extends Component<MilestonePayloadProps> { |
93 | 110 | </div> |
94 | 111 | </React.Fragment> |
95 | 112 | )} |
| 113 | + |
96 | 114 | {this.props.payload.options && ( |
97 | | - <React.Fragment> |
98 | | - {this.props.payload.options.map((option, i) => ( |
99 | | - <React.Fragment> |
| 115 | + <React.Fragment> |
| 116 | + <div className="milestone-payloads__options padding-t-s"> |
| 117 | + <div |
| 118 | + className="card--content__input" |
| 119 | + onClick={() => this.setState({ showOptions: !this.state.showOptions })} |
| 120 | + > |
| 121 | + <div className={classNames( |
| 122 | + "margin-r-t", |
| 123 | + "card--content__input--dropdown", |
| 124 | + { "opened": this.state.showOptions } |
| 125 | + )} |
| 126 | + > |
| 127 | + <DropdownIcon /> |
| 128 | + </div> |
| 129 | + <h3>Options</h3> |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + {this.state.showOptions && ( |
| 133 | + <div className="card--content--border-l"> |
| 134 | + {this.props.payload.options.map((option, idx) => ( |
| 135 | + <React.Fragment key={idx}> |
100 | 136 | { option.type === RECEIPT_MILESTONE_OPTION_TYPE && ( |
101 | | - <div className="card margin-t-m padding-l"> |
102 | | - <ReceiptPayload option={option} /> |
103 | | - </div> |
104 | | - )} |
| 137 | + <ReceiptMilestoneOption option={option} /> |
| 138 | + )} |
105 | 139 | { option.type === POW_MILESTONE_OPTION_TYPE && ( |
106 | | - <div className="card margin-t-m padding-l"> |
107 | | - <div className="card--label"> |
108 | | - Next PoW Score |
109 | | - </div> |
110 | | - <div className="card--value"> |
111 | | - {option.nextPoWScore} |
112 | | - </div> |
113 | | - <div className="card--label"> |
114 | | - Next PoW Score Milestone Index |
115 | | - </div> |
116 | | - <div className="card--value"> |
117 | | - {option.nextPoWScoreMilestoneIndex} |
118 | | - </div> |
119 | | - </div> |
120 | | - )} |
| 140 | + <PoWMilestoneOption option={option} /> |
| 141 | + )} |
121 | 142 | </React.Fragment> |
122 | | - ))} |
123 | | - </React.Fragment> |
| 143 | + ))} |
| 144 | + </div> |
| 145 | + )} |
| 146 | + </React.Fragment> |
124 | 147 | )} |
125 | | - {/* {this.props.payload.nextPoWScore !== 0 && this.props.payload.nextPoWScoreMilestoneIndex !== 0 && ( |
126 | | - <React.Fragment> |
127 | | - <div className="card--label"> |
128 | | - Next PoW Score |
129 | | - </div> |
130 | | - <div className="card--value"> |
131 | | - {this.props.payload.nextPoWScore} |
132 | | - </div> |
133 | | - <div className="card--label"> |
134 | | - Next PoW Score Milestone Index |
135 | | - </div> |
136 | | - <div className="card--value"> |
137 | | - {this.props.payload.nextPoWScoreMilestoneIndex} |
| 148 | + <div className="milestone-payloads__signatures padding-t-s"> |
| 149 | + <div |
| 150 | + className="card--content__input" |
| 151 | + onClick={() => this.setState({ showSignatures: !this.state.showSignatures })} |
| 152 | + > |
| 153 | + <div className={classNames( |
| 154 | + "margin-r-t", |
| 155 | + "card--content__input--dropdown", |
| 156 | + { "opened": this.state.showSignatures } |
| 157 | + )} |
| 158 | + > |
| 159 | + <DropdownIcon /> |
138 | 160 | </div> |
139 | | - </React.Fragment> |
140 | | - )} */} |
141 | | - <div className="card--label"> |
142 | | - Signatures |
| 161 | + <h3>Signatures</h3> |
| 162 | + </div> |
143 | 163 | </div> |
144 | | - <div className="card--value card--value__mono"> |
145 | | - {this.props.payload.signatures.map((sig, i) => ( |
146 | | - <div key={i} className="margin-b-s"> |
147 | | - <div className="card--label"> |
148 | | - Public Key |
| 164 | + {this.state.showSignatures && ( |
| 165 | + <div className="card--content--border-l"> |
| 166 | + {this.props.payload.signatures.map((sig, i) => ( |
| 167 | + <div key={i} className="margin-b-s"> |
| 168 | + <div className="card--label"> |
| 169 | + Public Key |
| 170 | + </div> |
| 171 | + <div className="card--value card--value__mono"> |
| 172 | + {sig.publicKey} |
| 173 | + </div> |
| 174 | + <div className="card--label"> |
| 175 | + Signature |
| 176 | + </div> |
| 177 | + <div className="card--value card--value__mono"> |
| 178 | + {sig.signature} |
| 179 | + </div> |
149 | 180 | </div> |
150 | | - <div className="card--value card--value__mono"> |
151 | | - {sig.publicKey} |
152 | | - </div> |
153 | | - <div className="card--label"> |
154 | | - Signature |
155 | | - </div> |
156 | | - <div className="card--value card--value__mono"> |
157 | | - {sig.signature} |
158 | | - </div> |
159 | | - </div> |
160 | | - ))} |
161 | | - </div> |
| 181 | + ))} |
| 182 | + </div> |
| 183 | + )} |
162 | 184 | </div> |
163 | 185 | ); |
164 | 186 | } |
|
0 commit comments