From 54d9f20fdd7e50a055df6baef60ce03cff6a2611 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Wed, 9 Oct 2024 21:02:35 -0400 Subject: [PATCH 1/4] rvv001 - Shield / De-Shield GUI - Forms for Shielding and De-shielding created TUI - Form to deshield is not implemented --- src/Zenith/CLI.hs | 6 -- src/Zenith/GUI.hs | 139 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 138 insertions(+), 7 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index 02b5fbe..6590189 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -676,12 +676,6 @@ mkshieldDeshieldForm bal = editShowableFieldWithValidate totalTransparent TotalTranspField (isAmountValid bal) , label "Total Shielded : " @@= editShowableFieldWithValidate totalShielded TotalShieldedField (isAmountValid bal) - , label "Select :" @@= - radioField - shieldOp - [ (Shield, ShieldField, "Shield") - , (Deshield, DeshieldField, "De-Shield") - ] , label "Amount: " @@= editShowableFieldWithValidate shAmt AmtField (isAmountValid bal) ] diff --git a/src/Zenith/GUI.hs b/src/Zenith/GUI.hs index b23ff0d..42f828d 100644 --- a/src/Zenith/GUI.hs +++ b/src/Zenith/GUI.hs @@ -126,6 +126,10 @@ data AppEvent | DeleteABEntry !T.Text | UpdateABDescrip !T.Text !T.Text | ResetRecipientValid + | ShowShield + | CloseShield + | ShowDeShield + | CloseDeShield deriving (Eq, Show) data AppModel = AppModel @@ -179,6 +183,12 @@ data AppModel = AppModel , _showABAddress :: !Bool , _updateABAddress :: !Bool , _privacyChoice :: !PrivacyPolicy + , _shieldZec :: !Bool + , _deShieldZec :: !Bool + , _tBalance :: !Integer + , _tBalanceValid :: !Bool + , _sBalance :: !Integer + , _sBalanceValid :: !Bool } deriving (Eq, Show) makeLenses ''AppModel @@ -228,6 +238,8 @@ buildUI wenv model = widgetTree , updateABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible` model ^. updateABAddress + , shieldOverlay `nodeVisible` model ^. shieldZec + , deShieldOverlay `nodeVisible` model ^. deShieldZec , msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB) ] mainWindow = @@ -293,6 +305,10 @@ buildUI wenv model = widgetTree [bgColor white, borderB 1 gray, padding 3] , box_ [alignLeft, onClick ShowAdrBook] (label "Address Book") `styleBasic` [bgColor white, borderB 1 gray, padding 3] + , box_ [alignLeft, onClick ShowShield] (label "Shield ZEC") `styleBasic` + [bgColor white, borderB 1 gray, padding 3] + , box_ [alignLeft, onClick ShowDeShield] (label "De-Shield ZEC") `styleBasic` + [bgColor white, borderB 1 gray, padding 3] ]) `styleBasic` [bgColor btnColor, padding 3] newBox = @@ -958,7 +974,118 @@ buildUI wenv model = widgetTree , label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline] , filler ] - + shieldOverlay = + alert CloseShield $ + box + (vstack + [ filler + , hstack + [ filler + , box_ + [] + (vstack + [ box_ + [alignMiddle] + (label "Shield Zcash" `styleBasic` + [textFont "Bold", textSize 12]) + , separatorLine `styleBasic` [fgColor btnColor] + , spacer + , hstack + [ label "Amount:" `styleBasic` + [width 50, textFont "Bold"] + , spacer + , numericField_ + sendAmount + [ decimals 8 + , minValue 0.0 + , maxValue + (fromIntegral (model ^. tBalance) / 100000000.0) + , validInput tBalanceValid + , onChange CheckAmount + ] `styleBasic` + [ width 150 + , styleIf + (not $ model ^. tBalanceValid) + (textColor red) + ] + ] + , spacer + , box_ + [alignMiddle] + (hstack + [ filler + , mainButton "Proceed" NotImplemented `nodeEnabled` + (model ^. amountValid && model ^. recipientValid) + , filler + ]) + ]) `styleBasic` + [radius 4, border 2 btnColor, bgColor white, padding 4] + , filler + ] + , filler + ]) `styleBasic` + [bgColor (white & L.a .~ 0.5)] + deShieldOverlay = + alert CloseDeShield $ + box + (vstack + [ filler + , hstack + [ filler + , box_ + [] + (vstack + [ box_ + [alignMiddle] + (label "De-Shield Zcash" `styleBasic` + [textFont "Bold", textSize 12]) + , separatorLine `styleBasic` [fgColor btnColor] + , spacer + , hstack + [ (label "Total Transparent : " `styleBasic` [ textFont "Bold" ]) + , (label "0.00" ) + ] + , spacer + , hstack + [ (label "Total Shielded : " `styleBasic` [ textFont "Bold" ]) + , (label "0.00" ) + ] + , spacer + , hstack + [ label "Amount:" `styleBasic` + [width 50, textFont "Bold"] + , spacer + , numericField_ + sendAmount + [ decimals 8 + , minValue 0.0 + , maxValue + (fromIntegral (model ^. sBalance) / 100000000.0) + , validInput sBalanceValid + , onChange CheckAmount + ] `styleBasic` + [ width 150 + , styleIf + (not $ model ^. sBalanceValid) + (textColor red) + ] + ] + , spacer + , box_ + [alignMiddle] + (hstack + [ filler + , mainButton "Proceed" NotImplemented `nodeEnabled` + (model ^. amountValid && model ^. recipientValid) + , filler + ]) + ]) `styleBasic` + [radius 4, border 2 btnColor, bgColor white, padding 4] + , filler + ] + , filler + ]) `styleBasic` + [bgColor (white & L.a .~ 0.5)] notImplemented = NotImplemented generateQRCodes :: Config -> IO () @@ -1349,6 +1476,10 @@ handleEvent wenv node model evt = model & msgAB ?~ "Function not implemented..." & menuPopup .~ False ] CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False] + ShowShield -> [ Model $ model & shieldZec .~ True & menuPopup .~ False ] + CloseShield -> [Model $ model & shieldZec .~ False] + ShowDeShield -> [ Model $ model & deShieldZec .~ True & menuPopup .~ False ] + CloseDeShield -> [Model $ model & deShieldZec .~ False] LoadAbList a -> [Model $ model & abaddressList .~ a] UpdateABDescrip d a -> [ Task $ updAddrBookDescrip (model ^. configuration) d a @@ -1697,6 +1828,12 @@ runZenithGUI config = do False False Full + False + False + 0 + False + 0 + False startApp model handleEvent buildUI (params hD) Left _e -> print "Zebra not available" where From 9acf18c503871ba51399b2be947c89145b7e8eda Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Fri, 11 Oct 2024 20:12:15 -0400 Subject: [PATCH 2/4] rvv001 - Shield Zec form updated --- src/Zenith/GUI.hs | 48 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/Zenith/GUI.hs b/src/Zenith/GUI.hs index 42f828d..a508c09 100644 --- a/src/Zenith/GUI.hs +++ b/src/Zenith/GUI.hs @@ -975,8 +975,7 @@ buildUI wenv model = widgetTree , filler ] shieldOverlay = - alert CloseShield $ - box + box (vstack [ filler , hstack @@ -991,32 +990,39 @@ buildUI wenv model = widgetTree , separatorLine `styleBasic` [fgColor btnColor] , spacer , hstack - [ label "Amount:" `styleBasic` + [ filler + , label ("Amount : " ) `styleBasic` [width 50, textFont "Bold"] , spacer - , numericField_ - sendAmount - [ decimals 8 - , minValue 0.0 - , maxValue - (fromIntegral (model ^. tBalance) / 100000000.0) - , validInput tBalanceValid - , onChange CheckAmount - ] `styleBasic` - [ width 150 - , styleIf - (not $ model ^. tBalanceValid) - (textColor red) - ] + , label (displayAmount (model ^. network) 100 ) `styleBasic` + [width 50, textFont "Bold"] + , filler +-- , spacer +-- , numericField_ +-- sendAmount +-- [ decimals 8 +-- , minValue 0.0 +-- , maxValue +-- (fromIntegral (model ^. tBalance) / 100000000.0) +-- , validInput tBalanceValid +-- , onChange CheckAmount +-- ] `styleBasic` +-- [ width 150 +-- , styleIf +-- (not $ model ^. tBalanceValid) +-- (textColor red) +-- ] ] , spacer , box_ [alignMiddle] (hstack - [ filler - , mainButton "Proceed" NotImplemented `nodeEnabled` - (model ^. amountValid && model ^. recipientValid) - , filler + [ filler + , mainButton "Proceed" NotImplemented `nodeEnabled` True +-- (model ^. amountValid && model ^. recipientValid) + , spacer + , mainButton "Cancel" CloseShield `nodeEnabled` True + , filler ]) ]) `styleBasic` [radius 4, border 2 btnColor, bgColor white, padding 4] From 324ed663c3784e507239a1c85bac2d0e30120799 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Fri, 11 Oct 2024 21:01:50 -0400 Subject: [PATCH 3/4] rvv001 - Shield - Deshield process DeShield form - Cancel button moved to the right of process button --- src/Zenith/GUI.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Zenith/GUI.hs b/src/Zenith/GUI.hs index a508c09..6f76bac 100644 --- a/src/Zenith/GUI.hs +++ b/src/Zenith/GUI.hs @@ -1032,7 +1032,6 @@ buildUI wenv model = widgetTree ]) `styleBasic` [bgColor (white & L.a .~ 0.5)] deShieldOverlay = - alert CloseDeShield $ box (vstack [ filler @@ -1081,8 +1080,10 @@ buildUI wenv model = widgetTree [alignMiddle] (hstack [ filler - , mainButton "Proceed" NotImplemented `nodeEnabled` - (model ^. amountValid && model ^. recipientValid) + , mainButton "Proceed" NotImplemented `nodeEnabled` True +-- (model ^. amountValid && model ^. recipientValid) + , spacer + , mainButton "Cancel" CloseDeShield `nodeEnabled` True , filler ]) ]) `styleBasic` From 53eac75aa57a56761614759e3559747aa5e650b6 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Mon, 14 Oct 2024 19:42:09 -0400 Subject: [PATCH 4/4] 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 " <>