Skip to content

Commit

Permalink
Add wallet tip updates to deposit wallet main page
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Dec 6, 2024
1 parent 8997e59 commit d0a4d38
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 36 deletions.
7 changes: 6 additions & 1 deletion lib/ui/src/Cardano/Wallet/UI/Common/Layer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ mkUILayer
-> UILayer s
mkUILayer throttling oobChan sessions' s0 = UILayer{..}
where
oobMessages = Tracer $ atomically . writeTChan oobChan . messageOfPush
oobMessages =
Tracer
$ throttling
. atomically
. writeTChan oobChan
. messageOfPush
sessions sid = do
sids <- readTVarIO sessions'
case Map.lookup sid sids of
Expand Down
7 changes: 6 additions & 1 deletion lib/ui/src/Cardano/Wallet/UI/Deposit/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ type Data =
:<|> "payments"
:> "reset"
:> SessionedHtml Post
:<|> "wallet"
:> "status"
:> SessionedHtml Get

type Home = SessionedHtml Get

Expand Down Expand Up @@ -300,6 +303,7 @@ modalLink :: Maybe Text -> Maybe Text -> Link
paymentsSignLink :: Link
paymentsSubmitLink :: Link
paymentsResetLink :: Link
walletStatusLink :: Link
homePageLink
:<|> aboutPageLink
:<|> networkPageLink
Expand Down Expand Up @@ -339,5 +343,6 @@ homePageLink
:<|> modalLink
:<|> paymentsSignLink
:<|> paymentsSubmitLink
:<|> paymentsResetLink =
:<|> paymentsResetLink
:<|> walletStatusLink =
allLinks (Proxy @UI)
11 changes: 4 additions & 7 deletions lib/ui/src/Cardano/Wallet/UI/Deposit/Handlers/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ import Servant
import qualified Data.ByteString.Lazy.Char8 as BL

getWallet
:: NetworkEnv IO x
-> SessionLayer WalletResource
-> (BL.ByteString -> html) -- alert
-> (WalletPresent -> Status -> html) -- success report
:: SessionLayer WalletResource
-> (WalletPresent -> html) -- success report
-> Handler html
getWallet nenv layer alert render = do
getWallet layer render = do
presence <- walletPresence layer
getStatus nenv layer alert (render presence)
pure $ render presence

initWalletWithXPub
:: SessionLayer WalletResource
Expand Down Expand Up @@ -145,7 +143,6 @@ getStatusRest nenv = do
<*> pure (slotToTime $ slotFromChainPoint tip)
<*> availableBalance
<*> networkTag

getStatus
:: NetworkEnv IO x
-> SessionLayer WalletResource
Expand Down
28 changes: 16 additions & 12 deletions lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import Cardano.Wallet.UI.Deposit.API
, walletMnemonicLink
, walletPostMnemonicLink
, walletPostXPubLink
, walletStatusLink
)
import Cardano.Wallet.UI.Deposit.Html.Common
( chainPointToSlotH
Expand Down Expand Up @@ -159,23 +160,26 @@ deleteWalletModalH =
"Cancel"
}

walletStatusH :: Status -> Html ()
walletStatusH status = do
box "Status" mempty
$ record (Just 13) Full Striped
$ do
simpleField "Tip Slot" $ do
chainPointToSlotH $ tip status
simpleField "Tip Time" $ do
maybe mempty (withOriginH timeH) (tipTime status)
simpleField "Balance" $ valueH $ balance status
simpleField "Network" $ networkTagH $ network status

walletElementH
:: (BL.ByteString -> Html ())
-> WalletPresent
-> Status
-> Html ()
walletElementH alert presence status = case presence of
walletElementH alert presence = case presence of
WalletPresent (WalletPublicIdentity xpub customers) -> do
div_ [class_ "row mt-2 gx-0"] $ do
box "Status" mempty
$ record (Just 13) Full Striped
$ do
simpleField "Tip" $ do
chainPointToSlotH $ tip status
simpleField "Tip Time" $ do
maybe mempty (withOriginH timeH) (tipTime status)
simpleField "Balance" $ valueH $ balance status
simpleField "Network" $ networkTagH $ network status
div_ [class_ "row mt-2 gx-0"]
$ sseH walletStatusLink "wallet-status" ["wallet-tip"]
div_ [class_ "row mt-2 gx-0"] $ do
box "Public Identity" mempty
$ record (Just 13) Full Striped
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/src/Cardano/Wallet/UI/Deposit/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import Cardano.Wallet.UI.Deposit.Server.Wallet
, servePostMnemonicWallet
, servePostXPubWallet
, serveWalletPage
, serveWalletStatus
)
import Control.Monad.Trans
( MonadIO (..)
Expand Down Expand Up @@ -183,7 +184,7 @@ serveUI wtc tr ul env dbDir config nid nl bs =
:<|> serveSSE ul
:<|> serveFavicon
:<|> serveMnemonic
:<|> serveWalletPage (networkEnv env) ul
:<|> serveWalletPage ul
:<|> servePostMnemonicWallet wtc tr env dbDir ul
:<|> servePostXPubWallet wtc tr env dbDir ul
:<|> serveDeleteWallet ul dbDir
Expand All @@ -209,6 +210,7 @@ serveUI wtc tr ul env dbDir config nid nl bs =
:<|> servePaymentsSign ul
:<|> servePaymentsSubmit ul
:<|> servePaymentsReset ul
:<|> serveWalletStatus (networkEnv env) ul

serveModal
:: UILayer WalletResource
Expand Down
34 changes: 21 additions & 13 deletions lib/ui/src/Cardano/Wallet/UI/Deposit/Server/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ import Prelude
import Cardano.Wallet.Deposit.IO
( WalletBootEnv
)
import Cardano.Wallet.Deposit.IO.Network.Type
( NetworkEnv
)
import Cardano.Wallet.Deposit.REST
( WalletResource
, deleteWallet
, initWallet
)
import Cardano.Wallet.Deposit.REST.Wallet.Create
( PostWalletViaMnemonic
, PostWalletViaXPub
)
import Cardano.Wallet.UI.Common.Handlers.Session
( withSessionLayer
)
Expand Down Expand Up @@ -45,13 +52,15 @@ import Cardano.Wallet.UI.Cookies
)
import Cardano.Wallet.UI.Deposit.Handlers.Wallet
( deleteWalletHandler
, getStatus
, getWallet
, postMnemonicWallet
, postXPubWallet
)
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
( deleteWalletModalH
, walletElementH
, walletStatusH
)
import Cardano.Wallet.UI.Deposit.Server.Lib
( alert
Expand All @@ -70,14 +79,6 @@ import Servant
( Handler
)

import Cardano.Wallet.Deposit.IO.Network.Type
( NetworkEnv
)
import Cardano.Wallet.Deposit.REST.Wallet.Create
( PostWalletViaMnemonic
, PostWalletViaXPub
)

serveMnemonic
:: Maybe Bool
-> Maybe RequestCookies
Expand All @@ -88,13 +89,12 @@ serveMnemonic hintOrClean =
<$> liftIO (pickMnemonic 15 hintOrClean)

serveWalletPage
:: NetworkEnv IO x
-> UILayer WalletResource
:: UILayer WalletResource
-> Maybe RequestCookies
-> Handler (CookieResponse RawHtml)
serveWalletPage nenv ul = withSessionLayer ul $ \layer -> do
getWallet nenv layer alert $ \presence status ->
renderSmoothHtml $ walletElementH alertH presence status
serveWalletPage ul = withSessionLayer ul $ \layer -> do
getWallet layer $ \presence ->
renderSmoothHtml $ walletElementH alertH presence

servePostMnemonicWallet
:: Tracer IO ()
Expand Down Expand Up @@ -146,3 +146,11 @@ serveDeleteWalletModal
-> Handler (CookieResponse RawHtml)
serveDeleteWalletModal ul = withSessionLayer ul $ \_ ->
pure $ renderSmoothHtml deleteWalletModalH

serveWalletStatus
:: NetworkEnv IO x
-> UILayer WalletResource
-> Maybe RequestCookies
-> Handler (CookieResponse RawHtml)
serveWalletStatus nenv ul = withSessionLayer ul $ \l ->
renderHtml <$> getStatus nenv l alertH walletStatusH
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ withInitializedWallet f =
withSystemTempDirectory "wallet-ui" $ \dir -> do
bootEnv <- fakeBootEnv
withWallet $ do
initWallet nullTracer bootEnv dir credentials 1
initWallet nullTracer nullTracer bootEnv dir credentials 1
letItInitialize
fundTheWallet (networkEnv bootEnv)
f
Expand Down

0 comments on commit d0a4d38

Please sign in to comment.