-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customer transactions history page
- Loading branch information
Showing
9 changed files
with
415 additions
and
42 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
104 changes: 104 additions & 0 deletions
104
lib/ui/src/Cardano/Wallet/UI/Deposit/Handlers/Transactions.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,104 @@ | ||
{-# LANGUAGE TupleSections #-} | ||
module Cardano.Wallet.UI.Deposit.Handlers.Transactions | ||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Deposit.Pure | ||
( Customer | ||
, TxSummary (..) | ||
, ValueTransfer (ValueTransfer) | ||
) | ||
import Cardano.Wallet.Deposit.REST | ||
( WalletResource | ||
) | ||
import Cardano.Wallet.Read | ||
( SlotNo (..) | ||
, txIdFromHash | ||
) | ||
import Cardano.Wallet.Read.Hash | ||
( hashFromStringAsHex | ||
) | ||
import Cardano.Wallet.UI.Common.Layer | ||
( SessionLayer (..) | ||
) | ||
import Cardano.Wallet.UI.Deposit.Handlers.Lib | ||
( catchRunWalletResourceHtml | ||
) | ||
import Control.Monad | ||
( replicateM | ||
) | ||
import Data.Foldable | ||
( toList | ||
) | ||
import Data.Function | ||
( on | ||
) | ||
import Data.List | ||
( sortBy | ||
) | ||
import Data.Maybe | ||
( fromJust | ||
) | ||
import Servant | ||
( Handler | ||
) | ||
import System.Random.Stateful | ||
( UniformRange (..) | ||
, mkStdGen | ||
, runStateGen_ | ||
) | ||
|
||
import qualified Cardano.Wallet.Deposit.REST as REST | ||
import qualified Cardano.Wallet.Read as Read | ||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
|
||
getCustomerHistory | ||
:: SessionLayer WalletResource | ||
-> (Bool -> [TxSummary] -> html) | ||
-> (BL.ByteString -> html) | ||
-> Customer | ||
-> Handler html | ||
getCustomerHistory layer render alert customer = do | ||
catchRunWalletResourceHtml layer alert (uncurry render) $ do | ||
fakeData customer . toList <$> REST.getCustomerHistory customer | ||
|
||
-- fake data generation until DB is implemented | ||
|
||
fakeData :: Customer -> [TxSummary] -> (Bool,[TxSummary]) | ||
fakeData c [] = (True, ) $ | ||
sortBy | ||
(on compare $ \(TxSummaryC _ cp _) -> cp ) | ||
$ txSummaryG (fromIntegral c) | ||
fakeData _c xs = (False, xs) | ||
|
||
unsafeMkTxId :: String -> Read.TxId | ||
unsafeMkTxId = txIdFromHash . fromJust . hashFromStringAsHex | ||
|
||
hexOfInt :: Int -> Char | ||
hexOfInt n = "0123456789abcdef" !! (n `mod` 16) | ||
|
||
txSummaryG :: Int -> [TxSummary] | ||
txSummaryG c = runStateGen_ pureGen $ \g -> do | ||
ns <- uniformRM (1, 10) g | ||
replicateM ns $ do | ||
txId <- txIdR g | ||
cp <- chainPointR g | ||
spent <- Read.ValueC <$> uniformRM (0, 1000) g <*> pure mempty | ||
received <- Read.ValueC <$> uniformRM (0, 1000) g <*> pure mempty | ||
pure $ TxSummaryC txId cp $ ValueTransfer spent received | ||
where | ||
pureGen = mkStdGen c | ||
txIdR g = do | ||
ls <- replicateM 64 $ hexOfInt <$> uniformRM (0, 15) g | ||
pure $ unsafeMkTxId ls | ||
headerHash g = replicateM 64 $ hexOfInt <$> uniformRM (0, 15) g | ||
chainPointR g = do | ||
slot <- uniformRM (0, 100) g | ||
case slot of | ||
0 -> pure Read.GenesisPoint | ||
_ -> do | ||
r <- hashFromStringAsHex <$> headerHash g | ||
case r of | ||
Just h -> pure $ Read.BlockPoint (SlotNo slot) h | ||
Nothing -> error "chainPointR: invalid hash" |
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,66 @@ | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Cardano.Wallet.UI.Deposit.Html.Lib | ||
( imageOverlay | ||
, overlayFakeDataH | ||
, selectCustomerH | ||
) | ||
where | ||
|
||
import Cardano.Wallet.UI.Common.Html.Htmx | ||
import Cardano.Wallet.UI.Common.Html.Lib (linkText) | ||
import Cardano.Wallet.UI.Common.Html.Pages.Lib (simpleField, AssocRow) | ||
import Cardano.Wallet.UI.Deposit.API (fakeDataBackgroundLink) | ||
import Data.Text.Class (ToText (..)) | ||
import Lucid | ||
( HtmlT | ||
, ToHtml (toHtml) | ||
, class_ | ||
, div_ | ||
, img_ | ||
, input_ | ||
, max_ | ||
, min_ | ||
, name_ | ||
, size_ | ||
, src_ | ||
, step_ | ||
, style_ | ||
, type_ | ||
, value_ | ||
) | ||
import Prelude | ||
import Data.Text (Text) | ||
import Servant (Link) | ||
import Cardano.Wallet.UI.Lib.ListOf (ListOf) | ||
|
||
imageOverlay :: Monad m => HtmlT m () | ||
imageOverlay = | ||
style_ [] | ||
$ toHtml @String | ||
".overlay-image { position: absolute; top: 0; left: 0; z-index: 10;\ | ||
\ width: 100%; opacity: 20%; }" | ||
|
||
overlayFakeDataH :: Monad m => HtmlT m () -> HtmlT m () | ||
overlayFakeDataH x = div_ [style_ "position: relative;"] $ do | ||
x | ||
img_ [class_ "overlay-image", src_ $ linkText fakeDataBackgroundLink] | ||
|
||
selectCustomerH :: Monad m => Text -> Link -> Int -> ListOf (AssocRow m) | ||
selectCustomerH identifier link trackedUsers = | ||
simpleField "Customer Number" | ||
$ div_ [class_ "d-flex justify-content-end"] | ||
$ input_ | ||
[ type_ "number" | ||
, hxTarget_ identifier | ||
, class_ "form-control" | ||
, hxTrigger_ "load, change" | ||
, hxPost_ $ linkText link | ||
, min_ "0" | ||
, max_ $ toText $ trackedUsers - 1 | ||
, step_ "1" | ||
, name_ "customer" | ||
, value_ "0" | ||
, size_ "5" | ||
, style_ "width: 7em" | ||
] |
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
Oops, something went wrong.