fix(@desktop/wallet): Show networks for Bridge txs (#11898)

This commit is contained in:
Cuteivist 2023-08-18 10:56:57 +02:00 committed by GitHub
parent ca5b07af42
commit faf4933262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 36 deletions

View File

@ -166,15 +166,23 @@ QtObject:
QtProperty[int] status: QtProperty[int] status:
read = getStatus read = getStatus
proc getChainId*(self: ActivityEntry): int {.slot.} = proc getChainIdIn*(self: ActivityEntry): int {.slot.} =
if self.metadata.payloadType == backend.PayloadType.MultiTransaction: return self.metadata.chainIdIn.get(ChainId(0)).int
error "getChainId: ActivityEntry is not a transaction"
return 0
if self.isInTransactionType(): QtProperty[int] chainIdIn:
return self.metadata.chainIdIn.get(ChainId(0)).int read = getChainIdIn
proc getChainIdOut*(self: ActivityEntry): int {.slot.} =
return self.metadata.chainIdOut.get(ChainId(0)).int return self.metadata.chainIdOut.get(ChainId(0)).int
QtProperty[int] chainIdOut:
read = getChainIdOut
proc getChainId*(self: ActivityEntry): int {.slot.} =
if self.isInTransactionType():
return self.getChainIdIn()
return self.getChainIdOut()
QtProperty[int] chainId: QtProperty[int] chainId:
read = getChainId read = getChainId

View File

@ -43,11 +43,11 @@ Item {
id: d id: d
readonly property bool isIncoming: transactionType === Constants.TransactionType.Received readonly property bool isIncoming: transactionType === Constants.TransactionType.Received
readonly property string networkShortName: root.isTransactionValid ? RootStore.getNetworkShortName(transaction.chainId) : "" readonly property string networkShortName: root.isTransactionValid ? RootStore.getNetworkShortName(transaction.chainId) : ""
readonly property string networkIcon: isTransactionValid ? RootStore.getNetworkIcon(transaction.chainId) : "" readonly property string networkIcon: isTransactionValid ? RootStore.getNetworkIcon(transaction.chainId) : "network/Network=Custom"
readonly property int blockNumber: root.isTransactionValid ? RootStore.hex2Dec(root.transaction.blockNumber) : 0 readonly property int blockNumber: root.isTransactionValid ? RootStore.hex2Dec(root.transaction.blockNumber) : 0
readonly property int toBlockNumber: 0 // TODO fill when bridge data is implemented readonly property int toBlockNumber: 0 // TODO fill when bridge data is implemented
readonly property string toNetworkIcon: "" // TODO fill when bridge data is implemented readonly property string networkShortNameOut: networkShortName
readonly property string toNetworkShortName: "" // TODO fill when bridge data is implemented readonly property string networkShortNameIn: transactionHeader.isMultiTransaction ? RootStore.getNetworkShortName(transaction.chainIdOut) : ""
readonly property string symbol: isTransactionValid ? transaction.symbol : "" readonly property string symbol: isTransactionValid ? transaction.symbol : ""
readonly property string inSymbol: isTransactionValid ? transaction.inSymbol : "" readonly property string inSymbol: isTransactionValid ? transaction.inSymbol : ""
readonly property string outSymbol: isTransactionValid ? transaction.outSymbol : "" readonly property string outSymbol: isTransactionValid ? transaction.outSymbol : ""
@ -77,7 +77,6 @@ Item {
readonly property real feeEthValue: root.isTransactionValid ? RootStore.getGasEthValue(transaction.totalFees.amount, 1) : 0 // TODO use directly? readonly property real feeEthValue: root.isTransactionValid ? RootStore.getGasEthValue(transaction.totalFees.amount, 1) : 0 // TODO use directly?
readonly property real feeFiatValue: root.isTransactionValid ? RootStore.getFiatValue(d.feeEthValue, Constants.ethToken, RootStore.currentCurrency) : 0 // TODO use directly? readonly property real feeFiatValue: root.isTransactionValid ? RootStore.getFiatValue(d.feeEthValue, Constants.ethToken, RootStore.currentCurrency) : 0 // TODO use directly?
readonly property int transactionType: root.isTransactionValid ? transaction.txType : Constants.TransactionType.Send readonly property int transactionType: root.isTransactionValid ? transaction.txType : Constants.TransactionType.Send
readonly property string toNetworkName: "" // TODO fill network name for bridge
property string decodedInputData: "" property string decodedInputData: ""
property bool loadingInputDate: false property bool loadingInputDate: false
@ -200,21 +199,25 @@ Item {
Layout.fillHeight: true Layout.fillHeight: true
title: qsTr("From") title: qsTr("From")
subTitle: { subTitle: {
if (!root.isTransactionValid)
return ""
switch(d.transactionType) { switch(d.transactionType) {
case Constants.TransactionType.Swap: case Constants.TransactionType.Swap:
return !!d.outSymbol ? d.outSymbol : " " return !!d.outSymbol ? d.outSymbol : " "
case Constants.TransactionType.Bridge: case Constants.TransactionType.Bridge:
return transactionHeader.networkName return transactionHeader.networkNameOut
default: default:
return "" return ""
} }
} }
asset.name: { asset.name: {
if (!root.isTransactionValid)
return ""
switch(d.transactionType) { switch(d.transactionType) {
case Constants.TransactionType.Swap: case Constants.TransactionType.Swap:
return Constants.tokenIcon(d.outSymbol) return Constants.tokenIcon(d.outSymbol)
case Constants.TransactionType.Bridge: case Constants.TransactionType.Bridge:
return !!d.networkIcon ? Style.svg(d.networkIcon) : "" return Style.svg(RootStore.getNetworkIcon(root.transaction.chainIdOut)) ?? Style.svg("network/Network=Custom")
default: default:
return "" return ""
} }
@ -231,7 +234,7 @@ Item {
case Constants.TransactionType.Swap: case Constants.TransactionType.Swap:
return !!d.inSymbol ? d.inSymbol : " " return !!d.inSymbol ? d.inSymbol : " "
case Constants.TransactionType.Bridge: case Constants.TransactionType.Bridge:
return d.toNetworkName return transactionHeader.networkNameIn ?? " "
default: default:
return "" return ""
} }
@ -241,7 +244,7 @@ Item {
case Constants.TransactionType.Swap: case Constants.TransactionType.Swap:
return Constants.tokenIcon(d.inSymbol) return Constants.tokenIcon(d.inSymbol)
case Constants.TransactionType.Bridge: case Constants.TransactionType.Bridge:
return !!d.toNetworkIcon ? Style.svg(d.toNetworkIcon) : "" return Style.svg(RootStore.getNetworkIcon(root.transaction.chainIdIn)) ?? Style.svg("network/Network=Custom")
default: default:
return "" return ""
} }
@ -258,7 +261,7 @@ Item {
rootStore: WalletStores.RootStore rootStore: WalletStores.RootStore
onButtonClicked: { onButtonClicked: {
if (d.transactionType === Constants.TransactionType.Swap || d.transactionType === Constants.TransactionType.Bridge) { if (d.transactionType === Constants.TransactionType.Swap || d.transactionType === Constants.TransactionType.Bridge) {
addressMenu.openEthAddressMenu(this, addresses[0], d.networkShortName) addressMenu.openEthAddressMenu(this, addresses[0], d.networkShortNameOut)
} else { } else {
addressMenu.openSenderMenu(this, addresses[0], d.networkShortName) addressMenu.openSenderMenu(this, addresses[0], d.networkShortName)
} }
@ -323,11 +326,11 @@ Item {
} }
TransactionDataTile { TransactionDataTile {
width: parent.width width: parent.width
title: qsTr("%1 Tx hash").arg(d.toNetworkName) title: qsTr("%1 Tx hash").arg(transactionHeader.networkNameIn)
subTitle: "" // TODO fill tx hash for Bridge subTitle: "" // TODO fill tx hash for Bridge
visible: !!subTitle visible: !!subTitle
buttonIconName: "more" buttonIconName: "more"
onButtonClicked: addressMenu.openTxMenu(this, subTitle, d.toNetworkShortName) onButtonClicked: addressMenu.openTxMenu(this, subTitle, d.networkShortNameIn)
} }
TransactionContractTile { TransactionContractTile {
// Used for Bridge and Swap to display 'From' network Protocol contract address // Used for Bridge and Swap to display 'From' network Protocol contract address
@ -353,8 +356,8 @@ Item {
// Used for Bridge to display 'To' network Protocol contract address // Used for Bridge to display 'To' network Protocol contract address
address: "" // TODO fill protocol contract address for 'to' network for Bridge address: "" // TODO fill protocol contract address for 'to' network for Bridge
symbol: "" // TODO fill protocol name for Bridge symbol: "" // TODO fill protocol name for Bridge
networkName: d.toNetworkName networkName: transactionHeader.networknameOut
shortNetworkName: d.toNetworkShortName shortNetworkName: d.networkShortNameOut
visible: !!subTitle && d.transactionType === Constants.TransactionType.Bridge visible: !!subTitle && d.transactionType === Constants.TransactionType.Bridge
} }
TransactionContractTile { TransactionContractTile {
@ -383,8 +386,8 @@ Item {
return "" return ""
} }
} }
networkName: d.toNetworkName networkName: transactionHeader.networkNameIn
shortNetworkName: d.toNetworkShortName shortNetworkName: d.networkShortNameIn
visible: root.isTransactionValid && !!subTitle visible: root.isTransactionValid && !!subTitle
} }
} }

View File

@ -60,6 +60,8 @@ StatusListItem {
readonly property double feeFiatValue: 0.0 // TODO fill when bridge data is implemented readonly property double feeFiatValue: 0.0 // TODO fill when bridge data is implemented
readonly property string networkColor: isModelDataValid ? rootStore.getNetworkColor(modelData.chainId) : "" readonly property string networkColor: isModelDataValid ? rootStore.getNetworkColor(modelData.chainId) : ""
readonly property string networkName: isModelDataValid ? rootStore.getNetworkFullName(modelData.chainId) : "" readonly property string networkName: isModelDataValid ? rootStore.getNetworkFullName(modelData.chainId) : ""
readonly property string networkNameIn: isMultiTransaction ? rootStore.getNetworkFullName(modelData.chainIdIn) : ""
readonly property string networkNameOut: isMultiTransaction ? rootStore.getNetworkFullName(modelData.chainIdOut) : ""
readonly property string addressNameTo: isModelDataValid ? walletRootStore.getNameForAddress(modelData.recipient) : "" readonly property string addressNameTo: isModelDataValid ? walletRootStore.getNameForAddress(modelData.recipient) : ""
readonly property string addressNameFrom: isModelDataValid ? walletRootStore.getNameForAddress(modelData.sender) : "" readonly property string addressNameFrom: isModelDataValid ? walletRootStore.getNameForAddress(modelData.sender) : ""
readonly property bool isNFT: isModelDataValid && modelData.isNFT readonly property bool isNFT: isModelDataValid && modelData.isNFT
@ -268,17 +270,16 @@ StatusListItem {
} }
// SUMMARY ADRESSES // SUMMARY ADRESSES
const toNetworkName = "" // TODO fill when bridge data is implemented
switch (type) { switch (type) {
case Constants.TransactionType.Swap: case Constants.TransactionType.Swap:
details += qsTr("From") + endl + modelData.outSymbol + endl2 details += qsTr("From") + endl + modelData.outSymbol + endl2
details += qsTr("To") + endl + modelData.inSymbol + endl2 details += qsTr("To") + endl + modelData.inSymbol + endl2
details += qsTr("In") + endl + root.fromAddress + endl2 details += qsTr("In") + endl + modelData.sender + endl2
break break
case Constants.TransactionType.Bridge: case Constants.TransactionType.Bridge:
details += qsTr("From") + endl + root.networkName + endl2 details += qsTr("From") + endl + networkNameOut + endl2
details += qsTr("To") + endl + toNetworkName + endl2 details += qsTr("To") + endl + networkNameIn + endl2
details += qsTr("In") + endl + modelData.from + endl2 details += qsTr("In") + endl + modelData.sender + endl2
break break
case Constants.TransactionType.ContractDeployment: case Constants.TransactionType.ContractDeployment:
details += qsTr("From") + endl + modelData.sender + endl2 details += qsTr("From") + endl + modelData.sender + endl2
@ -306,7 +307,7 @@ StatusListItem {
} }
const bridgeTxHash = "" // TODO fill tx hash for Bridge const bridgeTxHash = "" // TODO fill tx hash for Bridge
if (!!bridgeTxHash) { if (!!bridgeTxHash) {
details += qsTr("%1 Tx hash").arg(toNetworkName) + endl + bridgeTxHash + endl2 details += qsTr("%1 Tx hash").arg(networkNameOut) + endl + bridgeTxHash + endl2
} }
const protocolFromContractAddress = "" // TODO fill protocol contract address for 'from' network for Bridge and Swap const protocolFromContractAddress = "" // TODO fill protocol contract address for 'from' network for Bridge and Swap
if (!!protocolName && !!protocolFromContractAddress) { if (!!protocolName && !!protocolFromContractAddress) {
@ -320,7 +321,7 @@ StatusListItem {
} }
const protocolToContractAddress = "" // TODO fill protocol contract address for 'to' network for Bridge const protocolToContractAddress = "" // TODO fill protocol contract address for 'to' network for Bridge
if (!!protocolToContractAddress && !!protocolName) { if (!!protocolToContractAddress && !!protocolName) {
details += qsTr("%1 %2 contract address").arg(toNetworkName).arg(protocolName) + endl details += qsTr("%1 %2 contract address").arg(networkNameOut).arg(protocolName) + endl
details += protocolToContractAddress + endl2 details += protocolToContractAddress + endl2
} }
const swapContractAddress = "" // TODO fill swap contract address for Swap const swapContractAddress = "" // TODO fill swap contract address for Swap
@ -334,7 +335,7 @@ StatusListItem {
break break
case Constants.TransactionType.Bridge: case Constants.TransactionType.Bridge:
if (!!bridgeContractAddress) { if (!!bridgeContractAddress) {
details += qsTr("%1 %2 contract address").arg(toNetworkName).arg(modelData.symbol) + endl details += qsTr("%1 %2 contract address").arg(networkNameOut).arg(modelData.symbol) + endl
details += bridgeContractAddress + endl2 details += bridgeContractAddress + endl2
} }
break break
@ -351,7 +352,7 @@ StatusListItem {
if (type === Constants.TransactionType.Bridge) { if (type === Constants.TransactionType.Bridge) {
details += qsTr("Included in Block on %1").arg(networkName) + endl details += qsTr("Included in Block on %1").arg(networkName) + endl
details += rootStore.hex2Dec(modelData.blockNumber) + endl2 details += rootStore.hex2Dec(modelData.blockNumber) + endl2
details += qsTr("Included in Block on %1").arg(toNetworkName) + endl details += qsTr("Included in Block on %1").arg(networkNameOut) + endl
const bridgeBlockNumber = 0 // TODO fill when bridge data is implemented const bridgeBlockNumber = 0 // TODO fill when bridge data is implemented
details += rootStore.hex2Dec(bridgeBlockNumber) + endl2 details += rootStore.hex2Dec(bridgeBlockNumber) + endl2
} else { } else {
@ -430,8 +431,8 @@ StatusListItem {
details += valuesString + endl2 details += valuesString + endl2
} }
// Remove unicode characters // Remove no-break space
details = details.replace(/[^\x00-\x7F]/g, " "); details = details.replace(/[\xA0]/g, " ");
// Remove empty new lines at the end // Remove empty new lines at the end
return details.replace(/[\r\n\s]*$/, '') return details.replace(/[\r\n\s]*$/, '')
} }
@ -453,13 +454,12 @@ StatusListItem {
return qsTr("%1 at %2 via %3").arg(inTransactionValue).arg(toAddress).arg(networkName) return qsTr("%1 at %2 via %3").arg(inTransactionValue).arg(toAddress).arg(networkName)
case Constants.TransactionType.Swap: case Constants.TransactionType.Swap:
if (allAccounts) if (allAccounts)
return qsTr("%1 to %2 via %3 in %4").arg(outTransactionValue).arg(inTransactionValue).arg(networkName).arg(toAddress) return qsTr("%1 to %2 via %3 in %4").arg(outTransactionValue).arg(inTransactionValue).arg(networkName).arg(fromAddress)
return qsTr("%1 to %2 via %3").arg(outTransactionValue).arg(inTransactionValue).arg(networkName) return qsTr("%1 to %2 via %3").arg(outTransactionValue).arg(inTransactionValue).arg(networkName)
case Constants.TransactionType.Bridge: case Constants.TransactionType.Bridge:
let toNetworkName = "" // TODO fill when Bridge data is implemented
if (allAccounts) if (allAccounts)
return qsTr("%1 from %2 to %3 in %4").arg(inTransactionValue).arg(networkName).arg(toNetworkName).arg(toAddress) return qsTr("%1 from %2 to %3 in %4").arg(inTransactionValue).arg(networkNameOut).arg(networkNameIn).arg(fromAddress)
return qsTr("%1 from %2 to %3").arg(inTransactionValue).arg(networkName).arg(toNetworkName) return qsTr("%1 from %2 to %3").arg(inTransactionValue).arg(networkNameOut).arg(networkNameIn)
case Constants.TransactionType.ContractDeployment: case Constants.TransactionType.ContractDeployment:
const name = addressNameTo || addressNameFrom const name = addressNameTo || addressNameFrom
return !!modelData.contract ? qsTr("Contract %1 via %2 on %3").arg(Utils.compactAddress(modelData.contract, 4)).arg(name).arg(networkName) return !!modelData.contract ? qsTr("Contract %1 via %2 on %3").arg(Utils.compactAddress(modelData.contract, 4)).arg(name).arg(networkName)