Skip to content

Commit 16f4bfa

Browse files
committed
BTC amounts are now displayed alongside the dollar amounts (no separate views)
Add tests for status controller Change TransactionView to display BTC amounts as well as USD. Add Tests Minor Cleanup Added option for viewing past transactions in BTC Fix more merge-related issues
1 parent 88edf54 commit 16f4bfa

File tree

6 files changed

+137
-4
lines changed

6 files changed

+137
-4
lines changed

src/main/java/org/whispersystems/bithub/controllers/StatusController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private RecentTransactionsView createRecentTransactionsView(CoinbaseClient coinb
117117
return new RecentTransactionsView(recentTransactions, exchangeRate);
118118
}
119119

120+
120121
public void initializeUpdates(final CoinbaseClient coinbaseClient) {
121122
executor.scheduleAtFixedRate(new Runnable() {
122123
@Override

src/main/java/org/whispersystems/bithub/views/RecentTransactionsView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class RecentTransactionsView extends View {
3939

4040
public RecentTransactionsView(List<Transaction> recentTransactions, BigDecimal exchangeRate) {
4141
super("recent_transactions.mustache");
42-
42+
4343
for (Transaction transaction : recentTransactions) {
4444
try {
4545
if (isSentTransaction(transaction)) {

src/main/java/org/whispersystems/bithub/views/TransactionView.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ public class TransactionView {
3838

3939
private final String destination;
4040
private final String amount;
41+
private final String amountInBTC;
4142
private final String commitUrl;
4243
private final String commitSha;
4344
private final String timestamp;
4445

45-
public TransactionView(BigDecimal exchangeRate, String amount,
46+
public TransactionView(BigDecimal exchangeRate, String transactionAmount,
4647
String timestamp, String message)
4748
throws ParseException
4849
{
49-
this.amount = getAmountInDollars(exchangeRate, amount);
50+
this.amount = getAmountInDollars(exchangeRate, transactionAmount);
51+
this.amountInBTC = getAmountInBTC(transactionAmount);
5052
this.destination = parseDestinationFromMessage(message);
5153
this.timestamp = parseTimestamp(timestamp);
5254
this.commitUrl = parseUrlFromMessage(message);
@@ -60,6 +62,12 @@ private String getAmountInDollars(BigDecimal exchangeRate, String amount) {
6062
.toPlainString();
6163
}
6264

65+
private String getAmountInBTC(String amount) {
66+
return new BigDecimal(amount).abs()
67+
.setScale(4, RoundingMode.CEILING)
68+
.toPlainString();
69+
}
70+
6371
private String parseTimestamp(String timestamp) throws ParseException {
6472
int offendingColon = timestamp.lastIndexOf(':');
6573
String fixedTimestamp = timestamp.substring(0, offendingColon) + timestamp.substring(offendingColon + 1);
@@ -113,6 +121,10 @@ public String getAmount() {
113121
return amount;
114122
}
115123

124+
public String getAmountInBTC() {
125+
return amountInBTC;
126+
}
127+
116128
public String getCommitUrl() {
117129
return commitUrl;
118130
}

src/main/resources/org/whispersystems/bithub/views/recent_transactions.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
<ul>
4646
{{#transactions}}
47-
<li>Sent ${{amount}} USD to <a href="https://github.com/{{destination}}" target="_blank">{{destination}}</a> for <a href="{{commitUrl}}" target="_blank"><sha>{{commitSha}}</sha></a> {{timestamp}}.</li>
47+
<li>Sent ${{amount}} USD ({{amountInBTC}} BTC) to <a href="https://github.com/{{destination}}" target="_blank">{{destination}}</a> for <a href="{{commitUrl}}" target="_blank"><sha>{{commitSha}}</sha></a> {{timestamp}}.</li>
4848
{{/transactions}}
4949
</ul>
5050

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.whispersystems.bithub.tests.controllers;
2+
3+
import static com.yammer.dropwizard.testing.JsonHelpers.fromJson;
4+
import static com.yammer.dropwizard.testing.JsonHelpers.jsonFixture;
5+
import static org.fest.assertions.api.Assertions.assertThat;
6+
import static org.mockito.Mockito.mock;
7+
import static org.mockito.Mockito.when;
8+
9+
import java.math.BigDecimal;
10+
11+
import javax.ws.rs.core.MediaType;
12+
13+
import org.junit.Test;
14+
import org.whispersystems.bithub.client.CoinbaseClient;
15+
import org.whispersystems.bithub.controllers.StatusController;
16+
import org.whispersystems.bithub.entities.RecentTransactionsResponse;
17+
18+
import com.sun.jersey.api.client.ClientResponse;
19+
import com.yammer.dropwizard.testing.ResourceTest;
20+
import com.yammer.dropwizard.views.ViewMessageBodyWriter;
21+
22+
public class StatusControllerTest extends ResourceTest {
23+
24+
private static final BigDecimal PAYOUT_RATE = new BigDecimal(0.02);
25+
private static final BigDecimal BALANCE = new BigDecimal(10.01);
26+
private static final BigDecimal EXCHANGE_RATE = new BigDecimal(1.0);
27+
28+
private final CoinbaseClient coinbaseClient = mock(CoinbaseClient.class);
29+
30+
@Override
31+
protected void setUpResources() throws Exception {
32+
33+
when(coinbaseClient.getRecentTransactions()).thenReturn(fromJson(jsonFixture("payloads/transactions.json"), RecentTransactionsResponse.class).getTransactions());
34+
when(coinbaseClient.getAccountBalance()).thenReturn(BALANCE);
35+
when(coinbaseClient.getExchangeRate()).thenReturn(EXCHANGE_RATE);
36+
addResource(new StatusController(coinbaseClient, PAYOUT_RATE));
37+
38+
addProvider(ViewMessageBodyWriter.class);
39+
}
40+
41+
@Test
42+
public void testTransactionsHtml() throws Exception {
43+
ClientResponse response = client().resource("/v1/status/transactions/")
44+
.get(ClientResponse.class);
45+
46+
assertThat(response.getStatus()).isEqualTo(200);
47+
assertThat(response.getType()).isEqualTo(MediaType.TEXT_HTML_TYPE);
48+
assertThat(response.getEntity(String.class)).contains("<li>Sent $1.10 USD (1.1000 BTC)");
49+
}
50+
51+
@Test
52+
public void testTransactionsJson() throws Exception {
53+
ClientResponse response = client().resource("/v1/status/transactions/").queryParam("format", "json")
54+
.get(ClientResponse.class);
55+
56+
assertThat(response.getStatus()).isEqualTo(200);
57+
assertThat(response.getType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
58+
assertThat(response.getEntity(String.class)).contains("\"amount\":\"1.10\",\"amountInBTC\":\"1.1000\"");
59+
}
60+
61+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"current_user": {
3+
"id": "5011f33df8182b142400000e",
4+
"email": "user2@example.com",
5+
"name": "User Two"
6+
},
7+
"balance": {
8+
"amount": "50.00000000",
9+
"currency": "BTC"
10+
},
11+
"total_count": 2,
12+
"num_pages": 1,
13+
"current_page": 1,
14+
"transactions": [
15+
{
16+
"transaction": {
17+
"id": "5018f833f8182b129c00002f",
18+
"created_at": "2012-08-01T02:34:43-07:00",
19+
"amount": {
20+
"amount": "-1.10000000",
21+
"currency": "BTC"
22+
},
23+
"request": true,
24+
"status": "pending",
25+
"sender": {
26+
"id": "5011f33df8182b142400000e",
27+
"name": "User Two",
28+
"email": "user2@example.com"
29+
},
30+
"recipient": {
31+
"id": "5011f33df8182b142400000a",
32+
"name": "User One",
33+
"email": "user1@example.com"
34+
},
35+
"notes": "Commit payment:__moxie0__ https://github.com/WhisperSystems/BitHub/commit/88edf54e5b57c80ac05093a9be90965fd41291c2"
36+
}
37+
},
38+
{
39+
"transaction": {
40+
"id": "5018f833f8182b129c00002e",
41+
"created_at": "2012-08-01T02:36:43-07:00",
42+
"hsh": "9d6a7d1112c3db9de5315b421a5153d71413f5f752aff75bf504b77df4e646a3",
43+
"amount": {
44+
"amount": "-1.00000000",
45+
"currency": "BTC"
46+
},
47+
"request": false,
48+
"status": "complete",
49+
"sender": {
50+
"id": "5011f33df8182b142400000e",
51+
"name": "User Two",
52+
"email": "user2@example.com"
53+
},
54+
"recipient_address": "37muSN5ZrukVTvyVh3mT5Zc5ew9L9CBare",
55+
"notes": "Commit payment:__moxie0__ https://github.com/WhisperSystems/BitHub/commit/88edf54e5b57c80ac05093a9be90965fd41291c2"
56+
}
57+
}
58+
]
59+
}

0 commit comments

Comments
 (0)