Skip to content

Commit 2472613

Browse files
committed
[trello.com/c/Aw0Vfnmd] Code review improvments.
1 parent c87b13d commit 2472613

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Adamant/Services/AdamantCoinStorageService.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,37 @@ private extension AdamantCoinStorageService {
108108
.sink { [weak self] notification in
109109
let changes = notification.managedObjectContextChanges(of: CoinTransaction.self)
110110

111-
guard self != nil, self?.coinId != nil && self?.coinAddress != nil else {
111+
guard let self else {
112112
return
113113
}
114114

115-
let uniqueId = self!.coinId + self!.coinAddress
115+
let uniqueId = self.coinId + self.coinAddress
116116

117117
if let inserted = changes.inserted, !inserted.isEmpty {
118118
let filteredInserted: [TransactionDetails] = inserted.filter {
119119
$0.uniqueId == uniqueId
120120
}
121-
self?.transactions.append(contentsOf: filteredInserted)
121+
self.transactions.append(contentsOf: filteredInserted)
122122
}
123123

124124
if let updated = changes.updated, !updated.isEmpty {
125125
let filteredUpdated = updated.filter { $0.uniqueId == uniqueId }
126126

127127
filteredUpdated.forEach { coinTransaction in
128-
guard let index = self?.transactions.firstIndex(where: {
128+
guard let index = self.transactions.firstIndex(where: {
129129
$0.txId == coinTransaction.txId
130130
})
131131
else { return }
132132

133133
/*
134134
Workaround to correctly set isOutgoing when multiple transactions share the same txId across different accounts.
135135

136-
This situation can happen when sending funds from a regular account to a secret one — technically two different transactions, but with the same txId.
136+
This situation can happen when sending funds from a regular account to a secret one or vica versa — technically is the same transaction, but it should show different isOutgoing for sender and reciever.
137+
137138
Currently, there's no reliable way to assign a truly unique ID to each TransactionDetails instance, so this workaround helps distinguish them for now.
138139
PR - https://github.com/Adamant-im/adamant-iOS/pull/741
139140
*/
140-
self?.transactions[index] = SimpleTransactionDetails(
141+
self.transactions[index] = SimpleTransactionDetails(
141142
defaultCurrencySymbol: coinTransaction.defaultCurrencySymbol,
142143
txId: coinTransaction.txId,
143144
senderAddress: coinTransaction.senderAddress,
@@ -147,7 +148,7 @@ private extension AdamantCoinStorageService {
147148
feeValue: coinTransaction.feeValue,
148149
confirmationsValue: coinTransaction.confirmationsValue,
149150
blockValue: coinTransaction.blockValue,
150-
isOutgoing: self?.coinAddress == coinTransaction.senderAddress ? true : false,
151+
isOutgoing: self.coinAddress == coinTransaction.senderAddress ? true : false,
151152
transactionStatus: coinTransaction.transactionStatus,
152153
nonceRaw: coinTransaction.nonceRaw)
153154
}

0 commit comments

Comments
 (0)