File tree 4 files changed +12
-53
lines changed
etherscan-sample/src/main/java/jfyg/etherscan/helloetherescan
4 files changed +12
-53
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,10 @@ class SampleActivity : AppCompatActivity() {
32
32
fab.setOnClickListener {
33
33
34
34
// stat test
35
- stat.getLastPriceInBtc ()
35
+ stat.getEtherStatistics ()
36
36
.observeOn(AndroidSchedulers .mainThread())
37
37
.subscribeBy(
38
- onSuccess = { Log .d(TAG , " The current price of Ether in Btc: $it " ) },
38
+ onSuccess = { Log .d(TAG , " The current price of Ether in Btc: ${it.ethUsd} " ) },
39
39
onError = { Log .d(TAG , " error receiving stat" ) })
40
40
41
41
Original file line number Diff line number Diff line change 1
1
package jfyg.data.stat
2
2
3
3
import io.reactivex.Single
4
+ import jfyg.data.StatPrice
4
5
import jfyg.network.queries.ApiQuery
5
6
import jfyg.utils.ETH_PRICE
6
7
import jfyg.utils.ETH_SUPPLY
@@ -28,24 +29,9 @@ class Stats : StatsContract {
28
29
override fun getTotalSupplyInWei (): Single <Double > = supplyQuery.map { it.result?.toDouble()?.div(wei) }
29
30
30
31
/* *
31
- * Get ETHER LastPrice Price in btc
32
+ * Get Ether Statistics
32
33
*/
33
- override fun getLastPriceInUsd (): Single <Float > = priceQuery.map { it.result?.ethUsd?.toFloat() }
34
-
35
- /* *
36
- * Return timestamp
37
- */
38
- override fun getEthTimestamp (): Single <Long > = priceQuery.map { it.result?.ethUsdTimestamp?.toLong() }
39
-
40
- /* *
41
- * Get ETHER LastPrice Price in usd
42
- */
43
- override fun getLastPriceInBtc (): Single <Float > = priceQuery.map { it.result?.ethBtcTimestamp?.toFloat() }
44
-
45
- /* *
46
- * Return timestamp
47
- */
48
- override fun getBtcTimestamp (): Single <Long > = priceQuery.map { it.result?.ethBtcTimestamp?.toLong() }
34
+ override fun getEtherStatistics (): Single <StatPrice > = priceQuery.map { it.result }
49
35
50
36
/* *
51
37
* Return network status
Original file line number Diff line number Diff line change 1
1
package jfyg.data.stat
2
2
3
3
import io.reactivex.Single
4
+ import jfyg.data.StatPrice
4
5
5
6
/* *
6
7
* https://etherscan.io/apis#stats
@@ -18,24 +19,9 @@ internal interface StatsContract {
18
19
fun getTotalSupplyInWei (): Single <Double >
19
20
20
21
/* *
21
- * Get ETHER LastPrice Price in btc
22
+ * Get ETHER statistics
22
23
*/
23
- fun getLastPriceInBtc (): Single <Float >
24
-
25
- /* *
26
- * Return timestamp
27
- */
28
- fun getBtcTimestamp (): Single <Long >
29
-
30
- /* *
31
- * Get ETHER LastPrice Price in usd
32
- */
33
- fun getLastPriceInUsd (): Single <Float >
34
-
35
- /* *
36
- * Return timestamp
37
- */
38
- fun getEthTimestamp (): Single <Long >
24
+ fun getEtherStatistics (): Single <StatPrice >
39
25
40
26
/* *
41
27
* Return network status
Original file line number Diff line number Diff line change @@ -61,33 +61,20 @@ internal class StatsTest {
61
61
}
62
62
63
63
@Test
64
- fun getLastPriceInUsd () {
64
+ fun getEtherStatistics () {
65
65
val response = gson.fromJson(inputPrice, StatPriceResponse ::class .java)
66
66
assertEquals(" 377.67" , response.result?.ethUsd)
67
- }
68
-
69
- @Test
70
- fun getEthTimestamp () {
71
- val response = gson.fromJson(inputPrice, StatPriceResponse ::class .java)
72
- assertEquals(" 1523064526" , response.result?.ethUsdTimestamp)
73
- }
74
-
75
- @Test
76
- fun getLastPriceInBtc () {
77
- val response = gson.fromJson(inputPrice, StatPriceResponse ::class .java)
78
67
assertEquals(" 0.0557" , response.result?.ethBtc)
79
- }
80
-
81
- @Test
82
- fun getBtcTimestamp () {
83
- val response = gson.fromJson(inputPrice, StatPriceResponse ::class .java)
68
+ assertEquals(" 1523064526" , response.result?.ethUsdTimestamp)
84
69
assertEquals(" 1523064523" , response.result?.ethBtcTimestamp)
70
+
85
71
}
86
72
87
73
@Test
88
74
fun networkStatusIsDown () {
89
75
val response = gson.fromJson(inputBadResponse, BaseResponse ::class .java)
90
76
assertEquals(" 0" , response.status)
77
+
91
78
}
92
79
93
80
@Test
You can’t perform that action at this time.
0 commit comments