-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
247 lines (194 loc) · 8.17 KB
/
index.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import React, { Component } from 'react';
import TronWeb from 'tronweb';
import {
FormattedMessage,
FormattedNumber
} from 'react-intl';
import * as Icons from 'components/Icons';
import Utils from 'extension/utils.js';
import './Transaction.css';
class Transaction extends Component {
formattedDate() {
const date = new Date(this.props.date);
return date.toLocaleDateString('en-us', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
renderIcon() {
switch(this.props.txType) {
case 'TransferContract':
return <Icons.TopRightArrow className={ this.props.isMine ? 'iconSent' : 'iconReceived' } />;
case 'TransferAssetContract':
return <Icons.TokensIcon className={ this.props.isMine ? 'iconSent' : 'iconReceived' } />;
case 'ParticipateAssetIssueContract':
return <Icons.TokensIcon className='iconToken' />;
case 'VoteWitnessContract':
return <Icons.VoteIcon className='iconToken vote' />;
case 'AssetIssueContract':
return <Icons.PencilIcon className='iconToken' />;
case 'FreezeBalanceContract':
case 'UnfreezeBalanceContract':
return <Icons.SnowIcon className='iconFreeze' />;
case 'CreateSmartContract':
return <Icons.SmartContractIcon className='smartContract' />;
case 'TriggerSmartContract':
return <Icons.TriggerSmartContractIcon className='smartContract triggerSmartContract' />;
default:
return null;
}
}
renderLabel() {
switch(this.props.txType) {
case 'TransferContract':
if(this.props.isMine)
return <div className='txLabel red'><FormattedMessage id='words.sent' /></div>;
return <div className='txLabel green'><FormattedMessage id='words.received' /></div>;
case 'TransferAssetContract':
if(this.props.isMine)
return <div className='txLabel red'><FormattedMessage id='words.sentToken' /></div>;
return <div className='txLabel green'><FormattedMessage id='words.receivedToken' /></div>;
case 'ParticipateAssetIssueContract':
return <div className='txLabel'><FormattedMessage id='words.purchasedToken' /></div>;
case 'VoteWitnessContract':
return <div className='txLabel vote'><FormattedMessage id='account.transactions.voted' /></div>;
case 'AssetIssueContract':
return <div className='txLabel'><FormattedMessage id='account.transactions.tokenCreation' /></div>;
case 'FreezeBalanceContract':
return <div className='txLabel red'><FormattedMessage id='account.transactions.frozen' /></div>;
case 'UnfreezeBalanceContract':
return <div className='txLabel green no-margin'><FormattedMessage id='account.transactions.unfrozen' /></div>;
case 'CreateSmartContract':
return <div className='txLabel smartContract no-margin'><FormattedMessage id='account.transactions.deployContract' /></div>;
case 'TriggerSmartContract':
return <div className='txLabel smartContract triggerSmartContract'><FormattedMessage id='account.transactions.triggerContract' /></div>;
default:
return null;
}
}
renderAddress() {
switch(this.props.txType) {
case 'TransferContract':
case 'TransferAssetContract':
if(this.props.isMine)
return this.props.toAddress;
return this.props.ownerAddress;
case 'TriggerSmartContract':
return Utils.transformAddress(
this.props.contractAddress
);
case 'AssetIssueContract':
return Utils.hexToString(
this.props.name
);
case 'FreezeBalanceContract':
return (
<FormattedMessage id='account.transactions.triggerContract.amount' values={{
days: this.props.raw.parameter.value.frozen_duration
}} />
);
case 'VoteWitnessContract':
return (
<FormattedMessage id='account.transactions.vote.amount' values={{
amount: this.props.raw.parameter.value.votes.length
}} />
);
case 'ParticipateAssetIssueContract':
return TronWeb.address.fromHex(this.props.raw.parameter.value.to_address);
case 'UnfreezeBalanceContract':
return null;
case 'CreateSmartContract':
return null;
default:
return 'Unknown address';
}
}
renderAmount() {
if(this.props.txType === 'AssetIssueContract') {
return (
<div className={ 'txAmount red' }>
- <FormattedNumber value={ 1024 } />
<span class='margin-left'>TRX</span>
</div>
);
}
const {
raw,
isMine,
amount
} = this.props;
const className = this.props.date ? '' : ' no-margin';
if(this.props.txType == 'TransferContract') {
return (
<div className={ 'txAmount ' + (isMine ? 'red' : 'green') + className }>
{ isMine ? '- ' : '+ ' }
<FormattedNumber value={ Utils.sunToTron(amount) } minimumFractionDigits={ 0 } maximumFractionDigits={ 8 } />
<span className='margin-left'>TRX</span>
</div>
);
}
if(this.props.txType == 'VoteWitnessContract') {
return (
<div className={ 'txAmount red' + className }>
- <FormattedNumber value={ this.props.raw.parameter.value.votes.reduce((total, vote) => total + vote.vote_count, 0) } />
<span className='margin-left'>TP</span>
</div>
)
}
if(this.props.txType == 'FreezeBalanceContract') {
return (
<div className={ 'txAmount red' + className }>
- <FormattedNumber value={ this.props.raw.parameter.value.frozen_balance } />
<span className='margin-left'>TRX</span>
</div>
)
}
if(this.props.txType == 'ParticipateAssetIssueContract') {
return (
<div className={ 'txAmount green' + className }>
+ <FormattedNumber value={ this.props.raw.parameter.value.amount } />
<span className='margin-left'>
{ Utils.hexToString(raw.parameter.value.asset_name) }
</span>
</div>
)
}
if(!amount)
return null;
return (
<div className={ 'txAmount ' + (isMine ? 'red' : 'green') + className }>
{ isMine ? '- ' : '+ ' }
<FormattedNumber value={ amount } maximumFractionDigits={ 0 } />
<span class='margin-left'>
{ Utils.hexToString(raw.parameter.value.asset_name) }
</span>
</div>
);
}
render() {
const ignored = [
'AccountUpdateContract'
];
if(ignored.includes(this.props.txType))
return null;
return (
<div className='transaction'>
{ this.renderIcon() }
<div className='txInfoLeft'>
{ this.renderLabel() }
<div className='txAddress'>
{ this.renderAddress() }
</div>
</div>
<div className='txInfoRight'>
{ this.renderAmount() }
{ this.props.date && <div className='txDate'>
{ this.formattedDate() }
</div> }
</div>
</div>
);
}
}
export default Transaction;