Skip to content

Commit

Permalink
change get winner method
Browse files Browse the repository at this point in the history
  • Loading branch information
volodyaeleks committed Sep 23, 2021
1 parent 8fc84ad commit 97bfec0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion eleks/oracle/src/Contracts/MutualBet/StateMachine.hs
Expand Up @@ -29,7 +29,6 @@ import Data.Bool (bool)
import Data.Aeson (FromJSON, ToJSON)
import Data.Default (Default (def))
import Data.Either (fromRight)
import Data.Maybe (fromJust)
import Data.Monoid (Last (..))
import Data.Text (Text, pack)
import Data.Semigroup.Generic (GenericSemigroupMonoid (..))
Expand Down
20 changes: 9 additions & 11 deletions eleks/oracle/src/Types/Game.hs
Expand Up @@ -103,15 +103,13 @@ instance ToJSON Game where
instance Eq Game where
a == b = (a ^. fixture . fixtureId == b ^. fixture . fixtureId)

getWinnerTeamId :: Either String Game -> Maybe Integer
getWinnerTeamId :: Either String Game -> Either String Integer
getWinnerTeamId gameE = case gameE of
Left _ -> Nothing
Right game -> do
if ( (game ^. fixture . status . short) == FT)
then do
let team1 = game ^. teams . home
let team2 = game ^. teams . away
if (team1 ^. winner)
then return (team1 ^. teamId )
else return (team2 ^. teamId)
else Nothing
Right game | game ^. fixture . status . short /= FT -> Left "Game not finished"
Right game | game ^. fixture . status . short == FT -> do
let team1 = game ^. teams . home
let team2 = game ^. teams . away
if (team1 ^. winner)
then Right (team1 ^. teamId )
else Right (team2 ^. teamId)
Left e -> Left e

0 comments on commit 97bfec0

Please sign in to comment.