From 0d5161cdb284d9a12593c57e7e4764d9575d363d Mon Sep 17 00:00:00 2001 From: "Rene Vergara A." Date: Mon, 30 Sep 2024 20:16:09 -0400 Subject: [PATCH] rvv001 - Privacy Policy check added to Send transaction window Files affected: Zenith/GUI.hs , Zenith/CLI.hs , Zenith/Utils.hs --- src/Zenith/CLI.hs | 24 ++++++++++++------------ src/Zenith/GUI.hs | 4 ++-- src/Zenith/Utils.hs | 45 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index 1c963f4..2b4ff5d 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -108,7 +108,7 @@ import Zenith.Utils , displayZec , isRecipientValid , jsonNumber - , parseAddress + , parseAddressUA , showAddress , validBarValue ) @@ -618,16 +618,16 @@ mkInputForm = mkSendForm :: Integer -> SendInput -> Form SendInput e Name mkSendForm bal = newForm - [ label "To: " @@= editTextField sendTo RecField (Just 1) + [ label "Privacy Level :" @@= + radioField policyField [ (Full, PrivacyFullField, "Full") + , (Medium, PrivacyMediumField, "Medium") + , (Low, PrivacyLowField, "Low") + , (None, PrivacyNoneField, "None") + ] + , label "To: " @@= editTextField sendTo RecField (Just 1) , label "Amount: " @@= editShowableFieldWithValidate sendAmt AmtField (isAmountValid bal) , label "Memo: " @@= editTextField sendMemo MemoField (Just 1) - , label "Privacy Level :" @@= - radioField policyField [ (None, PrivacyNoneField, "None") - , (Low, PrivacyLowField, "Low") - , (Medium, PrivacyMediumField, "Medium") - , (Full, PrivacyFullField, "Full") - ] ] where isAmountValid :: Integer -> Float -> Bool @@ -1160,7 +1160,7 @@ appEvent (BT.VtyEvent e) = do (addressBookAbaddress (entityVal a)) 0.0 "" - None) + Full) BT.modify $ set dialogBox SendTx _ -> do BT.modify $ @@ -1332,7 +1332,7 @@ appEvent (BT.VtyEvent e) = do V.EvKey (V.KChar 's') [] -> do BT.modify $ set txForm $ - mkSendForm (s ^. balance) (SendInput "" 0.0 "" None) + mkSendForm (s ^. balance) (SendInput "" 0.0 "" Full) BT.modify $ set dialogBox SendTx V.EvKey (V.KChar 'b') [] -> BT.modify $ set dialogBox AdrBook @@ -1467,7 +1467,7 @@ runZenithTUI config = do 1.0 eventChan 0 - (mkSendForm 0 $ SendInput "" 0.0 "" None) + (mkSendForm 0 $ SendInput "" 0.0 "" Full) (L.list ABList (Vec.fromList abookList) 1) (mkNewABForm (AdrBookEntry "" "")) "" @@ -1689,7 +1689,7 @@ sendTransaction :: -> IO () sendTransaction pool chan zHost zPort znet accId bl amt ua memo = do BC.writeBChan chan $ TickMsg "Preparing transaction..." - case parseAddress ua znet of + case parseAddressUA ua znet of Nothing -> BC.writeBChan chan $ TickMsg "Incorrect address" Just outUA -> do res <- diff --git a/src/Zenith/GUI.hs b/src/Zenith/GUI.hs index 17713e3..442190e 100644 --- a/src/Zenith/GUI.hs +++ b/src/Zenith/GUI.hs @@ -57,7 +57,7 @@ import Zenith.Utils , isValidString , jsonNumber , padWithZero - , parseAddress + , parseAddressUA , showAddress , validBarValue ) @@ -1537,7 +1537,7 @@ sendTransaction :: -> IO () sendTransaction config znet accId bl amt ua memo sendMsg = do sendMsg $ ShowModal "Preparing transaction..." - case parseAddress ua znet of + case parseAddressUA ua znet of Nothing -> sendMsg $ ShowError "Incorrect address" Just outUA -> do let dbPath = c_dbPath config diff --git a/src/Zenith/Utils.hs b/src/Zenith/Utils.hs index e38beb1..c5d9395 100644 --- a/src/Zenith/Utils.hs +++ b/src/Zenith/Utils.hs @@ -13,7 +13,7 @@ import qualified Data.Text.Encoding as E import System.Directory import System.Process (createProcess_, shell) import Text.Regex.Posix -import ZcashHaskell.Orchard (encodeUnifiedAddress, isValidUnifiedAddress) +import ZcashHaskell.Orchard (encodeUnifiedAddress, isValidUnifiedAddress, parseAddress) import ZcashHaskell.Sapling (decodeSaplingAddress, isValidShieldedAddress) import ZcashHaskell.Transparent ( decodeExchangeAddress @@ -148,12 +148,39 @@ isExchangeAddressValid xa = isRecipientValidGUI :: PrivacyPolicy -> T.Text -> Bool isRecipientValidGUI p a = do - let adr = parseAddress a - case p of - Full -> True - Medium -> True - Low -> False - None -> False + let adr = parseAddress (E.encodeUtf8 a) + case p of + Full -> case adr of + Just a -> + case a of + Unified ua -> True + Sapling sa -> True + _ -> False + Nothing -> False + Medium -> case adr of + Just a -> + case a of + Unified ua -> True + Sapling sa -> True + _ -> False + Nothing -> False + Low -> case adr of + Just a -> + case a of + Unified ua -> True + Sapling sa -> True + Transparent ta -> True + Exchange ea -> True + _ -> False + Nothing -> False + + None -> case adr of + Just a -> + case a of + Transparent ta -> True + Exchange ea -> True + _ -> False + Nothing -> False isZecAddressValid :: T.Text -> Bool isZecAddressValid a = do @@ -168,8 +195,8 @@ isZecAddressValid a = do Just _a4 -> True Nothing -> False) -parseAddress :: T.Text -> ZcashNet -> Maybe UnifiedAddress -parseAddress a znet = +parseAddressUA :: T.Text -> ZcashNet -> Maybe UnifiedAddress +parseAddressUA a znet = case isValidUnifiedAddress (E.encodeUtf8 a) of Just a1 -> Just a1 Nothing ->