Skip to content

Commit 2373a5f

Browse files
authored
Merge pull request #25 from juspay/examples-V0.12
Examples v0.12
2 parents c30e323 + fc43826 commit 2373a5f

18 files changed

Lines changed: 3491 additions & 2344 deletions

File tree

examples/billpay-presto-ui/bower.json

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
1313
"tests"
1414
],
1515
"dependencies": {
16-
"purescript-prelude": "^3.0.0",
17-
"purescript-console": "^3.0.0",
18-
"purescript-aff": "^4.1.1",
19-
"purescript-transformers": "^3.2.0",
20-
"purescript-arrays": "^4.0.1",
21-
"purescript-foreign-generic": "^5.0.0",
22-
"purescript-free": "^4.1.0",
23-
"purescript-presto": "^0.3.0",
24-
"purescript-monad-loops": "^0.4.0",
25-
"purescript-folds": "^3.1.0",
26-
"purescript-newtype": "^2.0.0",
27-
"purescript-records": "^1.0.0"
16+
"purescript-prelude": "^4.0.0",
17+
"purescript-console": "^4.1.0",
18+
"purescript-aff": "^5.0.2",
19+
"purescript-transformers": "^4.1.0",
20+
"purescript-arrays": "^5.0.0",
21+
"purescript-foreign-generic": "^7.0.0",
22+
"purescript-free": "^5.1.0",
23+
"purescript-presto": "^0.4.0",
24+
"purescript-folds": "^4.0.0",
25+
"purescript-newtype": "^3.0.0"
2826
},
2927
"devDependencies": {
30-
"purescript-psci-support": "^3.0.0"
28+
"purescript-psci-support": "^4.0.0"
3129
},
3230
"version":"0.1"
3331
}

examples/billpay-presto-ui/src/Core.purs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@ module Core where
22

33
import Prelude
44

5-
import Control.Monad.Aff (launchAff_, makeAff, nonCanceler)
6-
import Control.Monad.Aff.AVar (makeVar)
7-
import Control.Monad.Eff (Eff)
5+
import Effect.Aff (launchAff_, makeAff, nonCanceler)
6+
import Effect.Aff.AVar (new)
7+
import Effect (Effect)
88
import Control.Monad.Except.Trans (runExceptT)
99
import Control.Monad.State.Trans as S
1010
import Data.Either (Either(..))
1111
import Data.Function.Uncurried (runFn2)
12-
import Data.StrMap (empty)
12+
import Foreign.Object (empty)
1313
import Engineering.Helpers.Commons (callAPI', mkNativeRequest, showUI')
1414
import Engineering.OS.Permission (checkIfPermissionsGranted, requestPermissions)
15-
import Engineering.Types.App (AppEffects)
1615
import Presto.Core.Flow (APIRunner, Flow, PermissionCheckRunner, PermissionRunner(..), PermissionTakeRunner, Runtime(..), UIRunner, run, forkUI)
1716
import Product.BillPay (billPayFlow)
1817
import UI.Types (InitScreen(..))
1918

20-
main :: Eff (AppEffects) Unit
19+
main :: Effect Unit
2120
main = do
2221
let runtime = Runtime uiRunner permissionRunner apiRunner
2322
let freeFlow = S.evalStateT (run runtime appFlow)
24-
launchAff_ (makeVar empty >>= freeFlow)
23+
launchAff_ (new empty >>= freeFlow)
2524
where
2625
uiRunner :: UIRunner
2726
uiRunner a = makeAff (\callback -> runFn2 showUI' (Right >>> callback) a *> pure nonCanceler)
@@ -52,4 +51,4 @@ initializeUI = forkUI InitScreen *> pure unit
5251
appFlow :: Flow Unit
5352
appFlow = do
5453
initializeUI
55-
mainFlow
54+
mainFlow

examples/billpay-presto-ui/src/Engineering/Helpers/Commons.purs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@ module Engineering.Helpers.Commons where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Exception (Error)
5+
import Effect (Effect)
6+
import Effect.Exception (Error)
77
import Control.Monad.Except.Trans (ExceptT(..))
88
import Data.Either (Either(..))
99
import Data.Function.Uncurried (Fn2)
1010
import Engineering.Types.App as App
1111
import Presto.Core.Flow (runUI)
1212
import Presto.Core.Types.API (Header(..), Headers(..), Request(..), URL)
13-
import Presto.Core.Types.App (UI)
1413
import Presto.Core.Types.Language.Interaction (class Interact)
1514

16-
foreign import showUI' :: forall e. Fn2 (String -> Eff (ui :: UI | e) Unit) String (Eff (ui :: UI | e) Unit)
17-
foreign import callAPI' :: forall e. (AffError e) -> (AffSuccess String e) -> NativeRequest -> (Eff e Unit)
15+
foreign import showUI' :: Fn2 (String -> Effect Unit) String (Effect Unit)
16+
foreign import callAPI' :: AffError -> AffSuccess String -> NativeRequest -> (Effect Unit)
1817

1918
type NativeHeader = { field :: String , value :: String}
2019
type NativeHeaders = Array NativeHeader
21-
type AffError e = (Error -> Eff e Unit)
22-
type AffSuccess s e = (s -> Eff e Unit)
20+
type AffError = (Error -> Effect Unit)
21+
type AffSuccess s = (s -> Effect Unit)
2322

2423

2524
newtype NativeRequest = NativeRequest

examples/billpay-presto-ui/src/Engineering/OS/Permission.purs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@ module Engineering.OS.Permission where
22

33
import Prelude
44

5-
import Control.Monad.Aff (Aff, makeAff, nonCanceler)
6-
import Control.Monad.Eff (Eff)
7-
import Control.Monad.Eff.Exception (Error, error)
85
import Control.Monad.Except (runExcept, throwError)
9-
import Control.Monad.Loops (allM)
10-
import Data.Array (zip)
6+
import Data.Array (zip, foldl)
117
import Data.Either (Either(..))
128
import Data.Foldable (all)
13-
import Data.Foreign.Generic (decodeJSON)
149
import Data.Function.Uncurried (Fn3, runFn3)
1510
import Data.List (fromFoldable)
11+
import Data.Traversable (sequence)
1612
import Data.Tuple (Tuple(..))
17-
import Presto.Core.Types.App (STORAGE)
13+
import Effect (Effect)
14+
import Effect.Aff (Aff, makeAff, nonCanceler)
15+
import Effect.Exception (Error, error)
16+
import Foreign.Generic (decodeJSON)
1817
import Presto.Core.Types.Language.Flow (Flow, checkPermissions, takePermissions)
1918
import Presto.Core.Types.Permission (Permission(..), PermissionResponse, PermissionStatus(..))
2019

21-
foreign import getPermissionStatus' :: forall e. Fn3 (Error -> EffStorage e Unit) (String -> EffStorage e Unit) String (EffStorage e Unit)
22-
foreign import requestPermission' :: forall e. Fn3 (Error -> EffStorage e Unit) (String -> EffStorage e Unit) String (EffStorage e Unit)
20+
foreign import getPermissionStatus' :: Fn3 (Error -> EffStorage Unit) (String -> EffStorage Unit) String (EffStorage Unit)
21+
foreign import requestPermission' :: Fn3 (Error -> EffStorage Unit) (String -> EffStorage Unit) String (EffStorage Unit)
2322

24-
type EffStorage e = Eff (storage :: STORAGE | e)
25-
type AffStorage e = Aff (storage :: STORAGE | e)
23+
type EffStorage = Effect
24+
type AffStorage = Aff
2625

2726
toAndroidPermission :: Permission -> String
2827
toAndroidPermission PermissionSendSms = "android.permission.READ_SMS"
@@ -57,7 +56,7 @@ storagePermissionGranted = do
5756
PermissionGranted -> pure true
5857
_ -> pure false
5958

60-
getPermissionStatus :: forall e. Permission -> AffStorage e Boolean
59+
getPermissionStatus :: Permission -> AffStorage Boolean
6160
getPermissionStatus permission = do
6261
permissionStr <- makeAff (\callback -> do
6362
runFn3 getPermissionStatus' (Left >>> callback) (Right >>> callback) (toAndroidPermission permission)
@@ -66,14 +65,15 @@ getPermissionStatus permission = do
6665
Right x -> pure x
6766
Left err -> throwError (error (show err))
6867

69-
checkIfPermissionsGranted :: forall e. Array Permission -> AffStorage e PermissionStatus
68+
checkIfPermissionsGranted :: Array Permission -> AffStorage PermissionStatus
7069
checkIfPermissionsGranted permissions = do
71-
check <- allM getPermissionStatus $ fromFoldable permissions
72-
pure $ if check
70+
pStatus <- sequence $ getPermissionStatus <$> permissions
71+
let res = foldl (\acc x -> if acc == false then false else x) true pStatus
72+
pure $ if res
7373
then PermissionGranted
7474
else PermissionDeclined
7575

76-
requestPermissions :: forall e. Array Permission -> AffStorage e (Array PermissionResponse)
76+
requestPermissions :: Array Permission -> AffStorage (Array PermissionResponse)
7777
requestPermissions permissions = do
7878
response <- makeAff (\callback -> do
7979
runFn3 requestPermission' (Left >>> callback) (Right >>> callback) $ show jPermission
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
module Engineering.Types.App where
22

3-
import Control.Monad.Aff.AVar (AVAR)
4-
import Control.Monad.Eff (kind Effect)
5-
import Control.Monad.Eff.Console (CONSOLE)
6-
import Control.Monad.Eff.Exception (EXCEPTION)
73
import Control.Monad.Except.Trans (ExceptT(..))
84
import Control.Monad.Free (Free)
95
import Data.Either (Either(..))
106
import Prelude (pure, (<$>))
11-
import Presto.Core.Types.App (LOCAL_STORAGE, NETWORK, STORAGE, UI)
127
import Presto.Core.Types.Language.Flow (FlowWrapper)
138

14-
foreign import data TIMER :: Effect
15-
16-
type AppEffects = (
17-
avar :: AVAR
18-
, exception :: EXCEPTION
19-
, exception :: EXCEPTION
20-
, ui :: UI
21-
, storage :: STORAGE
22-
, ls :: LOCAL_STORAGE
23-
, console :: CONSOLE
24-
, network :: NETWORK
25-
, timer :: TIMER)
26-
279
type Flow e a = (ExceptT e (Free FlowWrapper) a)
28-
2910

3011
liftLeft :: forall e b. e -> Flow e b
3112
liftLeft e = ExceptT (Left <$> pure e)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
module Product.Types where
22

3-
import Data.Foreign.Class (class Encode)
4-
import Data.Foreign.Generic (defaultOptions, genericEncode)
3+
import Foreign.Class (class Encode)
4+
import Foreign.Generic (defaultOptions, genericEncode)
55
import Data.Generic.Rep (class Generic)
66

77
type MobileNumber = String
88
type Amount = Number
99
type Operator = String
1010

1111
data BillPayStatus = SUCCESS | FAILURE
12-
data BillPayFailure = FetchOperatorFailure String
13-
| BillPaymentFailure String
14-
| UserAbort
15-
12+
data BillPayFailure = FetchOperatorFailure String
13+
| BillPaymentFailure String
14+
| UserAbort
15+
1616
derive instance genericBillPayStatus :: Generic BillPayStatus _
1717
instance encodeBillPayStatus :: Encode BillPayStatus where
18-
encode = genericEncode (defaultOptions { unwrapSingleConstructors = false })
18+
encode = genericEncode (defaultOptions { unwrapSingleConstructors = false })

examples/billpay-presto-ui/src/UI/Types.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
module UI.Types where
33

4-
import Control.Monad.Eff.Exception (Error)
5-
import Data.Foreign.Class (class Decode, class Encode)
6-
import Data.Foreign.Generic (defaultOptions, genericDecode, genericEncode)
4+
import Effect.Exception (Error)
5+
import Foreign.Class (class Decode, class Encode)
6+
import Foreign.Generic (defaultOptions, genericDecode, genericEncode)
77
import Data.Generic.Rep (class Generic)
88
import Presto.Core.Flow (class Interact, defaultInteract)
99
import Product.Types (Operator,MobileNumber,Amount,BillPayStatus)

examples/billpay-react/bower.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
"output"
88
],
99
"dependencies": {
10-
"purescript-prelude": "^3.0.0",
11-
"purescript-console": "^3.0.0",
12-
"purescript-aff": "^4.1.1",
13-
"purescript-transformers": "^3.2.0",
14-
"purescript-arrays": "^4.0.1",
15-
"purescript-foreign-generic": "^5.0.0",
16-
"purescript-free": "^4.1.0",
17-
"purescript-presto": "^0.3.0",
18-
"purescript-monad-loops": "^0.4.0",
19-
"purescript-folds": "^3.1.0",
20-
"purescript-newtype": "^2.0.0"
10+
"purescript-prelude": "^4.0.0",
11+
"purescript-console": "^4.1.0",
12+
"purescript-aff": "^5.0.2",
13+
"purescript-transformers": "^4.1.0",
14+
"purescript-arrays": "^5.0.0",
15+
"purescript-foreign-generic": "^7.0.0",
16+
"purescript-free": "^5.1.0",
17+
"purescript-presto": "^0.4.0",
18+
"purescript-folds": "^4.0.0",
19+
"purescript-newtype": "^3.0.0"
2120
},
2221
"devDependencies": {
23-
"purescript-psci-support": "^3.0.0"
22+
"purescript-psci-support": "^4.0.0"
2423
}
2524
}

examples/billpay-react/src/Core.purs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@ module Core where
22

33
import Prelude
44

5-
import Control.Monad.Aff (Aff, launchAff_, makeAff, nonCanceler)
6-
import Control.Monad.Aff.AVar (makeVar)
7-
import Control.Monad.Eff (Eff)
5+
import Effect.Aff (Aff, launchAff_, makeAff, nonCanceler)
6+
import Effect.Aff.AVar (new)
7+
import Effect (Effect)
88
import Control.Monad.Except.Trans (runExceptT)
99
import Control.Monad.State.Trans as S
1010
import Data.Either (Either(..))
1111
import Data.Function.Uncurried (runFn2)
12-
import Data.StrMap (empty)
12+
import Foreign.Object (empty)
1313
import Engineering.Helpers.Commons (callAPI', mkNativeRequest, showUI')
14-
import Engineering.Types.App (AppEffects)
1514
import Presto.Core.Flow (APIRunner, Flow, PermissionRunner(..), Runtime(..), UIRunner, run)
16-
import Presto.Core.Types.App (STORAGE)
1715
import Presto.Core.Types.Permission (Permission, PermissionResponse, PermissionStatus(..))
1816
import Product.BillPay (billPayFlow)
1917

20-
launchApp :: Eff (AppEffects) Unit
18+
launchApp :: Effect Unit
2119
launchApp = do
2220
let runtime = Runtime uiRunner permissionRunner apiRunner
2321
let freeFlow = S.evalStateT (run runtime mainFlow)
24-
launchAff_ (makeVar empty >>= freeFlow)
22+
launchAff_ (new empty >>= freeFlow)
2523
where
2624
uiRunner :: UIRunner
2725
uiRunner a = makeAff (\callback -> runFn2 showUI' (Right >>> callback) a *> pure nonCanceler)
@@ -40,8 +38,8 @@ mainFlow = do
4038
Right a -> pure unit
4139
Left a -> mainFlow
4240

43-
defaultPermissionStatus :: forall e. Array Permission -> Aff (storage :: STORAGE | e) PermissionStatus
41+
defaultPermissionStatus :: Array Permission -> Aff PermissionStatus
4442
defaultPermissionStatus permissions = makeAff (\callback -> (Right >>> callback) PermissionGranted *> pure nonCanceler)
4543

46-
defaultPermissionRequest :: forall e. Array Permission -> Aff (storage :: STORAGE | e) (Array PermissionResponse)
44+
defaultPermissionRequest :: Array Permission -> Aff (Array PermissionResponse)
4745
defaultPermissionRequest permissions = makeAff (\callback -> (Right >>> callback) [] *> pure nonCanceler)

examples/billpay-react/src/Engineering/Helpers/Commons.purs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@ module Engineering.Helpers.Commons where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Exception (Error)
5+
import Effect (Effect)
6+
import Effect.Exception (Error)
77
import Control.Monad.Except.Trans (ExceptT(..))
88
import Data.Either (Either(..))
99
import Data.Function.Uncurried (Fn2)
1010
import Engineering.Types.App as App
1111
import Presto.Core.Flow (runUI)
1212
import Presto.Core.Types.API (Header(..), Headers(..), Request(..), URL)
13-
import Presto.Core.Types.App (UI)
1413
import Presto.Core.Types.Language.Interaction (class Interact)
1514

16-
foreign import showUI' :: forall e. Fn2 (String -> Eff (ui :: UI | e) Unit) String (Eff (ui :: UI | e) Unit)
17-
foreign import callAPI' :: forall e. (AffError e) -> (AffSuccess String e) -> NativeRequest -> (Eff e Unit)
15+
foreign import showUI' :: Fn2 (String -> Effect Unit) String (Effect Unit)
16+
foreign import callAPI' :: AffError -> (AffSuccess String) -> NativeRequest -> (Effect Unit)
1817

1918
type NativeHeader = { field :: String , value :: String}
2019
type NativeHeaders = Array NativeHeader
21-
type AffError e = (Error -> Eff e Unit)
22-
type AffSuccess s e = (s -> Eff e Unit)
20+
type AffError = (Error -> Effect Unit)
21+
type AffSuccess s = (s -> Effect Unit)
2322

2423

2524
newtype NativeRequest = NativeRequest

0 commit comments

Comments
 (0)