Commit 257af97 1 parent 0c74206 commit 257af97 Copy full SHA for 257af97
File tree 9 files changed +167
-55
lines changed
9 files changed +167
-55
lines changed Original file line number Diff line number Diff line change @@ -243,6 +243,7 @@ import System.IOManager
243
243
)
244
244
import UnliftIO
245
245
( withAsync
246
+ , withSystemTempDirectory
246
247
)
247
248
248
249
import qualified Cardano.Pool.DB.Layer as Pool
@@ -390,12 +391,17 @@ serveWallet
390
391
case ms of
391
392
Nothing -> pure ()
392
393
Just (_port, socket) -> do
394
+ databaseDir' <- case databaseDir of
395
+ Nothing -> ContT
396
+ $ withSystemTempDirectory " deposit-wallet"
397
+ Just databaseDir' -> pure databaseDir'
393
398
r <- ContT withResource
394
399
ui <- Ui. withUILayer 1 r
395
400
sourceOfNewTip netLayer ui
396
401
let uiService =
397
402
startDepositUiServer
398
403
ui
404
+ databaseDir'
399
405
socket
400
406
sNetwork
401
407
netLayer
@@ -527,13 +533,15 @@ serveWallet
527
533
. ( HasSNetworkId n
528
534
)
529
535
=> UILayer WalletResource
536
+ -> FilePath
530
537
-> Socket
531
538
-> SNetworkId n
532
539
-> NetworkLayer IO (CardanoBlock StandardCrypto )
533
540
-> BlockchainSource
534
541
-> IO ()
535
542
startDepositUiServer
536
543
ui
544
+ databaseDir'
537
545
socket
538
546
_proxy
539
547
nl
@@ -544,6 +552,7 @@ serveWallet
544
552
Server. serve api
545
553
$ DepositUi. serveUI
546
554
ui
555
+ databaseDir'
547
556
(PageConfig " " " Deposit Cardano Wallet" )
548
557
_proxy
549
558
nl
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ library
55
55
Cardano.Wallet.UI.Common.Layer
56
56
Cardano.Wallet.UI.Cookies
57
57
Cardano.Wallet.UI.Deposit.API
58
+ Cardano.Wallet.UI.Deposit.Handlers.Lib
59
+ Cardano.Wallet.UI.Deposit.Handlers.Page
58
60
Cardano.Wallet.UI.Deposit.Handlers.Wallet
59
61
Cardano.Wallet.UI.Deposit.Html.Pages.About
60
62
Cardano.Wallet.UI.Deposit.Html.Pages.Page
@@ -107,6 +109,7 @@ library
107
109
, text
108
110
, text-class
109
111
, time
112
+ , transformers
110
113
, unliftio
111
114
112
115
hs-source-dirs : src
Original file line number Diff line number Diff line change
1
+ module Cardano.Wallet.UI.Deposit.Handlers.Lib
2
+ where
3
+
4
+ import Prelude
5
+
6
+ import Cardano.Wallet.Deposit.REST
7
+ ( WalletResource
8
+ , WalletResourceM
9
+ , runWalletResourceM
10
+ )
11
+ import Cardano.Wallet.UI.Common.Layer
12
+ ( SessionLayer (.. )
13
+ , stateL
14
+ )
15
+ import Control.Lens
16
+ ( view
17
+ )
18
+ import Control.Monad.Trans
19
+ ( MonadIO (.. )
20
+ )
21
+ import Control.Monad.Trans.Except
22
+ ( throwE
23
+ )
24
+ import Servant
25
+ ( Handler (.. )
26
+ , ServerError (.. )
27
+ , err500
28
+ )
29
+
30
+ import qualified Data.ByteString.Lazy.Char8 as BL
31
+
32
+ catchRunWalletResourceM
33
+ :: SessionLayer WalletResource
34
+ -> WalletResourceM a
35
+ -> Handler a
36
+ catchRunWalletResourceM layer f = do
37
+ r <- liftIO $ do
38
+ s <- view stateL <$> state layer
39
+ runWalletResourceM f s
40
+ case r of
41
+ Right a -> pure a
42
+ Left e -> Handler $ throwE $ err500{errBody = BL. pack $ show e}
43
+
44
+ catchRunWalletResourceHtml
45
+ :: SessionLayer WalletResource
46
+ -> (BL. ByteString -> html )
47
+ -> (a -> html )
48
+ -> WalletResourceM a
49
+ -> Handler html
50
+ catchRunWalletResourceHtml layer alert render f = liftIO $ do
51
+ s <- view stateL <$> state layer
52
+ r <- runWalletResourceM f s
53
+ pure $ case r of
54
+ Left e -> alert $ BL. pack $ show e
55
+ Right a -> render a
Original file line number Diff line number Diff line change
1
+ module Cardano.Wallet.UI.Deposit.Handlers.Page
2
+ where
3
+
4
+ import Prelude
5
+
6
+ import Cardano.Wallet.Deposit.REST
7
+ ( WalletResource
8
+ , walletExists
9
+ , walletPublicIdentity
10
+ )
11
+ import Cardano.Wallet.UI.Common.Handlers.Session
12
+ ( withSessionLayer
13
+ )
14
+ import Cardano.Wallet.UI.Common.Html.Html
15
+ ( RawHtml (.. )
16
+ )
17
+ import Cardano.Wallet.UI.Common.Html.Pages.Template.Head
18
+ ( PageConfig
19
+ )
20
+ import Cardano.Wallet.UI.Common.Layer
21
+ ( UILayer (.. )
22
+ )
23
+ import Cardano.Wallet.UI.Cookies
24
+ ( CookieResponse
25
+ , RequestCookies
26
+ )
27
+ import Cardano.Wallet.UI.Deposit.Handlers.Lib
28
+ ( catchRunWalletResourceM
29
+ )
30
+ import Cardano.Wallet.UI.Deposit.Html.Pages.Page
31
+ ( Page (.. )
32
+ , page
33
+ )
34
+ import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
35
+ ( WalletPresent (.. )
36
+ )
37
+ import Servant
38
+ ( Handler
39
+ )
40
+
41
+ pageHandler
42
+ :: UILayer WalletResource
43
+ -> FilePath
44
+ -> PageConfig
45
+ -> Page
46
+ -> Maybe RequestCookies
47
+ -> Handler (CookieResponse RawHtml )
48
+ pageHandler layer dir config x =
49
+ withSessionLayer layer $ \ session -> do
50
+ w <- catchRunWalletResourceM session $ do
51
+ test <- walletExists dir
52
+ identity <- walletPublicIdentity
53
+ pure $ if test then WalletPresent identity else WalletAbsent
54
+ pure $ page config x w
Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ import Cardano.Wallet.Deposit.IO
7
7
( WalletPublicIdentity
8
8
)
9
9
import Cardano.Wallet.Deposit.REST
10
- ( WalletResource
10
+ ( ErrWalletResource
11
+ , WalletResource
11
12
, WalletResourceM
12
13
, runWalletResourceM
13
14
, walletPublicIdentity
@@ -29,12 +30,20 @@ import Servant
29
30
import qualified Data.ByteString.Lazy.Char8 as BL
30
31
31
32
catchRunWalletResourceM
33
+ :: SessionLayer WalletResource
34
+ -> WalletResourceM a
35
+ -> IO (Either ErrWalletResource a )
36
+ catchRunWalletResourceM layer f = liftIO $ do
37
+ s <- view stateL <$> state layer
38
+ runWalletResourceM f s
39
+
40
+ catchRunWalletResourceHtml
32
41
:: SessionLayer WalletResource
33
42
-> (BL. ByteString -> html )
34
43
-> (a -> html )
35
44
-> WalletResourceM a
36
45
-> Handler html
37
- catchRunWalletResourceM layer alert render f = liftIO $ do
46
+ catchRunWalletResourceHtml layer alert render f = liftIO $ do
38
47
s <- view stateL <$> state layer
39
48
r <- runWalletResourceM f s
40
49
pure $ case r of
@@ -47,4 +56,4 @@ getWallet
47
56
-> (WalletPublicIdentity -> html ) -- success report
48
57
-> Handler html
49
58
getWallet layer alert render =
50
- catchRunWalletResourceM layer alert render walletPublicIdentity
59
+ catchRunWalletResourceHtml layer alert render walletPublicIdentity
Original file line number Diff line number Diff line change @@ -44,7 +44,8 @@ import Cardano.Wallet.UI.Deposit.Html.Pages.About
44
44
( aboutH
45
45
)
46
46
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
47
- ( walletH
47
+ ( WalletPresent
48
+ , walletH
48
49
)
49
50
import Control.Lens.Extras
50
51
( is
72
73
:: PageConfig
73
74
-- ^ Page configuration
74
75
-> Page
75
- -- ^ If a wallet was selected
76
+ -- ^ Current page
77
+ -> WalletPresent
78
+ -- ^ If a wallet is present
76
79
-> RawHtml
77
- page c@ PageConfig {.. } p = RawHtml
80
+ page c@ PageConfig {.. } p wp = RawHtml
78
81
$ renderBS
79
82
$ pageFromBodyH faviconLink c
80
83
$ bodyH (headerH prefix p)
81
84
$ case p of
82
85
About -> aboutH
83
86
Network -> networkH sseLink networkInfoLink
84
87
Settings -> settingsPageH sseLink settingsGetLink
85
- Wallet -> walletH
88
+ Wallet -> walletH wp
86
89
87
90
headerH :: Text -> Page -> Html ()
88
91
headerH prefix p =
Original file line number Diff line number Diff line change @@ -40,21 +40,23 @@ import Data.Text.Class
40
40
)
41
41
import Lucid
42
42
( Html
43
- , p_
44
43
)
45
44
46
45
import qualified Data.Text.Encoding as T
47
46
48
- walletH :: Html ()
49
- walletH = do
47
+ data WalletPresent = WalletPresent WalletPublicIdentity | WalletAbsent
48
+
49
+ walletH :: WalletPresent -> Html ()
50
+ walletH walletPresent = do
50
51
-- sseH sseLink walletLink "wallet" ["wallet"]
51
- p_
52
- " You have no wallet. Pls initialize it"
53
- newWalletH walletMnemonicLink $ PostWalletConfig
54
- { walletDataLink = walletLink
55
- , passwordVisibility = Just Hidden
56
- , namePresence = False
57
- }
52
+ case walletPresent of
53
+ WalletPresent wallet -> walletElementH wallet
54
+ WalletAbsent ->
55
+ newWalletH walletMnemonicLink $ PostWalletConfig
56
+ { walletDataLink = walletLink
57
+ , passwordVisibility = Just Hidden
58
+ , namePresence = False
59
+ }
58
60
59
61
base16 :: ByteString -> Text
60
62
base16 = T. decodeUtf8 . encode EBase16
You can’t perform that action at this time.
0 commit comments