Skip to content

Commit aab666d

Browse files
committed
add wallet
1 parent 500e8f2 commit aab666d

File tree

8 files changed

+297
-121
lines changed

8 files changed

+297
-121
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package fssi.base
2+
3+
import java.util.concurrent.atomic.AtomicReference
4+
5+
sealed trait Var[A] {
6+
def apply(a: A): this.type
7+
def apply(): Option[A]
8+
def unsafe(): A = apply().get
9+
10+
def :=(a: A): this.type = apply(a)
11+
12+
def map[B](f: A => B): Var[B] =
13+
apply().map(f).map(x => Var[B](x)).getOrElse(Var.empty[B])
14+
15+
def flatMap[B](f: A => Var[B]): Var[B] =
16+
apply().map(f).getOrElse(Var.empty[B])
17+
18+
def exists(f: A => Boolean): Boolean = {
19+
apply().exists(f)
20+
}
21+
22+
def foreach(f: A => Unit): Unit =
23+
apply().foreach(f)
24+
25+
def getOrElse(default: => A): A = apply().getOrElse(default)
26+
def update(f: A => A): this.type = {
27+
apply().map(f) match {
28+
case Some(newA) => apply(newA)
29+
case _ => this
30+
}
31+
}
32+
33+
def isEmpty: Boolean = apply().isEmpty
34+
def nonEmpty: Boolean = apply().nonEmpty
35+
def isDefined: Boolean = apply().isDefined
36+
def clear: Unit
37+
38+
}
39+
40+
object Var {
41+
def empty[A]: Var[A] = new SimpleVar[A]
42+
def apply[A](a: A): Var[A] = new SimpleVar[A]()(a)
43+
44+
private[Var] class SimpleVar[A]() extends Var[A] {
45+
private val container: AtomicReference[A] = new AtomicReference[A]()
46+
47+
override def apply(a: A): SimpleVar.this.type = {
48+
def _loop(a: A): SimpleVar.this.type =
49+
if (container.compareAndSet(container.get(), a)) this
50+
else _loop(a)
51+
52+
_loop(a)
53+
}
54+
55+
override def apply(): Option[A] = Option(container.get())
56+
57+
override def toString: String = {
58+
apply().map(_.toString).getOrElse("null")
59+
}
60+
61+
override def clear: Unit = container.set(null.asInstanceOf[A])
62+
}
63+
}

wallet/src/main/resources/ui/MainFrame.fxml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Region prefHeight="200.0" prefWidth="200.0" />
1414
<BorderPane fx:id="workspace" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: black;">
1515
<top>
16-
<StackPane prefHeight="60.0" prefWidth="200.0" BorderPane.alignment="CENTER">
16+
<StackPane maxHeight="-Infinity" minHeight="-Infinity" prefHeight="60.0" prefWidth="200.0" BorderPane.alignment="CENTER">
1717
<children>
1818
<StackPane maxHeight="-Infinity" minHeight="-Infinity" prefHeight="60.0" StackPane.alignment="BOTTOM_CENTER">
1919
<children>
@@ -333,6 +333,9 @@
333333
</children>
334334
</VBox>
335335
</left>
336+
<center>
337+
<StackPane prefHeight="150.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
338+
</center>
336339
</BorderPane>
337340
</children>
338341
</StackPane>

wallet/src/main/resources/ui/css/create_account.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77

88
.create_account_mouse_track_pad {
99
-fx-background-color: #0F171C;
10-
-fx-background-radius: 10px;
10+
-fx-background-radius: 10px 10px 0 0;
1111
-fx-border-width: 1px;
12-
-fx-border-color: #29414E;
13-
-fx-border-radius: 10px;
12+
-fx-border-color: #20333D;
13+
-fx-border-radius: 10px 10px 0 0;
14+
}
15+
16+
.create_account_mouse_track_result {
17+
-fx-background-color: #0F171C;
18+
-fx-background-radius: 0 0 10px 10px;
19+
-fx-border-width: 0 1px 1px 1px;
20+
-fx-border-color: #20333d;
21+
-fx-border-radius: 0 0 10px 10px;
1422
}
1523

1624
.create_account_field_label {

wallet/src/main/resources/ui/css/workspace.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
-fx-text-fill: #9bb7b7;
2323
}
2424

25+
.button_normal {
26+
-fx-background-color: #6D7884;
27+
-fx-font-size: 12px;
28+
-fx-text-fill: #080d13;
29+
-fx-background-radius: 5px;
30+
-fx-font-weight: bold;
31+
}
32+
33+
.button_normal:hover {
34+
-fx-background-color: #383f45;
35+
-fx-text-fill: #9bb7b7;
36+
}
37+
38+
2539
.file_chooser {
2640
-fx-background-color: #275571;
2741
-fx-font-size: 12px;
@@ -38,4 +52,11 @@
3852
.file_chooser:hover {
3953
-fx-background-color: #0f151f;
4054
-fx-text-fill: #a2c2c2;
55+
}
56+
57+
.text_common {
58+
-fx-background-color: transparent;
59+
-fx-border-color: #ADBBC4;
60+
-fx-border-width: 0 0 1px 0px;
61+
-fx-text-fill: #E9ECEF;
4162
}
Loading

wallet/src/main/resources/ui/workspace/create_account.fxml

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -27,116 +27,118 @@
2727
<Label maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" styleClass="workspace-title-text" text="Create Account" />
2828
</children>
2929
</HBox>
30-
<Label prefHeight="36.0" styleClass="create_account_step" text="1. Shake mouse below to create random numbers">
30+
<HBox fx:id="cCanvasParent" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onMouseDragged="#mouseDragged" onMousePressed="#mousePressed" onMouseReleased="#mouseReleased" prefHeight="400.0" prefWidth="804.0" styleClass="create_account_mouse_track_pad">
3131
<VBox.margin>
32-
<Insets left="10.0" />
33-
</VBox.margin>
34-
<padding>
35-
<Insets right="20.0" />
36-
</padding>
37-
</Label>
38-
<HBox fx:id="canvasParent" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onMouseDragged="#mouseDragged" onMousePressed="#mousePressed" onMouseReleased="#mouseReleased" prefHeight="160.0" prefWidth="200.0" styleClass="create_account_mouse_track_pad">
39-
<VBox.margin>
40-
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
32+
<Insets left="10.0" right="10.0" top="10.0" />
4133
</VBox.margin>
4234
<children>
43-
<Canvas fx:id="canvas" height="200.0" width="335.0" HBox.hgrow="ALWAYS" />
35+
<Canvas fx:id="cCanvas" height="200.0" width="335.0" HBox.hgrow="ALWAYS" />
4436
</children>
4537
<padding>
4638
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
4739
</padding>
4840
</HBox>
49-
<VBox prefWidth="100.0">
41+
<HBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" prefWidth="804.0" styleClass="create_account_mouse_track_result">
5042
<children>
51-
<Label styleClass="create_account_field_label" text="Random Numbers:">
52-
<padding>
53-
<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
54-
</padding>
55-
</Label>
56-
<HBox fx:id="canvasParent1" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" onMouseDragged="#mouseDragged" onMousePressed="#mousePressed" prefHeight="100.0" prefWidth="200.0" styleClass="create_account_mouse_track_pad">
57-
<padding>
58-
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
59-
</padding>
60-
<VBox.margin>
61-
<Insets top="10.0" />
62-
</VBox.margin>
63-
<children>
64-
<TextArea fx:id="randomTextArea" prefHeight="200.0" prefWidth="200.0" styleClass="create_account_random_text" wrapText="true" HBox.hgrow="ALWAYS" />
65-
</children>
66-
</HBox>
43+
<Label fx:id="cRandomText" styleClass="create_account_random_text" text="random text" />
6744
</children>
6845
<VBox.margin>
69-
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
46+
<Insets left="10.0" right="10.0" />
7047
</VBox.margin>
71-
</VBox>
72-
<Label prefHeight="36.0" styleClass="create_account_step" text="2. Input personal password to protect your private key">
7348
<padding>
74-
<Insets right="20.0" />
49+
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
7550
</padding>
76-
<VBox.margin>
77-
<Insets left="10.0" />
78-
</VBox.margin>
79-
</Label>
80-
<HBox alignment="CENTER_LEFT" prefWidth="200.0">
51+
</HBox>
52+
<HBox>
8153
<children>
82-
<Label maxHeight="-Infinity" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="100.0" styleClass="create_account_field_label" text="Password:">
83-
<padding>
84-
<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
85-
</padding>
86-
<HBox.margin>
87-
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
88-
</HBox.margin>
89-
</Label>
90-
<PasswordField maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="24.0" prefWidth="300.0" styleClass="create_account_password">
54+
<Button mnemonicParsing="false" onMouseClicked="#resetAll" prefHeight="36.0" prefWidth="100.0" styleClass="button_normal" text="Reset All">
9155
<HBox.margin>
9256
<Insets right="10.0" />
9357
</HBox.margin>
94-
</PasswordField>
95-
</children>
96-
</HBox>
97-
<HBox alignment="CENTER_LEFT" prefWidth="200.0">
98-
<children>
99-
<Label maxHeight="-Infinity" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="100.0" styleClass="create_account_field_label" text="Once More:">
100-
<padding>
101-
<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
102-
</padding>
58+
</Button>
59+
<Button mnemonicParsing="false" onMouseClicked="#generate" prefHeight="36.0" prefWidth="100.0" styleClass="button_primary" text="Generate">
10360
<HBox.margin>
104-
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
61+
<Insets right="10.0" />
10562
</HBox.margin>
106-
</Label>
107-
<PasswordField maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="24.0" prefWidth="300.0" styleClass="create_account_password">
63+
</Button>
64+
<Button mnemonicParsing="false" onMouseClicked="#saveAs" prefHeight="36.0" prefWidth="100.0" styleClass="button_primary" text="Save As ...">
10865
<HBox.margin>
109-
<Insets bottom="10.0" right="10.0" />
66+
<Insets right="10.0" />
11067
</HBox.margin>
111-
</PasswordField>
68+
</Button>
11269
</children>
70+
<VBox.margin>
71+
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
72+
</VBox.margin>
11373
</HBox>
114-
<Label prefHeight="36.0" styleClass="create_account_step" text="3. save your account">
115-
<padding>
116-
<Insets right="20.0" />
117-
</padding>
74+
<GridPane maxWidth="-Infinity" minWidth="-Infinity" prefWidth="804.0">
75+
<columnConstraints>
76+
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="70.0" />
77+
<ColumnConstraints hgrow="SOMETIMES" maxWidth="402.0" minWidth="10.0" prefWidth="363.0" />
78+
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="-Infinity" prefWidth="70.0" />
79+
<ColumnConstraints hgrow="SOMETIMES" maxWidth="302.0" minWidth="10.0" prefWidth="291.0" />
80+
</columnConstraints>
81+
<rowConstraints>
82+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
83+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
84+
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
85+
</rowConstraints>
11886
<VBox.margin>
119-
<Insets left="10.0" />
87+
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
12088
</VBox.margin>
121-
</Label>
122-
<HBox alignment="CENTER_LEFT" prefWidth="200.0">
12389
<children>
124-
<Button mnemonicParsing="false" onMouseClicked="#openFileChooser" styleClass="file_chooser" text="Save As ..." />
125-
<TextField fx:id="savePath" editable="false" styleClass="file_chooser_label" HBox.hgrow="ALWAYS">
126-
<HBox.margin>
90+
<Label alignment="CENTER_RIGHT" prefHeight="24.0" prefWidth="60.0" styleClass="create_account_field_label" text="ID:">
91+
<padding>
12792
<Insets right="10.0" />
128-
</HBox.margin>
93+
</padding>
94+
</Label>
95+
<Label alignment="CENTER_RIGHT" prefHeight="24.0" prefWidth="60.0" styleClass="create_account_field_label" text="Pub:" GridPane.columnIndex="2" GridPane.rowIndex="1">
96+
<padding>
97+
<Insets right="10.0" />
98+
</padding>
99+
</Label>
100+
<Label alignment="CENTER_RIGHT" prefHeight="24.0" prefWidth="60.0" styleClass="create_account_field_label" text="Prv:" GridPane.rowIndex="1">
101+
<padding>
102+
<Insets right="10.0" />
103+
</padding>
104+
</Label>
105+
<Label alignment="CENTER_RIGHT" prefHeight="24.0" prefWidth="60.0" styleClass="create_account_field_label" text="IV:" GridPane.columnIndex="2">
106+
<padding>
107+
<Insets right="10.0" />
108+
</padding>
109+
</Label>
110+
<TextField fx:id="cAccountId" editable="false" styleClass="text_common" GridPane.columnIndex="1">
111+
<GridPane.margin>
112+
<Insets right="10.0" />
113+
</GridPane.margin>
114+
</TextField>
115+
<TextField fx:id="cAccountIv" editable="false" styleClass="text_common" GridPane.columnIndex="3">
116+
<GridPane.margin>
117+
<Insets right="10.0" />
118+
</GridPane.margin>
119+
</TextField>
120+
<TextField fx:id="cAccountPrv" editable="false" styleClass="text_common" GridPane.columnIndex="1" GridPane.rowIndex="1">
121+
<GridPane.margin>
122+
<Insets right="10.0" />
123+
</GridPane.margin>
124+
</TextField>
125+
<TextField fx:id="cAccountPub" editable="false" styleClass="text_common" GridPane.columnIndex="3" GridPane.rowIndex="1">
126+
<GridPane.margin>
127+
<Insets right="10.0" />
128+
</GridPane.margin>
129+
</TextField>
130+
<Label alignment="CENTER_RIGHT" prefHeight="24.0" prefWidth="60.0" styleClass="create_account_field_label" text="Sec:" GridPane.rowIndex="2">
131+
<padding>
132+
<Insets right="10.0" />
133+
</padding>
134+
</Label>
135+
<TextField fx:id="cAccountSec" editable="false" styleClass="text_common" GridPane.columnIndex="1" GridPane.rowIndex="2">
136+
<GridPane.margin>
137+
<Insets right="10.0" />
138+
</GridPane.margin>
129139
</TextField>
130140
</children>
131-
<VBox.margin>
132-
<Insets left="10.0" top="10.0" />
133-
</VBox.margin>
134-
</HBox>
135-
<HBox alignment="CENTER_LEFT" prefWidth="200.0">
136-
<VBox.margin>
137-
<Insets left="10.0" top="20.0" />
138-
</VBox.margin>
139-
</HBox>
141+
</GridPane>
140142
</children>
141143
<stylesheets>
142144
<URL value="@../css/workspace.css" />

wallet/src/main/scala/fssi/wallet/WalletMain.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import scalafx.stage.StageStyle
1515
object WalletMain extends JFXApp with LoginFragment with MainFrameFragment {
1616
self =>
1717

18+
fssi.utils.crypto.registerBC()
1819
//load font
1920
Font.loadFont(getClass.getClassLoader.getResource("ui/font/Metropolis-Regular.otf").toExternalForm, 10)
2021

0 commit comments

Comments
 (0)