Skip to content

Commit aea2445

Browse files
authored
Merge pull request #208 from code-payments/fix/guard-against-any-relationship-balance-when-receive
fix(api/transactions): guard against empty relationship partial balance
2 parents bef9483 + 5f2b7de commit aea2445

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

api/src/main/java/com/getcode/network/client/TransactionReceiver.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,32 @@ class TransactionReceiver @Inject constructor(
5959
}
6060
}
6161

62-
fun receiveFromRelationship( organizer: Organizer, limit: Kin? = null): Kin {
62+
fun receiveFromRelationship(organizer: Organizer, limit: Kin? = null): Kin {
6363
var receivedTotal = Kin.fromKin(0)
6464

6565
run loop@{
6666
organizer.relationshipsLargestFirst().onEach { relationship ->
6767
Timber.d("Receiving from relationships: ${relationship.partialBalance}")
6868

69-
val intent = transactionRepository.receiveFromRelationship(
70-
relationship.domain, relationship.partialBalance, organizer
71-
).blockingGet()
69+
if (relationship.partialBalance > 0) {
70+
// Ignore empty relationship accounts
71+
} else {
72+
val intent = transactionRepository.receiveFromRelationship(
73+
domain = relationship.domain,
74+
amount = relationship.partialBalance,
75+
organizer = organizer
76+
).blockingGet()
7277

73-
receivedTotal += relationship.partialBalance
78+
receivedTotal += relationship.partialBalance
7479

75-
if (intent is IntentDeposit) {
76-
setTray(organizer, intent.resultTray)
77-
}
80+
if (intent is IntentDeposit) {
81+
setTray(organizer, intent.resultTray)
82+
}
7883

79-
// Bail early if a limit is set
80-
if (limit != null && receivedTotal >= limit) {
81-
return@loop // break loop
84+
// Bail early if a limit is set
85+
if (limit != null && receivedTotal >= limit) {
86+
return@loop // break loop
87+
}
8288
}
8389
}
8490
}

0 commit comments

Comments
 (0)