-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
163 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
convex-gui/src/main/java/convex/gui/wallet/TokenComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package convex.gui.wallet; | ||
|
||
import java.awt.Font; | ||
|
||
import javax.swing.Icon; | ||
import javax.swing.JButton; | ||
import javax.swing.JPanel; | ||
|
||
import convex.api.Convex; | ||
import convex.core.data.ACell; | ||
import convex.gui.components.ActionButton; | ||
import convex.gui.components.BalanceLabel; | ||
import convex.gui.components.CodeLabel; | ||
import convex.gui.utils.SymbolIcon; | ||
import convex.gui.utils.Toolkit; | ||
import convex.gui.wallet.WalletPanel.TokenInfo; | ||
import net.miginfocom.swing.MigLayout; | ||
|
||
@SuppressWarnings("serial") | ||
public class TokenComponent extends JPanel { | ||
|
||
protected Convex convex; | ||
|
||
protected BalanceLabel balanceLabel; | ||
|
||
private static SymbolIcon DEFAULT_ICON=SymbolIcon.get(0xf041, Toolkit.ICON_SIZE); | ||
|
||
public TokenComponent(Convex convex, TokenInfo token) { | ||
this.convex=convex; | ||
|
||
this.setLayout(new MigLayout("","["+(Toolkit.ICON_SIZE+10)+"][200][300][300]push")); | ||
this.setBorder(Toolkit.createEmptyBorder(20)); | ||
|
||
ACell tokenID=token.getID(); | ||
Icon icon=(tokenID==null)?Toolkit.CONVEX:DEFAULT_ICON; | ||
add(new JButton(icon)); | ||
|
||
String symbolName=token.symbol(); | ||
CodeLabel symLabel=new CodeLabel(symbolName); | ||
symLabel.setFont(Toolkit.MONO_FONT.deriveFont(Font.BOLD)); | ||
symLabel.setToolTipText(symbolName+" has Token ID: "+tokenID); | ||
add(symLabel); | ||
|
||
balanceLabel = new BalanceLabel(); | ||
balanceLabel.setFont(Toolkit.MONO_FONT); | ||
balanceLabel.setBalance(0); | ||
balanceLabel.setToolTipText("Account balance for "+symbolName); | ||
add(balanceLabel); | ||
|
||
JPanel actions=new JPanel(); | ||
actions.add(new ActionButton(0xe5d5,e->{ | ||
// refresh | ||
})); | ||
actions.add(new ActionButton(0xe872,e->{ | ||
WalletPanel.model.removeElement(token); | ||
})); | ||
add(actions,"dock east"); | ||
} | ||
} |
80 changes: 79 additions & 1 deletion
80
convex-gui/src/main/java/convex/gui/wallet/WalletPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,97 @@ | ||
package convex.gui.wallet; | ||
|
||
import java.awt.Color; | ||
|
||
import javax.swing.DefaultListModel; | ||
import javax.swing.JOptionPane; | ||
import javax.swing.JPanel; | ||
|
||
import convex.api.Convex; | ||
import convex.core.data.ACell; | ||
import convex.core.data.Cells; | ||
import convex.core.lang.Reader; | ||
import convex.gui.components.ActionButton; | ||
import convex.gui.components.ActionPanel; | ||
import convex.gui.components.ScrollyList; | ||
import convex.gui.components.Toast; | ||
import net.miginfocom.swing.MigLayout; | ||
|
||
@SuppressWarnings("serial") | ||
public class WalletPanel extends JPanel { | ||
public static class TokenInfo { | ||
private ACell id; | ||
|
||
public TokenInfo(ACell tokenID) { | ||
this.id=tokenID; | ||
} | ||
|
||
public ACell getID() { | ||
return id; | ||
} | ||
|
||
public String symbol() { | ||
return (id==null)?"CVM":"???"; | ||
} | ||
|
||
public int decimals() { | ||
return (id==null)?9:2; | ||
} | ||
|
||
public static TokenInfo forID(ACell tokenID) { | ||
TokenInfo tokenInfo=new TokenInfo(tokenID); | ||
return tokenInfo; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object a) { | ||
if (a instanceof TokenInfo) { | ||
return Cells.equals(id, ((TokenInfo)a).id); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
protected ScrollyList<TokenInfo> list; | ||
|
||
protected Convex convex; | ||
|
||
static DefaultListModel<TokenInfo> model= new DefaultListModel<TokenInfo>(); | ||
|
||
public WalletPanel(Convex convex) { | ||
this.convex=convex; | ||
setLayout(new MigLayout("fill")); | ||
|
||
list=new ScrollyList<>(model, token->{ | ||
return new TokenComponent(convex,token); | ||
}); | ||
|
||
add(list,"dock center"); | ||
// add(new AccountOverview(convex),"dock north"); | ||
|
||
model.addElement(new TokenInfo(null)); | ||
|
||
|
||
// add(new AccountChooserPanel(convex),"dock south"); | ||
|
||
ActionPanel ap=new ActionPanel(); | ||
ap.add(new ActionButton("Track Token",0xe145,e->{ | ||
String newID=JOptionPane.showInputDialog(WalletPanel.this, "Enter Token ID"); | ||
if (newID==null) return; | ||
try { | ||
ACell tokenID=newID.isBlank()?null:Reader.read(newID); | ||
TokenInfo token=TokenInfo.forID(tokenID); | ||
if (model.contains(token)) { | ||
Toast.display(WalletPanel.this, "Token already added",Color.ORANGE); | ||
} else { | ||
model.addElement(token); | ||
} | ||
} catch (Exception ex) { | ||
Toast.display(WalletPanel.this, "Error adding token: "+ex.getMessage(),Color.ORANGE); | ||
} | ||
})); | ||
ap.add(new ActionButton("Refresh",0xe5d5,e->{ | ||
list.refreshList(); | ||
})); | ||
add(ap,"dock south"); | ||
} | ||
} |