rvv001 - Show Balance in FIAT
GUI version ready
This commit is contained in:
parent
d3d5d88bbc
commit
1ed96dcbf8
2 changed files with 46 additions and 12 deletions
|
@ -127,7 +127,6 @@ import Zenith.Utils
|
||||||
, showAddress
|
, showAddress
|
||||||
, validBarValue
|
, validBarValue
|
||||||
, getZcashPrice
|
, getZcashPrice
|
||||||
, displayValue
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data Name
|
data Name
|
||||||
|
|
|
@ -36,7 +36,7 @@ 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 ((</>))
|
||||||
import Text.Printf
|
import Text.Printf (printf)
|
||||||
import Text.Wrap (FillScope(..), FillStrategy(..), WrapSettings(..), wrapText)
|
import Text.Wrap (FillScope(..), FillStrategy(..), WrapSettings(..), wrapText)
|
||||||
import TextShow hiding (toText)
|
import TextShow hiding (toText)
|
||||||
import ZcashHaskell.Keys (generateWalletSeedPhrase)
|
import ZcashHaskell.Keys (generateWalletSeedPhrase)
|
||||||
|
@ -75,6 +75,7 @@ import Zenith.Utils
|
||||||
, padWithZero
|
, padWithZero
|
||||||
, showAddress
|
, showAddress
|
||||||
, validBarValue
|
, validBarValue
|
||||||
|
, getZcashPrice
|
||||||
)
|
)
|
||||||
|
|
||||||
data AppEvent
|
data AppEvent
|
||||||
|
@ -148,6 +149,7 @@ data AppEvent
|
||||||
| StartSync
|
| StartSync
|
||||||
| TreeSync
|
| TreeSync
|
||||||
| ShowFIATBalance
|
| ShowFIATBalance
|
||||||
|
| DisplayFIATBalance Double Double
|
||||||
| CloseFIATBalance
|
| CloseFIATBalance
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
@ -208,7 +210,9 @@ data AppModel = AppModel
|
||||||
, _tBalanceValid :: !Bool
|
, _tBalanceValid :: !Bool
|
||||||
, _sBalance :: !Integer
|
, _sBalance :: !Integer
|
||||||
, _sBalanceValid :: !Bool
|
, _sBalanceValid :: !Bool
|
||||||
, _showFIATBalance :: !Bool
|
, _displayFIATBalance :: !Bool
|
||||||
|
, _zPrice :: !Double
|
||||||
|
, _aBal :: !Double
|
||||||
} deriving (Eq, Show)
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
makeLenses ''AppModel
|
makeLenses ''AppModel
|
||||||
|
@ -252,7 +256,8 @@ 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
|
-- , sfBalOverlay `nodeVisible` model ^. showFIATBalance
|
||||||
|
, dfBalOverlay `nodeVisible` model ^. displayFIATBalance
|
||||||
, showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible`
|
, showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible`
|
||||||
model ^.
|
model ^.
|
||||||
showABAddress
|
showABAddress
|
||||||
|
@ -330,7 +335,7 @@ 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, onClick ShowFIATBalance] (label "Balance in (") `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`
|
||||||
[bgColor btnColor, padding 3]
|
[bgColor btnColor, padding 3]
|
||||||
|
@ -997,12 +1002,18 @@ buildUI wenv model = widgetTree
|
||||||
, label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline]
|
, label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline]
|
||||||
, filler
|
, filler
|
||||||
]
|
]
|
||||||
sfBalOverlay =
|
dfBalOverlay =
|
||||||
alert CloseFIATBalance $
|
alert CloseFIATBalance $
|
||||||
hstack
|
vstack
|
||||||
[ filler
|
[ box_
|
||||||
, label "Account Balance in FIAT" `styleBasic` [textFont "Bold"]
|
[]
|
||||||
|
(label ("Account Balance in " <> (T.toUpper (c_currencyCode (model ^. configuration))) ) `styleBasic`
|
||||||
|
[textFont "Bold", textSize 12, textColor white]) `styleBasic`
|
||||||
|
[bgColor btnColor, radius 2, padding 3]
|
||||||
, filler
|
, filler
|
||||||
|
, (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` []
|
||||||
]
|
]
|
||||||
shieldOverlay =
|
shieldOverlay =
|
||||||
box
|
box
|
||||||
|
@ -1521,8 +1532,17 @@ handleEvent wenv node model evt =
|
||||||
--
|
--
|
||||||
-- Show Balance in FIAT
|
-- Show Balance in FIAT
|
||||||
--
|
--
|
||||||
ShowFIATBalance -> [Model $ model & showFIATBalance .~ True & menuPopup .~ False]
|
DisplayFIATBalance zpr abal ->
|
||||||
CloseFIATBalance -> [Model $ model & showFIATBalance .~ False]
|
[ Model $ model & zPrice .~ zpr & aBal .~ abal & displayFIATBalance .~ True & menuPopup .~ False
|
||||||
|
]
|
||||||
|
ShowFIATBalance ->
|
||||||
|
if model ^. network == MainNet
|
||||||
|
then [ Task $ sfBalance (model ^. configuration)
|
||||||
|
]
|
||||||
|
else [ Model $ model & zPrice .~ 0.0 & aBal .~ 0.0
|
||||||
|
, Event $ ShowError "Balance conversion not available for TestNet"
|
||||||
|
]
|
||||||
|
CloseFIATBalance -> [Model $ model & displayFIATBalance .~ False]
|
||||||
--
|
--
|
||||||
ShowShield ->
|
ShowShield ->
|
||||||
if model ^. tBalance > 0
|
if model ^. tBalance > 0
|
||||||
|
@ -1680,6 +1700,19 @@ handleEvent wenv node model evt =
|
||||||
pool <- runNoLoggingT $ initPool $ c_dbPath config
|
pool <- runNoLoggingT $ initPool $ c_dbPath config
|
||||||
res <- liftIO $ updateAdrsInAdrBook pool d a a
|
res <- liftIO $ updateAdrsInAdrBook pool d a a
|
||||||
return $ ShowMessage "Address Book entry updated!!"
|
return $ ShowMessage "Address Book entry updated!!"
|
||||||
|
--
|
||||||
|
dbal :: Integer -> Double
|
||||||
|
dbal a = fromIntegral a
|
||||||
|
--
|
||||||
|
sfBalance :: Config -> IO AppEvent
|
||||||
|
sfBalance config = do
|
||||||
|
zpr <- liftIO $ getZcashPrice $ c_currencyCode config
|
||||||
|
case zpr of
|
||||||
|
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 ::
|
scanZebra ::
|
||||||
T.Text
|
T.Text
|
||||||
|
@ -2038,6 +2071,8 @@ runZenithGUI config = do
|
||||||
shieldBal
|
shieldBal
|
||||||
False
|
False
|
||||||
False
|
False
|
||||||
|
0.0
|
||||||
|
0.0
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue