fix(qml): fix etherscan links for all networks
Also refactor code for reusability and readability. Closes: #13986
This commit is contained in:
parent
f12c6dfa40
commit
0958860bc9
|
@ -51,11 +51,11 @@ StatusMenu {
|
|||
}
|
||||
|
||||
StatusAction {
|
||||
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.arbiscan)
|
||||
enabled: root.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.arbiscan)
|
||||
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.arbitrum)
|
||||
enabled: root.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.arbitrum)
|
||||
icon.name: "link"
|
||||
onTriggered: {
|
||||
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.arbiscan, root.areTestNetworksEnabled, root.isGoerliEnabled, root.selectedAccount.address?? "")
|
||||
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.arbitrum, root.areTestNetworksEnabled, root.isGoerliEnabled, root.selectedAccount.address?? "")
|
||||
Global.openLink(link)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,11 +241,11 @@ StatusListItem {
|
|||
}
|
||||
|
||||
StatusAction {
|
||||
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.arbiscan)
|
||||
enabled: d.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.arbiscan)
|
||||
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.arbitrum)
|
||||
enabled: d.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.arbitrum)
|
||||
icon.name: "link"
|
||||
onTriggered: {
|
||||
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.arbiscan, root.areTestNetworksEnabled, root.isGoerliEnabled, d.visibleAddress ? d.visibleAddress : root.ens)
|
||||
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.arbitrum, root.areTestNetworksEnabled, root.isGoerliEnabled, d.visibleAddress ? d.visibleAddress : root.ens)
|
||||
Global.openLink(link)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,9 +107,9 @@ ColumnLayout {
|
|||
let link = Constants.networkExplorerLinks.etherscan
|
||||
if (areTestNetworksEnabled) {
|
||||
if (root.isGoerliEnabled) {
|
||||
link = Constants.networkExplorerLinks.sepoliaEtherscan
|
||||
} else {
|
||||
link = Constants.networkExplorerLinks.goerliEtherscan
|
||||
} else {
|
||||
link = Constants.networkExplorerLinks.sepoliaEtherscan
|
||||
}
|
||||
}
|
||||
Global.openLink("%1/nft/%2/%3".arg(link).arg(root.tokenAddress).arg(root.tokenId))
|
||||
|
|
|
@ -50,6 +50,7 @@ StatusMenu {
|
|||
id: d
|
||||
|
||||
property string selectedAddress: ""
|
||||
property string cleanSelectedAddress: d.selectedAddress.split(":").pop()
|
||||
|
||||
property string addressName: ""
|
||||
property string addressEns: ""
|
||||
|
@ -60,6 +61,10 @@ StatusMenu {
|
|||
|
||||
property int addressType: TransactionAddressMenu.AddressType.Address
|
||||
|
||||
readonly property QtObject exp: Constants.networkExplorerLinks
|
||||
readonly property QtObject chains: Constants.networkShortChainNames
|
||||
readonly property bool isAddress: d.addressType !== TransactionAddressMenu.Tx
|
||||
|
||||
function getViewText(target) {
|
||||
switch(d.addressType) {
|
||||
case TransactionAddressMenu.AddressType.Contract:
|
||||
|
@ -82,10 +87,10 @@ StatusMenu {
|
|||
function refreshShowOnActionsVisiblity(shortChainNameList) {
|
||||
for (let i = 0 ; i < shortChainNameList.length ; i++) {
|
||||
switch(shortChainNameList[i].toLowerCase()) {
|
||||
case Constants.networkShortChainNames.arbiscan.toLowerCase():
|
||||
case d.chains.arbitrum:
|
||||
showOnArbiscanAction.enabled = true
|
||||
break
|
||||
case Constants.networkShortChainNames.optimism.toLowerCase():
|
||||
case d.chains.optimism:
|
||||
showOnOptimismAction.enabled = true
|
||||
break
|
||||
default:
|
||||
|
@ -152,8 +157,8 @@ StatusMenu {
|
|||
}
|
||||
|
||||
showOnEtherscanAction.enabled = true
|
||||
showOnArbiscanAction.enabled = address.includes(Constants.networkShortChainNames.arbiscan + ":")
|
||||
showOnOptimismAction.enabled = address.includes(Constants.networkShortChainNames.optimism + ":")
|
||||
showOnArbiscanAction.enabled = address.includes(d.chains.arbitrum + ":")
|
||||
showOnOptimismAction.enabled = address.includes(d.chains.optimism + ":")
|
||||
d.refreshShowOnActionsVisiblity(chainShortNameList)
|
||||
saveAddressAction.enabled = d.addressName.length === 0
|
||||
editAddressAction.enabled = !isWalletAccount && !isContact && d.addressName.length > 0
|
||||
|
@ -210,16 +215,9 @@ StatusMenu {
|
|||
text: d.getViewText(qsTr("Etherscan"))
|
||||
icon.name: "link"
|
||||
onTriggered: {
|
||||
const type = d.addressType === TransactionAddressMenu.Tx ? Constants.networkExplorerLinks.txPath : Constants.networkExplorerLinks.addressPath
|
||||
let link = Constants.networkExplorerLinks.etherscan
|
||||
if (areTestNetworksEnabled) {
|
||||
if (root.isGoerliEnabled) {
|
||||
link = Constants.networkExplorerLinks.sepoliaEtherscan
|
||||
} else {
|
||||
link = Constants.networkExplorerLinks.goerliEtherscan
|
||||
}
|
||||
}
|
||||
Global.openLink("%1/%2/%3".arg(link).arg(type).arg(d.selectedAddress))
|
||||
let url = Utils.getEtherscanUrl(d.chains.mainnet, root.areTestNetworksEnabled, !root.isGoerliEnabled,
|
||||
d.cleanSelectedAddress, d.isAddress)
|
||||
Global.openLink(url)
|
||||
}
|
||||
}
|
||||
StatusAction {
|
||||
|
@ -228,9 +226,9 @@ StatusMenu {
|
|||
text: d.getViewText(qsTr("Arbiscan"))
|
||||
icon.name: "link"
|
||||
onTriggered: {
|
||||
const type = d.addressType === TransactionAddressMenu.Tx ? Constants.networkExplorerLinks.txPath : Constants.networkExplorerLinks.addressPath
|
||||
const link = areTestNetworksEnabled ? Constants.networkExplorerLinks.goerliArbiscan : Constants.networkExplorerLinks.arbiscan
|
||||
Global.openLink("%1/%2/%3".arg(link).arg(type).arg(d.selectedAddress))
|
||||
let url = Utils.getEtherscanUrl(d.chains.arbitrum, root.areTestNetworksEnabled, !root.isGoerliEnabled,
|
||||
d.cleanSelectedAddress, d.isAddress)
|
||||
Global.openLink(url)
|
||||
}
|
||||
}
|
||||
StatusAction {
|
||||
|
@ -239,9 +237,9 @@ StatusMenu {
|
|||
text: d.getViewText(qsTr("Optimism Explorer"))
|
||||
icon.name: "link"
|
||||
onTriggered: {
|
||||
const type = d.addressType === TransactionAddressMenu.Tx ? Constants.networkExplorerLinks.txPath : Constants.networkExplorerLinks.addressPath
|
||||
const link = areTestNetworksEnabled ? Constants.networkExplorerLinks.goerliOptimism : Constants.networkExplorerLinks.optimism
|
||||
Global.openLink("%1/%2/%3".arg(link).arg(type).arg(d.selectedAddress))
|
||||
let url = Utils.getEtherscanUrl(d.chains.optimism, root.areTestNetworksEnabled, !root.isGoerliEnabled,
|
||||
d.cleanSelectedAddress, d.isAddress)
|
||||
Global.openLink(url)
|
||||
}
|
||||
}
|
||||
StatusSuccessAction {
|
||||
|
|
|
@ -492,16 +492,16 @@ QtObject {
|
|||
let link = Constants.networkExplorerLinks.etherscan
|
||||
if (root.areTestNetworksEnabled) {
|
||||
if (root.isGoerliEnabled) {
|
||||
link = Constants.networkExplorerLinks.sepoliaEtherscan
|
||||
} else {
|
||||
link = Constants.networkExplorerLinks.goerliEtherscan
|
||||
} else {
|
||||
link = Constants.networkExplorerLinks.sepoliaEtherscan
|
||||
}
|
||||
}
|
||||
return link
|
||||
}
|
||||
|
||||
function getExplorerNameForNetwork(networkShortName) {
|
||||
if (networkShortName === Constants.networkShortChainNames.arbiscan) {
|
||||
if (networkShortName === Constants.networkShortChainNames.arbitrum) {
|
||||
return qsTr("Arbiscan Explorer")
|
||||
}
|
||||
if (networkShortName === Constants.networkShortChainNames.optimism) {
|
||||
|
|
|
@ -299,7 +299,7 @@ Item {
|
|||
width: parent.width
|
||||
title: d.transactionType === Constants.TransactionType.Swap || d.transactionType === Constants.TransactionType.Bridge ?
|
||||
qsTr("In") : qsTr("From")
|
||||
addresses: d.isTransactionValid && d.reEvaluateSender? [d.transaction.sender] : []
|
||||
addresses: d.isTransactionValid && d.reEvaluateSender? [d.transaction.from] : []
|
||||
contactsStore: root.contactsStore
|
||||
rootStore: WalletStores.RootStore
|
||||
onButtonClicked: {
|
||||
|
@ -342,7 +342,7 @@ Item {
|
|||
TransactionAddressTile {
|
||||
width: parent.width
|
||||
title: qsTr("To")
|
||||
addresses: d.isTransactionValid && visible && d.reEvaluateRecipient? [d.transaction.recipient] : []
|
||||
addresses: d.isTransactionValid && visible && d.reEvaluateRecipient? [d.transaction.to] : []
|
||||
contactsStore: root.contactsStore
|
||||
rootStore: WalletStores.RootStore
|
||||
onButtonClicked: addressMenu.openReceiverMenu(this, addresses[0], [d.networkShortName])
|
||||
|
|
|
@ -895,7 +895,7 @@ QtObject {
|
|||
|
||||
readonly property QtObject networkShortChainNames: QtObject {
|
||||
readonly property string mainnet: "eth"
|
||||
readonly property string arbiscan: "arb"
|
||||
readonly property string arbitrum: "arb"
|
||||
readonly property string optimism: "opt"
|
||||
}
|
||||
|
||||
|
|
|
@ -911,7 +911,7 @@ QtObject {
|
|||
}
|
||||
|
||||
function getActionNameForDisplayingAddressOnNetwork(networkShortName) {
|
||||
if (networkShortName === Constants.networkShortChainNames.arbiscan) {
|
||||
if (networkShortName === Constants.networkShortChainNames.arbitrum) {
|
||||
return qsTr("View on Arbiscan")
|
||||
}
|
||||
if (networkShortName === Constants.networkShortChainNames.optimism) {
|
||||
|
@ -921,7 +921,10 @@ QtObject {
|
|||
return qsTr("View on Etherscan")
|
||||
}
|
||||
|
||||
function getUrlForAddressOnNetwork(networkShortName, testnetMode, sepoliaEnabled, address) {
|
||||
function getEtherscanUrl(networkShortName, testnetMode, sepoliaEnabled, addressOrTx, isAddressNotTx) {
|
||||
const type = isAddressNotTx
|
||||
? Constants.networkExplorerLinks.addressPath
|
||||
: Constants.networkExplorerLinks.txPath
|
||||
let link = Constants.networkExplorerLinks.etherscan
|
||||
if (testnetMode) {
|
||||
if (sepoliaEnabled) {
|
||||
|
@ -931,7 +934,7 @@ QtObject {
|
|||
}
|
||||
}
|
||||
|
||||
if (networkShortName === Constants.networkShortChainNames.arbiscan) {
|
||||
if (networkShortName === Constants.networkShortChainNames.arbitrum) {
|
||||
link = Constants.networkExplorerLinks.arbiscan
|
||||
if (testnetMode) {
|
||||
if (sepoliaEnabled) {
|
||||
|
@ -951,7 +954,17 @@ QtObject {
|
|||
}
|
||||
}
|
||||
|
||||
return "%1/%2/%3".arg(link).arg(Constants.networkExplorerLinks.addressPath).arg(address)
|
||||
return "%1/%2/%3".arg(link).arg(type).arg(addressOrTx)
|
||||
}
|
||||
|
||||
// Etherscan URL for an address
|
||||
function getUrlForAddressOnNetwork(networkShortName, testnetMode, sepoliaEnabled, address) {
|
||||
return getEtherscanUrl(networkShortName, testnetMode, sepoliaEnabled, address, true /* is address */)
|
||||
}
|
||||
|
||||
// Etherscan URL for a transaction
|
||||
function getUrlForTxOnNetwork(networkShortName, testnetMode, sepoliaEnabled, tx) {
|
||||
return getEtherscanUrl(networkShortName, testnetMode, sepoliaEnabled, tx, false /* is TX */)
|
||||
}
|
||||
|
||||
// Leave this function at the bottom of the file as QT Creator messes up the code color after this
|
||||
|
|
Loading…
Reference in New Issue