Skip to content

Commit a9dcd36

Browse files
committed
feat(token): Added token view to the app
1 parent bc74b76 commit a9dcd36

File tree

12 files changed

+462
-51
lines changed

12 files changed

+462
-51
lines changed

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"react": "^16.12.0",
2121
"react-dom": "^16.12.0",
2222
"react-helmet": "^6.0.0",
23+
"react-jdenticon": "0.0.8",
2324
"react-qr-reader": "^2.2.1",
2425
"react-redux": "^7.2.0"
2526
},

src/components/admin-lte/admin-lte.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
text-transform: lowercase;
3232
}
3333
.components-container{
34-
min-height: calc(100vh - 100px);
34+
min-height: calc(100vh - var(--footer-height) - 50px);
3535
}
3636

3737
.sidebar-toggle:hover{

src/components/admin-lte/icons/index.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/components/admin-lte/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react"
22
import PropTypes from "prop-types"
33
import Audit from "./audit"
44
import Configure from "./configure"
5-
import Tokens from "./icons"
5+
import Tokens from "./tokens"
66
import Wallet from "./wallet"
77

88
import AdminLTE, { Sidebar, Navbar } from "adminlte-2-react"
@@ -71,7 +71,11 @@ class AdminLTEPage extends React.Component {
7171
setBchWallet={_this.props.setBchWallet}
7272
/>
7373
)}
74-
{_this.state.section === "Tokens" && <Tokens />}
74+
{_this.state.section === "Tokens" &&
75+
<Tokens
76+
walletInfo={_this.props.walletInfo}
77+
bchWallet={_this.props.bchWallet} />
78+
}
7579
{_this.state.section === "Configure" && (
7680
<Configure
7781
walletInfo={_this.props.walletInfo}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
import { Content, Row, Col, Box } from "adminlte-2-react"
4+
import TokenCard from "./token-card"
5+
import TokenModal from "./token-modal"
6+
import Spinner from "../../../images/loader.gif"
7+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
8+
9+
let _this
10+
class Tokens extends React.Component {
11+
constructor(props) {
12+
super(props)
13+
_this = this
14+
this.state = {
15+
tokens: [],
16+
selectedToken: "",
17+
showModal: false,
18+
inFetch: true,
19+
onEmptyTokensMsg: "No tokens found on this wallet..",
20+
}
21+
}
22+
23+
render() {
24+
const { JWT } = _this.props.walletInfo
25+
26+
return (
27+
<>
28+
{_this.state.inFetch ? (
29+
<div className="spinner">
30+
<img alt="Loading..." src={Spinner} width={100} />
31+
</div>
32+
) : (
33+
<Content>
34+
{!JWT && (
35+
<Box padding="true" className="container-nofound">
36+
<Row>
37+
<Col xs={12}>
38+
<FontAwesomeIcon
39+
className="icon btn-animation"
40+
size="lg"
41+
icon={"exclamation-triangle"}
42+
/>
43+
</Col>
44+
45+
<Col xs={12}>
46+
<em>
47+
You don't have a registered JWT, you could encounter
48+
errors viewing some of your tokens.
49+
</em>
50+
</Col>
51+
</Row>
52+
</Box>
53+
)}
54+
<br></br>
55+
{!_this.state.tokens.length && (
56+
<Box padding="true" className="container-nofound">
57+
<Row>
58+
<Col xs={12}>
59+
<em>{_this.state.onEmptyTokensMsg}</em>
60+
</Col>
61+
</Row>
62+
</Box>
63+
)}
64+
{_this.state.tokens.length && (
65+
<Row>
66+
{_this.state.tokens.map((val, i) => {
67+
return (
68+
<Col sm={4} key={`token-${i}`}>
69+
<TokenCard
70+
key={`token-${i}`}
71+
id={`token-${i}`}
72+
token={val}
73+
showToken={_this.showToken}
74+
/>
75+
</Col>
76+
)
77+
})}
78+
</Row>
79+
)}
80+
</Content>
81+
)}
82+
<TokenModal
83+
token={_this.state.selectedToken ? _this.state.selectedToken : {}}
84+
onHide={_this.toggleModal}
85+
show={_this.state.showModal}
86+
/>
87+
</>
88+
)
89+
}
90+
async componentDidMount() {
91+
const { mnemonic } = _this.props.walletInfo
92+
const bchWallet = _this.props.bchWallet
93+
let tokens = []
94+
let { onEmptyTokensMsg } = _this.state
95+
96+
if (mnemonic && bchWallet) {
97+
98+
try {
99+
await bchWallet.walletInfoPromise
100+
tokens = await bchWallet.listTokens()
101+
} catch (error) {
102+
console.error(error)
103+
if (error.error.match("rate limits")) onEmptyTokensMsg = error.error
104+
}
105+
} else {
106+
onEmptyTokensMsg =
107+
"You need to create or import a wallet first, to view tokens"
108+
}
109+
110+
111+
_this.setState({
112+
tokens,
113+
inFetch: false,
114+
onEmptyTokensMsg,
115+
})
116+
}
117+
showToken(selectedToken) {
118+
console.log("selectedToken", selectedToken)
119+
_this.setState({
120+
selectedToken,
121+
})
122+
_this.toggleModal()
123+
}
124+
toggleModal() {
125+
_this.setState({
126+
showModal: !_this.state.showModal,
127+
})
128+
}
129+
}
130+
Tokens.propTypes = {
131+
walletInfo: PropTypes.object.isRequired, // wallet info
132+
bchWallet: PropTypes.object, // get minimal-slp-wallet instance
133+
}
134+
export default Tokens
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
import { Row, Col, Box, Button } from "adminlte-2-react"
4+
import Jdenticon from "react-jdenticon"
5+
import "./token.css"
6+
let _this
7+
class TokenCard extends React.Component {
8+
constructor(props) {
9+
super(props)
10+
_this = this
11+
this.state = {}
12+
}
13+
render() {
14+
const token = _this.props.token
15+
return (
16+
<>
17+
<Box className="hover-shadow border-none mt-2" id="token-card">
18+
<Row className="text-center">
19+
<Col sm={12} className="text-center mt-2 ">
20+
<Jdenticon size="100" value={token.tokenId} />
21+
<hr></hr>
22+
</Col>
23+
<Col sm={12} className="flex justify-content-center ">
24+
<div className="info-container">
25+
<p className="info-content">
26+
<b>Ticker: </b>
27+
<span> {token.ticker}</span>
28+
</p>
29+
<p className="info-content">
30+
<b>Name: </b>
31+
<span>{token.name}</span>
32+
</p>
33+
34+
<p className="info-content">
35+
<b>Balance</b>
36+
<span>{token.qty}</span>
37+
</p>
38+
</div>
39+
</Col>
40+
41+
<Col sm={12} className="text-center ">
42+
<Button
43+
text="Show Token"
44+
type="primary"
45+
className="btn-lg"
46+
onClick={() => {
47+
_this.props.showToken(token)
48+
}}
49+
/>
50+
</Col>
51+
</Row>
52+
</Box>
53+
</>
54+
)
55+
}
56+
shouldComponentUpdate() {
57+
return false
58+
}
59+
}
60+
TokenCard.propTypes = {
61+
token: PropTypes.object.isRequired,
62+
showToken: PropTypes.func.isRequired,
63+
}
64+
export default TokenCard

0 commit comments

Comments
 (0)