From 56bf19a6f677fbf625aa4847f97f786bbeefc6f9 Mon Sep 17 00:00:00 2001 From: "Rene V. Vergara" Date: Thu, 26 Dec 2024 18:19:43 -0500 Subject: [PATCH] rvv001 - Issue 084 - Form to capture input from the user implemented for TUI & GUI Outgoing Viewing Key display support removed from TUI & GUI --- src/Zenith/CLI.hs | 54 +++++++++++++++++++++++++++++++++++++++++------ src/Zenith/GUI.hs | 8 +------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/Zenith/CLI.hs b/src/Zenith/CLI.hs index c894838..4b5acc5 100644 --- a/src/Zenith/CLI.hs +++ b/src/Zenith/CLI.hs @@ -182,6 +182,13 @@ newtype ShDshEntry = ShDshEntry makeLenses ''ShDshEntry +data PaymentInput = PaymentInput + { _pmtAmt :: !Scientific + , _pmtMemo :: !T.Text + } deriving (Show) + +makeLenses ''PaymentInput + data DialogType = WName | AName @@ -199,6 +206,7 @@ data DialogType | ShowFIATBalance | ViewingKeyMenu | ViewingKeyShow + | PaymentURIShow data DisplayType = AddrDisplay @@ -254,6 +262,7 @@ data State = State , _zprice :: !Double , _vkName :: !T.Text , _vkData :: !T.Text + , _pmtURIForm :: !(Form PaymentInput () Name) } makeLenses ''State @@ -325,6 +334,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] , capCommand "A" "ccounts" , capCommand "V" "iew address" , capCommand "S" "end Tx" + , capCommand2 "Gen " "U" "RI" , capCommand3 "ba" "L" ("ance (" ++ ( T.unpack (st ^. currencyCode) )++ ")" ) ]) , C.hCenter @@ -403,7 +413,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", "d", "k", "l", "q"] + map (C.hCenter . str) ["?", "Esc", "w", "a", "v", "s", "u", "b", "d", "k", "l", "q"] actionList = map (hLimit 40 . str) @@ -413,6 +423,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] , "Switch accounts" , "View address" , "Send Tx" + , "Gen URI" , "Address Book" , "Shield/De-Shield" , "Viewing Keys" @@ -463,6 +474,12 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] (renderForm (st ^. txForm) <=> C.hCenter (hBox [capCommand "↲ " "Send", capCommand " " "Cancel"])) + PaymentURIShow -> + D.renderDialog + (D.dialog (Just (str " Create Payment URI ")) Nothing 50) + (renderForm (st ^. pmtURIForm) <=> + C.hCenter + (hBox [capCommand "P" "rocess", capCommand3 " " " " "Cancel"])) DeshieldForm -> D.renderDialog (D.dialog (Just (str " De-Shield ZEC ")) Nothing 50) @@ -507,7 +524,7 @@ drawUI s = [splashDialog s, helpDialog s, displayDialog s, inputDialog s, ui s] D.renderDialog (D.dialog (Just (str " Viewing Keys ")) Nothing 50) (C.hCenter - (hBox [capCommand "F" "ull", capCommand "I" "ncoming", capCommand "O" "utgoing", capCommand3 "" "E" "xit"]) + (hBox [capCommand "F" "ull", capCommand "I" "ncoming", capCommand3 "" "E" "xit"]) ) Blank -> emptyWidget -- Address Book List @@ -781,6 +798,19 @@ mkSendForm bal = label s w = padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w +mkPaymentURIForm :: Integer -> PaymentInput -> Form PaymentInput e Name +mkPaymentURIForm bal = + newForm + [ label "Amount: " @@= + editShowableFieldWithValidate pmtAmt AmtField (isAmountValid bal) + , label "Memo: " @@= editTextField pmtMemo MemoField (Just 1) + ] + where + isAmountValid :: Integer -> Scientific -> Bool + isAmountValid b i = fromIntegral b >= (i * scientific 1 8) + label s w = + padBottom (Pad 1) $ vLimit 1 (hLimit 15 $ str s <+> fill ' ') <+> w + mkDeshieldForm :: Integer -> ShDshEntry -> Form ShDshEntry e Name mkDeshieldForm tbal = newForm @@ -1073,6 +1103,7 @@ appEvent (BT.AppEvent t) = do ViewingKeyShow -> return () ViewingKeyMenu -> return () ShowFIATBalance -> return() + PaymentURIShow -> return() Blank -> do if s ^. timer == 90 then do @@ -1695,13 +1726,16 @@ appEvent (BT.VtyEvent e) = do BT.modify $ set vkName "Incomming" BT.modify $ set vkData "VKIncoming->ztestsapling1tgjr4zppwk4ne8xy6gdq4z2gwq7dmf5jq8z2ctpn8nlmtse0a74fa5z0m8z383gmpgqz6q6duu4" BT.modify $ set dialogBox ViewingKeyShow - V.EvKey (V.KChar 'o') [] -> do - BT.modify $ set vkName "Outgoing" - BT.modify $ set vkData "VKOutgoing->ztestsapling1tgjr4zppwk4ne8xy6gdq4z2gwq7dmf5jq8z2ctpn8nlmtse0a74fa5z0m8z383gmpgqz6q6duu4" - BT.modify $ set dialogBox ViewingKeyShow V.EvKey (V.KChar 'e') [] -> BT.modify $ set dialogBox Blank ev -> return () - -- + -- + -- Payment URI Form Events + -- + PaymentURIShow -> do + case e of + V.EvKey V.KEsc [] -> BT.modify $ set dialogBox Blank + ev -> return () + -- -- Process any other event -- Blank -> do @@ -1727,6 +1761,11 @@ appEvent (BT.VtyEvent e) = do set txForm $ mkSendForm (s ^. balance) (SendInput "" 0.0 "" Full) BT.modify $ set dialogBox SendTx + V.EvKey (V.KChar 'u') [] -> do + BT.modify $ + set pmtURIForm $ + mkPaymentURIForm (s ^. balance) (PaymentInput 0.0 "") + BT.modify $ set dialogBox PaymentURIShow V.EvKey (V.KChar 'b') [] -> BT.modify $ set dialogBox AdrBook -- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @@ -1956,6 +1995,7 @@ runZenithTUI config = do 0 "" "" + (mkPaymentURIForm 0 $ PaymentInput 0.0 "" ) Left _e -> do print $ "No Zebra node available on port " <> diff --git a/src/Zenith/GUI.hs b/src/Zenith/GUI.hs index bc12801..0879302 100644 --- a/src/Zenith/GUI.hs +++ b/src/Zenith/GUI.hs @@ -83,7 +83,6 @@ data VkTypeDef = VkNone | VkFull | VkIncoming - | VkOutgoing deriving (Eq, Show) data AppEvent @@ -406,10 +405,6 @@ buildUI wenv model = widgetTree [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 @@ -1692,8 +1687,7 @@ handleEvent wenv node model evt = 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] - -- + -- -- Display PaymentURI Form -- DisplayPaymentURI -> [ Model $ model & paymentURIDisplay .~ True & menuPopup .~ False]