-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
127 lines (127 loc) · 2.96 KB
/
App.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React, { Component } from 'react'
import getAppName from './apps'
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
data: [],
page: 1,
}
}
componentDidMount() {
this.handlePage(1)
}
handlePage(page) {
if (page === '<<') {
page = 1
} else if (page === '>>') {
page = this.props.txs.length / 20
}
const offset = 20 * page
this.setState(state => {
state.page = page
state.data = this.props.txs.slice(offset - 20, offset - 1)
return state
})
}
content() {
const txs = this.state.data
let items = txs
.map(tx => {
return tx.out.filter(xput => xput.o1 === 'OP_RETURN').map(xput => {
console.log('tx.blk', tx.blk)
xput.h = tx.tx.h
xput.blk = tx.blk.i
return xput
})
})
items = items.flat().map(xput => {
const app = getAppName(xput.s2)
if (app === 'other') {
console.log('### app not detected', xput.s2)
}
return ({
s: xput.s2,
h: xput.h,
a: app,
blk: xput.blk
})
})
.map((tx, i) => {
const color = i % 2 === 0 ? '#dddddd' : 'white'
return (
<tr
style={{ backgroundColor: color }}
>
<td style={styles.cell}>{tx.blk}</td>
<td style={styles.cell}>{tx.h}</td>
<td style={styles.cell}>{tx.s}</td>
<td style={styles.cell}>{tx.a}</td>
</tr>
)
})
return items
}
footer() {
const idx = this.state.page
let pages = []
let left = idx - 4
if (left <= 0) left = 1
let right = idx + 4
if (right > Math.floor(this.props.txs.length / 20)) {
right = Math.floor(this.props.txs.length / 20)
}
for (let i = left; i < right; i++) {
pages.push(i)
}
pages.unshift('<<')
pages.push('>>')
return pages.map((page, i) => {
return <button onClick={() => this.handlePage(page)} key={i}>{page}</button>
})
}
render() {
return (
<div style={styles.container}>
<table>
<thead>
<tr>
<td style={styles.cell}>block</td>
<td style={styles.cell}>hash</td>
<td style={styles.cell}>id</td>
<td style={styles.cell}>name</td>
</tr>
</thead>
<tbody>
{this.content()}
</tbody>
</table>
<div style={styles.footer}>
{this.footer()}
</div>
</div>
)
}
}
const styles = {
container: {
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'column',
},
footer: {
display: 'flex',
flexDirection: 'row',
width: 400,
margin: 5,
justifyContent: 'space-between',
},
cell: {
paddingLeft: 5,
paddingRight: 5,
height: 30,
}
}