Repository navigation
Expand file tree
/
Copy pathwallet.jsx
More file actions
73 lines (67 loc) · 2 KB
/
Copy pathwallet.jsx
File metadata and controls
73 lines (67 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var React = require('react');
var ReactDOM = require('react-dom');
// Components
var EnterPrivateSeed = require('./components/EnterPrivateSeed.jsx');
var WalletRouter = require('./components/WalletRouter.jsx');
//Stores
var WalletStore = require('./stores/WalletStore');
//Actions
var ColuActions = require('./actions/ColuActions');
//Create the wallet
var Wallet = React.createClass({
getInitialState: function () {
return {
privateSeed: null,
assets: [],
error: null,
sentAsset: 0,
assetIdsForAddress: [],
updatedStatus: null,
hasWallet: localStorage.getItem('privateSeed')
};
},
componentWillMount: function() {
var currentPrivateSeed = localStorage.getItem('privateSeed');
//Initialize Colu, remember while this action is running you cannot dispatch another action (this will produce an error)
if (currentPrivateSeed) {
ColuActions.coluInit(currentPrivateSeed);
}
},
componentDidMount: function() {
//subscribe to the store
WalletStore.listen(this.onChange);
},
onChange: function(state) {
//Update this component's state with what's in the WalletSore
this.setState(state);
},
componentWillUnmount: function() {
//Stop updating component's state once it's not active
WalletStore.unlisten(this.onChange);
},
render: function() {
if (this.state.privateSeed) {//Returning user (because initialized with currentPrivateSeed): When colu is ready return the wallet content
return (
<div>
<EnterPrivateSeed />
<div className="wallet-main" >
<div className="private-seed">{this.state.privateSeed}</div>
<WalletRouter />
</div>
</div>
);
} else if (this.state.hasWallet) {//Returning user but colu is not ready yet, display loading
return (
<div>
<EnterPrivateSeed />
<p style={{textAlign:'center', color: '#4dd9b4'}}>loading...</p>
</div>
);
} else {//New user: display the enter private seed form only
return(
<EnterPrivateSeed />
);
}
}
});
ReactDOM.render(<Wallet />, document.getElementById('display'));