@@ -13,7 +13,7 @@ import Cardano.Wallet.UI.Common.Html.Htmx
13
13
, hxGet_
14
14
, hxPost_
15
15
, hxTarget_
16
- , useHtmxExtension
16
+
17
17
)
18
18
import Cardano.Wallet.UI.Common.Html.Lib
19
19
( linkText
@@ -49,25 +49,44 @@ import Servant
49
49
50
50
import qualified Data.Text as T
51
51
52
- mnemonicH :: Maybe [Text ] -> Html ()
53
- mnemonicH Nothing = " "
54
- mnemonicH (Just mnemonic) = do
55
- div_ [class_ " card" ] $ do
56
- div_
57
- [ class_ " card-body text-muted small"
58
- , id_ " copy-mnemonic"
59
- ]
60
- $ toHtml
61
- $ T. intercalate " " mnemonic
62
- copyButton " copy-mnemonic"
52
+ --------------------------------------------------------------------------------
53
+ -- Configuration
54
+ --------------------------------------------------------------------------------
55
+
56
+ -- | Configuration for the wallet creation form
57
+ data PostWalletConfig = PostWalletConfig
58
+ { passwordVisibility :: Maybe Visible
59
+ -- ^ Whether the password should be visible
60
+ , walletDataLink :: Link
61
+ -- ^ Link to post the form data to
62
+ , responseTarget :: Text
63
+ }
64
+
65
+ --------------------------------------------------------------------------------
66
+ -- Library
67
+ --------------------------------------------------------------------------------
68
+
69
+ -- | Add a form tag with the appropriate attributes for a POST request
70
+ postWalletFormTagH :: PostWalletConfig -> WHtml () -> WHtml ()
71
+ postWalletFormTagH PostWalletConfig {.. } =
72
+ form_
73
+ [ hxPost_ $ linkText walletDataLink
74
+ , hxExt_ " json-enc"
75
+ , hxTarget_ responseTarget
76
+ , autocomplete_ " off"
77
+ ]
78
+
79
+ --------------------------------------------------------------------------------
80
+ -- Wallet creation forms
81
+ --------------------------------------------------------------------------------
63
82
64
- newWalletH :: ( Maybe Bool -> Link ) -> PostWalletConfig -> WHtml ()
65
- newWalletH walletMnemonicLink config = do
66
- useHtmxExtension " json-enc "
83
+ -- | Widget to create a new wallet from a mnemonic
84
+ newWalletFromMnemonicH :: ( Maybe Bool -> Link ) -> PostWalletConfig -> WHtml ()
85
+ newWalletFromMnemonicH walletMnemonicLink config = do
67
86
div_ [class_ " btn-group mb-3" , role_ " group" ] $ do
68
87
button_
69
88
[ class_ " btn btn-outline-secondary"
70
- , hxGet_ $ linkText $ walletMnemonicLink Nothing
89
+ , hxGet_ $ linkText $ walletMnemonicLink $ Just False
71
90
, hxTarget_ " #menmonic"
72
91
]
73
92
" Hint a mnemonic"
@@ -80,53 +99,70 @@ newWalletH walletMnemonicLink config = do
80
99
81
100
div_ [id_ " menmonic" , class_ " mb-3" ] " "
82
101
83
- postWalletForm config
102
+ postWalletFormTagH config $ mnemonicSetupFieldsH config
84
103
85
- div_
86
- [ id_ " new_wallet"
104
+ -- | Display a mnemonic
105
+ mnemonicH :: Maybe [Text ] -> Html ()
106
+ mnemonicH Nothing = " "
107
+ mnemonicH (Just mnemonic) = do
108
+ div_ [class_ " card" ] $ do
109
+ div_
110
+ [ class_ " card-body text-muted small"
111
+ , id_ " copy-mnemonic"
112
+ ]
113
+ $ toHtml
114
+ $ T. intercalate " " mnemonic
115
+ copyButton " copy-mnemonic"
116
+
117
+ -- | Form fields for restoring a wallet from a mnemonic
118
+ mnemonicSetupFieldsH :: PostWalletConfig -> WHtml ()
119
+ mnemonicSetupFieldsH PostWalletConfig {.. } = do
120
+ input_
121
+ [ class_ " form-control form-control-lg mb-3"
122
+ , visibility
123
+ , name_ " mnemonicSentence"
124
+ , placeholder_ " Mnemonic Sentence"
87
125
]
88
- mempty
126
+ onShelley
127
+ $ input_
128
+ [ class_ " form-control form-control-lg mb-3"
129
+ , type_ " text"
130
+ , name_ " name"
131
+ , placeholder_ " Wallet Name"
132
+ ]
133
+ onShelley
134
+ $ input_
135
+ [ class_ " form-control form-control-lg mb-3"
136
+ , type_ " password"
137
+ , name_ " password"
138
+ , placeholder_ " Wallet Password"
139
+ ]
140
+ button_
141
+ [ class_ " btn btn-primary btn-block mb-3"
142
+ , type_ " submit"
143
+ ]
144
+ " Restore wallet from mnemonic"
145
+ where
146
+ visibility = type_ $ case passwordVisibility of
147
+ Just Visible -> " text"
148
+ Just Hidden -> " password"
149
+ Nothing -> " password"
89
150
90
- data PostWalletConfig = PostWalletConfig
91
- { passwordVisibility :: Maybe Visible
92
- , walletDataLink :: Link
93
- }
151
+ --------------------------------------------------------------------------------
152
+ -- Wallet restoration from public key
153
+ --------------------------------------------------------------------------------
94
154
95
- postWalletForm :: PostWalletConfig -> WHtml ()
96
- postWalletForm PostWalletConfig {.. } = form_
97
- [ hxPost_ $ linkText walletDataLink
98
- , hxExt_ " json-enc"
99
- , hxTarget_ " #new_wallet"
100
- , autocomplete_ " off"
101
- ]
102
- $ do
155
+ newWalletFromXPubH :: PostWalletConfig -> WHtml ()
156
+ newWalletFromXPubH config = do
157
+ postWalletFormTagH config $ do
103
158
input_
104
159
[ class_ " form-control form-control-lg mb-3"
105
- , visibility
106
- , name_ " mnemonicSentence "
107
- , placeholder_ " Mnemonic Sentence "
160
+ , type_ " text "
161
+ , name_ " xpub "
162
+ , placeholder_ " Extended Public Key "
108
163
]
109
- onShelley
110
- $ input_
111
- [ class_ " form-control form-control-lg mb-3"
112
- , type_ " text"
113
- , name_ " name"
114
- , placeholder_ " Wallet Name"
115
- ]
116
- onShelley
117
- $ input_
118
- [ class_ " form-control form-control-lg mb-3"
119
- , visibility
120
- , name_ " passphrase"
121
- , placeholder_ " Passphrase"
122
- ]
123
164
button_
124
165
[ class_ " btn btn-primary btn-block mb-3"
125
166
, type_ " submit"
126
167
]
127
- " Restore wallet"
128
- where
129
- visibility = type_ $ case passwordVisibility of
130
- Just Visible -> " text"
131
- Just Hidden -> " password"
132
- Nothing -> " password"
168
+ " Restore wallet from public key"
0 commit comments