-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This PR separates out the address query from the wallet details. This makes the navigation bar depends on the resource state. ADP-3456
- Loading branch information
Showing
10 changed files
with
288 additions
and
114 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
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
52 changes: 52 additions & 0 deletions
52
lib/ui/src/Cardano/Wallet/UI/Deposit/Handlers/Addresses.hs
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,52 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Cardano.Wallet.UI.Deposit.Handlers.Addresses | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Deposit.Pure | ||
( Customer | ||
) | ||
import Cardano.Wallet.Deposit.Read | ||
( Address | ||
) | ||
import Cardano.Wallet.Deposit.REST | ||
( WalletResource | ||
, customerAddress | ||
) | ||
import Cardano.Wallet.UI.Common.Layer | ||
( SessionLayer (..) | ||
) | ||
import Cardano.Wallet.UI.Deposit.Handlers.Lib | ||
( catchRunWalletResourceHtml | ||
, walletPresence | ||
) | ||
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet | ||
( WalletPresent | ||
) | ||
import Servant | ||
( Handler | ||
) | ||
|
||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
|
||
getAddresses | ||
:: SessionLayer WalletResource | ||
-> (WalletPresent -> html) -- success report | ||
-> Handler html | ||
getAddresses layer render = render <$> walletPresence layer | ||
|
||
getCustomerAddress | ||
:: SessionLayer WalletResource | ||
-> (Address -> html) | ||
-> (BL.ByteString -> html) | ||
-> Customer | ||
-> Handler html | ||
getCustomerAddress layer render alert customer = do | ||
catchRunWalletResourceHtml layer alert render' | ||
$ customerAddress customer | ||
where | ||
render' = \case | ||
Just a -> render a | ||
Nothing -> alert "Address not discovered" |
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
114 changes: 114 additions & 0 deletions
114
lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Addresses.hs
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,114 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Cardano.Wallet.UI.Deposit.Html.Pages.Addresses | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Deposit.IO | ||
( WalletPublicIdentity (..) | ||
) | ||
import Cardano.Wallet.Deposit.Read | ||
( Address | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Copy | ||
( copyButton | ||
, copyableHidden | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Htmx | ||
( hxPost_ | ||
, hxTarget_ | ||
, hxTrigger_ | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Lib | ||
( linkText | ||
) | ||
import Cardano.Wallet.UI.Common.Html.Pages.Lib | ||
( record | ||
, simpleField | ||
, sseH | ||
) | ||
import Cardano.Wallet.UI.Deposit.API | ||
( addressesLink | ||
, customerAddressLink | ||
) | ||
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet | ||
( WalletPresent (..) | ||
) | ||
import Cardano.Wallet.UI.Lib.Address | ||
( encodeMainnetAddress | ||
) | ||
import Cardano.Wallet.UI.Type | ||
( WHtml | ||
) | ||
import Data.Text.Class | ||
( ToText (..) | ||
) | ||
import Lucid | ||
( Html | ||
, HtmlT | ||
, ToHtml (..) | ||
, class_ | ||
, div_ | ||
, id_ | ||
, input_ | ||
, min_ | ||
, name_ | ||
, type_ | ||
, value_ | ||
) | ||
import Lucid.Html5 | ||
( max_ | ||
, step_ | ||
) | ||
|
||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
import qualified Data.Text as T | ||
|
||
addressesH :: WHtml () | ||
addressesH = do | ||
sseH addressesLink "addresses" ["wallet"] | ||
|
||
customerAddressH :: Monad m => Address -> HtmlT m () | ||
customerAddressH addr = div_ [class_ "d-flex justify-content-end"] $ do | ||
div_ (copyableHidden "address") $ toHtml encodedAddr | ||
div_ [class_ "d-block d-md-none"] $ toHtml addrShortened | ||
div_ [class_ "d-none d-md-block"] $ toHtml encodedAddr | ||
div_ [class_ "ms-1"] $ copyButton "address" | ||
where | ||
encodedAddr = encodeMainnetAddress addr | ||
addrShortened = | ||
T.take 10 (T.drop 5 encodedAddr) | ||
<> " .. " | ||
<> T.takeEnd 10 encodedAddr | ||
|
||
addressElementH :: (BL.ByteString -> Html ()) -> WalletPresent -> Html () | ||
addressElementH alert = \case | ||
WalletPresent (WalletPublicIdentity _xpub customers) -> do | ||
div_ [class_ "row mt-5"] $ do | ||
div_ [class_ "col"] $ record $ do | ||
simpleField "Customer Number" | ||
$ input_ | ||
[ type_ "number" | ||
, hxTarget_ "#customer-address" | ||
, class_ "form-control" | ||
, hxTrigger_ "load, change" | ||
, hxPost_ $ linkText customerAddressLink | ||
, min_ "0" | ||
, max_ $ toText $ customers - 1 | ||
, step_ "1" | ||
, name_ "customer" | ||
, value_ "0" | ||
, class_ "w-3" | ||
] | ||
simpleField "Address" $ div_ [id_ "customer-address"] mempty | ||
WalletAbsent -> alert "Wallet is absent" | ||
WalletFailedToInitialize err -> | ||
alert | ||
$ "Failed to initialize wallet" | ||
<> BL.pack (show err) | ||
WalletVanished e -> alert $ "Wallet vanished " <> BL.pack (show e) | ||
WalletInitializing -> alert "Wallet is initializing" | ||
WalletClosing -> alert "Wallet is closing" |
Oops, something went wrong.