From 53eac75aa57a56761614759e3559747aa5e650b6 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Mon, 14 Oct 2024 19:42:09 -0400 Subject: [PATCH] rvv001 - Shield / Deshield Forms - Shield form created - Deshield form created Both forms have the 'Process' button de-activated. Must be linked to the appropiate funciton --- src/Zenith/CLI.hs | 54 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index 6590189..baa61f4 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -164,7 +164,6 @@ makeLenses ''AdrBookEntry data ShDshEntry = ShDshEntry { _totalTransparent :: !Float , _totalShielded :: !Float - , _shieldOp :: !ShieldDeshieldOp , _shAmt :: !Float } deriving (Show) @@ -182,7 +181,8 @@ data DialogType | AdrBookForm | AdrBookUpdForm | AdrBookDelForm - | ShieldDeshieldForm + | DeshieldForm + | ShieldForm data DisplayType = AddrDisplay @@ -231,7 +231,8 @@ data State = State , _abCurAdrs :: !T.Text -- used for address book CRUD operations , _sentTx :: !(Maybe HexString) , _unconfBalance :: !Integer - , _shdshForm :: !(Form ShDshEntry () Name) + , _deshieldForm :: !(Form ShDshEntry () Name) + , _shieldForm :: !(Form ShDshEntry () Name) } makeLenses ''State @@ -290,7 +291,8 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] ,C.hCenter (hBox [ capCommand2 "Address " "B" "ook" - , capCommand2 "Shield/" "D" "eshield" + , capCommand2 "s" "H" "ield" + , capCommand "D" "e-shield" , capCommand "Q" "uit" , capCommand "?" " Help" , str $ show (st ^. timer) @@ -420,10 +422,16 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] (renderForm (st ^. txForm) <=> C.hCenter (hBox [capCommand "↲ " "Send", capCommand " " "Cancel"])) - ShieldDeshieldForm -> + DeshieldForm -> D.renderDialog - (D.dialog (Just (str " Shield / De-Shield ")) Nothing 50) - (renderForm (st ^. shdshForm) <=> + (D.dialog (Just (str " De-Shield Zec ")) Nothing 50) + (renderForm (st ^. deshieldForm) <=> + C.hCenter + (hBox [capCommand "P" "roceed", capCommand " " "Cancel"])) + ShieldForm -> + D.renderDialog + (D.dialog (Just (str " Shield Zec ")) Nothing 50) + (renderForm (st ^. shieldForm) <=> C.hCenter (hBox [capCommand "P" "roceed", capCommand " " "Cancel"])) Blank -> emptyWidget @@ -669,8 +677,8 @@ mkSendForm bal = label s w = padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w -mkshieldDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name -mkshieldDeshieldForm bal = +mkDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name +mkDeshieldForm bal = newForm [ label "Total Transp. : " @@= editShowableFieldWithValidate totalTransparent TotalTranspField (isAmountValid bal) @@ -685,6 +693,18 @@ mkshieldDeshieldForm bal = label s w = padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w +mkShieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name +mkShieldForm bal = + newForm + [ label "Amount to Shield: " @@= + editShowableFieldWithValidate shAmt AmtField (isAmountValid bal) + ] + where + isAmountValid :: Integer -> Float -> Bool + isAmountValid b i = (fromIntegral b / 100000000.0) >= i + label s w = + padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w + mkNewABForm :: AdrBookEntry -> Form AdrBookEntry e Name mkNewABForm = newForm @@ -933,7 +953,8 @@ appEvent (BT.AppEvent t) = do AdrBookForm -> return () AdrBookUpdForm -> return () AdrBookDelForm -> return () - ShieldDeshieldForm -> return () + DeshieldForm -> return () + ShieldForm -> return () Blank -> do if s ^. timer == 90 then do @@ -1182,14 +1203,14 @@ appEvent (BT.VtyEvent e) = do setFieldValid (isRecipientValidGUI (fs ^. policyField) (fs ^. sendTo)) RecField - ShieldDeshieldForm -> do + DeshieldForm -> do case e of V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank ev -> - BT.zoom shdshForm $ do + BT.zoom deshieldForm $ do handleFormEvent (BT.VtyEvent ev) -- fs <- BT.gets formState --- ev -> BT.zoom shdshForm $ L.handleListEvent ev +-- ev -> BT.zoom deshieldForm $ L.handleListEvent ev AdrBook -> do case e of V.EvKey (V.KChar 'x') [] -> @@ -1400,7 +1421,9 @@ appEvent (BT.VtyEvent e) = do V.EvKey (V.KChar 'b') [] -> BT.modify $ set dialogBox AdrBook V.EvKey (V.KChar 'd') [] -> - BT.modify $ set dialogBox ShieldDeshieldForm + BT.modify $ set dialogBox DeshieldForm + V.EvKey (V.KChar 'h') [] -> + BT.modify $ set dialogBox ShieldForm ev -> case r of Just AList -> @@ -1539,7 +1562,8 @@ runZenithTUI config = do "" Nothing uBal - (mkshieldDeshieldForm 0 (ShDshEntry 0 0 Shield 0.0 )) + (mkDeshieldForm 0 (ShDshEntry 0 0 0.0 )) + (mkShieldForm 0 (ShDshEntry 0 0 0.0 )) Left _e -> do print $ "No Zebra node available on port " <>