feat(savedaddresses): context menu - view on [network] (all available networks)

Part 3 of #13094
This commit is contained in:
Sale Djenic 2024-01-15 13:27:47 +01:00 committed by saledjenic
parent 3399148f61
commit 6eda2a4956
7 changed files with 92 additions and 57 deletions

View File

@ -30,8 +30,7 @@ StatusMenu {
})
property bool areTestNetworksEnabled: false
property bool isSepoliaEnabled: false
property string preferredSharingNetworks
property var preferredSharingNetworksArray
property var preferredSharedNetworkNamesArray
signal copyToClipboard(string address)
@ -42,40 +41,35 @@ StatusMenu {
}
StatusAction {
id: showOnEtherscanAction
text: qsTr("View address on Etherscan")
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.mainnet)
enabled: root.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.mainnet)
icon.name: "link"
onTriggered: {
let link = Constants.networkExplorerLinks.etherscan
if (areTestNetworksEnabled) {
if (root.isSepoliaEnabled) {
link = Constants.networkExplorerLinks.sepoliaEtherscan
} else {
link = Constants.networkExplorerLinks.goerliEtherscan
}
}
Global.openLink("%1/%2/%3".arg(link).arg(Constants.networkExplorerLinks.addressPath).arg(root.selectedAccount.address?? ""))
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.mainnet, root.areTestNetworksEnabled, root.isSepoliaEnabled, root.selectedAccount.address?? "")
Global.openLink(link)
}
}
StatusAction {
id: showOnArbiscanAction
text: qsTr("View address on Arbiscan")
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.arbiscan)
enabled: root.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.arbiscan)
icon.name: "link"
onTriggered: {
const link = areTestNetworksEnabled ? Constants.networkExplorerLinks.goerliArbiscan : Constants.networkExplorerLinks.arbiscan
Global.openLink("%1/%2/%3".arg(link).arg(Constants.networkExplorerLinks.addressPath).arg(root.selectedAccount.address?? ""))
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.arbiscan, root.areTestNetworksEnabled, root.isSepoliaEnabled, root.selectedAccount.address?? "")
Global.openLink(link)
}
}
StatusAction {
id: showOnOptimismAction
text: qsTr("View address on Optimism Explorer")
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.optimism)
enabled: root.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.optimism)
icon.name: "link"
onTriggered: {
const link = areTestNetworksEnabled ? Constants.networkExplorerLinks.goerliOptimistic : Constants.networkExplorerLinks.optimistic
Global.openLink("%1/%2/%3".arg(link).arg(Constants.networkExplorerLinks.addressPath).arg(root.selectedAccount.address?? ""))
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.optimism, root.areTestNetworksEnabled, root.isSepoliaEnabled, root.selectedAccount.address?? "")
Global.openLink(link)
}
}
StatusSuccessAction {
id: copyAddressAction
successText: qsTr("Address copied")

View File

@ -345,8 +345,7 @@ ColumnLayout {
selectedAccount: root.account
areTestNetworksEnabled: root.walletStore.areTestNetworksEnabled
isSepoliaEnabled: root.walletStore.isSepoliaEnabled
preferredSharingNetworks: d.preferredSharingNetworkShortNames
preferredSharingNetworksArray: d.preferredSharingNetworksArray
preferredSharedNetworkNamesArray: d.preferredSharingNetworkShortNames.split(":").filter(Boolean)
onCopyToClipboard: root.walletStore.copyToClipboard(address)
}

View File

@ -70,6 +70,7 @@ StatusListItem {
id: d
readonly property string visibleAddress: !!root.ens? root.ens : root.address
readonly property var preferredSharedNetworkNamesArray: root.chainShortNames.split(":").filter(Boolean)
}
components: [
@ -174,50 +175,43 @@ StatusListItem {
})
}
}
StatusMenuSeparator { }
StatusMenuSeparator {
visible: d.preferredSharedNetworkNamesArray.length > 0
}
StatusAction {
text: qsTr("View on Etherscan")
objectName: "viewOnEtherscanAction"
assetSettings.name: "external"
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.mainnet)
enabled: d.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.mainnet)
icon.name: "link"
onTriggered: {
var baseUrl = Constants.networkExplorerLinks.etherscan
if (root.areTestNetworksEnabled) {
if (root.isSepoliaEnabled) {
baseUrl = Constants.networkExplorerLinks.sepoliaEtherscan
} else {
baseUrl = Constants.networkExplorerLinks.goerliEtherscan
}
}
Global.openLink("%1/%2/%3".arg(baseUrl).arg(Constants.networkExplorerLinks.addressPath).arg(d.visibleAddress ? d.visibleAddress : root.ens))
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.mainnet, root.areTestNetworksEnabled, root.isSepoliaEnabled, d.visibleAddress ? d.visibleAddress : root.ens)
Global.openLink(link)
}
}
StatusAction {
text: qsTr("View on Arbiscan")
objectName: "viewOnArbiscanAction"
assetSettings.name: "external"
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.arbiscan)
enabled: d.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.arbiscan)
icon.name: "link"
onTriggered: {
var baseUrl = Constants.networkExplorerLinks.arbiscan
if (root.areTestNetworksEnabled) {
baseUrl = Constants.networkExplorerLinks.goerliArbiscan
}
Global.openLink("%1/%2/%3".arg(baseUrl).arg(Constants.networkExplorerLinks.addressPath).arg(d.visibleAddress ? d.visibleAddress : root.ens))
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.arbiscan, root.areTestNetworksEnabled, root.isSepoliaEnabled, d.visibleAddress ? d.visibleAddress : root.ens)
Global.openLink(link)
}
}
StatusAction {
text: qsTr("View on Optimism Explorer")
objectName: "viewOnOptimismExplorerAction"
assetSettings.name: "external"
text: Utils.getActionNameForDisplayingAddressOnNetwork(Constants.networkShortChainNames.optimism)
enabled: d.preferredSharedNetworkNamesArray.includes(Constants.networkShortChainNames.optimism)
icon.name: "link"
onTriggered: {
var baseUrl = Constants.networkExplorerLinks.optimistic
if (root.areTestNetworksEnabled) {
baseUrl = Constants.networkExplorerLinks.goerliOptimistic
}
Global.openLink("%1/%2/%3".arg(baseUrl).arg(Constants.networkExplorerLinks.addressPath).arg(d.visibleAddress ? d.visibleAddress : root.ens))
let link = Utils.getUrlForAddressOnNetwork(Constants.networkShortChainNames.optimism, root.areTestNetworksEnabled, root.isSepoliaEnabled, d.visibleAddress ? d.visibleAddress : root.ens)
Global.openLink(link)
}
}
StatusMenuSeparator { }
StatusAction {
text: qsTr("Remove saved address")
type: StatusAction.Type.Danger

View File

@ -230,7 +230,7 @@ StatusModal {
width: parent.width
height: Math.max(flow.height, editButton.height)
anchors.horizontalCenter: parent.horizontalCenter
visible: d.multiChainView && d.preferredChainIdsArray.length > 0
visible: d.multiChainView && (d.preferredChainIdsArray.length > 0 || root.changingPreferredChainsEnabled)
Flow {
id: flow

View File

@ -236,7 +236,7 @@ StatusMenu {
icon.name: "link"
onTriggered: {
const type = d.addressType === TransactionAddressMenu.Tx ? Constants.networkExplorerLinks.txPath : Constants.networkExplorerLinks.addressPath
const link = areTestNetworksEnabled ? Constants.networkExplorerLinks.goerliOptimistic : Constants.networkExplorerLinks.optimistic
const link = areTestNetworksEnabled ? Constants.networkExplorerLinks.goerliOptimism : Constants.networkExplorerLinks.optimism
Global.openLink("%1/%2/%3".arg(link).arg(type).arg(d.selectedAddress))
}
}

View File

@ -908,11 +908,15 @@ QtObject {
readonly property QtObject networkExplorerLinks: QtObject {
readonly property string etherscan: "https://etherscan.io"
readonly property string arbiscan: "https://arbiscan.io"
readonly property string optimistic: "https://optimistic.etherscan.io"
readonly property string optimism: "https://optimistic.etherscan.io"
readonly property string goerliEtherscan: "https://goerli.etherscan.io"
readonly property string goerliArbiscan: "https://goerli.arbiscan.io"
readonly property string goerliOptimistic: "https://goerli-optimism.etherscan.io"
readonly property string goerliOptimism: "https://goerli-optimism.etherscan.io"
readonly property string sepoliaEtherscan: "https://sepolia.etherscan.io/"
readonly property string sepoliaArbiscan: "https://sepolia.arbiscan.io/"
readonly property string sepoliaOptimism: "https://sepolia-optimism.etherscan.io/"
readonly property string addressPath: "address"
readonly property string txPath: "tx"

View File

@ -890,6 +890,50 @@ QtObject {
return ""
}
function getActionNameForDisplayingAddressOnNetwork(networkShortName) {
if (networkShortName === Constants.networkShortChainNames.arbiscan) {
return qsTr("View on Arbiscan")
}
if (networkShortName === Constants.networkShortChainNames.optimism) {
return qsTr("View on Optimism Explorer")
}
return qsTr("View on Etherscan")
}
function getUrlForAddressOnNetwork(networkShortName, testnetMode, sepoliaEnabled, address) {
let link = Constants.networkExplorerLinks.etherscan
if (testnetMode) {
if (sepoliaEnabled) {
link = Constants.networkExplorerLinks.sepoliaEtherscan
} else {
link = Constants.networkExplorerLinks.goerliEtherscan
}
}
if (networkShortName === Constants.networkShortChainNames.arbiscan) {
link = Constants.networkExplorerLinks.arbiscan
if (testnetMode) {
if (sepoliaEnabled) {
link = Constants.networkExplorerLinks.sepoliaArbiscan
} else {
link = Constants.networkExplorerLinks.goerliArbiscan
}
}
} else if (networkShortName === Constants.networkShortChainNames.optimism) {
link = Constants.networkExplorerLinks.optimism
if (testnetMode) {
if (sepoliaEnabled) {
link = Constants.networkExplorerLinks.sepoliaOptimism
} else {
link = Constants.networkExplorerLinks.goerliOptimism
}
}
}
return "%1/%2/%3".arg(link).arg(Constants.networkExplorerLinks.addressPath).arg(address)
}
// Leave this function at the bottom of the file as QT Creator messes up the code color after this
function isPunct(c) {
return /(!|\@|#|\$|%|\^|&|\*|\(|\)|\+|\||-|=|\\|{|}|[|]|"|;|'|<|>|\?|,|\.|\/)/.test(c)