Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
paluh committed Sep 15, 2023
1 parent 11c6362 commit 0859b77
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 119 deletions.
156 changes: 79 additions & 77 deletions src/Component/ContractList.purs
Original file line number Diff line number Diff line change
Expand Up @@ -404,89 +404,91 @@ mkContractList = do
]
DOM.td { className: "text-center" } $ DOM.small {} slotNoInfo

in do
let
conractIdStr = txOutRefToString contractId
copyToClipboard :: Effect Unit
copyToClipboard = window >>= navigator >>= clipboard >>= \c -> do
launchAff_ (Promise.toAffE $ Clipboard.writeText conractIdStr c)

DOM.tr { className: "align-middle" }
[ tdSlotInfo $ _.slotNo <<< un Runtime.BlockHeader <$> ContractInfo.createdAt ci
, tdSlotInfo $ _.slotNo <<< un Runtime.BlockHeader <$> ContractInfo.updatedAt ci
, DOM.td { className: "text-center" } $ DOM.span { className: "d-flex" }
[ DOM.a
do
let
onClick = case marloweInfo of
Just (MarloweInfo { state, currentContract, initialContract, initialState }) -> do
let
transactionEndpoints = _runtime.transactions <#> \(_ /\ transactionEndpoint) -> transactionEndpoint
setModalAction $ ContractDetails
{ contract: currentContract
, state
, initialState: initialState
, initialContract: initialContract
, transactionEndpoints
}
_ -> pure unit
{ className: "cursor-pointer text-decoration-none text-reset text-decoration-underline-hover truncate-text w-16rem d-inline-block"
, onClick: handler_ onClick
-- , disabled
}
[ text conractIdStr ]
, DOM.a
{ href: "#"
, onClick: handler_ copyToClipboard
, className: "cursor-pointer text-decoration-none text-decoration-underline-hover text-reset"
}
$ Icons.toJSX
$ unsafeIcon "clipboard-plus ms-1 d-inline-block"
]
, tdCentered
[ do
let
tags = runLiteTags contractTags
DOOM.text $ intercalate ", " tags
]
, tdCentered
[ do
case endpoints.transactions, marloweInfo of
Just transactionsEndpoint, Just (MarloweInfo { initialContract, state: Just state, currentContract: Just contract }) -> do
in
do
let
conractIdStr = txOutRefToString contractId

copyToClipboard :: Effect Unit
copyToClipboard = window >>= navigator >>= clipboard >>= \c -> do
launchAff_ (Promise.toAffE $ Clipboard.writeText conractIdStr c)

DOM.tr { className: "align-middle" }
[ tdSlotInfo $ _.slotNo <<< un Runtime.BlockHeader <$> ContractInfo.createdAt ci
, tdSlotInfo $ _.slotNo <<< un Runtime.BlockHeader <$> ContractInfo.updatedAt ci
, DOM.td { className: "text-center" } $ DOM.span { className: "d-flex" }
[ DOM.a
do
let
marloweContext = { initialContract, state, contract }
linkWithIcon
{ icon: unsafeIcon $ "fast-forward-fill" <> actionIconSizing
, label: mempty
, tooltipText: Just "Apply available inputs to the contract"
, tooltipPlacement: Just placement.left
, onClick: setModalAction $ ApplyInputs transactionsEndpoint marloweContext
}
_, Just (MarloweInfo { state: Nothing, currentContract: Nothing }) -> linkWithIcon
{ icon: unsafeIcon $ "file-earmark-check-fill success-color" <> actionIconSizing
, tooltipText: Just "Contract is completed - click on contract id to see in Marlowe Explorer"
, tooltipPlacement: Just placement.left
, label: mempty
, onClick: mempty
onClick = case marloweInfo of
Just (MarloweInfo { state, currentContract, initialContract, initialState }) -> do
let
transactionEndpoints = _runtime.transactions <#> \(_ /\ transactionEndpoint) -> transactionEndpoint
setModalAction $ ContractDetails
{ contract: currentContract
, state
, initialState: initialState
, initialContract: initialContract
, transactionEndpoints
}
_ -> pure unit
{ className: "cursor-pointer text-decoration-none text-reset text-decoration-underline-hover truncate-text w-16rem d-inline-block"
, onClick: handler_ onClick
-- , disabled
}
_, _ -> mempty
, case marloweInfo, possibleWalletContext of
Just (MarloweInfo { currencySymbol: Just currencySymbol, state: _, unclaimedPayouts }), Just { balance: Cardano.Value balance } -> do
[ text conractIdStr ]
, DOM.a
{ href: "#"
, onClick: handler_ copyToClipboard
, className: "cursor-pointer text-decoration-none text-decoration-underline-hover text-reset"
}
$ Icons.toJSX
$ unsafeIcon "clipboard-plus ms-1 d-inline-block"
]
, tdCentered
[ do
let
balance' = Map.filterKeys (\assetId -> Cardano.assetIdToString assetId `eq` currencySymbol) balance
roleTokens = map Cardano.assetIdToString <<< List.toUnfoldable <<< Set.toUnfoldable <<< Map.keys $ balance'
case Array.uncons (Array.intersect roleTokens (map (\(Payout { role }) -> role) unclaimedPayouts)) of
Just { head, tail } ->
tags = runLiteTags contractTags
DOOM.text $ intercalate ", " tags
]
, tdCentered
[ do
case endpoints.transactions, marloweInfo of
Just transactionsEndpoint, Just (MarloweInfo { initialContract, state: Just state, currentContract: Just contract }) -> do
let
marloweContext = { initialContract, state, contract }
linkWithIcon
{ icon: unsafeIcon $ "cash-coin warning-color" <> actionIconSizing
{ icon: unsafeIcon $ "fast-forward-fill" <> actionIconSizing
, label: mempty
, tooltipText: Just "This wallet has funds available for withdrawal from this contract. Click to submit a withdrawal"
, onClick: setModalAction $ Withdrawal runtime.withdrawalsEndpoint (NonEmptyArray.cons' head tail) contractId
, tooltipText: Just "Apply available inputs to the contract"
, tooltipPlacement: Just placement.left
, onClick: setModalAction $ ApplyInputs transactionsEndpoint marloweContext
}
_ -> mempty
_, _ -> mempty
]
]
_, Just (MarloweInfo { state: Nothing, currentContract: Nothing }) -> linkWithIcon
{ icon: unsafeIcon $ "file-earmark-check-fill success-color" <> actionIconSizing
, tooltipText: Just "Contract is completed - click on contract id to see in Marlowe Explorer"
, tooltipPlacement: Just placement.left
, label: mempty
, onClick: mempty
}
_, _ -> mempty
, case marloweInfo, possibleWalletContext of
Just (MarloweInfo { currencySymbol: Just currencySymbol, state: _, unclaimedPayouts }), Just { balance: Cardano.Value balance } -> do
let
balance' = Map.filterKeys (\assetId -> Cardano.assetIdToString assetId `eq` currencySymbol) balance
roleTokens = map Cardano.assetIdToString <<< List.toUnfoldable <<< Set.toUnfoldable <<< Map.keys $ balance'
case Array.uncons (Array.intersect roleTokens (map (\(Payout { role }) -> role) unclaimedPayouts)) of
Just { head, tail } ->
linkWithIcon
{ icon: unsafeIcon $ "cash-coin warning-color" <> actionIconSizing
, label: mempty
, tooltipText: Just "This wallet has funds available for withdrawal from this contract. Click to submit a withdrawal"
, onClick: setModalAction $ Withdrawal runtime.withdrawalsEndpoint (NonEmptyArray.cons' head tail) contractId
}
_ -> mempty
_, _ -> mempty
]
]
]
]
_ ->
Expand Down
69 changes: 30 additions & 39 deletions src/Component/CreateContract.purs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Data.Bifunctor (lmap)
import Data.BigInt.Argonaut (BigInt)
import Data.BigInt.Argonaut as BigInt
import Data.DateTime.Instant (Instant, instant, unInstant)
import Data.Either (Either(..), fromRight, hush)
import Data.Either (Either(..), hush)
import Data.Foldable as Foldable
import Data.FormURLEncoded.Query (FieldId(..), Query)
import Data.Identity (Identity)
Expand All @@ -47,7 +47,7 @@ import Data.Nullable as Nullable
import Data.String (Pattern(..), split, trim)
import Data.Time.Duration (Milliseconds(..), Seconds(..))
import Data.Traversable (for)
import Data.Tuple (fst, snd)
import Data.Tuple (snd)
import Data.Tuple.Nested (type (/\))
import Data.Validation.Semigroup (V(..))
import Debug (traceM)
Expand All @@ -57,9 +57,8 @@ import Effect.Class (liftEffect)
import Effect.Now (now)
import JS.Unsafe.Stringify (unsafeStringify)
import Language.Marlowe.Core.V1.Semantics.Types as V1
import Marlowe.Runtime.Web.Client (ClientError, uriOpts)
import Marlowe.Runtime.Web.Client (ClientError)
import Marlowe.Runtime.Web.Types (ContractEndpoint, PostContractsError, RoleTokenConfig(..), RolesConfig(..), Tags(..))
import Parsing as Parsing
import Partial.Unsafe (unsafeCrashWith)
import Polyform.Validator (liftFn)
import Polyform.Validator (liftFnEither, liftFnMMaybe) as Validator
Expand All @@ -80,18 +79,9 @@ import Web.File.FileList (FileList)
import Web.File.FileList as FileList
import Web.HTML.HTMLInputElement (HTMLInputElement)
import Web.HTML.HTMLInputElement as HTMLInputElement
import URI (RelativeRef(..), URI(..)) as URI
import URI.Extra.QueryPairs (QueryPairs(..), keyFromString, keyToString, valueFromString, valueToString) as URI
import URI.Extra.QueryPairs as URI.QueryPairs
import URI.HostPortPair (HostPortPair) as URI
import URI.HostPortPair as HostPortPair
import URI.URIRef (Fragment, HierPath, Host, Path, Port, RelPath, URIRefOptions, UserInfo) as URI
import URI.URIRef as URIRef
import Web.HTML (window)
import Web.HTML.Location as Location
import Web.HTML.Window as Window

newtype ContractJsonString = ContractJsonString String

derive instance Eq ContractJsonString
derive instance Newtype ContractJsonString _

Expand Down Expand Up @@ -165,11 +155,11 @@ mkContractFormSpec (possibleInitialContract /\ (AutoRun initialAutoRun)) = FormS
}

autoRun <- map AutoRun $ labelSubform autoRunFieldId $ booleanField
{ label: DOOM.text "Auto run"
, helpText: DOOM.text "Whether to run the contract creation process automatically"
, initial: initialAutoRun
, name: autoRunFieldId
}
{ label: DOOM.text "Auto run"
, helpText: DOOM.text "Whether to run the contract creation process automatically"
, initial: initialAutoRun
, name: autoRunFieldId
}
in
contract /\ tags /\ autoRun

Expand Down Expand Up @@ -369,26 +359,27 @@ mkComponent = do
Foldable.lookup fieldId fields

formBody = DOM.div { className: "form-group" }
[ DOM.div { className: "row mb-2" } $
DOM.div { className: "col-12 text-end" } $ do
let inputId = "contract-file-upload"
[ DOM.label { htmlFor: inputId, className: "btn btn-primary" }
[ R.text "Upload JSON" ]
, loadFileHiddenInputComponent
{ onFileload: case _ of
Just str -> do
let
allFields = formState.fields
void $ for (Map.lookup contractFieldId allFields) \{ onChange } -> do
let
str' = formatPossibleJSON str
onChange [str']

Nothing -> traceM "No file"
, id: inputId
, accept: "application/json"
}
]
[ DOM.div { className: "row mb-2" }
$ DOM.div { className: "col-12 text-end" }
$ do
let inputId = "contract-file-upload"
[ DOM.label { htmlFor: inputId, className: "btn btn-primary" }
[ R.text "Upload JSON" ]
, loadFileHiddenInputComponent
{ onFileload: case _ of
Just str -> do
let
allFields = formState.fields
void $ for (Map.lookup contractFieldId allFields) \{ onChange } -> do
let
str' = formatPossibleJSON str
onChange [ str' ]

Nothing -> traceM "No file"
, id: inputId
, accept: "application/json"
}
]
, lookupSubform contractFieldId
, lookupSubform tagFieldId
, lookupSubform autoRunFieldId
Expand Down
5 changes: 2 additions & 3 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ main configJson = do
let
-- FIXME: Slotting numbers have to be provided by Marlowe Runtime
slotting = case networkId of
Mainnet -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1591566291000" }
_ -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1666656000000" }

Mainnet -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1591566291000" }
_ -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1666656000000" }

CardanoMultiplatformLib.importLib >>= case _ of
Nothing -> liftEffect $ logger "Cardano serialization lib loading failed"
Expand Down

0 comments on commit 0859b77

Please sign in to comment.