Skip to content

Commit

Permalink
nice formatting of funds
Browse files Browse the repository at this point in the history
  • Loading branch information
brunjlar committed Jun 9, 2021
1 parent 24e3596 commit 30d6b92
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions code/week10/app/uniswap-client.hs
Expand Up @@ -8,22 +8,24 @@ module Main

import Control.Concurrent
import Control.Exception
import Control.Monad (when)
import Control.Monad (forM_, when)
import Control.Monad.IO.Class (MonadIO (..))
import Data.Aeson (Result (..), ToJSON, decode, fromJSON)
import qualified Data.ByteString.Lazy as LB
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy as LB
import Data.Monoid (Last (..))
import Data.Proxy (Proxy (..))
import Data.String (IsString (..))
import Data.Text (Text, pack)
import Data.UUID hiding (fromString)
import Ledger.Value (AssetClass (..), CurrencySymbol, flattenValue)
import Ledger.Value (AssetClass (..), CurrencySymbol, Value, flattenValue, TokenName (unTokenName))
import Network.HTTP.Req
import qualified Plutus.Contracts.Uniswap as US
import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse (..))
import Plutus.PAB.Webserver.Types
import System.Environment (getArgs)
import System.Exit (exitFailure)
import Text.Printf (printf)
import Text.Read (readMaybe)
import Wallet.Emulator.Types (Wallet (..))

Expand Down Expand Up @@ -82,9 +84,16 @@ getFunds cid = do
go = do
e <- getStatus cid
case e of
Right (US.Funds v) -> putStrLn $ "funds: " ++ show (flattenValue v)
Right (US.Funds v) -> showFunds v
_ -> go

showFunds :: Value -> IO ()
showFunds v = do
printf "\n currency symbol token name amount\n\n"
forM_ (flattenValue v) $ \(cs, tn, amt) ->
printf "%64s %66s %15d\n" (show cs) (show tn) amt
printf "\n"

getPools :: UUID -> IO ()
getPools cid = do
callEndpoint cid "pools" ()
Expand Down

0 comments on commit 30d6b92

Please sign in to comment.