mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-16 10:58:10 +00:00
* store: limit each BTCPay and Stripe call to 10 seconds * store: limit checkouts per provider and per client network * store: skip a timed-out provider for the rest of a poller pass * store: cancel a BTCPay invoice whose address cannot be read * store: take a checkout's network and provider tokens together * store: share the stall switch of the fake providers in tests * store: drop provider timeout checks that cannot fail * store: rename a test binding shadowing an import * store: keep a pass's reads after a timed-out provider list * store: log a failed checkout at the provider in true terms * store: document the host-name lookup outside the provider bound * store: test a created BTCPay invoice whose cancel fails --------- Co-authored-by: sh-agents <350651734+sh-agents@users.noreply.github.com>
31 lines
1018 B
Haskell
31 lines
1018 B
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Bots.StoreService.FakeHttp
|
|
( setSwitch,
|
|
stalledAnswer,
|
|
)
|
|
where
|
|
|
|
import Control.Concurrent (threadDelay)
|
|
import Control.Concurrent.STM (TVar, atomically, modifyTVar')
|
|
import Control.Monad (forever)
|
|
import qualified Data.Aeson as J
|
|
import qualified Data.Aeson.KeyMap as KM
|
|
import Data.ByteString.Builder (byteString)
|
|
import Data.Text (Text)
|
|
import Network.HTTP.Types (hContentType, ok200)
|
|
import Network.Wai (Response, responseStream)
|
|
|
|
setSwitch :: TVar s -> Text -> (Bool -> s -> s) -> J.Object -> IO (Maybe Text)
|
|
setSwitch state path set o = case KM.toList o of
|
|
[("on", J.Bool on)] -> Nothing <$ atomically (modifyTVar' state (set on))
|
|
_ -> pure (Just (path <> " takes {\"on\": <bool>}"))
|
|
|
|
stalledAnswer :: Response
|
|
stalledAnswer = responseStream ok200 [(hContentType, "application/json")] $ \write flush -> do
|
|
write (byteString "[") >> flush
|
|
forever $ threadDelay trickleMicros >> write (byteString " ") >> flush
|
|
|
|
trickleMicros :: Int
|
|
trickleMicros = 100000
|