Skip to content

Commit

Permalink
Change ConnectPanel to default to last Address used
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 5, 2024
1 parent 6a946a6 commit 7f457f7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions convex-gui/src/main/java/convex/gui/components/ConnectPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import convex.api.Convex;
import convex.core.crypto.wallet.AWalletEntry;
import convex.core.cvm.Address;
import convex.core.init.Init;
import convex.gui.components.account.AddressCombo;
import convex.gui.keys.KeyRingPanel;
Expand All @@ -33,7 +34,8 @@ public class ConnectPanel extends JPanel {

private static final Logger log = LoggerFactory.getLogger(ConnectPanel.class.getName());


private static Address lastAddress=null;

private HostCombo hostField;
private AddressCombo addressField;

Expand All @@ -51,14 +53,19 @@ public ConnectPanel() {

{ // Address selection
pan.add(new JLabel("Address"));
addressField=new AddressCombo(Init.GENESIS_ADDRESS);
addressField=new AddressCombo(getSuggestedAddress());
addressField.setToolTipText("Set the initial account address to use. \nNormally this should be an account for which you possess the private key. \nIf you don't have the private key, you can still view the account but cannot execute transactions.");
pan.add(addressField,"width 50:250:");
pan.add(Toolkit.makeHelp(addressField.getToolTipText()));
}

}

private static Address getSuggestedAddress() {
if (lastAddress!=null) return lastAddress;
return Init.GENESIS_ADDRESS;
}

public static Convex tryConnect(JComponent parent) {
return tryConnect(parent,"Enter Connection Details");
}
Expand All @@ -70,12 +77,14 @@ public static Convex tryConnect(JComponent parent,String prompt) {
prompt, JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,SymbolIcon.get(0xea77,Toolkit.ICON_SIZE));

if (result == JOptionPane.OK_OPTION) {
Address addr=pan.addressField.getAddress();
lastAddress=addr;
try {
String target=pan.hostField.getText();
InetSocketAddress sa=IPUtils.toInetSocketAddress(target);
log.info("Attempting connect to: "+sa);
Convex convex=Convex.connect(sa);
convex.setAddress(pan.addressField.getAddress());
convex.setAddress(addr);

HostCombo.registerGoodConnection(target);

Expand Down

0 comments on commit 7f457f7

Please sign in to comment.