-
Notifications
You must be signed in to change notification settings - Fork 0
/
quick-try.js
123 lines (111 loc) · 2.29 KB
/
quick-try.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
import * as React from 'react';
import {
render,
Message,
TextBlock,
Blocks,
Section,
Fields,
TextField,
Divider,
} from './src';
import createAxiosEngine from './src/engines/slack-axios';
function EtherscanLink({ tx }) {
return (
<Section>
<TextBlock>
<b>Transaction</b>
<br />
<a href={`https://www.etherscan.io/tx/${tx}`}>{tx}</a>
</TextBlock>
</Section>
);
}
class TransactionStatus extends React.Component {
state = {
confirmations: 28,
needed: 30,
};
timerID = undefined;
componentDidMount() {
if (this.state.confirmations < this.state.needed) {
this.timerID = setInterval(() => {
this.setState({
confirmations: this.state.confirmations + 1,
});
}, 3000);
}
}
componentWillUnmount() {
clearInterval(this.timerID);
}
render() {
const { confirmations } = this.state;
const status =
this.state.confirmations === this.state.needed ? 'Confirmed' : 'Pending';
if (status === 'Confirmed') {
clearInterval(this.timerID);
}
return (
<Section>
<Fields>
<TextField>
<span>
<b>Status</b>
<br />
{status}
</span>
</TextField>
<TextField>
<span>
<b>Confirmations</b>
<br />
{confirmations} / 30
</span>
</TextField>
</Fields>
</Section>
);
}
}
class StatefulMessage extends React.Component {
state = {
text: 'The Transaction is processing.',
};
componentDidMount() {
setTimeout(() => {
this.setState({
text: 'Changed',
});
}, 3000);
}
render() {
return (
<Section>
<TextBlock>{this.state.text}</TextBlock>
</Section>
);
}
}
function MyMessage({ tx }) {
return (
<Message channel="monitoring">
<Blocks>
<StatefulMessage />
<Divider />
<EtherscanLink tx={tx} />
<TransactionStatus tx={tx} />
<Divider />
</Blocks>
</Message>
);
}
render(
<MyMessage tx="0x822846e2d067847656f6ac3ea701fe1a1917c50053dd426ab793c1decaa910b5" />,
{
id: 'my-renderer-id',
engine: createAxiosEngine({
oauth_token: '<token>',
}),
},
);