Skip to content

Commit

Permalink
Merge pull request #13 from cypheron/add-send-panel-button-max-amount
Browse files Browse the repository at this point in the history
Add button to panel "Send Cash" for inserting max send-able amount
  • Loading branch information
TheTrunk authored May 5, 2019
2 parents 5ca4751 + c69a336 commit 9533a7b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/java/com/vaklinov/zcashui/SendCashPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class SendCashPanel

private ZelCashJCheckBox sendChangeBackToSourceAddress = null;

private ZelCashJButton maxAmountButton = null;
private ZelCashJButton sendButton = null;

private ZelCashJPanel operationStatusPanel = null;
Expand Down Expand Up @@ -181,6 +182,7 @@ public SendCashPanel(ZCashClientCaller clientCaller,
tempPanel.add(destinationAmountField = new ZelCashJTextField(13));
destinationAmountField.setHorizontalAlignment(SwingConstants.RIGHT);
tempPanel.add(new ZelCashJLabel(" ZEL "));
tempPanel.add(maxAmountButton = new ZelCashJButton(langUtil.getString("send.cash.panel.button.maxamount")));
amountPanel.add(tempPanel, BorderLayout.SOUTH);

ZelCashJPanel feePanel = new ZelCashJPanel(new BorderLayout());
Expand Down Expand Up @@ -251,6 +253,34 @@ public SendCashPanel(ZCashClientCaller clientCaller,
operationStatusPanel.add(dividerLabel);

// Wire the buttons
maxAmountButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String balance = lastAddressBalanceData[balanceAddressCombo.getSelectedIndex()][0];
String fee = transactionFeeField.getText();
String max = new DecimalFormat("########0.00######").format(Double.parseDouble(balance) - Double.parseDouble(fee));
destinationAmountField.setText(max);
} catch (Exception ex)
{
Log.error("Unexpected error: ", ex);

String errMessage = "";
if (ex instanceof WalletCallException)
{
errMessage = ((WalletCallException)ex).getMessage().replace(",", ",\n");
}

JOptionPane.showMessageDialog(
SendCashPanel.this.getRootPane().getParent(),
langUtil.getString("send.cash.panel.option.pane.error.text",errMessage),
langUtil.getString("send.cash.panel.option.pane.error.title"),
JOptionPane.ERROR_MESSAGE);
}
}
});
sendButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
Expand Down
3 changes: 2 additions & 1 deletion src/resources/messages/zelcash_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ send.cash.panel.label.memo.info=<html><span style=\"font-size:0.8em;\"> \
* Memo may be specified only if the destination is a Z (Private) address! </span>
send.cash.panel.label.amount=Amount to send:
send.cash.panel.label.fee=Transaction fee:
send.cash.panel.button.maxamount=Maximum
send.cash.panel.button.send=Send
send.cash.panel.label.send.warning=<html><span style=\"font-size:0.8em;\"> \
* When sending cash from a T (Transparent) address, the remaining unspent balance is sent to another \
Expand Down Expand Up @@ -982,4 +983,4 @@ wallet.operations.dialog.rescan.message=Are you sure you want to rescan your wal
You can check debug logs to confirm rescanning it`s executing in background. \n\
When it`s finished you will receive a confirmation message.
wallet.operations.dialog.rescan.complete.title=Rescan Complete
wallet.operations.dialog.rescan.complete.message=Rescan complete. Your wallet will now be restarted.
wallet.operations.dialog.rescan.complete.message=Rescan complete. Your wallet will now be restarted.

0 comments on commit 9533a7b

Please sign in to comment.