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:
read = getStatus
proc getChainId*(self: ActivityEntry): int {.slot.} =
if self.metadata.payloadType == backend.PayloadType.MultiTransaction:
error "getChainId: ActivityEntry is not a transaction"
return 0
proc getChainIdIn*(self: ActivityEntry): int {.slot.} =
return self.metadata.chainIdIn.get(ChainId(0)).int
if self.isInTransactionType():
return self.metadata.chainIdIn.get(ChainId(0)).int
QtProperty[int] chainIdIn:
read = getChainIdIn
proc getChainIdOut*(self: ActivityEntry): int {.slot.} =
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:
read = getChainId

View File

@ -43,11 +43,11 @@ Item {
id: d
readonly property bool isIncoming: transactionType === Constants.TransactionType.Received
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 toBlockNumber: 0 // TODO fill when bridge data is implemented
readonly property string toNetworkIcon: "" // TODO fill when bridge data is implemented
readonly property string toNetworkShortName: "" // TODO fill when bridge data is implemented
readonly property string networkShortNameOut: networkShortName
readonly property string networkShortNameIn: transactionHeader.isMultiTransaction ? RootStore.getNetworkShortName(transaction.chainIdOut) : ""
readonly property string symbol: isTransactionValid ? transaction.symbol : ""
readonly property string inSymbol: isTransactionValid ? transaction.inSymbol : ""
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 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 string toNetworkName: "" // TODO fill network name for bridge
property string decodedInputData: ""
property bool loadingInputDate: false
@ -200,21 +199,25 @@ Item {
Layout.fillHeight: true
title: qsTr("From")
subTitle: {
if (!root.isTransactionValid)
return ""
switch(d.transactionType) {
case Constants.TransactionType.Swap:
return !!d.outSymbol ? d.outSymbol : " "
case Constants.TransactionType.Bridge:
return transactionHeader.networkName
return transactionHeader.networkNameOut
default:
return ""
}
}
asset.name: {
if (!root.isTransactionValid)
return ""
switch(d.transactionType) {
case Constants.TransactionType.Swap:
return Constants.tokenIcon(d.outSymbol)
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:
return ""
}
@ -231,7 +234,7 @@ Item {
case Constants.TransactionType.Swap:
return !!d.inSymbol ? d.inSymbol : " "
case Constants.TransactionType.Bridge:
return d.toNetworkName
return transactionHeader.networkNameIn ?? " "
default:
return ""
}
@ -241,7 +244,7 @@ Item {
case Constants.TransactionType.Swap:
return Constants.tokenIcon(d.inSymbol)
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:
return ""
}
@ -258,7 +261,7 @@ Item {
rootStore: WalletStores.RootStore
onButtonClicked: {
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 {
addressMenu.openSenderMenu(this, addresses[0], d.networkShortName)
}
@ -323,11 +326,11 @@ Item {
}
TransactionDataTile {
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
visible: !!subTitle
buttonIconName: "more"
onButtonClicked: addressMenu.openTxMenu(this, subTitle, d.toNetworkShortName)
onButtonClicked: addressMenu.openTxMenu(this, subTitle, d.networkShortNameIn)
}
TransactionContractTile {
// 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
address: "" // TODO fill protocol contract address for 'to' network for Bridge
symbol: "" // TODO fill protocol name for Bridge
networkName: d.toNetworkName
shortNetworkName: d.toNetworkShortName
networkName: transactionHeader.networknameOut
shortNetworkName: d.networkShortNameOut
visible: !!subTitle && d.transactionType === Constants.TransactionType.Bridge
}
TransactionContractTile {
@ -383,8 +386,8 @@ Item {
return ""
}
}
networkName: d.toNetworkName
shortNetworkName: d.toNetworkShortName
networkName: transactionHeader.networkNameIn
shortNetworkName: d.networkShortNameIn
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 string networkColor: isModelDataValid ? rootStore.getNetworkColor(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 addressNameFrom: isModelDataValid ? walletRootStore.getNameForAddress(modelData.sender) : ""
readonly property bool isNFT: isModelDataValid && modelData.isNFT
@ -268,17 +270,16 @@ StatusListItem {
}
// SUMMARY ADRESSES
const toNetworkName = "" // TODO fill when bridge data is implemented
switch (type) {
case Constants.TransactionType.Swap:
details += qsTr("From") + endl + modelData.outSymbol + endl2
details += qsTr("To") + endl + modelData.inSymbol + endl2
details += qsTr("In") + endl + root.fromAddress + endl2
details += qsTr("In") + endl + modelData.sender + endl2
break
case Constants.TransactionType.Bridge:
details += qsTr("From") + endl + root.networkName + endl2
details += qsTr("To") + endl + toNetworkName + endl2
details += qsTr("In") + endl + modelData.from + endl2
details += qsTr("From") + endl + networkNameOut + endl2
details += qsTr("To") + endl + networkNameIn + endl2
details += qsTr("In") + endl + modelData.sender + endl2
break
case Constants.TransactionType.ContractDeployment:
details += qsTr("From") + endl + modelData.sender + endl2
@ -306,7 +307,7 @@ StatusListItem {
}
const bridgeTxHash = "" // TODO fill tx hash for Bridge
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
if (!!protocolName && !!protocolFromContractAddress) {
@ -320,7 +321,7 @@ StatusListItem {
}
const protocolToContractAddress = "" // TODO fill protocol contract address for 'to' network for Bridge
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
}
const swapContractAddress = "" // TODO fill swap contract address for Swap
@ -334,7 +335,7 @@ StatusListItem {
break
case Constants.TransactionType.Bridge:
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
}
break
@ -351,7 +352,7 @@ StatusListItem {
if (type === Constants.TransactionType.Bridge) {
details += qsTr("Included in Block on %1").arg(networkName) + endl
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
details += rootStore.hex2Dec(bridgeBlockNumber) + endl2
} else {
@ -430,8 +431,8 @@ StatusListItem {
details += valuesString + endl2
}
// Remove unicode characters
details = details.replace(/[^\x00-\x7F]/g, " ");
// Remove no-break space
details = details.replace(/[\xA0]/g, " ");
// Remove empty new lines at the end
return details.replace(/[\r\n\s]*$/, '')
}
@ -453,13 +454,12 @@ StatusListItem {
return qsTr("%1 at %2 via %3").arg(inTransactionValue).arg(toAddress).arg(networkName)
case Constants.TransactionType.Swap:
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)
case Constants.TransactionType.Bridge:
let toNetworkName = "" // TODO fill when Bridge data is implemented
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").arg(inTransactionValue).arg(networkName).arg(toNetworkName)
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(networkNameOut).arg(networkNameIn)
case Constants.TransactionType.ContractDeployment:
const name = addressNameTo || addressNameFrom
return !!modelData.contract ? qsTr("Contract %1 via %2 on %3").arg(Utils.compactAddress(modelData.contract, 4)).arg(name).arg(networkName)