|
1 | 1 | import React, { Component } from 'react';
|
2 |
| -import logo from './logo.svg'; |
| 2 | +import OCAPClient from '@arcblock/ocap-js'; |
| 3 | +import Layout from './components/Layout/'; |
| 4 | + |
3 | 5 | import './App.css';
|
4 | 6 |
|
5 | 7 | class App extends Component {
|
| 8 | + constructor(props) { |
| 9 | + super(props); |
| 10 | + this.state = { |
| 11 | + address: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', |
| 12 | + summary: null, |
| 13 | + loading: false, |
| 14 | + }; |
| 15 | + |
| 16 | + this.client = new OCAPClient({ |
| 17 | + dataSource: 'btc', |
| 18 | + httpBaseUrl: 'http://47.104.23.85:8080/api', // for dev in china |
| 19 | + // httpBaseUrl: 'https://ocap.arcblock.io/api', // for production |
| 20 | + enableSubscription: false, |
| 21 | + enableMutation: false, |
| 22 | + }); |
| 23 | + } |
| 24 | + |
| 25 | + async componentDidMount() { |
| 26 | + this.setState({ loading: true }); |
| 27 | + |
| 28 | + const summary = await this.client.accountByAddress({ |
| 29 | + address: this.state.address, |
| 30 | + }); |
| 31 | + |
| 32 | + this.setState({ loading: false, summary }); |
| 33 | + } |
| 34 | + |
6 | 35 | render() {
|
| 36 | + const { loading, summary, address } = this.state; |
| 37 | + |
7 | 38 | return (
|
8 |
| - <div className="App"> |
9 |
| - <header className="App-header"> |
10 |
| - <img src={logo} className="App-logo" alt="logo" /> |
11 |
| - <h1 className="App-title">Welcome to React</h1> |
12 |
| - </header> |
13 |
| - <p className="App-intro"> |
14 |
| - To get started, edit <code>src/App.js</code> and save to reload. |
| 39 | + <Layout> |
| 40 | + <h2>OCAP Data Fetching Demo</h2> |
| 41 | + {loading && ( |
| 42 | + <p>Loading account summary for Bitcoin Address: {address}</p> |
| 43 | + )} |
| 44 | + {loading || ( |
| 45 | + <div className="App-json"> |
| 46 | + <p>Account summary for Bitcoin account: {address}</p> |
| 47 | + <pre> |
| 48 | + <code>{JSON.stringify(summary, true, ' ')}</code> |
| 49 | + </pre> |
| 50 | + </div> |
| 51 | + )} |
| 52 | + <h2>Building your own DApp</h2> |
| 53 | + <p> |
| 54 | + Edit <code>src/App.js</code> and save to reload. |
15 | 55 | </p>
|
16 |
| - </div> |
| 56 | + </Layout> |
17 | 57 | );
|
18 | 58 | }
|
19 | 59 | }
|
|
0 commit comments