@@ -8,20 +8,24 @@ import Prelude
8
8
import Cardano.Address.Derivation
9
9
( XPub
10
10
)
11
+ import Cardano.Wallet.Deposit.Pure
12
+ ( Customer
13
+ )
11
14
import Cardano.Wallet.Deposit.REST
12
15
( ErrWalletResource
13
16
, WalletResource
14
17
, WalletResourceM
15
18
, runWalletResourceM
16
19
)
17
- import Cardano.Wallet.UI.Common.Handlers.Lib
18
- ( handleParseRequestError
19
- )
20
20
import Cardano.Wallet.UI.Common.Layer
21
21
( Push (Push )
22
22
, SessionLayer (.. )
23
23
, stateL
24
24
)
25
+ import Cardano.Wallet.UI.Deposit.API
26
+ ( PostWalletViaMenmonic (.. )
27
+ , PostWalletViaXPub (.. )
28
+ )
25
29
import Cardano.Wallet.UI.Deposit.Handlers.Lib
26
30
( walletPresent
27
31
)
@@ -34,24 +38,13 @@ import Control.Lens
34
38
import Control.Monad.Trans
35
39
( MonadIO (.. )
36
40
)
37
- import Data.Aeson
38
- ( Value
39
- , withObject
40
- , (.:)
41
- )
42
- import Data.Aeson.Types
43
- ( parseEither
44
- )
45
41
import Data.ByteArray.Encoding
46
42
( Base (.. )
47
43
, convertFromBase
48
44
)
49
45
import Data.ByteString
50
46
( ByteString
51
47
)
52
- import Data.Text
53
- ( Text
54
- )
55
48
import Servant
56
49
( Handler
57
50
)
@@ -91,12 +84,11 @@ initWalletWithXPub
91
84
:: SessionLayer WalletResource
92
85
-> (BL. ByteString -> html )
93
86
-> (() -> html )
94
- -> (XPub -> WalletResourceM a )
95
- -> XPub
87
+ -> (WalletResourceM a )
96
88
-> Handler html
97
- initWalletWithXPub l@ SessionLayer {sendSSE} alert render initWallet xpub = do
89
+ initWalletWithXPub l@ SessionLayer {sendSSE} alert render initWallet = do
98
90
liftIO $ sendSSE $ Push " wallet"
99
- r <- liftIO $ catchRunWalletResourceM l ( initWallet xpub)
91
+ r <- liftIO $ catchRunWalletResourceM l initWallet
100
92
case r of
101
93
Left e -> pure $ alert $ BL. pack $ show e
102
94
Right _ -> do
@@ -105,39 +97,33 @@ initWalletWithXPub l@SessionLayer{sendSSE} alert render initWallet xpub = do
105
97
106
98
postMnemonicWallet
107
99
:: SessionLayer WalletResource
108
- -> (XPub -> WalletResourceM a )
100
+ -> (XPub -> Customer -> WalletResourceM a )
109
101
-> (BL. ByteString -> html )
110
102
-> (() -> html )
111
- -> Value
103
+ -> PostWalletViaMenmonic
112
104
-> Handler html
113
- postMnemonicWallet l initWallet alert render v = do
114
- mnemonic <-
115
- handleParseRequestError
116
- $ parsePostWalletRequest v
117
- let xpub =
118
- Addresses. toXPub
119
- $ Addresses. generate (T. encodeUtf8 mnemonic)
120
- initWalletWithXPub l alert render initWallet xpub
121
-
122
- parsePostWalletRequest :: Value -> Either String Text
123
- parsePostWalletRequest = parseEither
124
- . withObject " create wallet request"
125
- $ \ o -> o .: " mnemonicSentence"
105
+ postMnemonicWallet
106
+ l
107
+ initWallet
108
+ alert
109
+ render
110
+ (PostWalletViaMenmonic mnemonic users) = do
111
+ let xpub =
112
+ Addresses. toXPub
113
+ $ Addresses. generate (T. encodeUtf8 mnemonic)
114
+ initWalletWithXPub l alert render $ initWallet xpub $ fromIntegral users
126
115
127
116
unBase64 :: ByteString -> Either String ByteString
128
117
unBase64 = convertFromBase Base64
129
118
130
119
postXPubWallet
131
120
:: SessionLayer WalletResource
132
- -> (XPub -> WalletResourceM a )
121
+ -> (XPub -> Customer -> WalletResourceM a )
133
122
-> (BL. ByteString -> html )
134
123
-> (() -> html )
135
- -> Value
124
+ -> PostWalletViaXPub
136
125
-> Handler html
137
- postXPubWallet l initWallet alert render v = do
138
- xpubText <-
139
- handleParseRequestError
140
- $ parsePostXPubRequest v
126
+ postXPubWallet l initWallet alert render (PostWalletViaXPub xpubText users) = do
141
127
case T. encodeUtf8 xpubText of
142
128
xpubByteString -> case unBase64 xpubByteString of
143
129
Left e -> pure $ alert $ BL. pack $ " Invalid base64: " <> e
@@ -147,12 +133,10 @@ postXPubWallet l initWallet alert render v = do
147
133
$ alert
148
134
$ BL. pack
149
135
$ " Invalid xpub: " <> show xpubText
150
- Just xpub -> initWalletWithXPub l alert render initWallet xpub
151
-
152
- parsePostXPubRequest :: Value -> Either String Text
153
- parsePostXPubRequest = parseEither
154
- . withObject " create wallet from xpub request"
155
- $ \ o -> o .: " xpub"
136
+ Just xpub ->
137
+ initWalletWithXPub l alert render
138
+ $ initWallet xpub
139
+ $ fromIntegral users
156
140
157
141
walletIsLoading
158
142
:: SessionLayer WalletResource
0 commit comments