module Network.MtGoxAPI.WalletNotifier
( initWalletNotifier
, updateWalletNotifier
, waitForBTCDeposit
, WalletNotifierHandle
) where
import Control.Applicative
import Control.Concurrent
import Control.Monad
import Network.MtGoxAPI.Types
newtype WalletNotifierHandle = WalletNotifierHandle { unWNH :: MVar () }
initWalletNotifier :: IO WalletNotifierHandle
initWalletNotifier = WalletNotifierHandle <$> newEmptyMVar
updateWalletNotifier :: WalletNotifierHandle -> StreamMessage -> IO ()
updateWalletNotifier handle (wo@WalletOperation {}) =
case woType wo of
BTCDeposit -> void $ tryPutMVar (unWNH handle) ()
_ -> return ()
updateWalletNotifier _ _ = return ()
waitForBTCDeposit :: WalletNotifierHandle -> IO ()
waitForBTCDeposit handle = void $ takeMVar (unWNH handle)