Skip to content

Commit 05b4957

Browse files
committed
feat: add loading state
1 parent d970b5b commit 05b4957

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

app/src/main/java/to/bitkit/models/NewTransactionSheetDetails.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ data class NewTransactionSheetDetails(
1717
val direction: NewTransactionSheetDirection,
1818
val paymentHashOrTxId: String? = null,
1919
val sats: Long,
20+
val isLoadingDetails: Boolean = false
2021
) {
2122
companion object {
2223
private const val BACKGROUND_TRANSACTION_KEY = "backgroundTransaction"

app/src/main/java/to/bitkit/ui/sheets/NewTransactionSheet.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ fun NewTransactionSheet(
5555
settingsViewModel: SettingsViewModel,
5656
) {
5757
val currencies by currencyViewModel.uiState.collectAsState()
58+
val newTransaction by appViewModel.newTransaction.collectAsState()
5859

5960
CompositionLocalProvider(
6061
LocalCurrencyViewModel provides currencyViewModel,
@@ -65,10 +66,9 @@ fun NewTransactionSheet(
6566
onDismissRequest = { appViewModel.hideNewTransactionSheet() },
6667
) {
6768
NewTransactionSheetView(
68-
details = appViewModel.newTransaction,
69+
details = newTransaction,
6970
onCloseClick = { appViewModel.hideNewTransactionSheet() },
7071
onDetailClick = {
71-
appViewModel.hideNewTransactionSheet()
7272
appViewModel.onClickActivityDetail()
7373
},
7474
)
@@ -171,6 +171,7 @@ fun NewTransactionSheetView(
171171
text = stringResource(R.string.wallet__send_details),
172172
onClick = onDetailClick,
173173
enabled = details.paymentHashOrTxId != null,
174+
isLoading = details.isLoadingDetails,
174175
modifier = Modifier
175176
.weight(1f)
176177
.testTag("details_button")

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,21 +1031,25 @@ class AppViewModel @Inject constructor(
10311031
}
10321032

10331033
fun onClickActivityDetail() {
1034-
val activityType = newTransaction.type.toActivityFilter()
1035-
val txType = newTransaction.direction.toTxType()
1036-
val paymentHashOrTxId = newTransaction.paymentHashOrTxId ?: return
1037-
1034+
val activityType = _newTransaction.value.type.toActivityFilter()
1035+
val txType = _newTransaction.value.direction.toTxType()
1036+
val paymentHashOrTxId = _newTransaction.value.paymentHashOrTxId ?: return
1037+
_newTransaction.update { it.copy(isLoadingDetails = true) }
10381038
viewModelScope.launch(bgDispatcher) {
10391039
activityRepo.findActivityByPaymentId(
10401040
paymentHashOrTxId = paymentHashOrTxId,
10411041
type = activityType,
10421042
txType = txType,
10431043
retry = true
10441044
).onSuccess { activity ->
1045+
_newTransaction.update { it.copy(isLoadingDetails = false) }
10451046
val nextRoute = Routes.ActivityDetail(activity.rawId())
10461047
mainScreenEffect(MainScreenEffect.Navigate(nextRoute))
1047-
}.onFailure {
1048+
hideNewTransactionSheet()
1049+
}.onFailure { e ->
10481050
Logger.error(msg = "Activity not found", context = TAG)
1051+
toast(e)
1052+
_newTransaction.update { it.copy(isLoadingDetails = false) }
10491053
}
10501054
}
10511055
}
@@ -1205,7 +1209,7 @@ class AppViewModel @Inject constructor(
12051209
var showNewTransaction by mutableStateOf(false)
12061210
private set
12071211

1208-
var newTransaction by mutableStateOf(
1212+
private val _newTransaction = MutableStateFlow(
12091213
NewTransactionSheetDetails(
12101214
type = NewTransactionSheetType.LIGHTNING,
12111215
direction = NewTransactionSheetDirection.RECEIVED,
@@ -1214,6 +1218,8 @@ class AppViewModel @Inject constructor(
12141218
)
12151219
)
12161220

1221+
val newTransaction = _newTransaction.asStateFlow()
1222+
12171223
fun setNewTransactionSheetEnabled(enabled: Boolean) {
12181224
isNewTransactionSheetEnabled = enabled
12191225
}
@@ -1242,7 +1248,7 @@ class AppViewModel @Inject constructor(
12421248
}
12431249
}
12441250

1245-
newTransaction = details
1251+
_newTransaction.update { details }
12461252
showNewTransaction = true
12471253
}
12481254

0 commit comments

Comments
 (0)