2023-03-15 09:17:25 +00:00
import QtQuick 2.13
2024-03-13 17:38:16 +00:00
import SortFilterProxyModel 0.2
2023-03-15 09:17:25 +00:00
import StatusQ . Core 0.1
2024-01-12 11:22:02 +00:00
import StatusQ . Core . Utils 0.1
2023-03-15 09:17:25 +00:00
import utils 1.0
QtObject {
id: root
readonly property var networkConnectionModuleInst: networkConnectionModule
2023-03-23 10:23:02 +00:00
readonly property bool isOnline: mainModule . isOnline
2023-04-25 16:54:50 +00:00
readonly property bool balanceCache: walletSectionAssets . hasBalanceCache
readonly property bool marketValuesCache: walletSectionAssets . hasMarketValuesCache
2023-03-23 10:23:02 +00:00
2024-09-13 12:19:26 +00:00
readonly property SortFilterProxyModel filteredflatNetworks: SortFilterProxyModel {
2024-03-13 17:38:16 +00:00
sourceModel: networksModule . flatNetworks
filters: ValueFilter { roleName: "isTest" ; value: networksModule . areTestNetworksEnabled }
}
2023-04-25 07:39:42 +00:00
readonly property var blockchainNetworksDown: ! ! networkConnectionModule . blockchainNetworkConnection . chainIds ? networkConnectionModule . blockchainNetworkConnection . chainIds . split ( ";" ) : [ ]
2024-09-16 20:12:02 +00:00
readonly property bool atleastOneBlockchainNetworkAvailable: blockchainNetworksDown . length < filteredflatNetworks . count
2023-03-15 09:17:25 +00:00
2023-03-23 10:23:02 +00:00
readonly property bool sendBuyBridgeEnabled: localAppSettings . testEnvironment || ( isOnline &&
2023-03-15 09:17:25 +00:00
( ! networkConnectionModule . blockchainNetworkConnection . completelyDown && atleastOneBlockchainNetworkAvailable ) &&
! networkConnectionModule . marketValuesNetworkConnection . completelyDown )
2023-04-04 11:31:04 +00:00
readonly property string sendBuyBridgeToolTipText: ! isOnline ? qsTr ( "Requires internet connection" ) :
noBlockchainAndMarketConnectionAndNoCache ?
qsTr ( "Requires POKT/Infura and CryptoCompare/CoinGecko, which are all currently unavailable" ) :
networkConnectionModule . blockchainNetworkConnection . completelyDown ||
( ! networkConnectionModule . blockchainNetworkConnection . completelyDown &&
! atleastOneBlockchainNetworkAvailable ) ?
qsTr ( "Requires Pocket Network(POKT) or Infura, both of which are currently unavailable" ) :
networkConnectionModule . marketValuesNetworkConnection . completelyDown ?
qsTr ( "Requires CryptoCompare or CoinGecko, both of which are currently unavailable" ) : ""
2023-03-15 09:17:25 +00:00
2023-11-22 19:58:02 +00:00
readonly property bool notOnlineWithNoCache: ! isOnline && ! balanceCache && ! marketValuesCache
2023-03-23 10:23:02 +00:00
readonly property string notOnlineWithNoCacheText: qsTr ( "Internet connection lost. Data could not be retrieved." )
2023-11-22 19:58:02 +00:00
readonly property bool noBlockchainConnectionAndNoCache: networkConnectionModule . blockchainNetworkConnection . completelyDown && ! balanceCache
2023-03-23 10:23:02 +00:00
readonly property string noBlockchainConnectionAndNoCacheText: qsTr ( "Token balances are fetched from Pocket Network (POKT) and Infura which are both curently unavailable" )
2023-11-22 19:58:02 +00:00
readonly property bool noMarketConnectionAndNoCache: networkConnectionModule . marketValuesNetworkConnection . completelyDown && ! marketValuesCache
2023-03-23 10:23:02 +00:00
readonly property string noMarketConnectionAndNoCacheText: qsTr ( "Market values are fetched from CryptoCompare and CoinGecko which are both currently unavailable" )
readonly property bool noBlockchainAndMarketConnectionAndNoCache: noBlockchainConnectionAndNoCache && noMarketConnectionAndNoCache
2023-11-22 19:58:02 +00:00
readonly property string noBlockchainAndMarketConnectionAndNoCacheText: qsTr ( "Market values and token balances use CryptoCompare/CoinGecko and POKT/Infura which are all currently unavailable." )
2023-03-23 10:23:02 +00:00
readonly property bool accountBalanceNotAvailable: notOnlineWithNoCache || noBlockchainConnectionAndNoCache || noMarketConnectionAndNoCache
readonly property string accountBalanceNotAvailableText: ! isOnline ? notOnlineWithNoCacheText :
noBlockchainAndMarketConnectionAndNoCache ? noBlockchainAndMarketConnectionAndNoCacheText :
networkConnectionModule . blockchainNetworkConnection . completelyDown ? noBlockchainConnectionAndNoCacheText :
networkConnectionModule . marketValuesNetworkConnection . completelyDown ? noBlockchainAndMarketConnectionAndNoCacheText : ""
2023-11-22 19:58:02 +00:00
readonly property bool noTokenBalanceAvailable: notOnlineWithNoCache || noBlockchainConnectionAndNoCache
2023-04-04 11:31:04 +00:00
2024-01-08 14:47:07 +00:00
readonly property bool ensNetworkAvailable: ! blockchainNetworksDown . includes ( mainModule . appNetworkId . toString ( ) )
2024-03-13 17:38:16 +00:00
readonly property string ensNetworkUnavailableText: qsTr ( "Requires POKT/Infura for %1, which is currently unavailable" ) . arg ( appNetworkName )
2024-01-08 14:47:07 +00:00
readonly property bool stickersNetworkAvailable: ! blockchainNetworksDown . includes ( mainModule . appNetworkId . toString ( ) )
2024-03-13 17:38:16 +00:00
readonly property string stickersNetworkUnavailableText: qsTr ( "Requires POKT/Infura for %1, which is currently unavailable" ) . arg ( appNetworkName )
readonly property string appNetworkName: ModelUtils . getByKey ( networksModule . flatNetworks , "chainId" , mainModule . appNetworkId , "chainName" )
2023-03-15 09:17:25 +00:00
2024-06-14 17:50:52 +00:00
// DEPRECATED, use getBlockchainNetworkDownText instead
2023-03-15 09:17:25 +00:00
function getBlockchainNetworkDownTextForToken ( balances ) {
2023-11-22 19:58:02 +00:00
if ( ! ! balances && ! networkConnectionModule . blockchainNetworkConnection . completelyDown && ! notOnlineWithNoCache ) {
2023-03-15 09:17:25 +00:00
let chainIdsDown = [ ]
for ( var i = 0 ; i < balances . count ; i ++ ) {
2024-01-12 11:22:02 +00:00
let chainId = ModelUtils . get ( i , "chainId" )
2023-03-15 09:17:25 +00:00
if ( blockchainNetworksDown . includes ( chainId ) )
chainIdsDown . push ( chainId )
}
if ( chainIdsDown . length > 0 ) {
return qsTr ( "Pocket Network (POKT) & Infura are currently both unavailable for %1. %1 balances are as of %2." )
. arg ( getChainIdsJointString ( chainIdsDown ) )
. arg ( LocaleUtils . formatDateTime ( new Date ( networkConnectionModule . blockchainNetworkConnection . lastCheckedAt * 1000 ) ) )
}
}
return ""
}
2024-06-14 17:50:52 +00:00
function getBlockchainNetworkDownText ( chains ) {
if ( chains . length === 0
|| networkConnectionModule . blockchainNetworkConnection . completelyDown
|| notOnlineWithNoCache )
return ""
let chainIdsDown = [ ]
for ( let i = 0 ; i < chains . length ; i ++ ) {
const chainId = chains [ i ]
if ( blockchainNetworksDown . includes ( chainId ) )
chainIdsDown . push ( chainId )
}
if ( chainIdsDown . length > 0 ) {
return qsTr ( "Pocket Network (POKT) & Infura are currently both unavailable for %1. %1 balances are as of %2." )
. arg ( getChainIdsJointString ( chainIdsDown ) )
. arg ( LocaleUtils . formatDateTime ( new Date ( networkConnectionModule . blockchainNetworkConnection . lastCheckedAt * 1000 ) ) )
}
return ""
}
2023-03-15 09:17:25 +00:00
function getMarketNetworkDownText ( ) {
2023-11-22 19:58:02 +00:00
if ( notOnlineWithNoCache )
return notOnlineWithNoCacheText
2023-03-23 10:23:02 +00:00
else if ( noBlockchainAndMarketConnectionAndNoCache )
return noBlockchainAndMarketConnectionAndNoCacheText
else if ( noMarketConnectionAndNoCache )
return noMarketConnectionAndNoCacheText
2023-03-15 09:17:25 +00:00
else
return ""
}
function getChainIdsJointString ( chainIdsDown ) {
let jointChainIdString = ""
for ( const chain of chainIdsDown ) {
jointChainIdString = ( ! ! jointChainIdString ) ? jointChainIdString + " & " : jointChainIdString
2024-03-13 17:38:16 +00:00
jointChainIdString += ModelUtils . getByKey ( networksModule . flatNetworks , "chainId" , parseInt ( chain ) , "chainName" )
2023-03-15 09:17:25 +00:00
}
return jointChainIdString
}
function retryConnection ( websiteDown ) {
switch ( websiteDown ) {
case Constants.walletConnections.blockchains:
networkConnectionModule . refreshBlockchainValues ( )
break
case Constants.walletConnections.market:
networkConnectionModule . refreshMarketValues ( )
break
case Constants.walletConnections.collectibles:
networkConnectionModule . refreshCollectiblesValues ( )
break
}
}
}