rvv001 - Viewing Key Display feature added to GUI module.

This commit is contained in:
Rene V. Vergara A. 2024-12-22 13:57:13 -05:00
parent 9d1293ea03
commit 62b6ee3f32
2 changed files with 98 additions and 6 deletions

View file

@ -33,6 +33,7 @@ import Database.Persist
import Lens.Micro ((&), (+~), (.~), (?~), (^.), set) import Lens.Micro ((&), (+~), (.~), (?~), (^.), set)
import Lens.Micro.TH import Lens.Micro.TH
import Monomer import Monomer
import qualified Monomer.Lens as L import qualified Monomer.Lens as L
import System.Directory (getHomeDirectory) import System.Directory (getHomeDirectory)
import System.FilePath ((</>)) import System.FilePath ((</>))
@ -78,6 +79,13 @@ import Zenith.Utils
, getZcashPrice , getZcashPrice
) )
data VkTypeDef
= VkNone
| VkFull
| VkIncoming
| VkOutgoing
deriving (Eq, Show)
data AppEvent data AppEvent
= AppInit = AppInit
| ShowMsg !T.Text | ShowMsg !T.Text
@ -88,6 +96,7 @@ data AppEvent
| AccountClicked | AccountClicked
| MenuClicked | MenuClicked
| NewClicked | NewClicked
| ViewingKeysClicked
| NewAddress !(Maybe (Entity ZcashAccount)) | NewAddress !(Maybe (Entity ZcashAccount))
| NewAccount !(Maybe (Entity ZcashWallet)) | NewAccount !(Maybe (Entity ZcashWallet))
| NewWallet | NewWallet
@ -151,6 +160,9 @@ data AppEvent
| ShowFIATBalance | ShowFIATBalance
| DisplayFIATBalance Double Double | DisplayFIATBalance Double Double
| CloseFIATBalance | CloseFIATBalance
| ShowViewingKey !VkTypeDef !T.Text
| CopyViewingKey !T.Text !T.Text
| CloseShowVK
deriving (Eq, Show) deriving (Eq, Show)
data AppModel = AppModel data AppModel = AppModel
@ -213,6 +225,10 @@ data AppModel = AppModel
, _displayFIATBalance :: !Bool , _displayFIATBalance :: !Bool
, _zPrice :: !Double , _zPrice :: !Double
, _aBal :: !Double , _aBal :: !Double
, _viewingKeyPopup :: !Bool
, _viewingKeyDisplay :: !Bool
, _vkTypeName :: !T.Text
, _vkData :: !T.Text
} deriving (Eq, Show) } deriving (Eq, Show)
makeLenses ''AppModel makeLenses ''AppModel
@ -256,7 +272,6 @@ buildUI wenv model = widgetTree
, modalOverlay `nodeVisible` isJust (model ^. modalMsg) , modalOverlay `nodeVisible` isJust (model ^. modalMsg)
, adrbookOverlay `nodeVisible` model ^. showAdrBook , adrbookOverlay `nodeVisible` model ^. showAdrBook
, newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry , newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry
-- , sfBalOverlay `nodeVisible` model ^. showFIATBalance
, dfBalOverlay `nodeVisible` model ^. displayFIATBalance , dfBalOverlay `nodeVisible` model ^. displayFIATBalance
, showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible` , showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible`
model ^. model ^.
@ -264,6 +279,7 @@ buildUI wenv model = widgetTree
, updateABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible` , updateABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible`
model ^. model ^.
updateABAddress updateABAddress
, showVKOverlay `nodeVisible` model ^. viewingKeyDisplay
, shieldOverlay `nodeVisible` model ^. shieldZec , shieldOverlay `nodeVisible` model ^. shieldZec
, deShieldOverlay `nodeVisible` model ^. deShieldZec , deShieldOverlay `nodeVisible` model ^. deShieldZec
, msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB) , msgAdrBookOverlay `nodeVisible` isJust (model ^. msgAB)
@ -335,6 +351,22 @@ buildUI wenv model = widgetTree
[bgColor white, borderB 1 gray, padding 3] [bgColor white, borderB 1 gray, padding 3]
, box_ [alignLeft, onClick ShowDeShield] (label "De-Shield ZEC") `styleBasic` , box_ [alignLeft, onClick ShowDeShield] (label "De-Shield ZEC") `styleBasic`
[bgColor white, borderB 1 gray, padding 3] [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` , box_ [alignLeft, onClick ShowFIATBalance] ( label ("Balance in " <> T.toUpper (c_currencyCode (model ^. configuration) ) ) ) `styleBasic`
[bgColor white, borderB 1 gray, padding 3] [bgColor white, borderB 1 gray, padding 3]
]) `styleBasic` ]) `styleBasic`
@ -356,6 +388,23 @@ buildUI wenv model = widgetTree
(hstack [label "Wallet", filler]) `styleBasic` (hstack [label "Wallet", filler]) `styleBasic`
[bgColor white, borderB 1 gray, padding 3] [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 = walletButton =
hstack hstack
[ label "Wallet: " `styleBasic` [textFont "Bold", textColor white] [ label "Wallet: " `styleBasic` [textFont "Bold", textColor white]
@ -1015,6 +1064,23 @@ buildUI wenv model = widgetTree
, filler , filler
, (label ( ( T.pack (printf "%.8f" (model ^. aBal) ) <> " ZEC = " <> ( T.pack (printf "%.2f" (( model ^. zPrice )*( model ^. aBal ) ) ) ) <> " " <> (T.toUpper (c_currencyCode (model ^. configuration))) ) ) ) `styleBasic` [] , (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 = shieldOverlay =
box box
(vstack (vstack
@ -1254,6 +1320,12 @@ handleEvent wenv node model evt =
False False
] ]
ConfirmCancel -> [Model $ model & confirmTitle .~ Nothing & mainInput .~ ""] 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] ShowSeed -> [Model $ model & showSeed .~ True & menuPopup .~ False]
ShowSend -> ShowSend ->
[ Model $ [ Model $
@ -1514,6 +1586,11 @@ handleEvent wenv node model evt =
, setClipboardData $ ClipboardText a , setClipboardData $ ClipboardText a
, Event $ ShowMessage "Address copied!!" , Event $ ShowMessage "Address copied!!"
] ]
CopyViewingKey t v ->
[ setClipboardData ClipboardEmpty
, setClipboardData $ ClipboardText v
, Event $ ShowMessage ( t <> " viewing key copied!!")
]
DeleteABEntry a -> DeleteABEntry a ->
[ Task $ deleteAdrBook (model ^. configuration) a [ Task $ deleteAdrBook (model ^. configuration) a
, Model $ , Model $
@ -1529,6 +1606,7 @@ handleEvent wenv node model evt =
model & msgAB ?~ "Function not implemented..." & menuPopup .~ False model & msgAB ?~ "Function not implemented..." & menuPopup .~ False
] ]
CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False] CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False]
CloseShowVK -> [Model $ model & vkTypeName .~ "" & vkData .~ "" & viewingKeyDisplay .~ False]
-- --
-- Show Balance in FIAT -- Show Balance in FIAT
-- --
@ -1544,6 +1622,15 @@ handleEvent wenv node model evt =
] ]
CloseFIATBalance -> [Model $ model & displayFIATBalance .~ False] 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 -> ShowShield ->
if model ^. tBalance > 0 if model ^. tBalance > 0
then [Model $ model & shieldZec .~ True & menuPopup .~ False] then [Model $ model & shieldZec .~ True & menuPopup .~ False]
@ -1711,7 +1798,6 @@ handleEvent wenv node model evt =
Just zp -> do Just zp -> do
let zbal = ( dbal (model ^. balance) ) / 100000000 let zbal = ( dbal (model ^. balance) ) / 100000000
return $ DisplayFIATBalance zp zbal 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 <> "]") Nothing -> return $ ShowMessage ( "Currency not supported [" <> c_currencyCode config <> "]")
scanZebra :: scanZebra ::
@ -2073,6 +2159,10 @@ runZenithGUI config = do
False False
0.0 0.0
0.0 0.0
False
False
""
""
startApp model handleEvent buildUI (params hD) startApp model handleEvent buildUI (params hD)
Left _e -> print "Zebra not available" Left _e -> print "Zebra not available"
where where

View file

@ -25,12 +25,14 @@ zebraHost = "127.0.0.1"
zebraPort = 18232 zebraPort = 18232
# ------------------------------------------------------------- # -------------------------------------------------------------
# currencyCode - ISO 4217 currency code # currencyCode - ISO 4217 currency code
# example of currency codes are: #
# Example of currency codes are:
#
# United States -> currencyCode = "usd" # United States -> currencyCode = "usd"
# Canada -> currencyCode = "cnd" # Canada -> currencyCode = "cnd"
# Australia -> currencyCode = "aud" # Australia -> currencyCode = "aud"
# Euro Region -> currencyCode = "eur" # Euro Region -> currencyCode = "eur"
# Great Britain -> currencyCode = "gbp" # Great Britain -> currencyCode = "gbp"
# Japan -> currencyCode = "jpy" # Japan -> currencyCode = "jpy"
# #
currencyCode = "usd" currencyCode = "usd"