mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-28 07:15:21 +00:00
fix(@desktop/wallet): use unique activity entry key
This commit is contained in:
parent
7c0eb01294
commit
293ffd647e
@ -138,11 +138,8 @@ QtObject:
|
|||||||
transactions:{$self.transactions},
|
transactions:{$self.transactions},
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
# TODO: is this the right way to pass transaction identity? Why not use the instance?
|
|
||||||
proc getId*(self: ActivityEntry): string {.slot.} =
|
proc getId*(self: ActivityEntry): string {.slot.} =
|
||||||
if self.isMultiTransaction():
|
return self.metadata.getKey()
|
||||||
return $(self.metadata.getMultiTransactionId().get())
|
|
||||||
return $(self.metadata.getTransactionIdentity().get().hash)
|
|
||||||
|
|
||||||
QtProperty[string] id:
|
QtProperty[string] id:
|
||||||
read = getId
|
read = getId
|
||||||
|
@ -101,17 +101,6 @@ QtObject:
|
|||||||
self.countChanged()
|
self.countChanged()
|
||||||
self.setHasMore(hasMore)
|
self.setHasMore(hasMore)
|
||||||
|
|
||||||
proc sameIdentity(e: entry.ActivityEntry, d: backend.Data): bool =
|
|
||||||
let m = e.getMetadata()
|
|
||||||
if m.getPayloadType() != d.payloadType:
|
|
||||||
return false
|
|
||||||
|
|
||||||
if m.getPayloadType() == MultiTransaction:
|
|
||||||
let dID = d.id.get()
|
|
||||||
return dID > 0 and m.getMultiTransactionId().get(0) == dID
|
|
||||||
|
|
||||||
return m.getTransactionIdentity().isSome() and d.transaction.isSome() and m.getTransactionIdentity().get() == d.transaction.get()
|
|
||||||
|
|
||||||
proc addNewEntries*(self: Model, newEntries: seq[entry.ActivityEntry], insertPositions: seq[int]) =
|
proc addNewEntries*(self: Model, newEntries: seq[entry.ActivityEntry], insertPositions: seq[int]) =
|
||||||
let parentModelIndex = newQModelIndex()
|
let parentModelIndex = newQModelIndex()
|
||||||
defer: parentModelIndex.delete
|
defer: parentModelIndex.delete
|
||||||
@ -128,7 +117,7 @@ QtObject:
|
|||||||
proc updateEntries*(self: Model, updates: seq[backend.Data]) =
|
proc updateEntries*(self: Model, updates: seq[backend.Data]) =
|
||||||
for i in countdown(self.entries.high, 0):
|
for i in countdown(self.entries.high, 0):
|
||||||
for j in countdown(updates.high, 0):
|
for j in countdown(updates.high, 0):
|
||||||
if sameIdentity(self.entries[i], updates[j]):
|
if self.entries[i].getId() == updates[j].key:
|
||||||
if updates[j].nftName.isSome():
|
if updates[j].nftName.isSome():
|
||||||
self.entries[i].setNftName(updates[j].nftName.get())
|
self.entries[i].setNftName(updates[j].nftName.get())
|
||||||
if updates[j].nftUrl.isSome():
|
if updates[j].nftUrl.isSome():
|
||||||
@ -143,12 +132,6 @@ QtObject:
|
|||||||
QtProperty[bool] hasMore:
|
QtProperty[bool] hasMore:
|
||||||
read = getHasMore
|
read = getHasMore
|
||||||
notify = hasMoreChanged
|
notify = hasMoreChanged
|
||||||
|
|
||||||
proc getIndex*(self: Model, txHash: string): int {.slot.} =
|
|
||||||
for i, e in self.entries:
|
|
||||||
if e.getId() == txHash:
|
|
||||||
return i
|
|
||||||
return -1
|
|
||||||
|
|
||||||
proc refreshItemsContainingAddress*(self: Model, address: string) =
|
proc refreshItemsContainingAddress*(self: Model, address: string) =
|
||||||
for i in 0..self.entries.high:
|
for i in 0..self.entries.high:
|
||||||
|
@ -295,6 +295,7 @@ type
|
|||||||
ActivityEntry* = object
|
ActivityEntry* = object
|
||||||
# Identification
|
# Identification
|
||||||
payloadType: PayloadType
|
payloadType: PayloadType
|
||||||
|
key: string
|
||||||
transaction: Option[TransactionIdentity]
|
transaction: Option[TransactionIdentity]
|
||||||
id: int
|
id: int
|
||||||
|
|
||||||
@ -327,6 +328,7 @@ type
|
|||||||
# Mirrors status-go/services/wallet/activity/activity.go EntryData
|
# Mirrors status-go/services/wallet/activity/activity.go EntryData
|
||||||
Data* = object
|
Data* = object
|
||||||
payloadType*: PayloadType
|
payloadType*: PayloadType
|
||||||
|
key*: string
|
||||||
transaction*: Option[TransactionIdentity]
|
transaction*: Option[TransactionIdentity]
|
||||||
id*: Option[int]
|
id*: Option[int]
|
||||||
|
|
||||||
@ -389,6 +391,9 @@ type
|
|||||||
proc getPayloadType*(ae: ActivityEntry): PayloadType =
|
proc getPayloadType*(ae: ActivityEntry): PayloadType =
|
||||||
return ae.payloadType
|
return ae.payloadType
|
||||||
|
|
||||||
|
proc getKey*(ae: ActivityEntry): string =
|
||||||
|
return ae.key
|
||||||
|
|
||||||
proc getTransactionIdentity*(ae: ActivityEntry): Option[TransactionIdentity] =
|
proc getTransactionIdentity*(ae: ActivityEntry): Option[TransactionIdentity] =
|
||||||
if ae.payloadType == PayloadType.MultiTransaction:
|
if ae.payloadType == PayloadType.MultiTransaction:
|
||||||
return none(TransactionIdentity)
|
return none(TransactionIdentity)
|
||||||
@ -408,6 +413,7 @@ proc toJson*(ae: ActivityEntry): JsonNode {.inline.} =
|
|||||||
return %*(ae)
|
return %*(ae)
|
||||||
|
|
||||||
proc fromJson*(e: JsonNode, T: typedesc[Data]): Data {.inline.} =
|
proc fromJson*(e: JsonNode, T: typedesc[Data]): Data {.inline.} =
|
||||||
|
const keyField = "key"
|
||||||
const transactionField = "transaction"
|
const transactionField = "transaction"
|
||||||
const idField = "id"
|
const idField = "id"
|
||||||
const transactionsField = "transactions"
|
const transactionsField = "transactions"
|
||||||
@ -433,6 +439,7 @@ proc fromJson*(e: JsonNode, T: typedesc[Data]): Data {.inline.} =
|
|||||||
const isNewField = "isNew"
|
const isNewField = "isNew"
|
||||||
result = T(
|
result = T(
|
||||||
payloadType: fromJson(e["payloadType"], PayloadType),
|
payloadType: fromJson(e["payloadType"], PayloadType),
|
||||||
|
key: e[keyField].getStr(),
|
||||||
transaction: if e.hasKey(transactionField):
|
transaction: if e.hasKey(transactionField):
|
||||||
fromJson(e[transactionField], Option[TransactionIdentity])
|
fromJson(e[transactionField], Option[TransactionIdentity])
|
||||||
else:
|
else:
|
||||||
@ -503,6 +510,7 @@ proc fromJson*(e: JsonNode, T: typedesc[ActivityEntry]): ActivityEntry {.inline.
|
|||||||
let zeroValue: UInt256 = "0x0".parse(UInt256, 16)
|
let zeroValue: UInt256 = "0x0".parse(UInt256, 16)
|
||||||
result = T(
|
result = T(
|
||||||
payloadType: data.payloadType,
|
payloadType: data.payloadType,
|
||||||
|
key: data.key,
|
||||||
transaction: data.transaction,
|
transaction: data.transaction,
|
||||||
id: if data.id.isSome: data.id.get() else: 0,
|
id: if data.id.isSome: data.id.get() else: 0,
|
||||||
transactions: data.transactions,
|
transactions: data.transactions,
|
||||||
@ -531,6 +539,7 @@ proc `$`*(self: ActivityEntry): string =
|
|||||||
else: "none(TransactionIdentity)"
|
else: "none(TransactionIdentity)"
|
||||||
return fmt"""ActivityEntry(
|
return fmt"""ActivityEntry(
|
||||||
payloadType:{$self.payloadType},
|
payloadType:{$self.payloadType},
|
||||||
|
key:{$self.key},
|
||||||
transaction:{transactionStr},
|
transaction:{transactionStr},
|
||||||
id:{self.id},
|
id:{self.id},
|
||||||
transactions:{self.transactions},
|
transactions:{self.transactions},
|
||||||
|
@ -2,10 +2,10 @@ import unittest, json, options
|
|||||||
|
|
||||||
import backend/activity
|
import backend/activity
|
||||||
|
|
||||||
const testOneNewJsonData = "{\"new\": [{\"pos\": 3, \"entry\": {\"payloadType\": 1, \"id\": 12, \"activityType\": 1, \"activityStatus\": 2, \"timestamp\": 1234567890, \"isNew\": true}}]}"
|
const testOneNewJsonData = "{\"new\": [{\"pos\": 3, \"entry\": {\"payloadType\": 1, \"key\": \"12ABCD\", \"id\": 12, \"activityType\": 1, \"activityStatus\": 2, \"timestamp\": 1234567890, \"isNew\": true}}]}"
|
||||||
const testOneNewJsonDataMissingIsNew = "{\"new\": [{\"pos\": 3, \"entry\": {\"payloadType\": 1, \"id\": 12, \"activityType\": 1, \"activityStatus\": 2, \"timestamp\": 1234567890}}]}"
|
const testOneNewJsonDataMissingIsNew = "{\"new\": [{\"pos\": 3, \"entry\": {\"payloadType\": 1, \"key\": \"12ABCD\", \"id\": 12, \"activityType\": 1, \"activityStatus\": 2, \"timestamp\": 1234567890}}]}"
|
||||||
const oneRemovedJsonTestData = "{\"removed\":[{\"chainId\": 7, \"hash\": \"0x5\", \"address\": \"0x6\"}]}"
|
const oneRemovedJsonTestData = "{\"removed\":[{\"chainId\": 7, \"hash\": \"0x5\", \"address\": \"0x6\"}]}"
|
||||||
const testAllSetJsonData = "{\"hasNewOnTop\": true, \"new\": [{\"pos\": 3, \"entry\": {\"payloadType\": 1, \"id\": 12, \"activityType\": 1, \"activityStatus\": 2, \"timestamp\": 1234567890, \"isNew\": true}}], \"removed\":[{\"chainId\": 7, \"hash\": \"0x5\", \"address\": \"0x6\"}]}"
|
const testAllSetJsonData = "{\"hasNewOnTop\": true, \"new\": [{\"pos\": 3, \"entry\": {\"payloadType\": 1, \"key\": \"12ABCD\", \"id\": 12, \"activityType\": 1, \"activityStatus\": 2, \"timestamp\": 1234567890, \"isNew\": true}}], \"removed\":[{\"chainId\": 7, \"hash\": \"0x5\", \"address\": \"0x6\"}]}"
|
||||||
|
|
||||||
suite "activity filter API json parsing":
|
suite "activity filter API json parsing":
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user