Publish Zenith beta version #80

Merged
pitmutt merged 90 commits from dev041 into master 2024-05-09 19:15:41 +00:00
Showing only changes of commit 7b7c653d02 - Show all commits

View file

@ -4,8 +4,6 @@
module Zenith.CLI where
import Control.Monad (void)
import Control.Monad.IO.Class (liftIO)
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Graphics.Vty as V
import Lens.Micro ((&), (.~), (^.), set)
@ -89,13 +87,13 @@ drawUI :: State -> [Widget Name]
drawUI s = [splashDialog s, helpDialog s, walletDialog s, ui s]
where
ui :: State -> Widget Name
ui s =
ui st =
joinBorders $
withBorderStyle unicode $
B.borderWithLabel (str $ "Zenith - " <> s ^. network) $
(C.center (listBox "Addresses" (s ^. addresses)) <+>
B.vBorder <+> C.center (listBox "Transactions" (s ^. transactions))) <=>
msgBox (s ^. msg)
B.borderWithLabel (str $ "Zenith - " <> st ^. network) $
(C.center (listBox "Addresses" (st ^. addresses)) <+>
B.vBorder <+> C.center (listBox "Transactions" (st ^. transactions))) <=>
msgBox (st ^. msg)
listBox :: String -> L.List Name String -> Widget Name
listBox titleLabel l =
C.vCenter $
@ -111,8 +109,8 @@ drawUI s = [splashDialog s, helpDialog s, walletDialog s, ui s]
vBox
[B.hBorderWithLabel (str "Messages"), hLimit 70 $ padRight Max $ str m]
helpDialog :: State -> Widget Name
helpDialog s =
if s ^. helpBox
helpDialog st =
if st ^. helpBox
then D.renderDialog
(D.dialog (Just (str "Commands")) Nothing 55)
(vBox ([C.hCenter $ str "Key", B.hBorder] <> keyList) <+>
@ -125,15 +123,15 @@ drawUI s = [splashDialog s, helpDialog s, walletDialog s, ui s]
(hLimit 40 . str)
["Open help", "Close dialog", "Create Wallet", "Quit"]
walletDialog :: State -> Widget Name
walletDialog s =
if s ^. walletBox
walletDialog st =
if st ^. walletBox
then D.renderDialog
(D.dialog (Just (str "Create Wallet")) Nothing 50)
(renderForm $ s ^. walletForm)
(renderForm $ st ^. walletForm)
else emptyWidget
splashDialog :: State -> Widget Name
splashDialog s =
if s ^. splashBox
splashDialog st =
if st ^. splashBox
then withBorderStyle unicodeBold $
D.renderDialog
(D.dialog Nothing Nothing 30)
@ -180,7 +178,7 @@ appEvent (BT.VtyEvent e) = do
case e of
V.EvKey V.KEsc [] -> do
BT.modify $ set helpBox False
ev -> return ()
_ev -> return ()
else do
if s ^. walletBox
then do
@ -190,7 +188,7 @@ appEvent (BT.VtyEvent e) = do
BT.modify $ set walletBox False
fs <- BT.zoom walletForm $ BT.gets formState
printMsg $
"Creating new wallet " <> (T.unpack $ fs ^. walName)
"Creating new wallet " <> T.unpack (fs ^. walName)
ev -> BT.zoom walletForm $ handleFormEvent (BT.VtyEvent ev)
else do
case e of
@ -203,12 +201,13 @@ appEvent (BT.VtyEvent e) = do
case r of
Just AList -> BT.zoom addresses $ L.handleListEvent ev
Just TList -> BT.zoom transactions $ L.handleListEvent ev
Nothing -> return ()
_anyName -> return ()
where
printMsg :: String -> BT.EventM Name State ()
printMsg s = BT.modify $ updateMsg s
updateMsg :: String -> State -> State
updateMsg = set msg
appEvent _ = return ()
theMap :: A.AttrMap
theMap =
@ -233,7 +232,7 @@ theApp =
}
runZenithCLI :: T.Text -> Int -> T.Text -> IO ()
runZenithCLI host port dbName = do
runZenithCLI host port dbFilePath = do
w <- checkZebra host port
case (w :: Maybe ZebraGetInfo) of
Just zebra -> do
@ -241,7 +240,7 @@ runZenithCLI host port dbName = do
case (bc :: Maybe ZebraGetBlockChainInfo) of
Nothing -> print "Unable to determine blockchain status"
Just chainInfo -> do
walList <- getWallets $ zgb_net chainInfo
walList <- getWallets dbFilePath $ zgb_net chainInfo
void $
M.defaultMain theApp $
State