From bc5690346cb21b0e2fd220d6555d1a67a5805523 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 13 May 2020 12:47:21 +0200 Subject: [PATCH] finalising wallet settings --- .DS_Store | Bin 0 -> 6148 bytes drongo | 2 +- src/.DS_Store | Bin 0 -> 6148 bytes .../sparrowwallet/sparrow/AppController.java | 6 +++- .../com/sparrowwallet/sparrow/MainApp.java | 4 +-- .../com/sparrowwallet/sparrow/io/Storage.java | 20 +++++++++++ .../sparrow/wallet/KeystoreController.java | 3 ++ .../sparrow/wallet/SettingsController.java | 33 ++++++++++-------- .../sparrow/wallet/WalletController.java | 23 ++++++++++++ .../sparrowwallet/sparrow/wallet/wallet.css | 5 +++ src/test/.DS_Store | Bin 0 -> 6148 bytes .../sparrowwallet/sparrow/io/StorageTest.java | 26 ++++++++++++-- src/test/resources/.DS_Store | Bin 0 -> 6148 bytes src/test/resources/com/.DS_Store | Bin 0 -> 6148 bytes .../resources/com/sparrowwallet/.DS_Store | Bin 0 -> 6148 bytes .../com/sparrowwallet/sparrow/.DS_Store | Bin 0 -> 6148 bytes .../sparrow/io/sparrow-single-seed-wallet | 1 + 17 files changed, 101 insertions(+), 22 deletions(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/test/.DS_Store create mode 100644 src/test/resources/.DS_Store create mode 100644 src/test/resources/com/.DS_Store create mode 100644 src/test/resources/com/sparrowwallet/.DS_Store create mode 100644 src/test/resources/com/sparrowwallet/sparrow/.DS_Store create mode 100644 src/test/resources/com/sparrowwallet/sparrow/io/sparrow-single-seed-wallet diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..81229e8d26382bd3469cb3d9bb2de3f1954844ac GIT binary patch literal 6148 zcmeH~Jqp4=5QS&dB4Cr!avKle4VIuM@B*S@B?yZB9^E%TjnP_yyn&f-XEsBUS7b9H zqQmpN5$Q#wgBxXSVPuMYE)TiO>2iLYjtb*@FJ*K=2U&T%hcRwa*e@u>x3=Er<$CqZN!+^)bZi z-VT<$t|nVB+C_8t(7dzS6a&*}7cEF&S{)2jfC`Khm`C2*`M-mIoBu~GOsN1B_%j7` zvE6S6yi}g8AFpTiLso6w;GkcQ@b(jc#E#+>+ztE17GO=bASy8a2)GOkRN$uyya2`( B5q1Co literal 0 HcmV?d00001 diff --git a/drongo b/drongo index b951f79c..766a986a 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit b951f79cfded507112cc7f213567c6a43c00e7e8 +Subproject commit 766a986abb72ea84317a405b93055abc3d1eaf22 diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c3ac046f6c51a2cd4bc2df32c603e493458c382e GIT binary patch literal 6148 zcmeH~F^{dt=u>Bl;zddfqZjB=JE!l7EiIwCR znHYd=e=Zwf1hAw#vGy=AV?N-4FWm9?zTD5J+wJN_+D8XGrH`2G=e8gPq<|EV0#ZN< z%t(Pe#+RQndL})J6p#Y*P{6+rh3>4$))}7;h8O|Jf#oo+W0oL`7s#4yovhF-rw7Yc zi!sFO(N31Ut|nV&Z-?dZVR>isDTZdf9afmotOgXMfE1W0u;}^d=l`Dm-~2ymQ7Q$b zz?&&x!|t%#@}=@@{quTWKW5d}jZVhp3{O7+O#CQb(Zjf3d_mS^>tuzdAAyiTK?=N7 FfnTX=61e~X literal 0 HcmV?d00001 diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 397b0187..90615d17 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -259,7 +259,11 @@ public class AppController implements Initializable { public Tab addWalletTab(File walletFile, ECKey encryptionPubKey, Wallet wallet) { try { - Tab tab = new Tab(walletFile.getName()); + String name = walletFile.getName(); + if(name.endsWith(".json")) { + name = name.substring(0, name.lastIndexOf('.')); + } + Tab tab = new Tab(name); TabData tabData = new TabData(TabData.TabType.WALLET); tab.setUserData(tabData); tab.setContextMenu(getTabContextMenu(tab)); diff --git a/src/main/java/com/sparrowwallet/sparrow/MainApp.java b/src/main/java/com/sparrowwallet/sparrow/MainApp.java index 3a5c43d4..25be1815 100644 --- a/src/main/java/com/sparrowwallet/sparrow/MainApp.java +++ b/src/main/java/com/sparrowwallet/sparrow/MainApp.java @@ -40,8 +40,8 @@ public class MainApp extends Application { wallet.setPolicyType(PolicyType.SINGLE); wallet.setScriptType(ScriptType.P2WPKH); - KeystoreImportDialog dlg = new KeystoreImportDialog(wallet); - dlg.showAndWait(); +// KeystoreImportDialog dlg = new KeystoreImportDialog(wallet); +// dlg.showAndWait(); stage.show(); } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index 9b348c40..3437763a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -62,6 +62,16 @@ public class Storage { throw new IOException("Could not create folder " + parent); } + if(!file.getName().endsWith(".json")) { + File jsonFile = new File(parent, file.getName() + ".json"); + if(file.exists()) { + if(!file.renameTo(jsonFile)) { + throw new IOException("Could not rename " + file.getName() + " to " + jsonFile.getName()); + } + } + file = jsonFile; + } + Writer writer = new FileWriter(file); gson.toJson(wallet, writer); writer.close(); @@ -73,6 +83,16 @@ public class Storage { throw new IOException("Could not create folder " + parent); } + if(file.getName().endsWith(".json")) { + File noJsonFile = new File(parent, file.getName().substring(0, file.getName().lastIndexOf('.'))); + if(file.exists()) { + if(!file.renameTo(noJsonFile)) { + throw new IOException("Could not rename " + file.getName() + " to " + noJsonFile.getName()); + } + } + file = noJsonFile; + } + OutputStreamWriter writer = new OutputStreamWriter(new DeflaterOutputStream(new ECIESOutputStream(new FileOutputStream(file), encryptionKey, getEncryptionMagic())), StandardCharsets.UTF_8); gson.toJson(wallet, writer); writer.close(); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java index d63b8899..03346972 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java @@ -63,6 +63,9 @@ public class KeystoreController extends WalletFormController implements Initiali Platform.runLater(this::setupValidation); selectSourcePane.managedProperty().bind(selectSourcePane.visibleProperty()); + if(keystore.isValid()) { + selectSourcePane.setVisible(false); + } updateType(); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index 0d61166b..69d7e7fa 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -88,14 +88,14 @@ public class SettingsController extends WalletFormController implements Initiali scriptType.getSelectionModel().select(policyType.getDefaultScriptType()); } + if(oldValue != null) { + clearKeystoreTabs(); + } + multisigFieldset.setVisible(policyType.equals(PolicyType.MULTI)); if(policyType.equals(PolicyType.MULTI)) { - totalKeystores.unbind(); - totalKeystores.set(0); totalKeystores.bind(multisigControl.highValueProperty()); } else { - totalKeystores.unbind(); - totalKeystores.set(0); totalKeystores.set(1); } }); @@ -159,9 +159,9 @@ public class SettingsController extends WalletFormController implements Initiali apply.setOnAction(event -> { try { - Optional optionalPubKey = askForWalletPassword(walletForm.getEncryptionPubKey()); + Optional optionalPubKey = requestEncryption(walletForm.getEncryptionPubKey()); if(optionalPubKey.isPresent()) { - walletForm.setEncryptionPubKey(ECKey.fromPublicOnly(optionalPubKey.get())); + walletForm.setEncryptionPubKey(optionalPubKey.get()); walletForm.save(); revert.setDisable(true); apply.setDisable(true); @@ -175,6 +175,11 @@ public class SettingsController extends WalletFormController implements Initiali setFieldsFromWallet(walletForm.getWallet()); } + private void clearKeystoreTabs() { + totalKeystores.unbind(); + totalKeystores.set(0); + } + private void setFieldsFromWallet(Wallet wallet) { if(wallet.getPolicyType() == null) { wallet.setPolicyType(PolicyType.SINGLE); @@ -261,7 +266,7 @@ public class SettingsController extends WalletFormController implements Initiali Platform.runLater(() -> apply.setDisable(!tabsValidate())); } - private Optional askForWalletPassword(ECKey existingPubKey) { + private Optional requestEncryption(ECKey existingPubKey) { WalletPasswordDialog.PasswordRequirement requirement; if(existingPubKey == null) { requirement = WalletPasswordDialog.PasswordRequirement.UPDATE_NEW; @@ -280,16 +285,14 @@ public class SettingsController extends WalletFormController implements Initiali ECKey encryptionFullKey = ECIESKeyCrypter.deriveECKey(password.get()); ECKey encryptionPubKey = ECKey.fromPublicOnly(encryptionFullKey); - if(existingPubKey != null) { - if(WalletForm.NO_PASSWORD_KEY.equals(existingPubKey) || existingPubKey.equals(encryptionPubKey)) { - return Optional.of(encryptionPubKey); - } else { - AppController.showErrorDialog("Incorrect Password", "The password was incorrect."); - return Optional.empty(); - } + + if(existingPubKey != null && !WalletForm.NO_PASSWORD_KEY.equals(existingPubKey) && !existingPubKey.equals(encryptionPubKey)) { + AppController.showErrorDialog("Incorrect Password", "The password was incorrect."); + return Optional.empty(); } - return Optional.of(encryptionFullKey); + walletForm.getWallet().encrypt(password.get()); + return Optional.of(encryptionPubKey); } return Optional.empty(); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java index 976a786f..432f571b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java @@ -2,10 +2,13 @@ package com.sparrowwallet.sparrow.wallet; import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.EventManager; +import javafx.application.Platform; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Node; +import javafx.scene.control.Toggle; +import javafx.scene.control.ToggleButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.BorderPane; import javafx.scene.layout.StackPane; @@ -61,5 +64,25 @@ public class WalletController extends WalletFormController implements Initializa throw new IllegalStateException("Can't find pane", e); } }); + + if(!walletForm.getWallet().isValid()) { + for(Toggle toggle : walletMenu.getToggles()) { + if(toggle.getUserData().equals(Function.SETTINGS)) { + toggle.setSelected(true); + } else { + ((ToggleButton)toggle).setDisable(true); + } + } + } + } + + public void selectFunction(Function function) { + Platform.runLater(() -> { + for(Toggle toggle : walletMenu.getToggles()) { + if(toggle.getUserData().equals(function)) { + toggle.setSelected(true); + } + } + }); } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css b/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css index 8ac6f650..ae854ac9 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css @@ -20,6 +20,11 @@ -fx-background-color: #1e88cf; } +.list-item:disabled { + -fx-background-color: #a0a1a7; + -fx-opacity: 1; +} + #walletPane { -fx-background-color: -fx-background; } \ No newline at end of file diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c10b9bb993a21f3b36d108c6ff719887729ad519 GIT binary patch literal 6148 zcmeHKyG{c^3>?E1K{P2T_ZRqsRTRE}A0Q-9Af%IsLVXqA#iucTAQ7F?M52ktl6Smb z&#i8X^BI7x4!e6`31C5Y#FsB~^K{28yi{q}hr-)EJl6V4s*h7CTk`OCk- z2VStphy$ao$G^wCOC|-RfE17dQa}ovsX+D7#qF7V(WHPBxLgJN`_Sl)y>Lp5PY0J6 z0f+lA49C} z?O@64YO)2RT{MRe%{!}2F))pG(Sih~)xkgosK7{pdE}j){|ETD`G3^HlnPLRKT|*# z`{RCxm&&vCry AZ2$lO literal 0 HcmV?d00001 diff --git a/src/test/resources/com/.DS_Store b/src/test/resources/com/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..60b9d678e1d1ed4935dca0d52f15ea3ba0ddb574 GIT binary patch literal 6148 zcmeHKyH3ME5S)b+kq}Z!%KHWW;1q=~;0JgFDoaKQh}IR~#iud*Xe>h)nrPPAo4fVS zoo))R7l3U)_P4+Wz?$xeFCUiX@7))6Q4u53xyJz`KKVRiSY-bmaPBpZcq8X9;}3Yj z`|JMr{4|b(r^%#%6p#W^Knh5K6DUwcb$xY$y|jfCkOJqWfPWtv-LV%=iSg;+5G??4 z#c&ws(Mu4U2Z+6JN@Rp)NhK!Ls>QIRGu|q%7fy*uhgI`ob+T25VsSe6Z;=k`i5jJV z6qqY;nahpW|2z60{r{Y#l@yQyXQhCxcK5q2uT-^laXGKGjs8IQoNu}t=Rx5R<(L@d imaZ zmjD(E0BhnHhzLxB3Jj`di=jbBykuTY90P+cn$3si&6*vG`t3Nsc)Dl}*xAUUyqODQoNOaaL;!d=IyrAGjIjPQl>i80h5~3oFOZ co)me-=Gd=^W1!O!cRG+i1Evd&3S3)(U*9ejxc~qF literal 0 HcmV?d00001 diff --git a/src/test/resources/com/sparrowwallet/sparrow/.DS_Store b/src/test/resources/com/sparrowwallet/sparrow/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dffb47f0f2e3e95d323b35f58498fb82ab8c4bf2 GIT binary patch literal 6148 zcmeH~JqiLr422W55Nx)zoW=uqgF*BJUO-d?LD)j<=jgutSh!ltA}^49lk9}ueZ|g3 zM0E2wuSGf$nZu2;vM?}3K9Q^Rm-GE}?E9M)(k4kO!8;jTf9)fw02QDDRDcRlf$=Di zNBMj)o=4)7Pys415(Vu0P~gUzY(f8YAovIX&QNy4+Gh!{SOKib7DNT6(F#VZ`WRw$ zZwE{6tH~COcF`O@H1Di7#lSS$MGF#`RtEzWpaKI0rjd7c{_o)5=KnzpQz}3O{!9U# zZTH&^UMkPlkJq#MA*;4-aL~6Sy!`|qv7>kicf<8!3$P|z5EU4I1Y8CND)3VUo`O#h AF8}}l literal 0 HcmV?d00001 diff --git a/src/test/resources/com/sparrowwallet/sparrow/io/sparrow-single-seed-wallet b/src/test/resources/com/sparrowwallet/sparrow/io/sparrow-single-seed-wallet new file mode 100644 index 00000000..44225ae5 --- /dev/null +++ b/src/test/resources/com/sparrowwallet/sparrow/io/sparrow-single-seed-wallet @@ -0,0 +1 @@ +QklFMQOXQWixo1F4kqJjn/7UeGDmbpNdMGPUP+vzRWdUE2vOcHfejUklKAzq1cTpK0mMEOOHCZ+yg0LxF29KMFQpoSpRTl6GRjnmpGIu3HPuu7bjbL6GvZQXFkvmK+9zsrllxZl6sYMjP4zoHJH6JgL4qGFpnM9n/mtOGYAuOw7zj4fm10teHLLgJLpkZ4ze0n/t8QhbyPPkeEoNmw/gt1PrwNDneKtALCNNdGopEq0QWD15OCEY7fSIfu0K1VO9oMZpOHs78p335Ka7bRRjuq+RWvZLz/X5hb9zVlFIu+KLW/preykMbfg4UiPcVHfc9wSLsmqZe9btYa3yxsem9xRW7J4gXMr7uqMTw/dlrK6XNg0wBXH6cuBed3M6Nu72Hz0OU+M64HEUnsGRYLgz3XcsZAU7+jeUQp6D8sVjH7GsPFIdZl0wzhWNHsgQGLoGXnWyvatsPsklW9BQ5U1d0PxeLxWppwj42Y7YA0+O3BrN7lUmD6xATNt9/xwVotPIllXT84r/OpzFbULzSBZ0uwwV+4tdCOa7FHPUed5gXZCPk6lhPHkz2N6Ehm3WGOQBQsoTfObefYUjHhB+a6Rpggm7QgkLhBEtgy7sPCV39fnRYM52uOwDUhNB8K/h/RadkMX51eXtbx23+LU+jM8zpi4T6yLM1Rq8H9YZ+rJXUIZPOHwX2ytnXkwHcYanThhxvQa55v3vbC5X/JFVSA+yik1CejXctjv9I++5mCCJtGpk/USAWzIb3nhKURPi/a3sg7y/n47s79AxvzvLndlY96UIaI1QVaNoaoJtt1+cBLzrXGlc4hChIqloZN4GJ4F1KabDuyXwagGvsd14zTH6ELAprmJkrd0l9JNTEBrJJbRqFEZj7CwrREyUkxGaiskca+ZyHm4LuwKo/6m5dKgiqyeMUB6WdZFXDERSp9ldf8n+o6OSxolEq4wWxM2uGdbHZTBsORq0JyIS4CQcfiC4UQoXJnQpGAfKWNsc1jS/x0BlV/9n2rhGxC0LRQZ2YbtLwfwd138= \ No newline at end of file