Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Nov 8, 2024
1 parent e792ae8 commit 608ad20
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/ui/cardano-wallet-ui.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ library
Cardano.Wallet.UI.Deposit.API.Addresses.Transactions
Cardano.Wallet.UI.Deposit.API.Common
Cardano.Wallet.UI.Deposit.API.Deposits.Deposits
Cardano.Wallet.UI.Deposit.API.Payments
Cardano.Wallet.UI.Deposit.Handlers.Addresses
Cardano.Wallet.UI.Deposit.Handlers.Addresses.Transactions
Cardano.Wallet.UI.Deposit.Handlers.Deposits.Customers
Expand All @@ -80,6 +81,7 @@ library
Cardano.Wallet.UI.Deposit.Html.Pages.Deposits.Times
Cardano.Wallet.UI.Deposit.Html.Pages.Deposits.TxIds
Cardano.Wallet.UI.Deposit.Html.Pages.Page
Cardano.Wallet.UI.Deposit.Html.Pages.Payments.Page
Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
Cardano.Wallet.UI.Deposit.Server
Cardano.Wallet.UI.Deposit.Server.Addresses
Expand All @@ -88,12 +90,14 @@ library
Cardano.Wallet.UI.Deposit.Server.Deposits.Times
Cardano.Wallet.UI.Deposit.Server.Deposits.TxIds
Cardano.Wallet.UI.Deposit.Server.Lib
Cardano.Wallet.UI.Deposit.Server.Payments.Page
Cardano.Wallet.UI.Deposit.Server.Wallet
Cardano.Wallet.UI.Deposit.Types.Payments
Cardano.Wallet.UI.Lib.Address
Cardano.Wallet.UI.Lib.Discretization
Cardano.Wallet.UI.Lib.ListOf
Cardano.Wallet.UI.Lib.Pagination.TimedSeq
Cardano.Wallet.UI.Lib.Pagination.Map
Cardano.Wallet.UI.Lib.Pagination.TimedSeq
Cardano.Wallet.UI.Lib.Pagination.Type
Cardano.Wallet.UI.Lib.Time.Direction
Cardano.Wallet.UI.Shelley.API
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/src/Cardano/Wallet/UI/Common/Html/Pages/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ where

import Prelude

import Cardano.Wallet.Deposit.Pure.API.Address
( encodeAddress
)
import Cardano.Wallet.Deposit.Read
( Address
)
Expand All @@ -48,9 +51,6 @@ import Cardano.Wallet.UI.Common.Html.Lib
, linkText
, truncatableText
)
import Cardano.Wallet.UI.Lib.Address
( encodeAddress
)
import Cardano.Wallet.UI.Lib.ListOf
( Cons (..)
, ListOf
Expand Down Expand Up @@ -274,7 +274,7 @@ showThousandDots = reverse . showThousandDots' . reverse . show
a <> if null b then [] else "." <> showThousandDots' b

addressH :: Monad m => WithCopy -> Address -> HtmlT m ()
addressH copy addr =
addressH copy addr = do
truncatableText copy ("address-text-" <> encodedAddr)
$ toHtml encodedAddr
where
Expand Down
20 changes: 19 additions & 1 deletion lib/ui/src/Cardano/Wallet/UI/Deposit/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ import Web.FormUrlEncoded
( FromForm (..)
)

import Cardano.Wallet.UI.Deposit.API.Payments
( NewPaymentParams
)
import qualified Data.ByteString.Lazy as BL

instance FromForm PostWalletViaMenmonic
Expand All @@ -80,6 +83,7 @@ data Page
| Wallet
| Addresses
| Deposits
| Payments

makePrisms ''Page

Expand All @@ -90,6 +94,7 @@ instance ToHttpApiData Page where
toUrlPiece Wallet = "wallet"
toUrlPiece Addresses = "addresses"
toUrlPiece Deposits = "deposits"
toUrlPiece Payments = "payments"

instance FromHttpApiData Page where
parseUrlPiece "about" = Right About
Expand All @@ -98,6 +103,7 @@ instance FromHttpApiData Page where
parseUrlPiece "wallet" = Right Wallet
parseUrlPiece "addresses" = Right Addresses
parseUrlPiece "deposits" = Right Deposits
parseUrlPiece "payments" = Right Payments
parseUrlPiece _ = Left "Invalid page"

-- | Pages endpoints
Expand All @@ -108,6 +114,7 @@ type Pages =
:<|> "wallet" :> SessionedHtml Get
:<|> "addresses" :> SessionedHtml Get
:<|> "deposits" :> SessionedHtml Get
:<|> "payments" :> SessionedHtml Get

-- | Data endpoints
type Data =
Expand Down Expand Up @@ -190,6 +197,9 @@ type Data =
:> QueryParam "customer" Customer
:> QueryParam "tx-id" TxId
:> SessionedHtml Post
:<|> "payments" :> SessionedHtml Get
:<|> "payments" :> "receiver" :> ReqBody '[FormUrlEncoded] NewPaymentParams
:> SessionedHtml Post

type Home = SessionedHtml Get

Expand All @@ -208,6 +218,8 @@ settingsPageLink :: Link
walletPageLink :: Link
addressesPageLink :: Link
depositPageLink :: Link
paymentsPageLink :: Link

networkInfoLink :: Link
settingsGetLink :: Link
settingsSseToggleLink :: Link
Expand Down Expand Up @@ -236,13 +248,16 @@ depositsTxIdsLink
:: Maybe (WithOrigin UTCTime) -> Maybe Customer -> Maybe Expand -> Link
depositsTxIdsPaginatingLink
:: Maybe (WithOrigin UTCTime) -> Maybe Customer -> Maybe TxId -> Link
paymentsLink :: Link
paymentsNewReceiverLink :: Link
homePageLink
:<|> aboutPageLink
:<|> networkPageLink
:<|> settingsPageLink
:<|> walletPageLink
:<|> addressesPageLink
:<|> depositPageLink
:<|> paymentsPageLink
:<|> networkInfoLink
:<|> settingsGetLink
:<|> settingsSseToggleLink
Expand All @@ -265,5 +280,8 @@ homePageLink
:<|> depositsCustomersLink
:<|> depositsCustomersPaginatingLink
:<|> depositsTxIdsLink
:<|> depositsTxIdsPaginatingLink =
:<|> depositsTxIdsPaginatingLink
:<|> paymentsLink
:<|> paymentsNewReceiverLink
=
allLinks (Proxy @UI)
34 changes: 34 additions & 0 deletions lib/ui/src/Cardano/Wallet/UI/Deposit/API/Payments.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Wallet.UI.Deposit.API.Payments
( NewPaymentParams (..)
)
where

import Prelude

import Cardano.Wallet.UI.Deposit.Types.Payments
( Receiver (..)
)
import Web.FormUrlEncoded
( FromForm (..)
, parseAll
, parseUnique
)

data NewPaymentParams = NewPaymentParams
{ receivers :: [Receiver]
, newReceiver :: Receiver
}
deriving (Eq, Show)

instance FromForm NewPaymentParams where
fromForm form = do
receivers <- parseAll "receiver-defined" form
address <- parseUnique "new-receiver-address" form
amount <- parseUnique "new-receiver-amount" form
let newReceiver = Receiver{address = address, amount = amount}
pure $ NewPaymentParams{receivers, newReceiver}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import System.IO.Unsafe
)

nMockDeposits :: Int
nMockDeposits = 100000
nMockDeposits = 10000

type TxHistoryCache = TVar (Maybe (UTCTime, [Address], TxHistory))

Expand Down
10 changes: 10 additions & 0 deletions lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Page.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Cardano.Wallet.UI.Deposit.API
, _Addresses
, _Deposits
, _Network
, _Payments
, _Settings
, _Wallet
, aboutPageLink
Expand All @@ -55,6 +56,8 @@ import Cardano.Wallet.UI.Deposit.API
, navigationLink
, networkInfoLink
, networkPageLink
, paymentsLink
, paymentsPageLink
, settingsGetLink
, settingsPageLink
, sseLink
Expand All @@ -69,6 +72,9 @@ import Cardano.Wallet.UI.Deposit.Html.Pages.Addresses
import Cardano.Wallet.UI.Deposit.Html.Pages.Deposits.Page
( depositsH
)
import Cardano.Wallet.UI.Deposit.Html.Pages.Payments.Page
( paymentsH
)
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
( WalletPresent
, isPresent
Expand Down Expand Up @@ -111,6 +117,7 @@ page c p = RawHtml
Wallet -> walletH
Addresses -> addressesH
Deposits -> depositsH depositsLink
Payments -> paymentsH paymentsLink

headerH :: Monad m => Page -> HtmlT m ()
headerH p = sseH (navigationLink $ Just p) "header" ["wallet"]
Expand All @@ -126,6 +133,9 @@ headerElementH p wp =
<> [ (is' _Deposits, depositPageLink, "Deposits")
| isPresent wp
]
<> [ (is' _Payments, paymentsPageLink, "Payments")
| isPresent wp
]
<> [ (is' _Network, networkPageLink, "Network")
, (is' _Settings, settingsPageLink, "Settings")
, (is' _About, aboutPageLink, "About")
Expand Down
147 changes: 147 additions & 0 deletions lib/ui/src/Cardano/Wallet/UI/Deposit/Html/Pages/Payments/Page.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}

module Cardano.Wallet.UI.Deposit.Html.Pages.Payments.Page
( paymentsH
, paymentsElementH
, receiversH
)
where

import Prelude

import Cardano.Wallet.Deposit.IO
( WalletPublicIdentity (..)
)
import Cardano.Wallet.UI.Common.Html.Htmx
( hxInclude_
, hxPost_
, hxTarget_
)
import Cardano.Wallet.UI.Common.Html.Lib
( AlertH
, WithCopy (..)
, linkText
, tdEnd
, thEnd
)
import Cardano.Wallet.UI.Common.Html.Pages.Lib
( addressH
, box
, showAdaOfLoveLace
, sseH
)
import Cardano.Wallet.UI.Deposit.API
( paymentsNewReceiverLink
)
import Cardano.Wallet.UI.Deposit.Html.Pages.Wallet
( WalletPresent (..)
, onWalletPresentH
)
import Cardano.Wallet.UI.Deposit.Types.Payments
( Receiver (..)
)
import Cardano.Wallet.UI.Type
( WHtml
)
import Control.Monad
( forM_
)
import Lucid
( Html
, ToHtml (toHtml)
, button_
, class_
, div_
, hidden_
, id_
, input_
, name_
, placeholder_
, table_
, tbody_
, thead_
, tr_
, type_
, value_
)
import Servant
( Link
, ToHttpApiData (toUrlPiece)
)

paymentsH :: Link -> WHtml ()
paymentsH paymentsLink = do
sseH paymentsLink "payments-page" ["wallet"]

newReceiverH :: Html ()
newReceiverH = do
div_
[id_ "new-receiver-form"]
$ do
input_
[ class_ "form-control"
, type_ "text"
, name_ "new-receiver-address"
, placeholder_ "Address"
]
input_
[ class_ "form-control"
, type_ "text"
, name_ "new-receiver-amount"
, placeholder_ "Amount"
]
button_
[ class_ "btn btn-primary"
, type_ "submit"
, hxPost_ $ linkText paymentsNewReceiverLink
, hxTarget_ "#receivers"
, hxInclude_ "#receivers-state , #new-receiver-form"
]
"Add"

settledReceiversH :: [Receiver] -> Html ()
settledReceiversH rs = do
table_ [class_ "table table-striped"] $ do
thead_ $ do
tr_ $ do
thEnd Nothing "Address"
thEnd (Just 7) "Amount"
tbody_ [id_ "receivers-state"]
$ forM_ rs
$ \r@Receiver{address, amount} -> do
tr_ $ do
tdEnd $ do
addressH WithCopy address
input_
[ hidden_ ""
, value_ $ toUrlPiece r
, name_ "receiver-defined"
]

tdEnd $ toHtml $ showAdaOfLoveLace amount

receiversH
:: [Receiver] -> Html ()
receiversH rs = do
settledReceiversH rs
newReceiverH

paymentsElementH
:: AlertH
-> WalletPresent
-> Html ()
paymentsElementH = onWalletPresentH $ \case
WalletPublicIdentity _xpub _customers ->
div_
[ class_ "row mt-3 gx-0"
]
$ do
box "New Payment" mempty
$ div_ [class_ "ms-3"]
$ do
box "Receivers" mempty
$ div_ [class_ "ms-3", id_ "receivers"]
$ receiversH []
box "Transaction" mempty mempty
box "Payments History" mempty "To be done"
Loading

0 comments on commit 608ad20

Please sign in to comment.