-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathApp.js
1375 lines (1216 loc) · 36.3 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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React from 'react';
import { StyleSheet, Text, View, TextInput, Button, TouchableOpacity, AsyncStorage, FlatList, Picker, Keyboard, Alert, Platform, RefreshControl, ScrollView, Linking, StatusBar } from 'react-native';
import autobind from 'autobind-decorator'
import { StackNavigator } from 'react-navigation';
import {VertPercentBar,HorizPercentBar} from './js/percent-bar';
//style sheet resource info
themeColor = '#2196F3';
const styles = StyleSheet.create({
centerText: {
textAlign: 'center',
},
cardTextInput: {
height: (Platform.OS == 'android' ? 40 : 20),
},
headerTouchableText: {
marginLeft: 20,
marginRight: 20,
color: themeColor,
},
cardText: {
margin: 5,
padding: 0,
fontSize: 15,
},
cardItem: {
margin: 10,
marginBottom: 0,
padding: 10,
backgroundColor: 'white',
borderRadius: 5,
},
cardItemHeading: {
textAlign: 'center',
padding: 2,
color: themeColor,
fontSize: 20,
},
homeAddressItemHeading: {
textAlign: 'center',
padding: 2,
color: themeColor,
fontSize: 20,
},
homeAddressItemText: {
textAlign: 'center',
padding: 2,
color: 'black',
fontSize: 15,
},
button: {
marginTop: 20,
margin: 10,
alignItems: 'center',
backgroundColor: themeColor,
borderRadius: 5
},
buttonText: {
padding: 5,
color: 'white',
fontSize: 20
},
avgHashBar: {
backgroundColor: themeColor,
borderRadius: 5,
},
nowHashBar: {
backgroundColor:'#7bdb78',
borderRadius: 5,
},
repHashBar: {
backgroundColor: '#888b91',
borderRadius: 5,
},
hashBarBG: {
backgroundColor:'white'
},
hourPickerButton: {
borderRadius: 5,
margin: 5,
backgroundColor: 'white',
borderColor: themeColor,
borderWidth: 2,
alignItems: 'center',
},
hourPickerButtonSelected: {
borderRadius: 5,
margin: 5,
backgroundColor: themeColor,
borderColor: themeColor,
borderWidth: 2,
alignItems: 'center',
},
hourPickerButtonText:{
alignSelf: 'center',
color: themeColor,
fontSize: 15,
textAlign: 'center',
margin: 8,
},
hourPickerButtonTextSelected:{
alignSelf: 'center',
color: 'white',
fontSize: 15,
textAlign: 'center',
margin: 8,
},
githubLink: {
textAlign: 'center',
color: themeColor,
textDecorationLine: 'underline',
},
headingLinkText: {
fontSize: 18,
color: themeColor,
marginLeft: 10,
},
infoText: {
textAlign: 'center',
padding: 10,
fontSize: 16,
},
infoTextTitle: {
textAlign: 'center',
padding: 10,
fontSize: 20,
},
infoLink: {
textAlign: 'center',
color: themeColor,
textDecorationLine: 'underline',
fontSize: 16,
padding: 10,
},
});
const HashrateUnits = {
ETH: 'Mh/s',
SIA: 'Mh/s',
ETC: 'Mh/s',
ZEC: 'Sol/s',
XMR: 'H/s',
PASC: 'MH/s',
}
const HashrateShareFactors = {
ETH: 8.5,
SIA: 86,
ETC: 8.5,
ZEC: 5.64,
XMR: 53,
PASC: 58,
}
class HomeScreen extends React.Component {
constructor(props){
super(props);
this.state = {
pairs: null,
};
}
static navigationOptions = ({navigation}) => ({
headerLeft: <TouchableOpacity onPress={()=>navigation.navigate('Info')}><Text style={styles.headingLinkText}>Info</Text></TouchableOpacity>,
});
/** Show help information
*/
showHelp(){
this.props.navigation.navigate('Info');
}
@autobind
fetchData(){
var eth_adds = [];
if(this.state.pairs){
//get all the ETH addresses
for(var i = 0; i<this.state.pairs.length; i++){
//once per pair
if(this.state.pairs[i].cryptocurrency == 'ETH' && this.state.pairs[i].address){
eth_adds.push(this.state.pairs[i].address);
}
}
//API limit of 20 per query
if(eth_adds.length > 20){
eth_adds = eth_adds.slice(0,20);
}
eth_adds_string = eth_adds.join(',');
//console.log('adds str' + eth_adds_string);
try{
fetch('https://api.etherscan.io/api?module=account&action=balancemulti&address=' + eth_adds_string + '&tag=latest&apikey=B1M9IPTS83TC4IAMD7F8ESWMTA8MR3VZ8M')
.then((response) => {
try{
r = response.json();
return r;
}catch(e){
console.log(e);
}
})
.then((responseJson) => {
p = this.state.pairs;
try{
this.addBalanceData(responseJson.result);
}catch(e){
console.log(e);
}
})
.catch((error) => {
console.error(error);
}
);
} catch(e){
console.log('Error parsing JSON for balance data');
}
}
}
@autobind
addBalanceData(data){
if(data){
data.forEach((entry) => {
balance = data ? entry.balance : 'No balance found';
address = data ? entry.account : null;
//console.log('adding balance for ' + address + ' as ' + balance);
p = this.state.pairs;
for(var i = 0; i<p.length; i++){
//once per pair
if(p[i].address === address){
//add address to the pair object in the pairs array
p[i].balance = balance;
}
}
this.setState({
pairs: p,
});
})
}
}
componentDidMount(){
//detect first launch
/** thanks to https://stackoverflow.com/questions/40715266/how-to-detect-first-launch-in-react-native */
AsyncStorage.getItem("alreadyLaunched").then(value => {
if(value == null){
//set launched flag
AsyncStorage.setItem('alreadyLaunched', '1');
//add the Demo address to the list if the address list is blank
AsyncStorage.getItem('@DatStore:addresses')
.then((add) => {
if(add == null || add.length < 1){
//sample address data array
d = [{
cryptocurrency: 'ETH',
address: '0xb576c106e18bc53a0294097b4fe9a525ec38ea5f',
name: 'Demo',
}];
//if the address list is blank
AsyncStorage.setItem('@DatStore:addresses',JSON.stringify(d));
//put the pairs into the array
this.setState({
pairs: d,
});
}
}).catch(error => {
console.log(error);
});
//show help first time
//this.showHelp();
}
});
//get the currency pairs
this.loadPairs().then(() =>{
//after pairs are loaded
this.fetchData()
});
}
loadPairs() {
return AsyncStorage.getItem('@DatStore:addresses')
.then((pp) => {
this.setState({
pairs: JSON.parse(pp)
},(e)=>{
//do nothing about the errors here
});
});
}
@autobind
promptDeletePair(pair) {
Alert.alert(
'Delete Address?',
pair.name + '\n'
+ pair.cryptocurrency + '\n'
+ pair.address,
[
{text: 'Yes', onPress: () => this.deletePair(pair)},
{text: 'No'}
],
)
}
deletePair(pair) {
AsyncStorage.getItem('@DatStore:addresses')
.then(async (pairs) => {
//parse strigified object
data = JSON.parse(pairs);
testFunc = (p) => {
if(
p.address == pair.address &&
p.name == pair.name &&
p.cryptocurrency == pair.cryptocurrency){
return true;
}
return false;
};
//find the entry to delete
toDeleteIndex = data.findIndex(testFunc);
//remove the long pressed and confirmed entry
data.splice(toDeleteIndex,1);
try{
//update the stored pair list
AsyncStorage.setItem('@DatStore:addresses',JSON.stringify(data)).then((f) =>{
//reload the list of entries
this.loadPairs();
});
}catch(e){
console.log('Failed to delete pair');
}
});
}
@autobind
navToAddressStats(pair){
const { navigate } = this.props.navigation;
navigate('AddressStats',pair);
}
@autobind
_onRefresh(){
console.log('tryna refresh');
this.fetchData();
}
render() {
const { navigate } = this.props.navigation;
return (
<View style={{flex:1, justifyContent: 'center'}}>
<StatusBar
barStyle={(Platform.OS === 'ios')?'dark-content':'dark-content'}
backgroundColor="white"
/>
<View style={{flex:2, justifyContent: 'center'}}>
<TouchableOpacity onPress={() => navigate('NewAddress')}>
<View style={styles.button}>
<Text style={styles.buttonText}>New Address</Text>
</View>
</TouchableOpacity>
</View>
<View style={{flex: 20,}}>
<AddressList style={{flex: 9,}}
data={this.state.pairs}
extraData={this.state}
onPressItem={this.navToAddressStats}
onLongPressItem={this.promptDeletePair}
onRefresh={this._onRefresh}
/>
</View>
<View style={{flex:1}}>
<Text onPress={() => Linking.openURL('http://www.github.com/david340804/nanostats')} style={styles.githubLink}>{'Peep the Github'}</Text>
</View>
</View>
);
}
}
class NewAddressScreen extends React.Component {
static navigationOptions = {
title: 'New Address',
};
constructor(props){
super(props);
this.state = {newAddress: null,cryptocurrency: 'ETH',name:null};
}
componentDidMount(){
this.loadAddresses();
}
loadAddresses() {
return AsyncStorage.getItem('@DatStore:addresses')
.then((add) => {
this.setState({
addresses: add
},(e)=>{
//do nothing about the errors here
});
}).catch(error => {
this.setState({
addresses: []
});
});
}
saveNewAddressAndHome() {
const { navigate } = this.props.navigation
AsyncStorage.getItem('@DatStore:addresses')
.then(async (pairs) => {
//parse strigified object
data = JSON.parse(pairs);
//the new currency-address pair
//take everything after last slash
var parsed;
try{
var n = this.state.newAddress.lastIndexOf('/');
parsed = this.state.newAddress.substring(n + 1);
}catch(e){
console.log('Error parsing new address string')
console.log(e);
}
if (! parsed){
//invalid address
//alert invalid address
return
}
newPair = {cryptocurrency: this.state.cryptocurrency,address: (parsed == -1)? this.state.newAddress: parsed,name: this.state.name};
//if there is already a pair array
if(data){
//append the new pair to the end
try {
data.push(newPair);
}catch (e){
console.log('Failed to append new data pair');
}
}else{
//no data, make the array
data=[newPair];
}
try{
//update the stored pair list
await AsyncStorage.setItem('@DatStore:addresses',JSON.stringify(data));
//go back home
navigate('Home');
//dismiss the keyboard
try {
Keyboard.dismiss();
}catch(e){
console.log('Failed to dismiss Keyboard');
}
}catch(e){
console.log('Failed to store updated addresses or navigate to Home');
}
});
}
render() {
return (
<View style={{flex:1, }}>
<View style={styles.cardItem}>
<TextInput
style={styles.cardText, styles.cardTextInput}
placeholder={'Account Nickname'}
onChangeText={(name) => this.setState({'name': name})}
/>
<Picker
selectedValue={this.state.cryptocurrency}
onValueChange={(itemValue,itemIndex) => this.setState({'cryptocurrency': itemValue})}>
<Picker.Item label={'Ethereum'} value={'ETH'}/>
<Picker.Item label={'Siacoin'} value={'SIA'}/>
<Picker.Item label={'Ethereum Classic'} value={'ETC'}/>
<Picker.Item label={'ZCash'} value={'ZEC'}/>
<Picker.Item label={'Monero'} value={'XMR'}/>
<Picker.Item label={'Pascal'} value={'PASC'}/>
</Picker>
<TextInput
style={styles.cardText, styles.cardTextInput}
placeholder={'Address or Nanopool URL'}
onChangeText={(address) => this.setState({'newAddress': address})}
onSubmitEditing={() => this.saveNewAddressAndHome()}
/>
</View>
<View style={styles.homeNewAddressButton}>
<TouchableOpacity onPress={() => this.saveNewAddressAndHome()}>
<View style={styles.button}>
<Text style={styles.buttonText}>Add Address</Text>
</View>
</TouchableOpacity>
</View>
</View>
);
}
}
class InfoScreen extends React.Component {
goHome(){
this.props.navigation.navigate('Home');
}
render() {
return (
<View style={{flex:1, }}>
<View style={styles.cardItem}>
<Text style={styles.infoTextTitle}>Thanks for downloading NanoStats!</Text>
<Text style={styles.infoText}>Feel free to check out the Demo address before adding your own :)</Text>
<Text style={styles.infoText}>To delete an address, long press its entry on the main NanoStats screen</Text>
<Text style={styles.infoText}>Powered by Etherscan.io APIs</Text>
<Text style={styles.infoText}>Feedback? Suggestions?</Text>
<Text style={styles.infoText}>Please hit me up at</Text>
<Text onPress={() => Linking.openURL('mailto:[email protected]')} style={styles.infoLink}>{'[email protected]'}</Text>
<Text style={styles.infoText}>Or drop an issue on the</Text>
<Text onPress={() => Linking.openURL('http://www.github.com/david340804/nanostats')} style={styles.infoLink}>{'NanoStats Github'}</Text>
<Text style={styles.infoText}>To see this again, press "Info" in the Top Left</Text>
</View>
</View>
)
}
}
/**
<TouchableOpacity onPress={() =>this.goHome()}>
<View style={styles.button}>
<Text style={styles.buttonText}>Dismiss</Text>
</View>
</TouchableOpacity>
*/
class AddressListItem extends React.PureComponent {
_onPress = () => {
this.props.onPressItem(this.props.item);
};
_onLongPress = () => {
this.props.onLongPressItem(this.props.item);
};
render() {
return (
<TouchableOpacity
onPress={this._onPress}
onLongPress={this._onLongPress}>
<View style={styles.cardItem}>
<Text style={styles.homeAddressItemHeading}>{this.props.item.name + ' : ' + this.props.item.cryptocurrency}</Text>
{this.props.item.cryptocurrency == 'ETH' ? <Text style={styles.homeAddressItemText}>{this.props.balance ? 'Wallet Balance: ' + wei2Rounded(this.props.balance,4) : '...'}</Text> : null}
<Text style={styles.homeAddressItemText}>{this.props.item.address}</Text>
</View>
</TouchableOpacity>
)
}
}
class AddressList extends React.PureComponent {
state = {
selected: (new Map(): Map<string, boolean>),
refreshing: false,
};
_keyExtractor = (item, index) => item.address;
_onPressItem = (pair) => {
this.props.onPressItem(pair);
};
_onLongPressItem = (pair) => {
this.props.onLongPressItem(pair);
};
_onRefresh() {
this.setState({refreshing: true});
this.props.onRefresh();
//fetchData().then(() => {
this.setState({refreshing: false});
//});
}
_renderItem = ({item}) => (
<AddressListItem
props={item}
item={item}
balance={item.balance}
onPressItem={this._onPressItem}
onLongPressItem={this._onLongPressItem}
selected={!!this.state.selected.get(item.id)}
/>
);
render() {
return (
<FlatList
data={this.props.data}
extraData={this.state}
keyExtractor={this._keyExtractor}
renderItem={this._renderItem}
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh.bind(this)}
/>
}
/>
);
}
}
class AddressStatsScreen extends React.Component {
static navigationOptions = ({navigation}) => ({
title: `${navigation.state.params.cryptocurrency + ' : ' + navigation.state.params.name}`,
});
constructor(props){
super(props);
this.state = {
balance: '...',
avghashrate: null,
accountData: {},
currentHashratePercent: 0.0,
workers: [],
cryptocurrency: '',
address: '',
chartData: [],
miningChartHours: 12,
miningChartBars: 12,
};
}
componentDidMount(){
this.fetchInfo();
//import the nav states to the main state
const { params } = this.props.navigation.state;
this.setState({
cryptocurrency: params.cryptocurrency,
address: params.address,
});
}
fetchInfo() {
const { params } = this.props.navigation.state;
//fetch balance
fetch('https://api.nanopool.org/v1/' + params.cryptocurrency.toString().toLowerCase() + '/balance/' + params.address.toString())
.then((response) => response.json())
.then((responseJson) => {
this.setState({
//update the balance state
balance: responseJson.data ? responseJson.data : 'Account not found',
}, function() {
// do something with new state
});
//got the balance
})
.catch((error) => {
console.error(error);
});
//fetch user overview data
fetch('https://api.nanopool.org/v1/' + params.cryptocurrency.toString().toLowerCase() + '/user/' + params.address.toString())
.then((response) => response.json())
.then((responseJson) => {
if(responseJson.data){
this.setState({
//update the balance state
accountData: responseJson.data,
avghashrate: responseJson.data.avgHashrate,
workers: responseJson.data.workers,
}, function() {
// do something with new state
this.parseAvgHashrates();
});
}
})
.catch((error) => {
console.error(error);
});
//fetch account hashrate historical data
fetch('https://api.nanopool.org/v1/' + params.cryptocurrency.toString().toLowerCase() + '/hashratechart/' + params.address.toString())
.then((response) => response.json())
.then((responseJson) => {
if(responseJson.data && responseJson.data[0]){
var d = responseJson.data;
//console.log('got data len ' + d.length);
dateSort(d);
//console.log('sorted length' + d.length);
i = 0; //index we are checking
cDate = parseInt(d[0].date); //timestamp of first data point
now = parseInt(Math.round(new Date() / 1000)); //current timestamp
while ( parseInt(d[i].date) < (now - (17*60))){
//while the current data point is not within the last 15 min
fDelta = 0;
nextIsBlank = (d[i+1] == undefined); // if next entry doesn't exist or is falsey
if(!nextIsBlank){
fDelta = (parseInt(d[i+1].date)-parseInt(d[i].date)); //forwardDelta of date (seconds)
}
reportingCycles = 10; //first x cycles are logged to console in detail
if(nextIsBlank || (fDelta > 600) ){
//if the next point doesn't exist or isn't the next sequential
d.splice(i+1,0,
{
date: parseInt(d[i].date) + (10*60),
shares: 0,
hashrate: 0,
}
);
}
i = i + 1;
}
this.setState({
//update the state
chartData: d,
}, function() {
//do something wit fetched data
});
}
})
.catch((error) => {
console.error(error);
});
}
@autobind
setMiningChartHours(hours){
var bars;
switch(hours){
case 1:
bars = 6;
break;
case 6:
bars = 8;
break;
case 12:
bars = 12;
break;
case 24:
bars = 24;
break;
default:
bars = 12;
}
this.setState({
miningChartHours: hours,
miningChartBars: bars,
})
}
@autobind
parseAvgHashrates(){
const { params } = this.props.navigation.state;
times = [1,3,6,12,24];
s = [];
//declare hash max and min at function scope
hashMax = null;
hashMin = null;
if(this.state.avghashrate){
//set first hashrate to both min and max
hashMax = parseInt(this.state.avghashrate['h' + times[0].toString()]);
hashMin = parseInt(this.state.avghashrate['h' + times[0].toString()]);
for(var i = 1;i < times.length; i++ ){
//next hashrate
h = parseInt(this.state.avghashrate['h' + times[i].toString()]);
hashMax = h > parseInt(hashMax) ? h : hashMax;
hashMin = h < parseInt(hashMin) ? h : hashMin;
}
h = parseInt(this.state.accountData.hashrate);
hashMax = h > parseInt(hashMax) ? h : hashMax;
hashMin = h < parseInt(hashMin) ? h : hashMin;
}
//generate the average hashrate line objects
for(var i = 0;i < times.length; i++ ){
s.push({
time: times[i].toString(),
rateText: (
this.state.avghashrate ?
Math.round(this.state.avghashrate['h' + times[i].toString()]).toString() + ' ' + HashrateUnits[params.cryptocurrency]
:
'...'),
rateDispPercent: (this.state.avghashrate ? (this.state.avghashrate['h' + times[i].toString()]) : 0)/(hashMax ? hashMax : 1)
});
};
currPercent = (this.state.accountData.hashrate? this.state.avghashrate: 0)/(hashMax ? hashMax : 1);
this.setState(
(prev)=>{
return({
parsedHashrates: s,
currentHashratePercent: (this.state.accountData.hashrate)/(hashMax ? hashMax : 1),
})
},
(a)=>{
}
);
}
render() {
const { params } = this.props.navigation.state;
return (
<RefreshableScrollView
style={{flex:1, backgroundColor:'white' }}>
<View style={styles.cardItem}>
<Text style={styles.cardItemHeading}>Info</Text>
<Text style={styles.cardText}>
{'Payout Balance : ' + this.state.balance + '\n' + params.address}
</Text>
</View>
<View style={styles.cardItem}>
<MiningChart
data={this.state.chartData}
cryptocurrency={params.cryptocurrency}
hours={this.state.miningChartHours}
bars={this.state.miningChartBars}
height={100}
/>
<MiningChartHourPicker
setHours={this.setMiningChartHours}
miningChartHours={this.state.miningChartHours}
/>
</View>
<View style={styles.cardItem}>
<Text style={[styles.cardItemHeading, {margin: 5}]}>Averages</Text>
<View style={{flex: 1, flexDirection: 'row'}}>
<View style={{flex: 3, marginRight: 5}}>
<Text style={{textAlign: 'right',}}>{'Now'}</Text>
</View>
<View style={{flex: 6}}>
<Text>{'Current Hashrate:' + (this.state.accountData && this.state.accountData.hashrate)?this.state.accountData.hashrate + ' ' + HashrateUnits[this.state.cryptocurrency]:'nah'}</Text>
</View>
<View style={{flex: 14, margin: 2}}>
<HorizPercentBar
percent={this.state.currentHashratePercent}
barStyle={styles.nowHashBar}
barBackgroundStyle={styles.hashBarBG}/>
</View>
</View>
<AvgHashratesBarChart
hashrates={this.state.parsedHashrates}/>
</View>
<View style={styles.cardItem}>
<Text style={[styles.cardItemHeading, {margin: 5}]}>Workers</Text>
<WorkerTable
data={this.state.workers}
hashrateUnit={HashrateUnits[this.state.cryptocurrency]}
themeColor={themeColor}
/>
</View>
<View style={{height: 10}}/>
</RefreshableScrollView>
);
}
}
/**
props:
hashrates - array of hashrates objects
*/
class AvgHashratesBarChart extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View>
{this.props.hashrates ? this.props.hashrates.map(function(rateSet,index){
return (
<View style={{flexDirection: 'row'}} key={index}>
<View style={{flex: 3, marginRight: 5}}>
<Text style={{textAlign: 'right',}}>{rateSet.time + 'h'}</Text>
</View>
<View style={{flex: 6}}>
<Text style={{textAlign: 'left',}}>{rateSet.rateText}</Text>
</View>
<View style={{flex: 14,margin: 2}}>
<HorizPercentBar
percent={rateSet.rateDispPercent}
barStyle={styles.avgHashBar}
barBackgroundStyle={styles.hashBarBG}/>
</View>
</View>
)})
: <Text>{'Fetching...'}</Text>
}
</View>
)
}
}
class WorkerTable extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View>
<View style={{flexDirection: 'row', margin: 5, borderBottomWidth: 1, borderBottomColor: this.props.themeColor ? this.props.themeColor : 'black'}}>
<View style={{flex: 1, marginRight: 5}}>
<Text style={{textAlign: 'right',}}>{'Name'}</Text>
</View>
<View style={{flex: 1, marginRight: 5}}>
<Text style={{textAlign: 'right',}}>{'Current'}</Text>
</View>
<View style={{flex: 1,margin: 1}}>
<Text style={{textAlign: 'right',}}>{'3h'}</Text>
</View>
<View style={{flex: 1}}>
<Text style={{textAlign: 'right',}}>{'6h'}</Text>
</View>
<View style={{flex: 1,margin: 1}}>
<Text style={{textAlign: 'right',}}>{'12h'}</Text>
</View>
</View>
{this.props.data ? this.props.data.map(function(worker,index){
return (
<View style={{flexDirection: 'row', margin: 5}} key={index}>
<View style={{flex: 1, marginRight: 5}}>
<Text style={{textAlign: 'right',}}>{worker.id}</Text>
</View>
<View style={{flex: 1, marginRight: 5}}>
<Text style={{textAlign: 'right',}}>{worker.hashrate}</Text>
</View>
<View style={{flex: 1,margin: 2}}>
<Text style={{textAlign: 'right',}}>{worker.h3}</Text>
</View>
<View style={{flex: 1}}>
<Text style={{textAlign: 'right',}}>{worker.h6}</Text>
</View>
<View style={{flex: 1,margin: 2}}>
<Text style={{textAlign: 'right',}}>{worker.h12}</Text>
</View>
</View>
)})
: null
}