fix(wallet): Repeat transaction updates (#15571)

This commit is contained in:
Cuteivist 2024-07-31 13:58:05 +02:00 committed by GitHub
parent 5d4afba07f
commit 20620e04cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 63 additions and 30 deletions

View File

@ -6,6 +6,7 @@ import StatusQ.Models 0.1
import utils 1.0 import utils 1.0
import SortFilterProxyModel 0.2 import SortFilterProxyModel 0.2
import StatusQ.Core.Utils 0.1 as SQUtils
QtObject { QtObject {
id: root id: root
@ -107,4 +108,26 @@ QtObject {
function getDetailedCollectible(chainId, contractAddress, tokenId) { function getDetailedCollectible(chainId, contractAddress, tokenId) {
walletSection.collectibleDetailsController.getDetailedCollectible(chainId, contractAddress, tokenId) walletSection.collectibleDetailsController.getDetailedCollectible(chainId, contractAddress, tokenId)
} }
function hasNFT(ownerAddress, chainId, tokenId, tokenAddress) {
const uid = getUidForData(tokenId, tokenAddress, chainId)
ownerAddress = ownerAddress.toLowerCase()
const ownership = SQUtils.ModelUtils.getByKey(_allCollectiblesModel, "uid", uid, "ownership")
if (!ownership)
return false
for (let i = 0; i < ownership.count; i++) {
const accountAddress = SQUtils.ModelUtils.get(ownership, i, "accountAddress").toLowerCase()
if (accountAddress !== ownerAddress)
continue
const tokenBalanceStr = SQUtils.ModelUtils.get(ownership, i, "balance").toLowerCase()
if (tokenBalanceStr !== "")
return true
}
return false
}
function getUidForData(tokenId, tokenAddress, chainId) {
return _allCollectiblesModel.getUidForData(tokenId, tokenAddress, chainId)
}
} }

View File

@ -315,17 +315,9 @@ QtObject {
function getAssetForSendTx(tx) { function getAssetForSendTx(tx) {
if (tx.isNFT) { if (tx.isNFT) {
return { return collectiblesStore.getUidForData(tx.tokenID, tx.tokenAddress, tx.chainId)
uid: tx.tokenID,
chainId: tx.chainId,
name: tx.nftName,
imageUrl: tx.nftImageUrl,
collectionUid: "",
collectionName: ""
}
} else {
return tx.symbol
} }
return tx.symbol
} }
function isTxRepeatable(tx) { function isTxRepeatable(tx) {
@ -336,12 +328,14 @@ QtObject {
if (!res || res.walletType === Constants.watchWalletType) if (!res || res.walletType === Constants.watchWalletType)
return false return false
if (tx.isNFT) { if (!tx.amount) {
// TODO #12275: check if account owns enough NFT // Ignore incorrect transactions
} else { return false
// TODO #12275: Check if account owns enough tokens
} }
if (tx.isNFT && !root.collectiblesStore.hasNFT(tx.sender, tx.chainId, tx.tokenID, tx.tokenAddress)) {
return false
}
return true return true
} }

View File

@ -767,7 +767,7 @@ Item {
property alias tx: d.transaction property alias tx: d.transaction
visible: { visible: {
if (!d.isTransactionValid || root.overview.isWatchOnlyAccount) if (!d.isTransactionValid || root.overview.isWatchOnlyAccount || root.overview.isAllAccounts)
return false return false
return WalletStores.RootStore.isTxRepeatable(tx) return WalletStores.RootStore.isTxRepeatable(tx)
@ -780,7 +780,8 @@ Item {
tx.recipient, tx.recipient,
asset, asset,
tx.isNFT, tx.isNFT,
tx.amount) tx.amount,
tx.chainId)
root.sendModal.preSelectedAccountAddress = req.preSelectedAccount.address root.sendModal.preSelectedAccountAddress = req.preSelectedAccount.address
root.sendModal.preSelectedRecipient = req.preSelectedRecipient root.sendModal.preSelectedRecipient = req.preSelectedRecipient
@ -789,6 +790,7 @@ Item {
root.sendModal.preSelectedHoldingType = req.preSelectedHoldingType root.sendModal.preSelectedHoldingType = req.preSelectedHoldingType
root.sendModal.preSelectedSendType = req.preSelectedSendType root.sendModal.preSelectedSendType = req.preSelectedSendType
root.sendModal.preDefinedAmountToSend = req.preDefinedAmountToSend root.sendModal.preDefinedAmountToSend = req.preDefinedAmountToSend
root.sendModal.preSelectedChainId = req.preSelectedChainId
root.sendModal.onlyAssets = false root.sendModal.onlyAssets = false
root.sendModal.open() root.sendModal.open()
} }

View File

@ -1626,6 +1626,7 @@ Item {
property int preSelectedHoldingType: Constants.TokenType.Unknown property int preSelectedHoldingType: Constants.TokenType.Unknown
property int preSelectedSendType: Constants.SendType.Unknown property int preSelectedSendType: Constants.SendType.Unknown
property string preDefinedAmountToSend property string preDefinedAmountToSend
property int preSelectedChainId: 0
property bool onlyAssets: false property bool onlyAssets: false
sourceComponent: SendPopups.SendModal { sourceComponent: SendPopups.SendModal {
@ -1644,6 +1645,7 @@ Item {
sendModal.preSelectedAccountAddress = "" sendModal.preSelectedAccountAddress = ""
sendModal.preSelectedRecipient = undefined sendModal.preSelectedRecipient = undefined
sendModal.preDefinedAmountToSend = "" sendModal.preDefinedAmountToSend = ""
sendModal.preSelectedChainId = 0
} }
} }
onLoaded: { onLoaded: {
@ -1651,8 +1653,9 @@ Item {
item.preSelectedAccountAddress = sendModal.preSelectedAccountAddress item.preSelectedAccountAddress = sendModal.preSelectedAccountAddress
} }
if (!!sendModal.preSelectedRecipient) { if (!!sendModal.preSelectedRecipient) {
item.preSelectedRecipient = sendModal.preSelectedRecipient // NOTE Should be assigned in that order: type then recipient
item.preSelectedRecipientType = sendModal.preSelectedRecipientType item.preSelectedRecipientType = sendModal.preSelectedRecipientType
item.preSelectedRecipient = sendModal.preSelectedRecipient
} }
if(sendModal.preSelectedSendType !== Constants.SendType.Unknown) { if(sendModal.preSelectedSendType !== Constants.SendType.Unknown) {
item.preSelectedSendType = sendModal.preSelectedSendType item.preSelectedSendType = sendModal.preSelectedSendType
@ -1664,6 +1667,9 @@ Item {
if(preDefinedAmountToSend != "") { if(preDefinedAmountToSend != "") {
item.preDefinedAmountToSend = preDefinedAmountToSend item.preDefinedAmountToSend = preDefinedAmountToSend
} }
if(!!sendModal.preSelectedChainId) {
item.preSelectedChainId = sendModal.preSelectedChainId
}
} }
} }

View File

@ -200,7 +200,7 @@ StatusListItem {
readonly property bool isLightTheme: Style.current.name === Constants.lightThemeName readonly property bool isLightTheme: Style.current.name === Constants.lightThemeName
property color animatedBgColor property color animatedBgColor
property int txType: walletRootStore.transactionType(modelData) property int txType: walletRootStore.transactionType(root.modelData)
function addressesEqual(address1, address2) { function addressesEqual(address1, address2) {
return address1.toUpperCase() == address2.toUpperCase() return address1.toUpperCase() == address2.toUpperCase()

View File

@ -29,9 +29,9 @@ QtObject {
preSelectedRecipientType: Helpers.RecipientAddressObjectType.Address, preSelectedRecipientType: Helpers.RecipientAddressObjectType.Address,
preSelectedRecipient: null, preSelectedRecipient: null,
preSelectedHoldingType: Constants.TokenType.Unknown, preSelectedHoldingType: Constants.TokenType.Unknown,
preSelectedHolding: null,
preSelectedHoldingID: "", preSelectedHoldingID: "",
preDefinedAmountToSend: "", preDefinedAmountToSend: "",
preSelectedChainId: 0,
preSelectedSendType: Constants.SendType.Transfer preSelectedSendType: Constants.SendType.Transfer
} }
} }
@ -43,7 +43,8 @@ QtObject {
recipientAddress, recipientAddress,
token, token,
isCollectible, isCollectible,
amount) { amount,
chainId) {
let req = createSendModalRequirements() let req = createSendModalRequirements()
req.preSelectedSendType = Constants.SendType.Transfer req.preSelectedSendType = Constants.SendType.Transfer
@ -70,14 +71,9 @@ QtObject {
req.preSelectedRecipient = recipientAddress req.preSelectedRecipient = recipientAddress
} }
// Holdings related properties: req.preSelectedHoldingType = isCollectible ? Constants.TokenType.ERC721 : Constants.TokenType.ERC20
if (isCollectible) { req.preSelectedHoldingID = token
req.preSelectedHoldingType = Constants.TokenType.ERC721 req.preSelectedChainId = chainId
req.preSelectedHolding = token
} else {
req.preSelectedHoldingType = Constants.TokenType.ERC20
req.preSelectedHoldingID = token
}
req.preDefinedAmountToSend = LocaleUtils.numberToLocaleString(amount) req.preDefinedAmountToSend = LocaleUtils.numberToLocaleString(amount)

View File

@ -40,6 +40,7 @@ StatusDialog {
property alias preSelectedRecipientType: recipientInputLoader.selectedRecipientType property alias preSelectedRecipientType: recipientInputLoader.selectedRecipientType
property string preDefinedAmountToSend property string preDefinedAmountToSend
property int preSelectedChainId: 0
property string stickersPackId property string stickersPackId
// token symbol // token symbol
@ -146,6 +147,10 @@ StatusDialog {
readonly property bool isSelectedHoldingValidAsset: !!selectedHolding && selectedHoldingType === Constants.TokenType.ERC20 readonly property bool isSelectedHoldingValidAsset: !!selectedHolding && selectedHoldingType === Constants.TokenType.ERC20
onSelectedHoldingChanged: { onSelectedHoldingChanged: {
if (!selectedHolding) {
return
}
if (d.selectedHoldingType === Constants.TokenType.ERC20) { if (d.selectedHoldingType === Constants.TokenType.ERC20) {
if(!d.ensOrStickersPurpose && store.sendType !== Constants.SendType.Bridge) if(!d.ensOrStickersPurpose && store.sendType !== Constants.SendType.Bridge)
store.setSendType(Constants.SendType.Transfer) store.setSendType(Constants.SendType.Transfer)
@ -251,6 +256,11 @@ StatusDialog {
amountToSend.setValue(delocalized) amountToSend.setValue(delocalized)
} }
if (!!popup.preSelectedChainId) {
popup.preDefinedAmountToSend = popup.preDefinedAmountToSend.replace(Qt.locale().decimalPoint, '.')
store.updateRoutePreferredChains(popup.preSelectedChainId)
}
if (!!popup.stickersPackId) { if (!!popup.stickersPackId) {
d.extraParamsJson = "{\"%1\":\"%2\"}".arg(Constants.suggestedRoutesExtraParamsProperties.packId).arg(popup.stickersPackId) d.extraParamsJson = "{\"%1\":\"%2\"}".arg(Constants.suggestedRoutesExtraParamsProperties.packId).arg(popup.stickersPackId)

View File

@ -324,15 +324,17 @@ ColumnLayout {
tx.recipient, tx.recipient,
asset, asset,
tx.isNFT, tx.isNFT,
tx.amount) tx.amount,
tx.chainId)
root.sendModal.preSelectedAccountAddress = req.preSelectedAccount.address root.sendModal.preSelectedAccountAddress = req.preSelectedAccount.address
root.sendModal.preSelectedRecipient = req.preSelectedRecipient root.sendModal.preSelectedRecipient = req.preSelectedRecipient
root.sendModal.preSelectedRecipientType = req.preSelectedRecipientType root.sendModal.preSelectedRecipientType = req.preSelectedRecipientType
root.sendModal.preSelectedHoldingID = req.preSelectedHoldingID ?? req.preSelectedHolding.uid root.sendModal.preSelectedHoldingID = req.preSelectedHoldingID
root.sendModal.preSelectedHoldingType = req.preSelectedHoldingType root.sendModal.preSelectedHoldingType = req.preSelectedHoldingType
root.sendModal.preSelectedSendType = req.preSelectedSendType root.sendModal.preSelectedSendType = req.preSelectedSendType
root.sendModal.preDefinedAmountToSend = req.preDefinedAmountToSend root.sendModal.preDefinedAmountToSend = req.preDefinedAmountToSend
root.sendModal.preSelectedChainId = req.preSelectedChainId
root.sendModal.onlyAssets = false root.sendModal.onlyAssets = false
root.sendModal.open() root.sendModal.open()
} }