|
1 | | -import { IOutputResponse, UnitsHelper } from "@iota/iota.js"; |
| 1 | +import { IOutputResponse } from "@iota/iota.js"; |
| 2 | +import classNames from "classnames"; |
2 | 3 | import React, { ReactNode } from "react"; |
3 | 4 | import { Link, RouteComponentProps } from "react-router-dom"; |
4 | 5 | import { ReactComponent as ChevronLeftIcon } from "../../../assets/chevron-left.svg"; |
5 | 6 | import { ServiceFactory } from "../../../factories/serviceFactory"; |
6 | 7 | import { NodeConfigService } from "../../../services/nodeConfigService"; |
7 | 8 | import { TangleService } from "../../../services/tangleService"; |
8 | 9 | import { Bech32AddressHelper } from "../../../utils/bech32AddressHelper"; |
| 10 | +import { FormatHelper } from "../../../utils/formatHelper"; |
9 | 11 | import AsyncComponent from "../../components/layout/AsyncComponent"; |
10 | 12 | import Spinner from "../../components/layout/Spinner"; |
11 | 13 | import Bech32Address from "../../components/tangle/Bech32Address"; |
12 | 14 | import Output from "../../components/tangle/Output"; |
| 15 | +import { ReactComponent as DropdownIcon } from "./../../../assets/dropdown-arrow.svg"; |
13 | 16 | import "./Address.scss"; |
14 | 17 | import { AddressRouteProps } from "./AddressRouteProps"; |
15 | 18 | import { AddressState } from "./AddressState"; |
@@ -44,6 +47,7 @@ class Address extends AsyncComponent<RouteComponentProps<AddressRouteProps>, Add |
44 | 47 | ...Bech32AddressHelper.buildAddress(props.match.params.address, this._bech32Hrp), |
45 | 48 | formatFull: false, |
46 | 49 | statusBusy: true, |
| 50 | + showTokens: false, |
47 | 51 | status: "Loading outputs..." |
48 | 52 | }; |
49 | 53 | } |
@@ -113,43 +117,83 @@ class Address extends AsyncComponent<RouteComponentProps<AddressRouteProps>, Add |
113 | 117 | <h3 className="secondary margin-l-s">Back to Explorer</h3> |
114 | 118 | </Link> |
115 | 119 | <div className="card margin-t-m padding-l"> |
116 | | - <h2>Address</h2> |
117 | | - <Bech32Address |
118 | | - activeLinks={false} |
119 | | - addressDetails={this.state.bech32AddressDetails} |
120 | | - /> |
121 | | - {this.state.balance !== undefined && ( |
122 | | - <div> |
123 | | - <div className="card--label"> |
124 | | - Balance |
| 120 | + <div className="card--content padding-0"> |
| 121 | + <h2>Address</h2> |
| 122 | + <Bech32Address |
| 123 | + activeLinks={false} |
| 124 | + addressDetails={this.state.bech32AddressDetails} |
| 125 | + /> |
| 126 | + {this.state.balance !== undefined && ( |
| 127 | + <div> |
| 128 | + <div className="card--label"> |
| 129 | + Balance |
| 130 | + </div> |
| 131 | + <div className="card--value card--value__mono"> |
| 132 | + <button |
| 133 | + className="card--value--button" |
| 134 | + type="button" |
| 135 | + onClick={() => this.setState( |
| 136 | + { |
| 137 | + formatFull: !this.state.formatFull |
| 138 | + } |
| 139 | + )} |
| 140 | + > |
| 141 | + {FormatHelper.getInstance().amount( |
| 142 | + Number(this.state.balance), |
| 143 | + this.state.formatFull |
| 144 | + )} |
| 145 | + </button> |
| 146 | + </div> |
| 147 | + {this.state.address?.nativeTokens && ( |
| 148 | + <React.Fragment> |
| 149 | + <div |
| 150 | + className="card--content__input margin-t-s" |
| 151 | + onClick={() => this.setState({ showTokens: !this.state.showTokens })} |
| 152 | + > |
| 153 | + <div className={classNames( |
| 154 | + "margin-r-t", |
| 155 | + "card--content__input--dropdown", |
| 156 | + { "opened": this.state.showTokens } |
| 157 | + )} |
| 158 | + > |
| 159 | + <DropdownIcon /> |
| 160 | + </div> |
| 161 | + <h3 className="card--content__input--label"> |
| 162 | + Native Tokens |
| 163 | + </h3> |
| 164 | + </div> |
| 165 | + {this.state.showTokens && |
| 166 | + Object.keys(this.state.address?.nativeTokens).map((key, idx) => ( |
| 167 | + <div className="card--content--border-l" key={idx}> |
| 168 | + <div className="card--label"> |
| 169 | + Token Id |
| 170 | + </div> |
| 171 | + <div className="card--value card--value__mono"> |
| 172 | + {key} |
| 173 | + </div> |
| 174 | + <div className="card--label"> |
| 175 | + Amount |
| 176 | + </div> |
| 177 | + <div className="card--value card--value__mono"> |
| 178 | + {this.state.address?.nativeTokens[key].toString()} |
| 179 | + </div> |
| 180 | + </div> |
| 181 | + ))} |
| 182 | + </React.Fragment> |
| 183 | + )} |
125 | 184 | </div> |
126 | | - <div className="card--value card--value__mono"> |
127 | | - <button |
128 | | - className="card--value--button" |
129 | | - type="button" |
130 | | - onClick={() => this.setState( |
131 | | - { |
132 | | - formatFull: !this.state.formatFull |
133 | | - } |
134 | | - )} |
135 | | - > |
136 | | - {this.state.formatFull |
137 | | - ? `${this.state.balance} i` |
138 | | - : UnitsHelper.formatBest(Number(this.state.balance))} |
139 | | - </button> |
| 185 | + )} |
| 186 | + {this.state.status && ( |
| 187 | + <div className="middle row margin-t-m"> |
| 188 | + {this.state.statusBusy && (<Spinner compact={true} />)} |
| 189 | + <p className="status margin-l-s"> |
| 190 | + {this.props.match.params.address} |
| 191 | + <br /> |
| 192 | + {this.state.status} |
| 193 | + </p> |
140 | 194 | </div> |
141 | | - </div> |
142 | | - )} |
143 | | - {this.state.status && ( |
144 | | - <div className="middle row margin-t-m"> |
145 | | - {this.state.statusBusy && (<Spinner compact={true} />)} |
146 | | - <p className="status margin-l-s"> |
147 | | - {this.props.match.params.address} |
148 | | - <br /> |
149 | | - {this.state.status} |
150 | | - </p> |
151 | | - </div> |
152 | | - )} |
| 195 | + )} |
| 196 | + </div> |
153 | 197 | </div> |
154 | 198 |
|
155 | 199 | {this.state.outputs && |
|
0 commit comments