Skip to content

Commit 0c74206

Browse files
committed
Add deposit wallet wallet UI page
1 parent 74c3b9d commit 0c74206

File tree

8 files changed

+187
-11
lines changed

8 files changed

+187
-11
lines changed

lib/exe/cardano-wallet-exe.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ library
8888
, cardano-wallet-secrets
8989
, cardano-wallet-ui
9090
, contra-tracer
91+
, customer-deposit-wallet
9192
, data-default
9293
, directory
9394
, extra

lib/exe/lib/Cardano/Wallet/Application.hs

+9-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ import Cardano.Wallet.DB.Layer
9595
import Cardano.Wallet.DB.Sqlite.Migration.Old
9696
( DefaultFieldValues (..)
9797
)
98+
import Cardano.Wallet.Deposit.IO.Resource
99+
( withResource
100+
)
101+
import Cardano.Wallet.Deposit.REST
102+
( WalletResource
103+
)
98104
import Cardano.Wallet.Flavor
99105
( CredFromOf
100106
, KeyFlavorS (..)
@@ -384,7 +390,8 @@ serveWallet
384390
case ms of
385391
Nothing -> pure ()
386392
Just (_port, socket) -> do
387-
ui <- Ui.withUILayer 1 ()
393+
r <- ContT withResource
394+
ui <- Ui.withUILayer 1 r
388395
sourceOfNewTip netLayer ui
389396
let uiService =
390397
startDepositUiServer
@@ -519,7 +526,7 @@ serveWallet
519526
:: forall n
520527
. ( HasSNetworkId n
521528
)
522-
=> UILayer ()
529+
=> UILayer WalletResource
523530
-> Socket
524531
-> SNetworkId n
525532
-> NetworkLayer IO (CardanoBlock StandardCrypto)

lib/ui/cardano-wallet-ui.cabal

+3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ library
5555
Cardano.Wallet.UI.Common.Layer
5656
Cardano.Wallet.UI.Cookies
5757
Cardano.Wallet.UI.Deposit.API
58+
Cardano.Wallet.UI.Deposit.Handlers.Wallet
5859
Cardano.Wallet.UI.Deposit.Html.Pages.About
5960
Cardano.Wallet.UI.Deposit.Html.Pages.Page
61+
Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
6062
Cardano.Wallet.UI.Deposit.Server
6163
Cardano.Wallet.UI.Lib.ListOf
6264
Cardano.Wallet.UI.Shelley.API
@@ -89,6 +91,7 @@ library
8991
, containers
9092
, contra-tracer
9193
, cookie
94+
, customer-deposit-wallet
9295
, exceptions
9396
, generic-lens
9497
, http-media

lib/ui/src/Cardano/Wallet/UI/Deposit/API.hs

+17-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
module Cardano.Wallet.UI.Deposit.API where
1515

16+
import Prelude
17+
1618
import Cardano.Wallet.UI.Common.API
1719
( Image
1820
, SessionedHtml
@@ -30,6 +32,7 @@ import Servant
3032
, Link
3133
, Post
3234
, Proxy (..)
35+
, QueryParam
3336
, allLinks
3437
, (:<|>) (..)
3538
, (:>)
@@ -42,13 +45,20 @@ type Pages =
4245
"about" :> SessionedHtml Get
4346
:<|> "network" :> SessionedHtml Get
4447
:<|> "settings" :> SessionedHtml Get
48+
:<|> "wallet" :> SessionedHtml Get
49+
4550
-- | Data endpoints
4651
type Data =
4752
"network" :> "info" :> SessionedHtml Get
4853
:<|> "settings" :> SessionedHtml Get
4954
:<|> "settings" :> "sse" :> "toggle" :> SessionedHtml Post
5055
:<|> "sse" :> (CookieRequest :> SSE)
5156
:<|> "favicon.ico" :> Get '[Image] BL.ByteString
57+
:<|> "wallet"
58+
:> "mnemonic"
59+
:> QueryParam "clean" Bool
60+
:> SessionedHtml Get
61+
:<|> "wallet" :> SessionedHtml Get
5262

5363
type Home = SessionedHtml Get
5464

@@ -69,14 +79,19 @@ settingsGetLink :: Link
6979
settingsSseToggleLink :: Link
7080
sseLink :: Link
7181
faviconLink :: Link
72-
82+
walletMnemonicLink :: Maybe Bool -> Link
83+
walletPageLink :: Link
84+
walletLink :: Link
7385
homePageLink
7486
:<|> aboutPageLink
7587
:<|> networkPageLink
7688
:<|> settingsPageLink
89+
:<|> walletPageLink
7790
:<|> networkInfoLink
7891
:<|> settingsGetLink
7992
:<|> settingsSseToggleLink
8093
:<|> sseLink
81-
:<|> faviconLink =
94+
:<|> faviconLink
95+
:<|> walletMnemonicLink
96+
:<|> walletLink =
8297
allLinks (Proxy @UI)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module Cardano.Wallet.UI.Deposit.Handlers.Wallet
2+
where
3+
4+
import Prelude
5+
6+
import Cardano.Wallet.Deposit.IO
7+
( WalletPublicIdentity
8+
)
9+
import Cardano.Wallet.Deposit.REST
10+
( WalletResource
11+
, WalletResourceM
12+
, runWalletResourceM
13+
, walletPublicIdentity
14+
)
15+
import Cardano.Wallet.UI.Common.Layer
16+
( SessionLayer (..)
17+
, stateL
18+
)
19+
import Control.Lens
20+
( view
21+
)
22+
import Control.Monad.Trans
23+
( MonadIO (..)
24+
)
25+
import Servant
26+
( Handler
27+
)
28+
29+
import qualified Data.ByteString.Lazy.Char8 as BL
30+
31+
catchRunWalletResourceM
32+
:: SessionLayer WalletResource
33+
-> (BL.ByteString -> html)
34+
-> (a -> html)
35+
-> WalletResourceM a
36+
-> Handler html
37+
catchRunWalletResourceM layer alert render f = liftIO $ do
38+
s <- view stateL <$> state layer
39+
r <- runWalletResourceM f s
40+
pure $ case r of
41+
Left e -> alert $ BL.pack $ show e
42+
Right a -> render a
43+
44+
getWallet
45+
:: SessionLayer WalletResource
46+
-> (BL.ByteString -> html) -- problem report
47+
-> (WalletPublicIdentity -> html) -- success report
48+
-> Handler html
49+
getWallet layer alert render =
50+
catchRunWalletResourceM layer alert render walletPublicIdentity

lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Page.hs

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ import Cardano.Wallet.UI.Deposit.API
3838
, settingsGetLink
3939
, settingsPageLink
4040
, sseLink
41+
, walletPageLink
4142
)
4243
import Cardano.Wallet.UI.Deposit.Html.Pages.About
4344
( aboutH
4445
)
46+
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
47+
( walletH
48+
)
4549
import Control.Lens.Extras
4650
( is
4751
)
@@ -60,6 +64,7 @@ data Page
6064
= About
6165
| Network
6266
| Settings
67+
| Wallet
6368

6469
makePrisms ''Page
6570

@@ -69,14 +74,15 @@ page
6974
-> Page
7075
-- ^ If a wallet was selected
7176
-> RawHtml
72-
page c@PageConfig{..} p = RawHtml
77+
page c@PageConfig{..} p = RawHtml
7378
$ renderBS
7479
$ pageFromBodyH faviconLink c
7580
$ bodyH (headerH prefix p)
7681
$ case p of
7782
About -> aboutH
7883
Network -> networkH sseLink networkInfoLink
7984
Settings -> settingsPageH sseLink settingsGetLink
85+
Wallet -> walletH
8086

8187
headerH :: Text -> Page -> Html ()
8288
headerH prefix p =
@@ -85,4 +91,5 @@ headerH prefix p =
8591
[ (is _About p, aboutPageLink, "About")
8692
, (is _Network p, networkPageLink, "Network")
8793
, (is _Settings p, settingsPageLink, "Settings")
94+
, (is _Wallet p, walletPageLink, "Wallet")
8895
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
module Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
2+
where
3+
4+
import Prelude
5+
6+
import Cardano.Address.Derivation
7+
( xpubChainCode
8+
, xpubPublicKey
9+
)
10+
import Cardano.Wallet.Deposit.IO
11+
( WalletPublicIdentity (..)
12+
)
13+
import Cardano.Wallet.UI.Common.API
14+
( Visible (..)
15+
)
16+
import Cardano.Wallet.UI.Common.Html.Pages.Lib
17+
( record
18+
, simpleField
19+
)
20+
import Cardano.Wallet.UI.Common.Html.Pages.Wallet
21+
( PostWalletConfig (..)
22+
, newWalletH
23+
)
24+
import Cardano.Wallet.UI.Deposit.API
25+
( walletLink
26+
, walletMnemonicLink
27+
)
28+
import Codec.Binary.Encoding
29+
( AbstractEncoding (..)
30+
, encode
31+
)
32+
import Data.ByteString
33+
( ByteString
34+
)
35+
import Data.Text
36+
( Text
37+
)
38+
import Data.Text.Class
39+
( ToText (..)
40+
)
41+
import Lucid
42+
( Html
43+
, p_
44+
)
45+
46+
import qualified Data.Text.Encoding as T
47+
48+
walletH :: Html ()
49+
walletH = do
50+
-- 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+
}
58+
59+
base16 :: ByteString -> Text
60+
base16 = T.decodeUtf8 . encode EBase16
61+
62+
walletElementH :: WalletPublicIdentity -> Html ()
63+
walletElementH (WalletPublicIdentity xpub customers) = do
64+
record $ do
65+
simpleField "XPub" $ record $ do
66+
simpleField "public key" $ base16 $ xpubPublicKey xpub
67+
simpleField "other" $ base16 $ xpubChainCode xpub
68+
simpleField "Known customers" $ toText customers

lib/ui/src/Cardano/Wallet/UI/Deposit/Server.hs

+31-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import Cardano.Wallet.Api.Http.Server.Handlers.NetworkInformation
1616
import Cardano.Wallet.Api.Types
1717
( ApiWalletMode (..)
1818
)
19+
import Cardano.Wallet.Deposit.REST
20+
( WalletResource
21+
)
1922
import Cardano.Wallet.Network
2023
( NetworkLayer
2124
)
@@ -36,6 +39,9 @@ import Cardano.Wallet.UI.Common.Handlers.SSE
3639
import Cardano.Wallet.UI.Common.Handlers.State
3740
( getState
3841
)
42+
import Cardano.Wallet.UI.Common.Handlers.Wallet
43+
( pickMnemonic
44+
)
3945
import Cardano.Wallet.UI.Common.Html.Html
4046
( RawHtml (..)
4147
, renderHtml
@@ -53,6 +59,9 @@ import Cardano.Wallet.UI.Common.Html.Pages.Settings
5359
import Cardano.Wallet.UI.Common.Html.Pages.Template.Head
5460
( PageConfig
5561
)
62+
import Cardano.Wallet.UI.Common.Html.Pages.Wallet
63+
( mnemonicH
64+
)
5665
import Cardano.Wallet.UI.Common.Layer
5766
( SessionLayer (..)
5867
, UILayer (..)
@@ -68,10 +77,16 @@ import Cardano.Wallet.UI.Deposit.API
6877
( UI
6978
, settingsSseToggleLink
7079
)
80+
import Cardano.Wallet.UI.Deposit.Handlers.Wallet
81+
( getWallet
82+
)
7183
import Cardano.Wallet.UI.Deposit.Html.Pages.Page
7284
( Page (..)
7385
, page
7486
)
87+
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
88+
( walletElementH
89+
)
7590
import Control.Monad.Trans
7691
( MonadIO (..)
7792
)
@@ -99,7 +114,7 @@ import qualified Cardano.Read.Ledger.Block.Block as Read
99114
import qualified Data.ByteString.Lazy as BL
100115

101116
pageHandler
102-
:: UILayer ()
117+
:: UILayer a
103118
-> PageConfig
104119
-> Page
105120
-> Maybe RequestCookies
@@ -114,37 +129,47 @@ showTime = formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S"
114129
serveUI
115130
:: forall n
116131
. HasSNetworkId n
117-
=> UILayer ()
132+
=> UILayer WalletResource
118133
-> PageConfig
119134
-> SNetworkId n
120135
-> NetworkLayer IO Read.ConsensusBlock
121136
-> BlockchainSource
122137
-> Server UI
123-
serveUI ul config _ nl bs =
138+
serveUI ul config _ nl bs =
124139
ph About
125140
:<|> ph About
126141
:<|> ph Network
127142
:<|> ph Settings
143+
:<|> ph Wallet
128144
:<|> sessioning (renderHtml . networkInfoH showTime <$> getNetworkInformation nid nl mode)
129145
:<|> wsl (\l -> getState l (renderHtml . settingsStateH settingsSseToggleLink))
130146
:<|> wsl (\l -> toggleSSE l $> RawHtml "")
131147
:<|> withSessionLayerRead (sse . sseConfig)
132148
:<|> serveFavicon
149+
:<|> (\c -> sessioning $ renderHtml . mnemonicH <$> liftIO (pickMnemonic 15 c))
150+
:<|> wsl (\l -> getWallet l alert (renderHtml . walletElementH))
133151
where
134152
ph = pageHandler ul config
135153
_ok _ = renderHtml . rogerH @Text $ "ok"
136-
_alert = renderHtml . alertH
154+
alert = renderHtml . alertH
137155
nid = networkIdVal (sNetworkId @n)
138156
mode = case bs of
139157
NodeSource{} -> Node
140158
_ = networkInfoH
141159
wsl = withSessionLayer ul
142-
withSessionLayerRead :: (SessionLayer () -> Handler a) -> Maybe RequestCookies -> Handler a
160+
withSessionLayerRead
161+
:: (SessionLayer WalletResource -> Handler a)
162+
-> Maybe RequestCookies
163+
-> Handler a
143164
withSessionLayerRead f = withSessionRead $ \k -> do
144165
s <- liftIO $ sessions ul k
145166
f s
146167

147-
withSessionLayer :: UILayer () -> (SessionLayer () -> Handler a) -> Maybe RequestCookies -> Handler (CookieResponse a)
168+
withSessionLayer
169+
:: UILayer s
170+
-> (SessionLayer s -> Handler a)
171+
-> Maybe RequestCookies
172+
-> Handler (CookieResponse a)
148173
withSessionLayer ulayer f = withSession $ \k -> do
149174
s <- liftIO $ sessions ulayer k
150175
f s

0 commit comments

Comments
 (0)