@@ -2,6 +2,7 @@ package to.bitkit.ui.screens.wallets.activity
22
33import android.content.Intent
44import androidx.compose.foundation.layout.Arrangement
5+ import androidx.compose.foundation.layout.Box
56import androidx.compose.foundation.layout.Column
67import androidx.compose.foundation.layout.ColumnScope
78import androidx.compose.foundation.layout.Row
@@ -73,55 +74,117 @@ fun ActivityExploreScreen(
7374 route : Routes .ActivityExplore ,
7475 onBackClick : () -> Unit ,
7576) {
76- val activities by listViewModel.filteredActivities.collectAsStateWithLifecycle()
77- val item = activities?.find { it.rawId() == route.id } ? : return
77+ val uiState by detailViewModel.uiState.collectAsStateWithLifecycle()
7878
79- val app = appViewModel ? : return
80- val context = LocalContext .current
81-
82- val txDetails by detailViewModel.txDetails.collectAsStateWithLifecycle()
83- var boostTxDoesExist by remember { mutableStateOf<Map <String , Boolean >>(emptyMap()) }
84-
85- LaunchedEffect (item) {
86- if (item is Activity .Onchain ) {
87- detailViewModel.fetchTransactionDetails(item.v1.txId)
88- if (item.v1.boostTxIds.isNotEmpty()) {
89- boostTxDoesExist = detailViewModel.getBoostTxDoesExist(item.v1.boostTxIds)
90- }
91- } else {
92- detailViewModel.clearTransactionDetails()
93- }
79+ // Load activity on composition
80+ LaunchedEffect (route.id) {
81+ detailViewModel.loadActivity(route.id)
9482 }
9583
84+ // Clear state on disposal
9685 DisposableEffect (Unit ) {
9786 onDispose {
98- detailViewModel.clearTransactionDetails ()
87+ detailViewModel.clearActivityState ()
9988 }
10089 }
10190
10291 ScreenColumn {
103- AppTopBar (
104- titleText = stringResource(item.getScreenTitleRes()),
105- onBackClick = onBackClick,
106- actions = { DrawerNavIcon () },
107- )
108- ActivityExploreContent (
109- item = item,
110- txDetails = txDetails,
111- boostTxDoesExist = boostTxDoesExist,
112- onCopy = { text ->
113- app.toast(
114- type = Toast .ToastType .SUCCESS ,
115- title = context.getString(R .string.common__copied),
116- description = text.ellipsisMiddle(40 ),
92+ when (val loadState = uiState.activityLoadState) {
93+ is ActivityDetailViewModel .ActivityLoadState .Initial ,
94+ is ActivityDetailViewModel .ActivityLoadState .Loading ,
95+ -> {
96+ // Loading state
97+ AppTopBar (
98+ titleText = stringResource(R .string.wallet__activity),
99+ onBackClick = onBackClick,
100+ actions = { DrawerNavIcon () },
117101 )
118- },
119- onClickExplore = { txid ->
120- val url = getBlockExplorerUrl(txid)
121- val intent = Intent (Intent .ACTION_VIEW , url.toUri())
122- context.startActivity(intent)
123- },
124- )
102+ Box (
103+ modifier = Modifier
104+ .fillMaxHeight()
105+ .padding(16 .dp),
106+ contentAlignment = Alignment .Center
107+ ) {
108+ CircularProgressIndicator ()
109+ }
110+ }
111+
112+ is ActivityDetailViewModel .ActivityLoadState .Error -> {
113+ // Error state
114+ AppTopBar (
115+ titleText = stringResource(R .string.wallet__activity),
116+ onBackClick = onBackClick,
117+ actions = { DrawerNavIcon () },
118+ )
119+ Column (
120+ modifier = Modifier
121+ .fillMaxHeight()
122+ .padding(16 .dp),
123+ horizontalAlignment = Alignment .CenterHorizontally ,
124+ verticalArrangement = Arrangement .Center
125+ ) {
126+ BodySSB (
127+ text = loadState.message,
128+ modifier = Modifier .padding(bottom = 16 .dp)
129+ )
130+ PrimaryButton (
131+ text = stringResource(R .string.common__back),
132+ onClick = onBackClick
133+ )
134+ }
135+ }
136+
137+ is ActivityDetailViewModel .ActivityLoadState .Success -> {
138+ val item = loadState.activity
139+ val app = appViewModel ? : return @ScreenColumn
140+ val context = LocalContext .current
141+
142+ val txDetails by detailViewModel.txDetails.collectAsStateWithLifecycle()
143+ var boostTxDoesExist by remember { mutableStateOf<Map <String , Boolean >>(emptyMap()) }
144+
145+ LaunchedEffect (item) {
146+ if (item is Activity .Onchain ) {
147+ detailViewModel.fetchTransactionDetails(item.v1.txId)
148+ if (item.v1.boostTxIds.isNotEmpty()) {
149+ boostTxDoesExist = detailViewModel.getBoostTxDoesExist(item.v1.boostTxIds)
150+ }
151+ } else {
152+ detailViewModel.clearTransactionDetails()
153+ }
154+ }
155+
156+ DisposableEffect (Unit ) {
157+ onDispose {
158+ detailViewModel.clearTransactionDetails()
159+ }
160+ }
161+
162+ AppTopBar (
163+ titleText = stringResource(item.getScreenTitleRes()),
164+ onBackClick = onBackClick,
165+ actions = { DrawerNavIcon () },
166+ )
167+
168+ val toastMessage = stringResource(R .string.common__copied)
169+ ActivityExploreContent (
170+ item = item,
171+ txDetails = txDetails,
172+ boostTxDoesExist = boostTxDoesExist,
173+ onCopy = { text ->
174+ app.toast(
175+ type = Toast .ToastType .SUCCESS ,
176+ title = toastMessage,
177+ description = text.ellipsisMiddle(40 ),
178+ )
179+ },
180+ onClickExplore = { txid ->
181+ val url = getBlockExplorerUrl(txid)
182+ val intent = Intent (Intent .ACTION_VIEW , url.toUri())
183+ context.startActivity(intent)
184+ },
185+ )
186+ }
187+ }
125188 }
126189}
127190
0 commit comments