summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 9c8d552..644b2d3 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -60,13 +60,14 @@ data CurrentConversation
initGlobalState :: IO GlobalState
initGlobalState = do
globalStorage <- memoryStorage
- identity <- createIdentity globalStorage Nothing Nothing
- globalHead <- storeHead globalStorage $ LocalState
- { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] }
- peerListVar <- newMVar []
- currentConversationVar <- newMVar NoCurrentConversation
- conversationsVar <- newMVar []
- return GlobalState {..}
+ (either (fail . showErebosError) return =<<) $ runExceptT $ flip runReaderT globalStorage $ do
+ identity <- createIdentity Nothing Nothing
+ globalHead <- storeHead globalStorage $ LocalState
+ { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] }
+ peerListVar <- liftIO $ newMVar []
+ currentConversationVar <- liftIO $ newMVar NoCurrentConversation
+ conversationsVar <- liftIO $ newMVar []
+ return GlobalState {..}
foreign export javascript setup :: IO ()
setup :: IO ()
@@ -112,16 +113,15 @@ setup = do
watchConversations gs
let devName = T.pack "WebApp"
- let st = globalStorage
- owner <- createIdentity st Nothing Nothing
- identity <- createIdentity st (Just devName) (Just owner)
-
- shared <- wrappedStore st $ SharedState
- { ssPrev = []
- , ssType = Just $ sharedTypeID @(Maybe ComposedIdentity) Proxy
- , ssValue = [ storedRef $ idExtData owner ]
- }
- flip runReaderT globalHead $ do
+ (either (fail . showErebosError) return =<<) $ runExceptT $ flip runReaderT globalHead $ do
+ owner <- createIdentity Nothing Nothing
+ identity <- createIdentity (Just devName) (Just owner)
+
+ shared <- mstore SharedState
+ { ssPrev = []
+ , ssType = Just $ sharedTypeID @(Maybe ComposedIdentity) Proxy
+ , ssValue = [ storedRef $ idExtData owner ]
+ }
updateLocalState_ $ \_ -> do
mstore $ LocalState
{ lsPrev = Nothing