From 398f4f1dcf54c116e7cf83ef81dc05b892225c91 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Tue, 1 Oct 2024 20:47:45 -0400 Subject: [PATCH 1/4] rvv001 - Privacy Policy control addedin TUI's send transaction form This feature is similar to GUI's implementation. --- src/Zenith/CLI.hs | 3 ++- src/Zenith/Utils.hs | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index f18493a..4522913 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -107,6 +107,7 @@ import Zenith.Utils ( displayTaz , displayZec , isRecipientValid + , isRecipientValidGUI , jsonNumber , parseAddressUA , showAddress @@ -1132,7 +1133,7 @@ appEvent (BT.VtyEvent e) = do fs <- BT.gets formState BT.modify $ setFieldValid - (isRecipientValid (fs ^. sendTo)) + (isRecipientValidGUI (fs ^. policyField) (fs ^. sendTo)) RecField AdrBook -> do case e of diff --git a/src/Zenith/Utils.hs b/src/Zenith/Utils.hs index c5d9395..5d1ed4d 100644 --- a/src/Zenith/Utils.hs +++ b/src/Zenith/Utils.hs @@ -173,7 +173,6 @@ isRecipientValidGUI p a = do Exchange ea -> True _ -> False Nothing -> False - None -> case adr of Just a -> case a of From 25b6a097c7cda10bf2498bdc7a9374a8b4d8bb5b Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Wed, 2 Oct 2024 20:29:51 -0400 Subject: [PATCH 2/4] rvv001 - Address Validation for PrivacyPolicy = Low Transparent, Sapling, Orchard -> Accepted Exchange -> rejected --- src/Zenith/Utils.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Zenith/Utils.hs b/src/Zenith/Utils.hs index 5d1ed4d..b9355f0 100644 --- a/src/Zenith/Utils.hs +++ b/src/Zenith/Utils.hs @@ -170,7 +170,6 @@ isRecipientValidGUI p a = do Unified ua -> True Sapling sa -> True Transparent ta -> True - Exchange ea -> True _ -> False Nothing -> False None -> case adr of From cf2f77e5109ded1f6f79d7d27895e192262cf357 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Fri, 4 Oct 2024 21:01:13 -0400 Subject: [PATCH 3/4] rvv001 -TUI - Form to process Shielding and De-Shielding zec has been implemented The functionality to do the process is pending. --- src/Zenith/CLI.hs | 80 ++++++++++++++++++++++++++++++++++++++------- src/Zenith/Types.hs | 5 +++ 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index 4522913..8a76b5c 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -102,6 +102,7 @@ import Zenith.Types , PrivacyPolicy(..) , UnifiedAddressDB(..) , ZcashNetDB(..) + , ShieldDeshieldOp(..) ) import Zenith.Utils ( displayTaz @@ -132,6 +133,8 @@ data Name | PrivacyLowField | PrivacyMediumField | PrivacyFullField + | ShieldField + | DeshieldField deriving (Eq, Show, Ord) data DialogInput = DialogInput @@ -156,6 +159,13 @@ data AdrBookEntry = AdrBookEntry makeLenses ''AdrBookEntry +data ShDshEntry = ShDshEntry + { _shieldOp :: !ShieldDeshieldOp + , _shAmt :: !Float + } deriving (Show) + +makeLenses ''ShDshEntry + data DialogType = WName | AName @@ -168,6 +178,7 @@ data DialogType | AdrBookForm | AdrBookUpdForm | AdrBookDelForm + | ShieldDeshieldForm data DisplayType = AddrDisplay @@ -216,6 +227,7 @@ data State = State , _abCurAdrs :: !T.Text -- used for address book CRUD operations , _sentTx :: !(Maybe HexString) , _unconfBalance :: !Integer + , _shdshForm :: !(Form ShDshEntry () Name) } makeLenses ''State @@ -263,17 +275,24 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] (C.hCenter (str ("Last block seen: " ++ show (st ^. syncBlock) ++ "\n")) <=> listTxBox " Transactions " (st ^. network) (st ^. transactions))) <=> - C.hCenter - (hBox - [ capCommand "W" "allets" - , capCommand "A" "ccounts" - , capCommand "V" "iew address" - , capCommand "S" "end Tx" - , capCommand2 "Address " "B" "ook" - , capCommand "Q" "uit" - , capCommand "?" " Help" - , str $ show (st ^. timer) - ]) + (vBox + [C.hCenter + (hBox + [ capCommand "W" "allets" + , capCommand "A" "ccounts" + , capCommand "V" "iew address" + , capCommand3 "" "S" "end Tx" + ]) + ,C.hCenter + (hBox + [ capCommand2 "Address " "B" "ook" + , capCommand2 "Shield/" "D" "eshield" + , capCommand "Q" "uit" + , capCommand "?" " Help" + , str $ show (st ^. timer) + ]) + ] + ) listBox :: Show e => String -> L.List Name e -> Widget Name listBox titleLabel l = C.vCenter $ @@ -339,7 +358,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] else emptyWidget where keyList = - map (C.hCenter . str) ["?", "Esc", "w", "a", "v", "s", "b", "q"] + map (C.hCenter . str) ["?", "Esc", "w", "a", "v", "s", "b", "d", "q"] actionList = map (hLimit 40 . str) @@ -350,6 +369,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] , "View address" , "Send Tx" , "Address Book" + , "Shield/De-Shield" , "Quit" ] inputDialog :: State -> Widget Name @@ -396,6 +416,12 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] (renderForm (st ^. txForm) <=> C.hCenter (hBox [capCommand "↲ " "Send", capCommand " " "Cancel"])) + ShieldDeshieldForm -> + D.renderDialog + (D.dialog (Just (str " Shield / De-Shield ")) Nothing 50) + (renderForm (st ^. shdshForm) <=> + C.hCenter + (hBox [capCommand "P" "roceed", capCommand " " "Cancel"])) Blank -> emptyWidget -- Address Book List AdrBook -> @@ -639,6 +665,24 @@ 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 = + newForm + [ label "Select :" @@= + radioField + shieldOp + [ (Shield, ShieldField, "Shield") + , (Deshield, DeshieldField, "De-Shield") + ] + , label "Amount: " @@= + 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 @@ -887,6 +931,7 @@ appEvent (BT.AppEvent t) = do AdrBookForm -> return () AdrBookUpdForm -> return () AdrBookDelForm -> return () + ShieldDeshieldForm -> return () Blank -> do if s ^. timer == 90 then do @@ -1135,6 +1180,14 @@ appEvent (BT.VtyEvent e) = do setFieldValid (isRecipientValidGUI (fs ^. policyField) (fs ^. sendTo)) RecField + ShieldDeshieldForm -> do + case e of + V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank + ev -> + BT.zoom shdshForm $ do + handleFormEvent (BT.VtyEvent ev) +-- fs <- BT.gets formState +-- ev -> BT.zoom shdshForm $ L.handleListEvent ev AdrBook -> do case e of V.EvKey (V.KChar 'x') [] -> @@ -1344,6 +1397,8 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set dialogBox SendTx V.EvKey (V.KChar 'b') [] -> BT.modify $ set dialogBox AdrBook + V.EvKey (V.KChar 'd') [] -> + BT.modify $ set dialogBox ShieldDeshieldForm ev -> case r of Just AList -> @@ -1482,6 +1537,7 @@ runZenithTUI config = do "" Nothing uBal + (mkshieldDeshieldForm 0 (ShDshEntry Shield 0.0 )) Left _e -> do print $ "No Zebra node available on port " <> diff --git a/src/Zenith/Types.hs b/src/Zenith/Types.hs index 0a3d58d..8b7762f 100644 --- a/src/Zenith/Types.hs +++ b/src/Zenith/Types.hs @@ -207,6 +207,11 @@ data PrivacyPolicy $(deriveJSON defaultOptions ''PrivacyPolicy) +data ShieldDeshieldOp + = Shield + | Deshield + deriving (Eq, Show, Read, Ord) + -- ** `zebrad` -- | Type for modeling the tree state response data ZebraTreeInfo = ZebraTreeInfo From e02551c9ffe3a1405dec58f9a34b2c85615dfcc0 Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Mon, 7 Oct 2024 19:47:28 -0400 Subject: [PATCH 4/4] rvv001 - Shield / Deshield form Fields to display Total transparent funts and total Shielded Funds added. A funtion to update the latest total values has to be included --- src/Zenith/CLI.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index 8a76b5c..02b5fbe 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -135,6 +135,8 @@ data Name | PrivacyFullField | ShieldField | DeshieldField + | TotalTranspField + | TotalShieldedField deriving (Eq, Show, Ord) data DialogInput = DialogInput @@ -160,7 +162,9 @@ data AdrBookEntry = AdrBookEntry makeLenses ''AdrBookEntry data ShDshEntry = ShDshEntry - { _shieldOp :: !ShieldDeshieldOp + { _totalTransparent :: !Float + , _totalShielded :: !Float + , _shieldOp :: !ShieldDeshieldOp , _shAmt :: !Float } deriving (Show) @@ -668,7 +672,11 @@ mkSendForm bal = mkshieldDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name mkshieldDeshieldForm bal = newForm - [ label "Select :" @@= + [ label "Total Transp. : " @@= + editShowableFieldWithValidate totalTransparent TotalTranspField (isAmountValid bal) + , label "Total Shielded : " @@= + editShowableFieldWithValidate totalShielded TotalShieldedField (isAmountValid bal) + , label "Select :" @@= radioField shieldOp [ (Shield, ShieldField, "Shield") @@ -1537,7 +1545,7 @@ runZenithTUI config = do "" Nothing uBal - (mkshieldDeshieldForm 0 (ShDshEntry Shield 0.0 )) + (mkshieldDeshieldForm 0 (ShDshEntry 0 0 Shield 0.0 )) Left _e -> do print $ "No Zebra node available on port " <>