Skip to content

Commit

Permalink
Format JSON uploaded from the file
Browse files Browse the repository at this point in the history
  • Loading branch information
paluh committed Sep 15, 2023
1 parent 343ee3f commit 0ae21ab
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/Component/CreateContract.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import Component.MarloweYaml (marloweYaml)
import Component.Types (MkComponentM, WalletInfo)
import Component.Widgets (link, spinner)
import Contrib.Polyform.Batteries.UrlEncoded (requiredV')
import Contrib.Polyform.FormSpecBuilder (FormSpecBuilderT(..))
import Contrib.Polyform.FormSpecBuilder (FormSpecBuilderT)
import Contrib.Polyform.FormSpecBuilder as FormSpecBuilder
import Contrib.Polyform.FormSpecBuilder as StatelessFormSpecBuilder
import Contrib.Polyform.FormSpecs.StatelessFormSpec (StatelessFormSpec, mapRender)
import Contrib.Polyform.FormSpecs.StatelessFormSpec (StatelessFormSpec)
import Contrib.Polyform.FormSpecs.StatelessFormSpec as StatelessFormSpec
import Contrib.Polyform.FormSpecs.StatelessFormSpec as StatlessFormSpec
import Contrib.React.Basic.Hooks.UseMooreMachine (useMooreMachine)
Expand All @@ -25,14 +25,14 @@ import Control.Monad.Maybe.Trans (MaybeT(..), runMaybeT)
import Control.Monad.Reader.Class (asks)
import Control.Promise (Promise)
import Control.Promise as Promise
import Data.Argonaut (decodeJson, encodeJson, parseJson, stringifyWithIndent)
import Data.Argonaut (decodeJson, encodeJson, jsonParser, parseJson, stringifyWithIndent)
import Data.Array as Array
import Data.Array.NonEmpty (NonEmptyArray)
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(..))
import Data.Either (Either(..), hush)
import Data.Foldable as Foldable
import Data.FormURLEncoded.Query (FieldId(..), Query)
import Data.Identity (Identity)
Expand All @@ -57,13 +57,13 @@ import Effect.Now (now)
import JS.Unsafe.Stringify (unsafeStringify)
import Language.Marlowe.Core.V1.Semantics.Types as V1
import Marlowe.Runtime.Web.Client (ClientError)
import Marlowe.Runtime.Web.Types (ContractEndpoint, Metadata(..), PostContractsError, RoleTokenConfig(..), RolesConfig(..), Tags(..))
import Marlowe.Runtime.Web.Types (ContractEndpoint, PostContractsError, RoleTokenConfig(..), RolesConfig(..), Tags(..))
import Partial.Unsafe (unsafeCrashWith)
import Polyform.Validator (liftFn)
import Polyform.Validator (liftFnEither, liftFnMMaybe) as Validator
import React.Basic (fragment) as DOOM
import React.Basic.DOM (css)
import React.Basic.DOM as DOOM
import React.Basic.DOM (div, div_, input, text) as DOOM
import React.Basic.DOM as R
import React.Basic.DOM.Simplified.Generated as DOM
import React.Basic.Events (handler_)
Expand Down Expand Up @@ -111,7 +111,7 @@ mkContractFormSpec (possibleInitialContract /\ (AutoRun initialAutoRun)) = FormS
-> FormSpecBuilderT Identity (LabeledFormSpec Effect) Query a
labelSubform name formSpecBuilder = do
let
label :: forall err i o m. StatelessFormSpec m (Array JSX) err i ~> StatelessFormSpec m (Array (FieldId /\ JSX)) err i
label :: forall err i m. StatelessFormSpec m (Array JSX) err i ~> StatelessFormSpec m (Array (FieldId /\ JSX)) err i
label = StatlessFormSpec.mapRender $ map \subformJSX ->
name /\ subformJSX
StatelessFormSpecBuilder.hoistFormSpec label formSpecBuilder
Expand Down Expand Up @@ -147,17 +147,7 @@ mkContractFormSpec (possibleInitialContract /\ (AutoRun initialAutoRun)) = FormS
, name: Just tagFieldId
}

autoRun <- -- AutoRun <$>
-- FIXME: This should be documented I left this as an example of more hard core lifting of validator
-- let
-- toAutoRun = liftBuilderM $ pure $ liftValidator $ liftFnM \value -> do
-- let
-- value' = AutoRun value
-- -- onAutoRunChange value'
-- pure value'

-- FormSpecBuilderT builderM (StatelessBootstrapFormSpec validatorM) Query Boolean
map AutoRun $ labelSubform autoRunFieldId $ booleanField
autoRun <- map AutoRun $ labelSubform autoRunFieldId $ booleanField
{ label: DOOM.text "Auto run"
, helpText: DOOM.text "Whether to run the contract creation process automatically"
, initial: initialAutoRun
Expand Down Expand Up @@ -371,7 +361,11 @@ mkComponent = do
let
allFields = formState.fields
void $ for (Map.lookup contractFieldId allFields) \{ onChange } -> do
onChange [str]
let
str' = fromMaybe str do
json <- hush $ jsonParser str
pure $ stringifyWithIndent 2 $ encodeJson json
onChange [str']

Nothing -> traceM "No file"
, id: inputId
Expand Down

0 comments on commit 0ae21ab

Please sign in to comment.