fix(@desktop/wallet): Handle testnet explorer links (#11016)
This commit is contained in:
parent
16304ab26b
commit
82dced8826
|
@ -20,10 +20,6 @@ StatusMenu {
|
|||
|
||||
property var contactsStore
|
||||
|
||||
// TODO get those names from model
|
||||
readonly property string arbiscanShortChainName: "arb"
|
||||
readonly property string optimismShortChainName: "opt"
|
||||
|
||||
signal openSendModal(address: string)
|
||||
|
||||
enum AddressType {
|
||||
|
@ -46,6 +42,8 @@ StatusMenu {
|
|||
|
||||
property string contractName: ""
|
||||
|
||||
property bool isGoerliTestnet: false
|
||||
|
||||
property int addressType: TransactionAddressMenu.AddressType.Address
|
||||
|
||||
function getViewText(target) {
|
||||
|
@ -67,6 +65,35 @@ StatusMenu {
|
|||
}
|
||||
}
|
||||
|
||||
function refreshShowOnActionsVisiblity(shortChainName) {
|
||||
switch(shortChainName.toLowerCase()) {
|
||||
case Constants.networkShortChainNames.arbiscan.toLowerCase():
|
||||
case Constants.networkShortChainNames.goerliArbiscan.toLowerCase():
|
||||
showOnArbiscanAction.enabled = true
|
||||
break
|
||||
case Constants.networkShortChainNames.optimism.toLowerCase():
|
||||
case Constants.networkShortChainNames.goerliOptimism.toLowerCase():
|
||||
showOnOptimismAction.enabled = true
|
||||
break
|
||||
default:
|
||||
showOnEtherscanAction.enabled = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function refreshIsTestnet(shortChainName) {
|
||||
switch(shortChainName.toLowerCase()) {
|
||||
case Constants.networkShortChainNames.goerliMainnet.toLowerCase():
|
||||
case Constants.networkShortChainNames.goerliArbiscan.toLowerCase():
|
||||
case Constants.networkShortChainNames.goerliOptimism.toLowerCase():
|
||||
d.isGoerliTestnet = true
|
||||
return
|
||||
default:
|
||||
d.isGoerliTestnet = false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function openMenu(delegate) {
|
||||
const x = delegate.width - 40
|
||||
const y = delegate.height / 2 + 20
|
||||
|
@ -89,17 +116,17 @@ StatusMenu {
|
|||
}
|
||||
}
|
||||
|
||||
function openSenderMenu(delegate, address) {
|
||||
function openSenderMenu(delegate, address, chainShortName = "") {
|
||||
d.addressType = TransactionAddressMenu.AddressType.Sender
|
||||
openEthAddressMenu(delegate, address, true, false)
|
||||
openEthAddressMenu(delegate, address, chainShortName)
|
||||
}
|
||||
|
||||
function openReceiverMenu(delegate, address) {
|
||||
function openReceiverMenu(delegate, address, chainShortName = "") {
|
||||
d.addressType = TransactionAddressMenu.AddressType.Receiver
|
||||
openEthAddressMenu(delegate, address)
|
||||
openEthAddressMenu(delegate, address, chainShortName)
|
||||
}
|
||||
|
||||
function openEthAddressMenu(delegate, address) {
|
||||
function openEthAddressMenu(delegate, address, chainShortName = "") {
|
||||
d.selectedAddress = address
|
||||
|
||||
address = address.toLowerCase()
|
||||
|
@ -120,10 +147,11 @@ StatusMenu {
|
|||
d.addressName = contactData.isContact ? contactData.name : WalletStores.RootStore.getNameForAddress(address)
|
||||
d.addressEns = RootStore.getEnsForSavedWalletAddress(address)
|
||||
d.addressChains = RootStore.getChainShortNamesForSavedWalletAddress(address)
|
||||
d.refreshIsTestnet(chainShortName)
|
||||
|
||||
showOnEtherscanAction.enabled = true
|
||||
showOnArbiscanAction.enabled = address.includes(root.arbiscanShortChainName + ":")
|
||||
showOnOptimismAction.enabled = address.includes(root.optimismShortChainName + ":")
|
||||
showOnArbiscanAction.enabled = address.includes(Constants.networkShortChainNames.arbiscan + ":")
|
||||
showOnOptimismAction.enabled = address.includes(Constants.networkShortChainNames.optimism + ":")
|
||||
saveAddressAction.enabled = d.addressName.length === 0
|
||||
editAddressAction.enabled = !isWalletAccount && !isContact && d.addressName.length > 0
|
||||
copyAddressAction.isSuccessState = false
|
||||
|
@ -136,14 +164,8 @@ StatusMenu {
|
|||
function openTxMenu(delegate, address, chainShortName="") {
|
||||
d.addressType = TransactionAddressMenu.AddressType.Tx
|
||||
d.selectedAddress = address
|
||||
chainShortName = chainShortName.toLowerCase()
|
||||
if (chainShortName === root.arbiscanShortChainName) {
|
||||
showOnArbiscanAction.enabled = true
|
||||
} else if (chainShortName === root.optimismShortChainName) {
|
||||
showOnOptimismAction.enabled = true
|
||||
} else {
|
||||
showOnEtherscanAction.enabled = true
|
||||
}
|
||||
d.refreshShowOnActionsVisiblity(chainShortName)
|
||||
d.refreshIsTestnet(chainShortName)
|
||||
d.openMenu(delegate)
|
||||
}
|
||||
|
||||
|
@ -151,14 +173,8 @@ StatusMenu {
|
|||
d.addressType = TransactionAddressMenu.AddressType.Contract
|
||||
d.contractName = name
|
||||
d.selectedAddress = address
|
||||
chainShortName = chainShortName.toLowerCase()
|
||||
if (chainShortName === root.arbiscanShortChainName) {
|
||||
showOnArbiscanAction.enabled = true
|
||||
} else if (chainShortName === root.optimismShortChainName) {
|
||||
showOnOptimismAction.enabled = true
|
||||
} else {
|
||||
showOnEtherscanAction.enabled = true
|
||||
}
|
||||
d.refreshShowOnActionsVisiblity(chainShortName)
|
||||
d.refreshIsTestnet(chainShortName)
|
||||
d.openMenu(delegate)
|
||||
}
|
||||
|
||||
|
@ -195,6 +211,7 @@ StatusMenu {
|
|||
onClosed: {
|
||||
d.addressType = TransactionAddressMenu.AddressType.Address
|
||||
d.contractName = ""
|
||||
d.isGoerliTestnet = false
|
||||
|
||||
showOnEtherscanAction.enabled = false
|
||||
showOnArbiscanAction.enabled = false
|
||||
|
@ -216,7 +233,8 @@ StatusMenu {
|
|||
assetSettings.name: "link"
|
||||
onTriggered: {
|
||||
const type = d.addressType === TransactionAddressMenu.Tx ? "tx" : "address"
|
||||
Global.openLink("https://etherscan.io/%1/%2".arg(type).arg(d.selectedAddress))
|
||||
const link = d.isGoerliTestnet ? Constants.networkExplorerLinks.goerliEtherscan : Constants.networkExplorerLinks.etherscan
|
||||
Global.openLink("%1/%2/%3".arg(link).arg(type).arg(d.selectedAddress))
|
||||
}
|
||||
}
|
||||
StatusAction {
|
||||
|
@ -226,7 +244,8 @@ StatusMenu {
|
|||
assetSettings.name: "link"
|
||||
onTriggered: {
|
||||
const type = d.addressType === TransactionAddressMenu.Tx ? "tx" : "address"
|
||||
Global.openLink("https://arbiscan.io/%1/%2".arg(type).arg(d.selectedAddress))
|
||||
const link = d.isGoerliTestnet ? Constants.networkExplorerLinks.goerliArbiscan : Constants.networkExplorerLinks.arbiscan
|
||||
Global.openLink("%1/%2/%3".arg(link).arg(type).arg(d.selectedAddress))
|
||||
}
|
||||
}
|
||||
StatusAction {
|
||||
|
@ -236,7 +255,8 @@ StatusMenu {
|
|||
assetSettings.name: "link"
|
||||
onTriggered: {
|
||||
const type = d.addressType === TransactionAddressMenu.Tx ? "tx" : "address"
|
||||
Global.openLink("https://optimistic.etherscan.io/%1/%2".arg(type).arg(d.selectedAddress))
|
||||
const link = d.isGoerliTestnet ? Constants.networkExplorerLinks.goerliOptimistic : Constants.networkExplorerLinks.optimistic
|
||||
Global.openLink("%1/%2/%3".arg(link).arg(type).arg(d.selectedAddress))
|
||||
}
|
||||
}
|
||||
StatusCopyAction {
|
||||
|
|
|
@ -224,9 +224,9 @@ Item {
|
|||
rootStore: WalletStores.RootStore
|
||||
onButtonClicked: {
|
||||
if (transactionHeader.transactionType === TransactionDelegate.Swap || transactionHeader.transactionType === TransactionDelegate.Bridge) {
|
||||
addressMenu.openEthAddressMenu(this, addresses[0])
|
||||
addressMenu.openEthAddressMenu(this, addresses[0], d.networkShortName)
|
||||
} else {
|
||||
addressMenu.openSenderMenu(this, addresses[0])
|
||||
addressMenu.openSenderMenu(this, addresses[0], d.networkShortName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ Item {
|
|||
addresses: root.isTransactionValid ? [root.transaction.to] : []
|
||||
contactsStore: root.contactsStore
|
||||
rootStore: WalletStores.RootStore
|
||||
onButtonClicked: addressMenu.openReceiverMenu(this, addresses[0])
|
||||
onButtonClicked: addressMenu.openReceiverMenu(this, addresses[0], d.networkShortName)
|
||||
visible: transactionHeader.transactionType !== TransactionDelegate.Swap && transactionHeader.transactionType !== TransactionDelegate.Bridge && transactionHeader.transactionType !== TransactionDelegate.Destroy
|
||||
}
|
||||
TransactionDataTile {
|
||||
|
|
|
@ -772,6 +772,24 @@ QtObject {
|
|||
readonly property string networkMainnet: "Mainnet"
|
||||
readonly property string networkRopsten: "Ropsten"
|
||||
|
||||
readonly property QtObject networkShortChainNames: QtObject {
|
||||
readonly property string mainnet: "eth"
|
||||
readonly property string arbiscan: "arb"
|
||||
readonly property string optimism: "opt"
|
||||
readonly property string goerliMainnet: "goEth"
|
||||
readonly property string goerliArbiscan: "goArb"
|
||||
readonly property string goerliOptimism: "goOpt"
|
||||
}
|
||||
|
||||
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 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 api_request: "api-request"
|
||||
readonly property string web3SendAsyncReadOnly: "web3-send-async-read-only"
|
||||
readonly property string web3DisconnectAccount: "web3-disconnect-account"
|
||||
|
|
Loading…
Reference in New Issue