Skip to content

Commit

Permalink
- fix UI crash on closing trade
Browse files Browse the repository at this point in the history
  • Loading branch information
rodvar committed Jan 14, 2025
1 parent eae85ab commit a80b06e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ abstract class BasePresenter(private val rootPresenter: MainPresenter?): ViewPre
}

override fun showSnackbar(message: String, isError: Boolean) {
uiScope.launch {
uiScope.launch(Dispatchers.Main) {
snackbarHostState.showSnackbar(message, withDismissAction = true)
}
}
Expand Down Expand Up @@ -175,13 +175,16 @@ abstract class BasePresenter(private val rootPresenter: MainPresenter?): ViewPre
}

override fun goBack(): Boolean {
try {
log.i { "goBack default implementation" }
return rootNavigator.popBackStack()
} catch (e: Exception) {
log.e(e) { "Failed to navigate back" }
return false
var wentBack = false
uiScope.launch {
try {
log.i { "goBack default implementation" }
wentBack = rootNavigator.popBackStack()
} catch (e: Exception) {
log.e(e) { "Failed to navigate back" }
}
}
return wentBack;
}

@CallSuper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ class BuyerState4Presenter(

fun onCloseTrade() {
jobs.add(CoroutineScope(BackgroundDispatcher).launch {
tradesServiceFacade.closeTrade()
val result = tradesServiceFacade.closeTrade()
when {
// TODO review
result.isFailure -> leaveScreen()
result.isSuccess -> leaveScreen()
}
})
}


fun leaveScreen() {
presenterScope.launch {
navigateBack()
}
}

fun onExportTradeDate() {
jobs.add(CoroutineScope(BackgroundDispatcher).launch {
tradesServiceFacade.exportTradeDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SellerState3aPresenter(

fun onConfirmedBtcSent() {
require(paymentProof.value.isNotEmpty())
job = CoroutineScope(BackgroundDispatcher).launch {
job = backgroundScope.launch {
tradesServiceFacade.sellerConfirmBtcSent(paymentProof.value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ class SellerState4Presenter(

fun onCloseTrade() {
jobs.add(CoroutineScope(BackgroundDispatcher).launch {
tradesServiceFacade.closeTrade()
val result = tradesServiceFacade.closeTrade()
when {
// TODO review
result.isFailure -> leaveScreen()
result.isSuccess -> leaveScreen()
}
})
}

fun leaveScreen() {
presenterScope.launch {
navigateBack()
}
}

fun onExportTradeDate() {
jobs.add(CoroutineScope(BackgroundDispatcher).launch {
tradesServiceFacade.exportTradeDate()
Expand Down

0 comments on commit a80b06e

Please sign in to comment.