From dc0c527e4185c84cb9a527f5c218375f87e738d4 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Fri, 15 Nov 2024 02:04:00 -0300 Subject: [PATCH] feat(activity): reworked activity context menu --- .../panels/ContractInfoButtonWithMenu.qml | 8 +- .../AppLayouts/Wallet/views/RightTabView.qml | 1 - ui/imports/shared/views/HistoryView.qml | 130 +++--------------- .../shared/views/TransactionContextMenu.qml | 25 ++++ ui/imports/utils/Utils.qml | 38 +++++ vendor/status-go | 2 +- 6 files changed, 83 insertions(+), 121 deletions(-) create mode 100644 ui/imports/shared/views/TransactionContextMenu.qml diff --git a/ui/app/AppLayouts/Wallet/panels/ContractInfoButtonWithMenu.qml b/ui/app/AppLayouts/Wallet/panels/ContractInfoButtonWithMenu.qml index 85815d481d..7f7288949c 100644 --- a/ui/app/AppLayouts/Wallet/panels/ContractInfoButtonWithMenu.qml +++ b/ui/app/AppLayouts/Wallet/panels/ContractInfoButtonWithMenu.qml @@ -28,13 +28,7 @@ StatusFlatButton { onClicked: moreMenu.popup(-moreMenu.width + width, height + 4) function getExplorerName() { - if (root.networkShortName === Constants.networkShortChainNames.arbitrum) { - return qsTr("Arbiscan") - } - if (root.networkShortName === Constants.networkShortChainNames.optimism) { - return qsTr("Optimistic") - } - return qsTr("Etherscan") + return Utils.getChainExplorerName(root.networkShortName) } StatusMenu { diff --git a/ui/app/AppLayouts/Wallet/views/RightTabView.qml b/ui/app/AppLayouts/Wallet/views/RightTabView.qml index 04cbc239a5..5a4f8a22a6 100644 --- a/ui/app/AppLayouts/Wallet/views/RightTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/RightTabView.qml @@ -429,7 +429,6 @@ RightTabBaseView { communitiesStore: root.communitiesStore currencyStore: root.sharedRootStore.currencyStore showAllAccounts: RootStore.showAllAccounts - sendModal: root.sendModal filterVisible: filterButton.checked } } diff --git a/ui/imports/shared/views/HistoryView.qml b/ui/imports/shared/views/HistoryView.qml index f3503ee6f0..3d19563e84 100644 --- a/ui/imports/shared/views/HistoryView.qml +++ b/ui/imports/shared/views/HistoryView.qml @@ -37,7 +37,6 @@ ColumnLayout { property CurrenciesStore currencyStore property bool showAllAccounts: false property bool displayValues: true - property var sendModal property bool filterVisible property bool disableShadowOnScroll: false property bool hideVerticalScrollbar: false @@ -279,125 +278,32 @@ ColumnLayout { } } - StatusMenu { - id: delegateMenu + Component { + id: txContextMenu - hideDisabledItems: true + TransactionContextMenu { + required property var modelData - property var transaction - property var transactionDelegate + readonly property var firstTx: SQUtils.ModelUtils.get(modelData.transactions, 0) + readonly property int firstTxChainId: !!firstTx ? firstTx.chainId : 0 + readonly property string firstTxHash: !!firstTx ? firstTx.txHash : "" - function openMenu(delegate, mouse, data) { - if (!delegate || !data) - return + readonly property string networkShortName: Utils.getNetworkShortName(firstTxChainId) + readonly property bool isNetworkTestnet: Utils.isChainIDTestnet(firstTxChainId) - delegateMenu.transactionDelegate = delegate - delegateMenu.transaction = data - popup(delegate, mouse.x, mouse.y) - } + hideDisabledItems: true - onClosed: { - delegateMenu.transaction = null - delegateMenu.transactionDelegate = null - } + networkExplorerName: Utils.getChainExplorerName(networkShortName) - StatusAction { - id: repeatTransactionAction + onClosed: destroy() - text: qsTr("Repeat transaction") - icon.name: "rotate" - - property alias tx: delegateMenu.transaction - - enabled: { - if (!overview.isWatchOnlyAccount && !tx) - return false - return root.walletRootStore.isTxRepeatable(tx) + onCopyTxHashRequested: { + ClipboardUtils.setText(firstTxHash) } - onTriggered: { - if (!tx) - return - let asset = root.walletRootStore.getAssetForSendTx(tx) - - const req = Helpers.lookupAddressesForSendModal(root.walletRootStore.accounts, - root.walletRootStore.savedAddresses, - tx.sender, - tx.recipient, - asset, - tx.isNFT, - tx.amount, - tx.chainId) - - root.sendModal.preSelectedAccountAddress = req.preSelectedAccount.address - root.sendModal.preSelectedRecipient = req.preSelectedRecipient - root.sendModal.preSelectedRecipientType = req.preSelectedRecipientType - root.sendModal.preSelectedHoldingID = req.preSelectedHoldingID - root.sendModal.preSelectedHoldingType = req.preSelectedHoldingType - root.sendModal.preSelectedSendType = req.preSelectedSendType - root.sendModal.preDefinedAmountToSend = req.preDefinedAmountToSend - root.sendModal.preSelectedChainId = req.preSelectedChainId - root.sendModal.onlyAssets = false - root.sendModal.open() - } - } - StatusSuccessAction { - text: qsTr("Copy details") - successText: qsTr("Details copied") - icon.name: "copy" - onTriggered: { - if (!delegateMenu.transactionDelegate) - return - root.walletRootStore.addressWasShown(delegateMenu.transaction.sender) - if (delegateMenu.transaction.sender !== delegateMenu.transaction.recipient) { - root.walletRootStore.addressWasShown(delegateMenu.transaction.recipient) - } - - root.walletRootStore.fetchTxDetails(delegateMenu.transaction.id) - let detailsObj = root.walletRootStore.getTxDetails() - let detailsString = delegateMenu.transactionDelegate.getDetailsString(detailsObj) - ClipboardUtils.setText(detailsString) - } - } - StatusMenuSeparator { - visible: filterAction.enabled - } - StatusAction { - id: filterAction - text: qsTr("Filter by similar") - icon.name: "filter" - onTriggered: { - const store = root.walletRootStore.currentActivityFiltersStore - const tx = delegateMenu.transaction - - store.autoUpdateFilter = false - store.resetAllFilters() - - const currentAddress = overview.mixedcaseAddress.toUpperCase() - - store.toggleType(tx.txType) - // Contract deployment has always ETH symbol. Symbol doesn't affect this type - if (tx.txType !== Constants.TransactionType.ContractDeployment) { - const symbol = tx.symbol - if (!!symbol) - store.toggleToken(symbol) - const inSymbol = tx.inSymbol - if (!!inSymbol && inSymbol !== symbol) - store.toggleToken(inSymbol) - } - if (showAllAccounts || tx.txType !== Constants.TransactionType.Bridge) { - const recipient = tx.recipient.toUpperCase() - if (!!recipient && recipient !== currentAddress && !/0X0+$/.test(recipient)) - store.toggleRecents(recipient) - } - if (tx.isNFT) { - const uid = store.collectiblesList.getUidForData(tx.tokenID, tx.tokenAddress, tx.chainId) - if (!!uid) - store.toggleCollectibles(uid) - } - - store.autoUpdateFilter = true - store.applyAllFilters() + onViewTxOnExplorerRequested: { + let link = Utils.getUrlForTxOnNetwork(networkShortName, isNetworkTestnet, firstTxHash) + Global.openLink(link) } } } @@ -460,7 +366,7 @@ ColumnLayout { community: isModelDataValid && !!communityId && !!root.communitiesStore ? root.communitiesStore.getCommunityDetailsAsJson(communityId) : null onClicked: { if (mouse.button === Qt.RightButton) { - delegateMenu.openMenu(this, mouse, modelData) + txContextMenu.createObject(this, { modelData }).popup(mouse) } } } diff --git a/ui/imports/shared/views/TransactionContextMenu.qml b/ui/imports/shared/views/TransactionContextMenu.qml new file mode 100644 index 0000000000..79e0538abc --- /dev/null +++ b/ui/imports/shared/views/TransactionContextMenu.qml @@ -0,0 +1,25 @@ +import QtQuick 2.15 + +import StatusQ.Popups 0.1 + +StatusMenu { + id: root + + required property string networkExplorerName + + signal viewTxOnExplorerRequested + signal copyTxHashRequested + + StatusAction { + objectName: "viewTxOnExplorerItem" + text: qsTr("View on ") + networkExplorerName + icon.name: "link" + onTriggered: root.viewTxOnExplorerRequested() + } + StatusAction { + objectName: "copyTxHashItem" + text: qsTr("Copy transaction hash") + icon.name: "copy" + onTriggered: root.copyTxHashRequested() + } +} diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index 1c26cb7a19..cd50a73e09 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -644,6 +644,44 @@ QtObject { return getEtherscanUrl(networkShortName, testnetMode, tx, false /* is TX */) } + // Get Chain Explorer name + function getChainExplorerName(networkShortName) { + if (networkShortName === Constants.networkShortChainNames.arbitrum) { + return qsTr("Arbiscan") + } + if (networkShortName === Constants.networkShortChainNames.optimism) { + return qsTr("Optimistic") + } + return qsTr("Etherscan") + } + + // Get ShortName for ChainID + function getNetworkShortName(chainID) { + switch (chainID) { + case Constants.chains.mainnetChainId: + case Constants.chains.sepoliaChainId: + return Constants.networkShortChainNames.mainnet + case Constants.chains.arbitrumChainId: + case Constants.chains.arbitrumSepoliaChainId: + return Constants.networkShortChainNames.arbitrum + case Constants.chains.optimismChainId: + case Constants.chains.optimismSepoliaChainId: + return Constants.networkShortChainNames.optimism + } + return "" + } + + // Is given ChainID a testnet + function isChainIDTestnet(chainID) { + switch (chainID) { + case Constants.chains.mainnetChainId: + case Constants.chains.arbitrumChainId: + case Constants.chains.optimismChainId: + return false + } + return true + } + // 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) diff --git a/vendor/status-go b/vendor/status-go index 7ee45bab1c..b2e83c39a6 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 7ee45bab1cc6ef6da24ade1826f11152153d4783 +Subproject commit b2e83c39a64f8301463b8479bbe766ebe5edf963