2023-09-12 09:26:25 +00:00
|
|
|
pragma Singleton
|
|
|
|
|
|
|
|
import QtQml 2.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import StatusQ.Internal 0.1 as Internal
|
|
|
|
|
|
|
|
import AppLayouts.Communities.controls 1.0
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
|
|
|
|
// Given a specific network model and an index inside the model, it gets the chain name.
|
|
|
|
function getChainName(model, index) {
|
|
|
|
return ModelUtils.get(model, index, "chainName") ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a specific network model and an index inside the model, it gets the chain icon url.
|
|
|
|
function getChainIconUrl(model, index) {
|
|
|
|
return ModelUtils.get(model, index, "iconUrl") ?? ""
|
|
|
|
}
|
|
|
|
|
2024-03-13 17:38:16 +00:00
|
|
|
// Given a network model, it looks for the provided chainId and returns
|
2023-09-12 09:26:25 +00:00
|
|
|
// the layer network model that contains the specific chain. If not found, returns undefined.
|
2024-03-13 17:38:16 +00:00
|
|
|
function getLayerNetworkModelByChainId(networksModel, chainId) {
|
2023-09-12 09:26:25 +00:00
|
|
|
if(chainId) {
|
2024-03-13 17:38:16 +00:00
|
|
|
if(!!networksModel && ModelUtils.contains(networksModel, "chainId", chainId))
|
|
|
|
return networksModel
|
2023-09-12 09:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default value if chainId is not part of any provided layer network model
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
2024-03-13 17:38:16 +00:00
|
|
|
// Given a network model, it looks for the provided chainId and returns
|
2023-09-12 09:26:25 +00:00
|
|
|
// the index of the the specific chain. If not found, returns 0 value.
|
2024-03-13 17:38:16 +00:00
|
|
|
function getChainIndexByChainId(networksModel, chainId) {
|
|
|
|
if(!!networksModel && chainId !== undefined)
|
|
|
|
return ModelUtils.indexOf(networksModel, "chainId", chainId)
|
|
|
|
|
|
|
|
// Default value if no model specified
|
|
|
|
return 0
|
|
|
|
}
|
2023-09-12 09:26:25 +00:00
|
|
|
|
2024-03-13 17:38:16 +00:00
|
|
|
function getChainIndexForFirstLayer2Network(networksModel) {
|
|
|
|
if(!!networksModel)
|
|
|
|
return ModelUtils.indexOf(networksModel, "layer", 2)
|
2023-09-12 09:26:25 +00:00
|
|
|
|
2024-03-13 17:38:16 +00:00
|
|
|
// Default value if no model specified
|
2023-09-12 09:26:25 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|