@@ -14,7 +14,7 @@ import CompoundComponents.Eth.Ethereum as Ethereum exposing (Account(..), AssetA
1414import CompoundComponents.Eth.Ledger exposing (LedgerAccount (..) )
1515import CompoundComponents.Eth.Network as Network exposing (Network (..) , networkId )
1616import CompoundComponents.Ether.BNTransaction as BNTransaction exposing (BNTransactionMsg )
17- import CompoundComponents.Functions exposing (handleError )
17+ import CompoundComponents.Functions as Functions exposing (handleError )
1818import CompoundComponents.Utils.CompoundHtmlAttributes exposing (HrefLinkType (..) , class , href , id , target )
1919import CompoundComponents.Utils.Time
2020import DappInterface.ClaimCompModal as ClaimCompModal
@@ -41,7 +41,7 @@ import Http
4141import Json.Decode
4242import Json.Encode
4343import Liquidate
44- import Port exposing (askNetwork , askNewBlock , giveAccountBalance , giveError , giveNewBlock , setGasPrice , setTitle )
44+ import Port exposing (askNetwork , askNewBlock , askNewBlockAsync , giveAccountBalance , giveError , giveNewBlock , setGasPrice , setTitle )
4545import Preferences exposing (PreferencesMsg (..) , preferencesInit , preferencesSubscriptions , preferencesUpdate )
4646import Repl
4747import Strings.Translations as Translations
@@ -274,6 +274,7 @@ init { path, configurations, configAbiFiles, dataProviders, apiBaseUrlMap, userA
274274 , governanceState = Eth . Governance . init
275275 , errors = []
276276 , currentTime = Nothing
277+ , lastNewBlockTime = Nothing
277278 , currentTimeZone = Time . utc
278279 , browserType = browserType
279280 , proposeModel = Propose . emptyState
@@ -747,14 +748,48 @@ update msg ({ page, configs, apiBaseUrlMap, account, transactionState, bnTransac
747748
748749 updateCompoundState =
749750 Eth . Compound . handleAccountLiquidityCalculation oracleState compoundState
751+
752+ canCheckForPendingTrxs =
753+ let
754+ pendingTransactions =
755+ Transaction . getAllPendingTransactions model. network model. transactionState. transactions
756+ in
757+ if List . isEmpty pendingTransactions then
758+ Nothing
759+
760+ else
761+ Just True
762+
763+ -- The new block checker in ports now checks every 1 minute
764+ -- but if we have pending transactions, then lets continue
765+ -- to trigger an async block check every 20 seconds.
766+ ( lastNewBlockTimestamp, askNewBlockAsyncCmd ) =
767+ Functions . map3
768+ canCheckForPendingTrxs
769+ model. blockNumber
770+ model. lastNewBlockTime
771+ ( \ _ currentBlockNumber actualLastNewBlockTime ->
772+ if Time . posixToMillis actualLastNewBlockTime + 20000 > Time . posixToMillis time then
773+ ( Just time
774+ , askNewBlockAsync currentBlockNumber
775+ )
776+
777+ else
778+ ( model. lastNewBlockTime, Cmd . none )
779+ )
780+ |> Maybe . withDefault ( model. lastNewBlockTime, Cmd . none )
750781 in
751782 ( { model
752783 | currentTime = Just time
784+ , lastNewBlockTime = lastNewBlockTimestamp
753785 , borrowingContainerState = updatedBorrowingContainerState
754786 , voteModel = updatedVoteModel
755787 , compoundState = updateCompoundState
756788 }
757- , Cmd . map voteTranslator loadDelegateeCmd
789+ , Cmd . batch
790+ [ Cmd . map voteTranslator loadDelegateeCmd
791+ , askNewBlockAsyncCmd
792+ ]
758793 )
759794
760795 CheckVersion time ->
@@ -786,7 +821,12 @@ update msg ({ page, configs, apiBaseUrlMap, account, transactionState, bnTransac
786821 ( model, Cmd . none )
787822
788823 SetBlockNumber blockNumber ->
789- ( { model | blockNumber = Just blockNumber }, newBlockCmd apiBaseUrlMap model. network blockNumber model. blockNumber model )
824+ ( { model
825+ | blockNumber = Just blockNumber
826+ , lastNewBlockTime = model. currentTime
827+ }
828+ , newBlockCmd apiBaseUrlMap model. network blockNumber model. blockNumber model
829+ )
790830
791831 WrappedTransactionMsg transactionMsg ->
792832 let
0 commit comments