A simple deposit and profit bytom dapp demo
Revision | 4f7638eef514506b9ef927078700c163c051f775 (tree) |
---|---|
Time | 2019-07-22 14:57:36 |
Author | Zhiting Lin <zlin035@uott...> |
Commiter | Zhiting Lin |
fixed the account referesh error.
@@ -15,13 +15,13 @@ import GetContractArgs from "./constants"; | ||
15 | 15 | import Bytom from 'bytom-js-sdk' |
16 | 16 | |
17 | 17 | class App extends Component { |
18 | - componentDidMount(){ | |
18 | + componentWillMount(){ | |
19 | 19 | const { bytom, setBytom } = this.props; |
20 | 20 | if(!bytom){ |
21 | 21 | document.addEventListener('chromeBytomLoaded', bytomExtension => { |
22 | 22 | const bytom = window.bytom; |
23 | - setBytom(bytom); | |
24 | 23 | this.bytomLoaded(bytom); |
24 | + setBytom(bytom); | |
25 | 25 | }); |
26 | 26 | }else { |
27 | 27 | this.bytomLoaded(bytom); |
@@ -38,13 +38,14 @@ class App extends Component { | ||
38 | 38 | |
39 | 39 | try { |
40 | 40 | const BYTOM_ACCOUNT = await bytom.enable() |
41 | - this.props.updateConnection(true) | |
42 | 41 | |
43 | 42 | const bytomAPI = new Bytom(networks, '') |
44 | 43 | bytomAPI.setNetType(bytom.net) |
45 | 44 | |
46 | 45 | global.bytomAPI = bytomAPI |
47 | 46 | |
47 | + this.props.updateConnection(true) | |
48 | + | |
48 | 49 | // Check to see if the user has signed in/out of their |
49 | 50 | // bytom wallet or switched accounts |
50 | 51 | let accountInterval = setInterval(function () { |
@@ -27,7 +27,9 @@ class Account extends Component { | ||
27 | 27 | const account = bytom.default_account |
28 | 28 | this.setState({ account }) |
29 | 29 | if(account){ |
30 | - this.props.updateBalances(account.accountId) | |
30 | + if(global.bytomAPI){ | |
31 | + this.props.updateBalances(account.accountId) | |
32 | + } | |
31 | 33 | this.listBalance(account, GetContractArgs().assetDeposited) |
32 | 34 | } |
33 | 35 | } |