Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6903e29

Browse files
centrys-victortheotniel
authored andcommitted
Some tooltips and slip0010 fixes (#79)
1 parent ad9027e commit 6903e29

5 files changed

Lines changed: 34 additions & 23 deletions

File tree

src/main/java/org/aion/wallet/account/AccountManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private AccountDTO addInternalAccount(int derivation) throws ValidationException
168168
return null;
169169
}
170170
final ECKey firstDerivation = root.deriveHardened(new int[]{44, 60, 0, 0, derivation}).getEcKey();
171-
AccountDTO account = createAccountWithPrivateKey(TypeConverter.toJsonHex(firstDerivation.computeAddress(firstDerivation.getPubKey())), firstDerivation.getPrivKeyBytes(), false);
171+
AccountDTO account = createAccountWithPrivateKey(TypeConverter.toJsonHex(firstDerivation.computeAddress(firstDerivation.getPubKey())), firstDerivation.getPrivKeyBytes(), false, derivation);
172172
EventPublisher.fireTransactionFinished();
173173
return account;
174174
}
@@ -186,7 +186,7 @@ private AccountDTO addExternalAccount(final ECKey key, final byte[] fileContent,
186186
if (!Keystore.exist(address)) {
187187
address = Keystore.create(password, key);
188188
if (AddressUtils.isValid(address)) {
189-
accountDTO = createAccountWithPrivateKey(address, key.getPrivKeyBytes(), true);
189+
accountDTO = createImportedAccountFromPrivateKey(address, key.getPrivKeyBytes());
190190
} else {
191191
throw new ValidationException("Failed to save keystore file");
192192
}
@@ -195,7 +195,7 @@ private AccountDTO addExternalAccount(final ECKey key, final byte[] fileContent,
195195
}
196196
} else {
197197
if (!addressToAccount.keySet().contains(address)) {
198-
accountDTO = createAccountWithPrivateKey(address, key.getPrivKeyBytes(), true);
198+
accountDTO = createImportedAccountFromPrivateKey(address, key.getPrivKeyBytes());
199199
} else {
200200
throw new ValidationException("Account already exists!");
201201
}
@@ -280,7 +280,11 @@ private void handleSettingsChanged(final SettingsEvent event) {
280280
}
281281
}
282282

283-
private AccountDTO createAccountWithPrivateKey(final String address, final byte[] privateKeyBytes, boolean isImported) {
283+
private AccountDTO createImportedAccountFromPrivateKey(final String address, final byte[] privateKeyBytes) {
284+
return createAccountWithPrivateKey(address, privateKeyBytes, true, -1);
285+
}
286+
287+
private AccountDTO createAccountWithPrivateKey(final String address, final byte[] privateKeyBytes, boolean isImported, int derivation) {
284288
if (address == null) {
285289
log.error("Can't create account with null address");
286290
return null;
@@ -292,13 +296,9 @@ private AccountDTO createAccountWithPrivateKey(final String address, final byte[
292296
final String name = getStoredAccountName(address);
293297
final String balance = BalanceUtils.formatBalance(balanceProvider.apply(address));
294298

295-
AccountDTO account = new AccountDTO(name, address, balance, currencySupplier.get());
299+
AccountDTO account = new AccountDTO(name, address, balance, currencySupplier.get(), isImported, derivation);
296300
account.setPrivateKey(privateKeyBytes);
297301
account.setActive(true);
298-
account.setImported(isImported);
299-
if (!isImported) {
300-
account.setDerivationIndex(walletStorage.getMasterAccountDerivations());
301-
}
302302
addressToAccount.put(account.getPublicAddress(), account);
303303
return account;
304304
}
@@ -338,7 +338,7 @@ private String getStoredAccountName(final String publicAddress) {
338338
private AccountDTO getNewAccount(final String publicAddress) {
339339
final String name = getStoredAccountName(publicAddress);
340340
final String balance = BalanceUtils.formatBalance(balanceProvider.apply(publicAddress));
341-
return new AccountDTO(name, publicAddress, balance, currencySupplier.get());
341+
return new AccountDTO(name, publicAddress, balance, currencySupplier.get(), true, -1);
342342
}
343343

344344
private void storeAccountName(final String address, final String name) {

src/main/java/org/aion/wallet/dto/AccountDTO.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ public class AccountDTO {
1313
private String balance; //TODO this has to be BigInteger
1414
private String name;
1515
private boolean active;
16-
private boolean isImported;
17-
private int derivationIndex = -1;
16+
private final boolean isImported;
17+
private final int derivationIndex;
1818
private final BufferedImage qrCode;
1919

20-
public AccountDTO(final String name, final String publicAddress, final String balance, final String currency) {
20+
public AccountDTO(final String name, final String publicAddress, final String balance, final String currency, boolean isImported, int derivationIndex) {
2121
this.name = name;
2222
this.publicAddress = TypeConverter.toJsonHex(publicAddress);
2323
this.balance = balance;
2424
this.currency = currency;
2525
this.qrCode = QRCodeUtils.writeQRCode(publicAddress);
26+
this.isImported = isImported;
27+
this.derivationIndex = derivationIndex;
2628
}
2729

2830
public String getName() {
@@ -69,18 +71,10 @@ public boolean isImported() {
6971
return isImported;
7072
}
7173

72-
public void setImported(boolean imported) {
73-
isImported = imported;
74-
}
75-
7674
public int getDerivationIndex() {
7775
return derivationIndex;
7876
}
7977

80-
public void setDerivationIndex(int derivationIndex) {
81-
this.derivationIndex = derivationIndex;
82-
}
83-
8478
public BufferedImage getQrCode() {
8579
return qrCode;
8680
}

src/main/java/org/aion/wallet/ui/components/SendController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class SendController extends AbstractController {
2828

2929
private static final String SUCCESS_MESSAGE = "Transaction finished";
3030

31+
private static final Tooltip NRG_LIMIT_TOOLTIP = new Tooltip("NRG limit");
32+
33+
private static final Tooltip NRG_PRICE_TOOLTIP = new Tooltip("NRG price");
34+
3135
private final BlockchainConnector blockchainConnector = BlockchainConnector.getInstance();
3236

3337
@FXML
@@ -62,6 +66,8 @@ protected void registerEventBusConsumer() {
6266

6367
@Override
6468
protected void internalInit(final URL location, final ResourceBundle resources) {
69+
nrgInput.setTooltip(NRG_LIMIT_TOOLTIP);
70+
nrgPriceInput.setTooltip(NRG_PRICE_TOOLTIP);
6571
setDefaults();
6672
if (!ConfigUtils.isEmbedded()) {
6773
passwordInput.setVisible(false);

src/main/java/org/aion/wallet/ui/components/account/AccountCellItem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javafx.scene.control.ContentDisplay;
66
import javafx.scene.control.ListCell;
77
import javafx.scene.control.TextField;
8+
import javafx.scene.control.Tooltip;
89
import javafx.scene.image.Image;
910
import javafx.scene.image.ImageView;
1011
import javafx.scene.input.KeyCode;
@@ -33,6 +34,10 @@ public class AccountCellItem extends ListCell<AccountDTO> {
3334

3435
private static final String NAME_INPUT_FIELDS_STYLE = "name-input-fields";
3536

37+
private static final Tooltip CONNECT_ACCOUNT_TOOLTIP = new Tooltip("Connect with this account");
38+
39+
private static final Tooltip CONNECTED_ACCOUNT_TOOLTIP = new Tooltip("Connected account");
40+
3641
private final UnlockAccountDialog accountUnlockDialog = new UnlockAccountDialog();
3742

3843
@FXML
@@ -60,6 +65,7 @@ private void loadFXML() {
6065
loader.setRoot(this);
6166
loader.load();
6267
name.setOnKeyPressed(this::submitNameOnEnterPressed);
68+
Tooltip.install(editNameButton, new Tooltip("Edit account name"));
6369
} catch (IOException e) {
6470
throw new RuntimeException(e);
6571
}
@@ -98,9 +104,13 @@ protected void updateItem(AccountDTO item, boolean empty) {
98104
if (item.isActive()) {
99105
final InputStream resource = getClass().getResourceAsStream(ICON_CONNECTED);
100106
accountSelectButton.setImage(new Image(resource));
107+
Tooltip.uninstall(accountSelectButton, CONNECT_ACCOUNT_TOOLTIP);
108+
Tooltip.install(accountSelectButton, CONNECTED_ACCOUNT_TOOLTIP);
101109
} else {
102110
final InputStream resource = getClass().getResourceAsStream(ICON_DISCONNECTED);
103111
accountSelectButton.setImage(new Image(resource));
112+
Tooltip.uninstall(accountSelectButton, CONNECTED_ACCOUNT_TOOLTIP);
113+
Tooltip.install(accountSelectButton, CONNECT_ACCOUNT_TOOLTIP);
104114
}
105115

106116
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);

src/main/java/org/aion/wallet/ui/components/partials/UnlockMasterAccountDialog.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class UnlockMasterAccountDialog {
3131
public void unlockMasterAccount(final InputEvent mouseEvent) {
3232
try {
3333
blockchainConnector.unlockMasterAccount(passwordField.getText());
34+
close(mouseEvent);
3435
} catch (Exception e) {
3536
showInvalidFieldsError(e.getMessage());
3637
}
@@ -66,8 +67,8 @@ public void open(MouseEvent mouseEvent) {
6667
popup.show(eventSource.getScene().getWindow());
6768
}
6869

69-
public void close() {
70-
popup.hide();
70+
public void close(InputEvent eventSource) {
71+
((Node) eventSource.getSource()).getScene().getWindow().hide();
7172
}
7273

7374
@FXML

0 commit comments

Comments
 (0)