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
|
||||
, validBarValue
|
||||
, getZcashPrice
|
||||
, displayValue
|
||||
)
|
||||
|
||||
data Name
|
||||
|
|
|
@ -36,7 +36,7 @@ import Monomer
|
|||
import qualified Monomer.Lens as L
|
||||
import System.Directory (getHomeDirectory)
|
||||
import System.FilePath ((</>))
|
||||
import Text.Printf
|
||||
import Text.Printf (printf)
|
||||
import Text.Wrap (FillScope(..), FillStrategy(..), WrapSettings(..), wrapText)
|
||||
import TextShow hiding (toText)
|
||||
import ZcashHaskell.Keys (generateWalletSeedPhrase)
|
||||
|
@ -75,6 +75,7 @@ import Zenith.Utils
|
|||
, padWithZero
|
||||
, showAddress
|
||||
, validBarValue
|
||||
, getZcashPrice
|
||||
)
|
||||
|
||||
data AppEvent
|
||||
|
@ -148,6 +149,7 @@ data AppEvent
|
|||
| StartSync
|
||||
| TreeSync
|
||||
| ShowFIATBalance
|
||||
| DisplayFIATBalance Double Double
|
||||
| CloseFIATBalance
|
||||
deriving (Eq, Show)
|
||||
|
||||
|
@ -208,7 +210,9 @@ data AppModel = AppModel
|
|||
, _tBalanceValid :: !Bool
|
||||
, _sBalance :: !Integer
|
||||
, _sBalanceValid :: !Bool
|
||||
, _showFIATBalance :: !Bool
|
||||
, _displayFIATBalance :: !Bool
|
||||
, _zPrice :: !Double
|
||||
, _aBal :: !Double
|
||||
} deriving (Eq, Show)
|
||||
|
||||
makeLenses ''AppModel
|
||||
|
@ -252,7 +256,8 @@ buildUI wenv model = widgetTree
|
|||
, modalOverlay `nodeVisible` isJust (model ^. modalMsg)
|
||||
, adrbookOverlay `nodeVisible` model ^. showAdrBook
|
||||
, newAdrBkOverlay `nodeVisible` model ^. newAdrBkEntry
|
||||
, sfBalOverlay `nodeVisible` model ^. showFIATBalance
|
||||
-- , sfBalOverlay `nodeVisible` model ^. showFIATBalance
|
||||
, dfBalOverlay `nodeVisible` model ^. displayFIATBalance
|
||||
, showABAddressOverlay (model ^. abdescrip) (model ^. abaddress) `nodeVisible`
|
||||
model ^.
|
||||
showABAddress
|
||||
|
@ -330,7 +335,7 @@ 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, 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]
|
||||
]) `styleBasic`
|
||||
[bgColor btnColor, padding 3]
|
||||
|
@ -997,12 +1002,18 @@ buildUI wenv model = widgetTree
|
|||
, label_ (txtWrapN (fromMaybe "" (model ^. msgAB)) 64) [multiline]
|
||||
, filler
|
||||
]
|
||||
sfBalOverlay =
|
||||
dfBalOverlay =
|
||||
alert CloseFIATBalance $
|
||||
hstack
|
||||
[ filler
|
||||
, label "Account Balance in FIAT" `styleBasic` [textFont "Bold"]
|
||||
vstack
|
||||
[ box_
|
||||
[]
|
||||
(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
|
||||
, (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 =
|
||||
box
|
||||
|
@ -1521,8 +1532,17 @@ handleEvent wenv node model evt =
|
|||
--
|
||||
-- Show Balance in FIAT
|
||||
--
|
||||
ShowFIATBalance -> [Model $ model & showFIATBalance .~ True & menuPopup .~ False]
|
||||
CloseFIATBalance -> [Model $ model & showFIATBalance .~ False]
|
||||
DisplayFIATBalance zpr abal ->
|
||||
[ 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 ->
|
||||
if model ^. tBalance > 0
|
||||
|
@ -1680,6 +1700,19 @@ handleEvent wenv node model evt =
|
|||
pool <- runNoLoggingT $ initPool $ c_dbPath config
|
||||
res <- liftIO $ updateAdrsInAdrBook pool d a a
|
||||
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 ::
|
||||
T.Text
|
||||
|
@ -2038,6 +2071,8 @@ runZenithGUI config = do
|
|||
shieldBal
|
||||
False
|
||||
False
|
||||
0.0
|
||||
0.0
|
||||
startApp model handleEvent buildUI (params hD)
|
||||
Left _e -> print "Zebra not available"
|
||||
where
|
||||
|
|
Loading…
Reference in a new issue