diff --git a/convex-gui/src/main/java/convex/gui/MainGUI.java b/convex-gui/src/main/java/convex/gui/MainGUI.java index 199e9a20c..eae6186bf 100644 --- a/convex-gui/src/main/java/convex/gui/MainGUI.java +++ b/convex-gui/src/main/java/convex/gui/MainGUI.java @@ -35,25 +35,25 @@ public MainGUI() { ActionPanel actionPanel=new ActionPanel(); actionPanel.setLayout(new MigLayout("center,align center,fillx")); - JComponent wallet=createLaunchButton("Wallet",Toolkit.WALLET_ICON,this::launchWallet); + JComponent wallet=createLaunchButton("Wallet",Toolkit.WALLET_ICON,this::launchWallet,"Open a Convex Wallet, connecting to any existing network"); actionPanel.add(wallet); - JComponent testNet=createLaunchButton("Peer Manager",Toolkit.TESTNET_ICON,this::launchTestNet); + JComponent testNet=createLaunchButton("Peer Manager",Toolkit.TESTNET_ICON,this::launchTestNet,"Launch a DevNet with the Peer Manager. This gives you a test network you can use freely for testing and development purposes."); actionPanel.add(testNet); - JComponent latticeFS=createLaunchButton("Lattice Filesystem",Toolkit.DLFS_ICON,this::launchDLFS); + JComponent latticeFS=createLaunchButton("Lattice Filesystem",Toolkit.DLFS_ICON,this::launchDLFS,"Launch a DLFS file browser. EXPERIMENTAL."); actionPanel.add(latticeFS); - JComponent terminal=createLaunchButton("Client Terminal",Toolkit.TERMINAL_ICON,this::launchTerminalClient); + JComponent terminal=createLaunchButton("Client Terminal",Toolkit.TERMINAL_ICON,this::launchTerminalClient,"Open a Convex REPL terminal, connecting to any existing network"); actionPanel.add(terminal); - JComponent hacker=createLaunchButton("Hacker Tools",Toolkit.HACKER_ICON,this::launchTools); + JComponent hacker=createLaunchButton("Hacker Tools",Toolkit.HACKER_ICON,this::launchTools,"Open a set of useful tools for hackers and power users."); actionPanel.add(hacker); - JComponent discord=createLaunchButton("Discord",Toolkit.ECOSYSTEM_ICON,this::launchDiscord); + JComponent discord=createLaunchButton("Discord",Toolkit.ECOSYSTEM_ICON,this::launchDiscord,"Go to the Convex community Discord (opens web browser)."); actionPanel.add(discord); - JComponent www=createLaunchButton("convex.world",Toolkit.WWW_ICON,this::launchWebsite); + JComponent www=createLaunchButton("convex.world",Toolkit.WWW_ICON,this::launchWebsite,"Go to the Convex main website (opens web browser)."); actionPanel.add(www); add(actionPanel); @@ -96,11 +96,12 @@ public void launchWebsite() { Toolkit.launchBrowser("https://convex.world"); } - public JPanel createLaunchButton(String label, ImageIcon icon, Runnable cmd) { + public JPanel createLaunchButton(String label, ImageIcon icon, Runnable cmd, String tooltip) { JButton butt=new JButton(icon); butt.addActionListener(e->{ EventQueue.invokeLater(cmd); }); + butt.setToolTipText(tooltip); JLabel lab = new JLabel(label); lab.setHorizontalAlignment(SwingConstants.CENTER); diff --git a/convex-gui/src/main/java/convex/gui/components/DecimalAmountField.java b/convex-gui/src/main/java/convex/gui/components/DecimalAmountField.java index 5c87e1fec..0d5ca469c 100644 --- a/convex-gui/src/main/java/convex/gui/components/DecimalAmountField.java +++ b/convex-gui/src/main/java/convex/gui/components/DecimalAmountField.java @@ -114,7 +114,14 @@ public void setText(String text) { super.setText(text.trim()); } - static AInteger parse(String text, int decimals, boolean exact) { + /** + * Parse a string as an integer amount with the specified number of decimals + * @param text String to parse + * @param decimals Number of decimals in result quantity + * @param exact If true, conversion will require an exact conversion + * @return Integer amount, or null if not convertible + */ + public static AInteger parse(String text, int decimals, boolean exact) { try { text=text.trim(); BigDecimal dec=new BigDecimal(text); diff --git a/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java b/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java index 0b4d01181..a76f82696 100644 --- a/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java +++ b/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java @@ -63,7 +63,7 @@ public AccountChooserPanel(Convex convex) { keyCombo.addItemListener(e->{ if (e.getStateChange()==ItemEvent.DESELECTED) { // key pair was deselected and/or set to null - convex.setKeyPair(null); + setKeyPair(null); return; }; AWalletEntry we=(AWalletEntry)e.getItem(); diff --git a/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java b/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java index a8fe2584b..58fd1e026 100644 --- a/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java @@ -2,12 +2,18 @@ import java.awt.BorderLayout; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; import convex.api.Convex; +import convex.core.data.AccountKey; +import convex.core.data.prim.AInteger; import convex.gui.components.ActionButton; import convex.gui.components.ActionPanel; +import convex.gui.components.DecimalAmountField; +import convex.gui.utils.SymbolIcon; @SuppressWarnings("serial") public class PeerStakePanel extends JPanel { @@ -25,7 +31,38 @@ public PeerStakePanel(Convex convex) { add(ap,BorderLayout.SOUTH); ap.add(new ActionButton("Refresh", 0xe5d5, e->peerTable.refresh()) ); - ap.add(new ActionButton("Set Stake...", 0xf5dc, e->peerTable.refresh()) ); + ap.add(new ActionButton("Set Stake...", 0xf5dc, e->{ + int row=peerTable.getSelectedRow(); + if (row<0) { + JOptionPane.showMessageDialog(this,"Select a peer to set stake on"); + return; + } + Object val=peerTable.getValueAt(row, 0); + AccountKey peerKey=AccountKey.parse(val); + if (peerKey!=null) { + Object stk=JOptionPane.showInputDialog(this, + "Enter desired stake for peer "+peerKey, + "Set Peer Stake...", + JOptionPane.QUESTION_MESSAGE, + SymbolIcon.get(0xf56e), + null, + "0.0"); + if (!(stk instanceof String)) return; + AInteger amt=DecimalAmountField.parse((String) stk, 9, true); + if (amt==null) { + JOptionPane.showMessageDialog(this,"Input amount not valid. Must be a qantity in Convex Gold, e.g. '1000.01' "); + return; + } + convex.transact("(set-stake "+peerKey+" "+amt+")").thenAcceptAsync(r->{ + if (r.isError()) { + SwingUtilities.invokeLater(()->{ + JOptionPane.showMessageDialog(this,"Stake setting failed: "+r,"Staking problem",JOptionPane.ERROR_MESSAGE); + }); + } + peerTable.refresh(); + }); + } + })); } }