Parametrize input form

This commit is contained in:
Rene Vergara 2024-06-17 15:47:56 -05:00
parent 71cc28434a
commit eae4bfc949
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 75 additions and 7 deletions

BIN
assets/1F616_color.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -40,6 +40,7 @@ import Zenith.Utils (displayAmount, showAddress)
data AppEvent data AppEvent
= AppInit = AppInit
| ShowMsg !T.Text | ShowMsg !T.Text
| ShowError !T.Text
| CloseMsg | CloseMsg
| WalletClicked | WalletClicked
| AccountClicked | AccountClicked
@ -59,6 +60,8 @@ data AppEvent
| LoadAccs ![Entity ZcashAccount] | LoadAccs ![Entity ZcashAccount]
| ConfirmCancel | ConfirmCancel
| SaveAddress | SaveAddress
| SaveAccount
| SaveWallet
deriving (Eq, Show) deriving (Eq, Show)
data AppModel = AppModel data AppModel = AppModel
@ -87,6 +90,7 @@ data AppModel = AppModel
, _confirmAccept :: !T.Text , _confirmAccept :: !T.Text
, _confirmCancel :: !T.Text , _confirmCancel :: !T.Text
, _confirmEvent :: !AppEvent , _confirmEvent :: !AppEvent
, _inError :: !Bool
} deriving (Eq, Show) } deriving (Eq, Show)
makeLenses ''AppModel makeLenses ''AppModel
@ -444,7 +448,14 @@ buildUI wenv model = widgetTree
] ]
msgOverlay = msgOverlay =
alert CloseMsg $ alert CloseMsg $
hstack [filler, label $ fromMaybe "" (model ^. msg), filler] hstack
[ filler
, image_ "./assets/1F616_color.png" [fitHeight] `styleBasic`
[height 44, width 44] `nodeVisible`
(model ^. inError)
, label $ fromMaybe "" (model ^. msg)
, filler
]
confirmOverlay = confirmOverlay =
confirm_ confirm_
(model ^. confirmEvent) (model ^. confirmEvent)
@ -533,6 +544,8 @@ handleEvent wenv node model evt =
case evt of case evt of
AppInit -> [] AppInit -> []
ShowMsg t -> [Model $ model & msg ?~ t & menuPopup .~ False] ShowMsg t -> [Model $ model & msg ?~ t & menuPopup .~ False]
ShowError t ->
[Model $ model & msg ?~ t & menuPopup .~ False & inError .~ True]
WalletClicked -> [Model $ model & walPopup .~ True] WalletClicked -> [Model $ model & walPopup .~ True]
AccountClicked -> [Model $ model & accPopup .~ True] AccountClicked -> [Model $ model & accPopup .~ True]
MenuClicked -> [Model $ model & menuPopup .~ True] MenuClicked -> [Model $ model & menuPopup .~ True]
@ -541,13 +554,51 @@ handleEvent wenv node model evt =
[ Model $ [ Model $
model & confirmTitle ?~ "New Address" & confirmAccept .~ "Create" & model & confirmTitle ?~ "New Address" & confirmAccept .~ "Create" &
confirmCancel .~ confirmCancel .~
"Cancel" "Cancel" &
confirmEvent .~
SaveAddress &
menuPopup .~
False
]
NewAccount ->
[ Model $
model & confirmTitle ?~ "New Account" & confirmAccept .~ "Create" &
confirmCancel .~
"Cancel" &
confirmEvent .~
SaveAccount &
menuPopup .~
False
]
NewWallet ->
[ Model $
model & confirmTitle ?~ "New Wallet" & confirmAccept .~ "Create" &
confirmCancel .~
"Cancel" &
confirmEvent .~
SaveWallet &
menuPopup .~
False
] ]
NewAccount -> [Event $ ShowMsg "You clicked new account"]
NewWallet -> [Event $ ShowMsg "You clicked new wallet"]
ConfirmCancel -> [Model $ model & confirmTitle .~ Nothing & mainInput .~ ""] ConfirmCancel -> [Model $ model & confirmTitle .~ Nothing & mainInput .~ ""]
SaveAddress -> SaveAddress ->
[Event $ ShowMsg $ "You saved address: " <> model ^. mainInput] [ if T.length (model ^. mainInput) > 1
then Event $ ShowMsg $ "You saved address: " <> model ^. mainInput
else Event $ ShowError "Invalid input"
, Event ConfirmCancel
]
SaveAccount ->
[ if T.length (model ^. mainInput) > 1
then Event $ ShowMsg $ "You saved account: " <> model ^. mainInput
else Event $ ShowError "Invalid input"
, Event ConfirmCancel
]
SaveWallet ->
[ if T.length (model ^. mainInput) > 1
then Event $ ShowMsg $ "You saved wallet: " <> model ^. mainInput
else Event $ ShowError "Invalid input"
, Event ConfirmCancel
]
SetPool p -> SetPool p ->
[ Model $ model & selPool .~ p [ Model $ model & selPool .~ p
, Task $ , Task $
@ -606,7 +657,7 @@ handleEvent wenv node model evt =
LoadTxs t -> [Model $ model & transactions .~ t] LoadTxs t -> [Model $ model & transactions .~ t]
LoadAddrs a -> [Model $ model & addresses .~ a, Event $ SetPool Orchard] LoadAddrs a -> [Model $ model & addresses .~ a, Event $ SetPool Orchard]
LoadAccs a -> [Model $ model & accounts .~ a, Event $ SwitchAcc 0] LoadAccs a -> [Model $ model & accounts .~ a, Event $ SwitchAcc 0]
CloseMsg -> [Model $ model & msg .~ Nothing] CloseMsg -> [Model $ model & msg .~ Nothing & inError .~ False]
where where
currentWallet = currentWallet =
if null (model ^. wallets) if null (model ^. wallets)
@ -690,6 +741,7 @@ runZenithGUI config = do
"" ""
"" ""
SaveAddress SaveAddress
False
startApp model handleEvent buildUI params startApp model handleEvent buildUI params
Left e -> do Left e -> do
initDb dbFilePath initDb dbFilePath
@ -722,6 +774,7 @@ runZenithGUI config = do
"" ""
"" ""
SaveAddress SaveAddress
False
startApp model handleEvent buildUI params startApp model handleEvent buildUI params
where where
params = params =

View file

@ -63,7 +63,22 @@ zenithTheme =
hiliteTextStyle & hiliteTextStyle &
L.active . L.active .
L.btnMainStyle . L.text ?~ L.btnMainStyle . L.text ?~
hiliteTextStyle hiliteTextStyle &
L.basic .
L.textFieldStyle . L.text ?~
baseTextStyle &
L.hover .
L.textFieldStyle . L.text ?~
baseTextStyle &
L.focus .
L.textFieldStyle . L.text ?~
baseTextStyle &
L.active .
L.textFieldStyle . L.text ?~
baseTextStyle &
L.focusHover .
L.textFieldStyle . L.text ?~
baseTextStyle
zenithThemeColors :: BaseThemeColors zenithThemeColors :: BaseThemeColors
zenithThemeColors = zenithThemeColors =