From 62b6ee3f32b7ce28b8bb3382f2996268858b3543 Mon Sep 17 00:00:00 2001 From: "Rene V. Vergara" Date: Sun, 22 Dec 2024 13:57:13 -0500 Subject: [PATCH] rvv001 - Viewing Key Display feature added to GUI module. --- src/Zenith/GUI.hs | 96 +++++++++++++++++++++++++++++++++++++++++++++-- zenith.cfg | 8 ++-- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/src/Zenith/GUI.hs b/src/Zenith/GUI.hs index 9a85c73..5d465d1 100644 --- a/src/Zenith/GUI.hs +++ b/src/Zenith/GUI.hs @@ -33,6 +33,7 @@ import Database.Persist import Lens.Micro ((&), (+~), (.~), (?~), (^.), set) import Lens.Micro.TH import Monomer + import qualified Monomer.Lens as L import System.Directory (getHomeDirectory) import System.FilePath (()) @@ -78,6 +79,13 @@ import Zenith.Utils , getZcashPrice ) +data VkTypeDef + = VkNone + | VkFull + | VkIncoming + | VkOutgoing + deriving (Eq, Show) + data AppEvent = AppInit | ShowMsg !T.Text @@ -88,6 +96,7 @@ data AppEvent | AccountClicked | MenuClicked | NewClicked + | ViewingKeysClicked | NewAddress !(Maybe (Entity ZcashAccount)) | NewAccount !(Maybe (Entity ZcashWallet)) | NewWallet @@ -151,6 +160,9 @@ data AppEvent | ShowFIATBalance | DisplayFIATBalance Double Double | CloseFIATBalance + | ShowViewingKey !VkTypeDef !T.Text + | CopyViewingKey !T.Text !T.Text + | CloseShowVK deriving (Eq, Show) data AppModel = AppModel @@ -213,6 +225,10 @@ data AppModel = AppModel , _displayFIATBalance :: !Bool , _zPrice :: !Double , _aBal :: !Double + , _viewingKeyPopup :: !Bool + , _viewingKeyDisplay :: !Bool + , _vkTypeName :: !T.Text + , _vkData :: !T.Text } deriving (Eq, Show) makeLenses ''AppModel @@ -256,7 +272,6 @@ buildUI wenv model = widgetTree , modalOverlay `nodeVisible` isJust (model ^. modalMsg) , adrbookOverlay `nodeVisible` model ^. showAdrBook , newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry - -- , sfBalOverlay `nodeVisible` model ^. showFIATBalance , dfBalOverlay `nodeVisible` model ^. displayFIATBalance , showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible` model ^. @@ -264,6 +279,7 @@ buildUI wenv model = widgetTree , updateABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible` model ^. updateABAddress + , showVKOverlay `nodeVisible` model ^. viewingKeyDisplay , shieldOverlay `nodeVisible` model ^. shieldZec , deShieldOverlay `nodeVisible` model ^. deShieldZec , msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB) @@ -335,6 +351,22 @@ buildUI wenv model = widgetTree [bgColor white, borderB 1 gray, padding 3] , box_ [alignLeft, onClick ShowDeShield] (label "De-Shield ZEC") `styleBasic` [bgColor white, borderB 1 gray, padding 3] + , box_ + [alignLeft] + (vstack + [ box_ + [alignLeft, onClick ViewingKeysClicked] + (hstack + [ label "Viewing Keys" + , filler + , widgetIf (not $ model ^. viewingKeyPopup) $ + remixIcon remixMenuUnfoldFill + , widgetIf (model ^. viewingKeyPopup) $ + remixIcon remixMenuFoldFill + ]) + , widgetIf (model ^. viewingKeyPopup) $ animSlideIn viewingKeysBox + ]) `styleBasic` + [bgColor white, borderB 1 gray, padding 3] , box_ [alignLeft, onClick ShowFIATBalance] ( label ("Balance in " <> T.toUpper (c_currencyCode (model ^. configuration) ) ) ) `styleBasic` [bgColor white, borderB 1 gray, padding 3] ]) `styleBasic` @@ -356,6 +388,23 @@ buildUI wenv model = widgetTree (hstack [label "Wallet", filler]) `styleBasic` [bgColor white, borderB 1 gray, padding 3] ]) + viewingKeysBox = + box_ + [alignMiddle] + (vstack + [ box_ + [alignLeft, onClick (ShowViewingKey VkFull "VKFull->ztestsapling1tgjr4zppwk4ne8xy6gdq4z2gwq7dmf5jq8z2ctpn8nlmtse0a74fa5z0m8z383gmpgqz6q6duu4")] + (hstack [label "Full VK", filler]) `styleBasic` + [bgColor white, borderB 1 gray, padding 3] + , box_ + [alignLeft, onClick $ (ShowViewingKey VkIncoming "VKIncoming->ztestsapling1tgjr4zppwk4ne8xy6gdq4z2gwq7dmf5jq8z2ctpn8nlmtse0a74fa5z0m8z383gmpgqz6q6duu4")] + (hstack [label "Incoming VK", filler]) `styleBasic` + [bgColor white, borderB 1 gray, padding 3] + , box_ + [alignLeft, onClick $ (ShowViewingKey VkOutgoing "VKOutgoing->ztestsapling1tgjr4zppwk4ne8xy6gdq4z2gwq7dmf5jq8z2ctpn8nlmtse0a74fa5z0m8z383gmpgqz6q6duu4")] + (hstack [label "Outgoing VK", filler]) `styleBasic` + [bgColor white, borderB 1 gray, padding 3] + ]) walletButton = hstack [ label "Wallet: " `styleBasic` [textFont "Bold", textColor white] @@ -1014,7 +1063,24 @@ buildUI wenv model = widgetTree , (label ("1 ZEC = " <> ( T.pack (printf "%.2f" ( model ^. zPrice ))) <> " " <> (T.toUpper (c_currencyCode (model ^. configuration))) ) ) `styleBasic` [] , filler , (label ( ( T.pack (printf "%.8f" (model ^. aBal) ) <> " ZEC = " <> ( T.pack (printf "%.2f" (( model ^. zPrice )*( model ^. aBal ) ) ) ) <> " " <> (T.toUpper (c_currencyCode (model ^. configuration))) ) ) ) `styleBasic` [] - ] + ] + showVKOverlay = + alert CloseShowVK $ + vstack + [ box_ + [] + (label ((model ^. vkTypeName) <> " Viewing Key") `styleBasic` + [textFont "Bold", textColor white, textSize 12, padding 3]) `styleBasic` + [bgColor btnColor, radius 2, padding 3] + , spacer + , hstack [filler, label_ (txtWrapN (model ^. vkData) 64) [multiline], filler] + , spacer + , hstack + [ filler + , button "Copy to Clipboard" $ CopyViewingKey (model ^. vkTypeName) (model ^. vkData) + , filler + ] + ] shieldOverlay = box (vstack @@ -1254,6 +1320,12 @@ handleEvent wenv node model evt = False ] ConfirmCancel -> [Model $ model & confirmTitle .~ Nothing & mainInput .~ ""] + ViewingKeysClicked -> [Model $ model & viewingKeyPopup .~ not (model ^. viewingKeyPopup)] + NewAddress vk -> + [ Model $ + model & confirmTitle ?~ "New Address" & + confirmCancel .~ "Cancel" & menuPopup .~ False + ] ShowSeed -> [Model $ model & showSeed .~ True & menuPopup .~ False] ShowSend -> [ Model $ @@ -1514,6 +1586,11 @@ handleEvent wenv node model evt = , setClipboardData $ ClipboardText a , Event $ ShowMessage "Address copied!!" ] + CopyViewingKey t v -> + [ setClipboardData ClipboardEmpty + , setClipboardData $ ClipboardText v + , Event $ ShowMessage ( t <> " viewing key copied!!") + ] DeleteABEntry a -> [ Task $ deleteAdrBook (model ^. configuration) a , Model $ @@ -1529,6 +1606,7 @@ handleEvent wenv node model evt = model & msgAB ?~ "Function not implemented..." & menuPopup .~ False ] CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False] + CloseShowVK -> [Model $ model & vkTypeName .~ "" & vkData .~ "" & viewingKeyDisplay .~ False] -- -- Show Balance in FIAT -- @@ -1544,6 +1622,15 @@ handleEvent wenv node model evt = ] CloseFIATBalance -> [Model $ model & displayFIATBalance .~ False] -- + -- Show Viewing Keys + -- + ShowViewingKey vkType vkText -> + case vkType of + VkFull -> [ Model $ model & vkTypeName .~ "Full" & vkData .~ vkText & viewingKeyDisplay .~ True & menuPopup .~ False] + VkIncoming -> [ Model $ model & vkTypeName .~ "Incoming" & vkData .~ vkText & viewingKeyDisplay .~ True & menuPopup .~ False] + VkOutgoing -> [ Model $ model & vkTypeName .~ "Outgoing" & vkData .~ vkText & viewingKeyDisplay .~ True & menuPopup .~ False] + -- + -- ShowShield -> if model ^. tBalance > 0 then [Model $ model & shieldZec .~ True & menuPopup .~ False] @@ -1711,7 +1798,6 @@ handleEvent wenv node model evt = Just zp -> do let zbal = ( dbal (model ^. balance) ) / 100000000 return $ DisplayFIATBalance zp zbal -{- return $ ShowMessage ( ( T.pack (printf "%.8f" zbal) ) <> " ZEC = " <> ( T.pack (printf "%.2f" ( zbal * zp ) ) ) <> " " <> (c_currencyCode config) )-} Nothing -> return $ ShowMessage ( "Currency not supported [" <> c_currencyCode config <> "]") scanZebra :: @@ -2073,6 +2159,10 @@ runZenithGUI config = do False 0.0 0.0 + False + False + "" + "" startApp model handleEvent buildUI (params hD) Left _e -> print "Zebra not available" where diff --git a/zenith.cfg b/zenith.cfg index f10ab4c..4b1d448 100644 --- a/zenith.cfg +++ b/zenith.cfg @@ -25,12 +25,14 @@ zebraHost = "127.0.0.1" zebraPort = 18232 # ------------------------------------------------------------- # currencyCode - ISO 4217 currency code -# example of currency codes are: +# +# Example of currency codes are: +# # United States -> currencyCode = "usd" # Canada -> currencyCode = "cnd" # Australia -> currencyCode = "aud" -# Euro Region -> currencyCode = "eur" +# Euro Region -> currencyCode = "eur" # Great Britain -> currencyCode = "gbp" -# Japan -> currencyCode = "jpy" +# Japan -> currencyCode = "jpy" # currencyCode = "usd"