Skip to content

Commit 57d09ad

Browse files
committed
feat(services/opencode): refresh account info after successful transactions
Expose refreshAccountState() on AccountController and call it from TransactionController after submitIntent, voidGiftCard, buy, and sell success so timelock unlock detection and account health checks are picked up promptly instead of waiting for the next reconnect or polling cycle. Also add missing updateLimits call in BillTransactionManager receiveGiftCard to match the give/grab/fund flows. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 4cc810f commit 57d09ad

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

services/opencode/src/main/kotlin/com/getcode/opencode/controllers/AccountController.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ class AccountController @Inject constructor(
112112
)
113113
}
114114

115+
suspend fun refreshAccountState() {
116+
fetchAdditionalAccountInfo()
117+
}
118+
115119
private suspend fun fetchAdditionalAccountInfo() {
116120
val owner = cluster.value
117121
if (owner == null) {

services/opencode/src/main/kotlin/com/getcode/opencode/controllers/TransactionController.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import kotlinx.coroutines.flow.map
5151
import kotlinx.coroutines.flow.mapNotNull
5252
import kotlinx.coroutines.flow.onEach
5353
import kotlinx.coroutines.flow.takeWhile
54+
import kotlinx.coroutines.launch
5455
import java.util.concurrent.atomic.AtomicInteger
5556
import javax.inject.Inject
5657
import javax.inject.Singleton
@@ -66,6 +67,10 @@ class TransactionController @Inject constructor(
6667
) : TransactionOperations {
6768
val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
6869

70+
private fun refreshAccountState() {
71+
scope.launch { accountController.refreshAccountState() }
72+
}
73+
6974
private val _limits = MutableStateFlow<Limits?>(Limits.Empty)
7075
override val limits: StateFlow<Limits?>
7176
get() = _limits.asStateFlow()
@@ -187,6 +192,7 @@ class TransactionController @Inject constructor(
187192
type = TraceType.User
188193
)
189194
return repository.voidGiftCard(owner.authority.keyPair, vault)
195+
.onSuccess { refreshAccountState() }
190196
.onFailure {
191197
trace(
192198
tag = "Transactions",
@@ -275,7 +281,7 @@ class TransactionController @Inject constructor(
275281
source = source,
276282
fund = fund,
277283
verifiedState = verifiedState,
278-
)
284+
).onSuccess { refreshAccountState() }
279285
},
280286
onFailure = { error ->
281287
trace(
@@ -304,6 +310,7 @@ class TransactionController @Inject constructor(
304310
of = of,
305311
verifiedState = verifiedState
306312
)
313+
.onSuccess { refreshAccountState() }
307314
.onFailure { error ->
308315
trace(
309316
tag = "TransactionController",
@@ -329,6 +336,7 @@ class TransactionController @Inject constructor(
329336
intent: IntentType,
330337
authority: KeyPair,
331338
): Result<IntentType> = repository.submitIntent(scope, intent, authority)
339+
.onSuccess { refreshAccountState() }
332340

333341
suspend fun getIntentMetadata(
334342
intentId: PublicKey,

services/opencode/src/main/kotlin/com/getcode/opencode/managers/BillTransactionManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ class BillTransactionManager @Inject constructor(
262262
receiveTransactor?.start(claimIfOwned)
263263
?.onSuccess { (token, amount) ->
264264
onReceived(token, amount)
265+
transactionController.updateLimits(owner, force = true)
265266
}?.onFailure {
266267
onError(it)
267268
transactor.dispose()

0 commit comments

Comments
 (0)