Fixed balance display and start send tx.

This commit is contained in:
jwinterm
2016-01-24 11:37:59 -08:00
parent 93c7391f11
commit 77b6128c8e
7 changed files with 93 additions and 25 deletions
@@ -15,13 +15,14 @@ public class DaemonRPC {
String getlastblock;
public DaemonRPC () {
address = "http://node.moneroclub.com:8880/json_rpc";
// address = "http://node.moneroclub.com:8880/json_rpc";
// address = "http://localhost:18081/json_rpc";
getlastblock = "{\"jsonrpc\":\"2.0\",\"id\":\"test\",\"method\":\"getlastblockheader\",\"params\":[]}";
}
public void getinfo (final DaemonValues daemonvalues) {
public void getinfo (final DaemonValues daemonvalues, String nodeaddress) {
HttpRequest httpGet = new HttpRequest(HttpMethods.POST);
httpGet.setUrl(address);
httpGet.setUrl(nodeaddress + "/json_rpc");
httpGet.setContent(getlastblock);
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
@@ -78,6 +78,7 @@ public class MainScreen extends AbstractScreen {
// Transaction processing stuff
ArrayList<Tx> txlist;
int txcount;
double calcbalance;
DecimalFormat df;
@@ -87,6 +88,7 @@ public class MainScreen extends AbstractScreen {
wq = new AtomicQueue<String>(1000);
txlist = new ArrayList<Tx>();
txcount = 0;
calcbalance = 0;
df = new DecimalFormat("#.############");
Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json"));
@@ -152,7 +154,7 @@ public class MainScreen extends AbstractScreen {
daemonview = new DaemonView(game);
walletview = new WalletView(game, walletsaverpc);
transactionview = new TransactionView(game);
transactionview = new TransactionView(game, stage);
historyview = new HistoryView(game);
viewcontainer.add(daemonview.daemonlayout).expand().fill();
screenlayout.add(viewcontainer);
@@ -210,8 +212,8 @@ public class MainScreen extends AbstractScreen {
if (fivesectimer == true) {
// Timer task to check balance from simplewallet
balancerpc.getinfo(balancevalues);
walletview.lockedvalue.setText(balancevalues.getLockedbalance().toString());
walletview.unlockedvalue.setText(balancevalues.getUnlockedbalance().toString());
walletview.lockedvalue.setText(df.format(balancevalues.getLockedbalance()/1e12) + " XMR");
walletview.unlockedvalue.setText(df.format(balancevalues.getUnlockedbalance()/1e12) + " XMR");
if (balancevalues.isChecked()) {
walletview.lockedvalue.setStyle(game.uiSkin.get("greenlabel", LabelStyle.class));
walletview.unlockedvalue.setStyle(game.uiSkin.get("greenlabel", LabelStyle.class));
@@ -224,7 +226,8 @@ public class MainScreen extends AbstractScreen {
}
if (tensectimer == true) {
// Timer task to get network info from daemon
daemonrpc.getinfo(daemonvalues);
Gdx.app.log(LightWallet.LOG, "Checking daemon...");
daemonrpc.getinfo(daemonvalues, game.walletvalues.getNode());
daemonview.Update(daemonvalues);
tensectimer = false;
accum10s = 0;
@@ -331,7 +334,6 @@ public class MainScreen extends AbstractScreen {
// Cycle through list of transactions from queue in last 60 s
if (txlist.size() > 0) {
for (int i = 0; i < txlist.size(); i++) {
Gdx.app.log(LightWallet.LOG, i + ": newtx is - " + newtx);
// If newtx flag then create a new temporary tx
if (newtx == true) {
temptx = new Tx();
@@ -383,6 +385,13 @@ public class MainScreen extends AbstractScreen {
}
});
historyview.getContainer().add(tmpbtn).fillX().row();
if (line.split(" | ")[0].equals("RECEIVED")) {
calcbalance += Double.parseDouble(tmpbtn.getText().toString().split(" | ")[2]);
} else {
calcbalance -= Double.parseDouble(tmpbtn.getText().toString().split(" | ")[2]);
}
walletview.calcedvalue.setText(df.format(calcbalance) + " XMR");
txcount += 1;
}
}
linenum += 1;
@@ -1,14 +1,20 @@
package com.jw.lightwallet.screens;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.jw.lightwallet.LightWallet;
public class TransactionView {
LightWallet game;
Stage stage;
Table txlayout;
@@ -26,8 +32,9 @@ public class TransactionView {
int padvalue;
public TransactionView (LightWallet game) {
public TransactionView (LightWallet game, final Stage stage) {
this.game = game;
this.stage = stage;
txlayout = new Table();
padvalue = 15;
@@ -42,8 +49,8 @@ public class TransactionView {
txlayout.add(amountlabel).pad(padvalue).width(100);
txlayout.add(amountvalue).pad(padvalue).width(100).row();
mixinlabel = new Label("Mixin level: ", game.uiSkin);
mixinvalue = new TextField("", game.uiSkin);
mixinlabel = new Label("Mixin level (default 4, minimum 2): ", game.uiSkin);
mixinvalue = new TextField("4", game.uiSkin);
txlayout.add(mixinlabel).pad(padvalue).width(100);
txlayout.add(mixinvalue).pad(padvalue).width(50).row();
@@ -55,7 +62,61 @@ public class TransactionView {
sendbtn = new TextButton("Payola!", game.uiSkin);
txlayout.add(new Label("", game.uiSkin));
txlayout.add(sendbtn);
// Setup popup for bad addresses
final Dialog badaddress = new Dialog("Bad address!", game.uiSkin, "dialog") {
public void result(Object obj) {
System.out.println("result "+obj);
}
};
Label badaddresslabel = new Label("Monero addresses begin with a '4' and are 95 characters long.", game.uiSkin);
badaddresslabel.setWrap(true);
badaddress.add(badaddresslabel).width(400).row();
badaddress.button("Continue", true).addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
badaddress.remove();
}
});
badaddress.key(Keys.ENTER, true); //sends "true" when the ENTER key is pressed
sendbtn.addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
// Setup flags to check each tx input
boolean isAddressGood = false;
boolean isAmountGood = false;
boolean isMixinGood = false;
boolean isIdGood = false;
String address = addressvalue.getText();
if (address.length() == 95) {
if (address.substring(0, 1).equals('4')) {
isAddressGood = true;
}
} else {
badaddress.show(stage);
}
long amount = 0;
try {
amount = (long) ((long) Double.parseDouble(amountvalue.getText())*1e12);
} catch (java.lang.NumberFormatException e) {
System.out.print("No amount :(");
}
int mixin = 4;
try {
mixin = Integer.parseInt(mixinvalue.getText());
} catch (java.lang.NumberFormatException e) {
System.out.print("No mixin :(");
}
String id = idvalue.getText();
System.out.print(address + "\n" + amount + "\n" + mixin + "\n" + id);
}
});
}
@@ -38,7 +38,7 @@ public class WalletView {
this.walletsaverpc = walletsaverpc;
walletlayout = new Table();
padvalue = 10;
padvalue = 12;
namelabel = new Label("Name: ", game.uiSkin);
namevalue = new Label(game.walletvalues.getName(), game.uiSkin);
@@ -67,7 +67,7 @@ public class WalletView {
walletlayout.add(lockedvalue).pad(padvalue).row();
calcedlabel = new Label("Calculated balance: ", game.uiSkin);
calcedvalue = new Label("Loading...", game.uiSkin);
calcedvalue = new Label("None", game.uiSkin);
walletlayout.add(calcedlabel).pad(padvalue);
walletlayout.add(calcedvalue).pad(padvalue).row();
@@ -27,7 +27,6 @@ public class BalanceRPC {
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
public void handleHttpResponse(HttpResponse httpResponse) {
response = httpResponse.getResultAsString();
//System.out.print("Balance response: " + response);
BalanceResponse balanceresponse = new Gson().fromJson(response, BalanceResponse.class);
balancevalues.setLockedbalance(balanceresponse.getResult().getLockedbalance());
balancevalues.setUnlockedbalance(balanceresponse.getResult().getUnlockedbalance());
@@ -1,7 +1,5 @@
package com.jw.lightwallet.wallet;
import com.jw.lightwallet.wallet.BalanceResult;
public class BalanceResponse {
String id;
@@ -2,20 +2,20 @@ package com.jw.lightwallet.wallet;
public class BalanceResult {
long unlockedbalance;
long lockedbalance;
long unlocked_balance;
long balance;
public long getUnlockedbalance() {
return unlockedbalance;
return unlocked_balance;
}
public void setUnlockedbalance(long unlockedbalance) {
this.unlockedbalance = unlockedbalance;
public void setUnlockedbalance(long unlocked_balance) {
this.unlocked_balance = unlocked_balance;
}
public long getLockedbalance() {
return lockedbalance;
return balance;
}
public void setLockedbalance(long lockedbalance) {
this.lockedbalance = lockedbalance;
public void setLockedbalance(long balance) {
this.balance = balance;
}
}