-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a page handler that feed the correct state to the wallet page
- Loading branch information
Showing
9 changed files
with
169 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Cardano.Wallet.UI.Deposit.Handlers.Lib | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Deposit.REST | ||
( WalletResource | ||
, WalletResourceM | ||
, runWalletResourceM | ||
) | ||
import Cardano.Wallet.UI.Common.Layer | ||
( SessionLayer (..) | ||
, stateL | ||
) | ||
import Control.Lens | ||
( view | ||
) | ||
import Control.Monad.Trans | ||
( MonadIO (..) | ||
) | ||
import Control.Monad.Trans.Except | ||
( throwE | ||
) | ||
import Servant | ||
( Handler (..) | ||
, ServerError (..) | ||
, err500 | ||
) | ||
|
||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
|
||
catchRunWalletResourceM | ||
:: SessionLayer WalletResource | ||
-> WalletResourceM a | ||
-> Handler a | ||
catchRunWalletResourceM layer f = do | ||
r <- liftIO $ do | ||
s <- view stateL <$> state layer | ||
runWalletResourceM f s | ||
case r of | ||
Right a -> pure a | ||
Left e -> Handler $ throwE $ err500{errBody = BL.pack $ show e} | ||
|
||
catchRunWalletResourceHtml | ||
:: SessionLayer WalletResource | ||
-> (BL.ByteString -> html) | ||
-> (a -> html) | ||
-> WalletResourceM a | ||
-> Handler html | ||
catchRunWalletResourceHtml layer alert render f = liftIO $ do | ||
s <- view stateL <$> state layer | ||
r <- runWalletResourceM f s | ||
pure $ case r of | ||
Left e -> alert $ BL.pack $ show e | ||
Right a -> render a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module Cardano.Wallet.UI.Deposit.Handlers.Page | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Deposit.REST | ||
( WalletResource | ||
, walletExists | ||
, walletPublicIdentity | ||
) | ||
import Cardano.Wallet.UI.Common.Handlers.Session | ||
( withSessionLayer | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Html | ||
( RawHtml (..) | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Pages.Template.Head | ||
( PageConfig | ||
) | ||
import Cardano.Wallet.UI.Common.Layer | ||
( UILayer (..) | ||
) | ||
import Cardano.Wallet.UI.Cookies | ||
( CookieResponse | ||
, RequestCookies | ||
) | ||
import Cardano.Wallet.UI.Deposit.Handlers.Lib | ||
( catchRunWalletResourceM | ||
) | ||
import Cardano.Wallet.UI.Deposit.Html.Pages.Page | ||
( Page (..) | ||
, page | ||
) | ||
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet | ||
( WalletPresent (..) | ||
) | ||
import Servant | ||
( Handler | ||
) | ||
|
||
newtype DatabaseDir = DatabaseDir FilePath | ||
|
||
pageHandler | ||
:: UILayer WalletResource | ||
-> FilePath | ||
-> PageConfig | ||
-> Page | ||
-> Maybe RequestCookies | ||
-> Handler (CookieResponse RawHtml) | ||
pageHandler layer dir config x = | ||
withSessionLayer layer $ \session -> do | ||
w <- catchRunWalletResourceM session $ do | ||
test <- walletExists dir | ||
identity <- walletPublicIdentity | ||
pure $ if test then WalletPresent identity else WalletAbsent | ||
pure $ page config x w |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.