Skip to content

Commit 7947e1c

Browse files
committed
refactor: split trezor ui state
1 parent cd6c766 commit 7947e1c

9 files changed

Lines changed: 326 additions & 158 deletions

File tree

app/src/main/java/to/bitkit/ui/screens/trezor/AddressSection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private fun PreviewAddressSectionLoading() {
150150
AppThemeSurface {
151151
AddressSection(
152152
trezorState = TrezorPreviewData.connectedState,
153-
uiState = TrezorUiState(isGettingAddress = true),
153+
uiState = TrezorUiState(network = TrezorNetworkState(isGettingAddress = true)),
154154
onGetAddress = {},
155155
onIncrementIndex = {},
156156
)

app/src/main/java/to/bitkit/ui/screens/trezor/BalanceLookupSection.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,12 @@ private fun PreviewBalanceLookupWithAddressInfo() {
330330
private fun PreviewBalanceLookupLoading() {
331331
AppThemeSurface {
332332
BalanceLookupSection(
333-
uiState = TrezorUiState(lookupInput = "xpub6C...", isLookingUp = true),
333+
uiState = TrezorUiState(
334+
lookup = TrezorLookupState(
335+
input = "xpub6C...",
336+
isLookingUp = true,
337+
),
338+
),
334339
isDeviceConnected = false,
335340
onInputChange = {},
336341
onLookup = {},

app/src/main/java/to/bitkit/ui/screens/trezor/PublicKeySection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private fun PreviewPublicKeySectionLoading() {
176176
AppThemeSurface {
177177
PublicKeySection(
178178
trezorState = TrezorPreviewData.connectedState,
179-
uiState = TrezorUiState(isGettingPublicKey = true),
179+
uiState = TrezorUiState(network = TrezorNetworkState(isGettingPublicKey = true)),
180180
onGetPublicKey = {},
181181
)
182182
}

app/src/main/java/to/bitkit/ui/screens/trezor/SendTransactionSection.kt

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ internal fun SendTransactionSection(
6868
)
6969
VerticalSpacer(8.dp)
7070

71-
when (uiState.sendStep) {
72-
SendStep.FORM -> ComposeForm(
71+
when (val step = uiState.sendStep) {
72+
SendStep.Form -> ComposeForm(
7373
uiState = uiState,
7474
onAddressChange = onAddressChange,
7575
onAmountChange = onAmountChange,
@@ -78,24 +78,20 @@ internal fun SendTransactionSection(
7878
onCoinSelectionChange = onCoinSelectionChange,
7979
onCompose = onCompose,
8080
)
81-
SendStep.REVIEW -> uiState.composeResult?.let { result ->
82-
ReviewSection(
83-
result = result,
84-
isDeviceConnected = isDeviceConnected,
85-
isSigning = uiState.isSigning,
86-
onSign = onSign,
87-
onBack = onBack,
88-
)
89-
}
90-
SendStep.SIGNED -> uiState.signedTxResult?.let { signedTx ->
91-
SignedResultSection(
92-
signedTx = signedTx,
93-
isBroadcasting = uiState.isBroadcasting,
94-
broadcastTxid = uiState.broadcastTxid,
95-
onBroadcast = onBroadcast,
96-
onReset = onReset,
97-
)
98-
}
81+
is SendStep.Review -> ReviewSection(
82+
result = step.composeResult,
83+
isDeviceConnected = isDeviceConnected,
84+
isSigning = uiState.isSigning,
85+
onSign = onSign,
86+
onBack = onBack,
87+
)
88+
is SendStep.Signed -> SignedResultSection(
89+
signedTx = step.signedTx,
90+
isBroadcasting = uiState.isBroadcasting,
91+
broadcastTxid = step.broadcastTxid,
92+
onBroadcast = onBroadcast,
93+
onReset = onReset,
94+
)
9995
}
10096
}
10197
}
@@ -405,9 +401,11 @@ private fun PreviewSendFormFilled() {
405401
AppThemeSurface {
406402
SendTransactionSection(
407403
uiState = TrezorUiState(
408-
sendAddress = "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
409-
sendAmountSats = "45000",
410-
sendFeeRate = "5",
404+
send = TrezorSendState(
405+
address = "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
406+
amountSats = "45000",
407+
feeRate = "5",
408+
),
411409
),
412410
isDeviceConnected = true,
413411
onAddressChange = {},

app/src/main/java/to/bitkit/ui/screens/trezor/SignMessageSection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private fun PreviewSignMessageSectionWithSignature() {
158158
private fun PreviewSignMessageSectionSigning() {
159159
AppThemeSurface {
160160
SignMessageSection(
161-
uiState = TrezorUiState(isSigningMessage = true),
161+
uiState = TrezorUiState(message = TrezorMessageState(isSigningMessage = true)),
162162
onMessageChange = {},
163163
onSignMessage = {},
164164
onVerifyMessage = {},

app/src/main/java/to/bitkit/ui/screens/trezor/TransactionHistorySection.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ private fun PreviewTransactionHistoryEmpty() {
175175
private fun PreviewTransactionHistoryLoading() {
176176
AppThemeSurface {
177177
TransactionHistorySection(
178-
uiState = TrezorUiState(txHistoryInput = "vpub5Y...", isLoadingTxHistory = true),
178+
uiState = TrezorUiState(
179+
txHistory = TrezorTxHistoryState(
180+
input = "vpub5Y...",
181+
isLoading = true,
182+
),
183+
),
179184
onInputChange = {},
180185
onLookup = {},
181186
)

app/src/main/java/to/bitkit/ui/screens/trezor/TrezorPreviewData.kt

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -201,36 +201,42 @@ internal object TrezorPreviewData {
201201
)
202202

203203
val uiStateWithSignature = TrezorUiState(
204-
selectedNetwork = BitkitCoreNetwork.REGTEST,
205-
lastSignature = "H3bK9x...signature...base64==",
206-
lastSigningAddress = SAMPLE_ADDRESS,
204+
network = TrezorNetworkState(selectedNetwork = BitkitCoreNetwork.REGTEST),
205+
message = TrezorMessageState(
206+
lastSignature = "H3bK9x...signature...base64==",
207+
lastSigningAddress = SAMPLE_ADDRESS,
208+
),
207209
)
208210

209211
val uiStateWithAccountInfo = TrezorUiState(
210-
selectedNetwork = BitkitCoreNetwork.REGTEST,
211-
lookupInput = SAMPLE_XPUB,
212-
accountInfoResult = sampleAccountInfoResult,
212+
network = TrezorNetworkState(selectedNetwork = BitkitCoreNetwork.REGTEST),
213+
lookup = TrezorLookupState(
214+
input = SAMPLE_XPUB,
215+
accountInfoResult = sampleAccountInfoResult,
216+
),
213217
)
214218

215219
val uiStateWithAddressInfo = TrezorUiState(
216-
selectedNetwork = BitkitCoreNetwork.REGTEST,
217-
lookupInput = SAMPLE_ADDRESS,
218-
addressInfoResult = sampleAddressInfoResult,
220+
network = TrezorNetworkState(selectedNetwork = BitkitCoreNetwork.REGTEST),
221+
lookup = TrezorLookupState(
222+
input = SAMPLE_ADDRESS,
223+
addressInfoResult = sampleAddressInfoResult,
224+
),
219225
)
220226

221227
val uiStateReview = TrezorUiState(
222-
selectedNetwork = BitkitCoreNetwork.REGTEST,
223-
sendStep = SendStep.REVIEW,
224-
sendAddress = "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
225-
sendAmountSats = "45000",
226-
sendFeeRate = "5",
227-
composeResult = sampleComposeResult,
228+
network = TrezorNetworkState(selectedNetwork = BitkitCoreNetwork.REGTEST),
229+
send = TrezorSendState(
230+
address = "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
231+
amountSats = "45000",
232+
feeRate = "5",
233+
step = SendStep.Review(sampleComposeResult),
234+
),
228235
)
229236

230237
val uiStateSigned = TrezorUiState(
231-
selectedNetwork = BitkitCoreNetwork.REGTEST,
232-
sendStep = SendStep.SIGNED,
233-
signedTxResult = sampleSignedTx,
238+
network = TrezorNetworkState(selectedNetwork = BitkitCoreNetwork.REGTEST),
239+
send = TrezorSendState(step = SendStep.Signed(sampleSignedTx)),
234240
)
235241

236242
val sampleWalletBalance = WalletBalance(
@@ -290,15 +296,20 @@ internal object TrezorPreviewData {
290296
)
291297

292298
val uiStateWithTxHistory = TrezorUiState(
293-
selectedNetwork = BitkitCoreNetwork.REGTEST,
294-
txHistoryInput = SAMPLE_XPUB,
295-
txHistoryResult = sampleTransactionHistoryResult,
299+
network = TrezorNetworkState(selectedNetwork = BitkitCoreNetwork.REGTEST),
300+
txHistory = TrezorTxHistoryState(
301+
input = SAMPLE_XPUB,
302+
result = sampleTransactionHistoryResult,
303+
),
296304
)
297305

298306
val uiStateBroadcast = TrezorUiState(
299-
selectedNetwork = BitkitCoreNetwork.REGTEST,
300-
sendStep = SendStep.SIGNED,
301-
signedTxResult = sampleSignedTx,
302-
broadcastTxid = "c4d5e6f7a8b9c4d5e6f7a8b9c4d5e6f7a8b9c4d5e6f7a8b9c4d5e6f7a8b9c4d5",
307+
network = TrezorNetworkState(selectedNetwork = BitkitCoreNetwork.REGTEST),
308+
send = TrezorSendState(
309+
step = SendStep.Signed(
310+
signedTx = sampleSignedTx,
311+
broadcastTxid = "c4d5e6f7a8b9c4d5e6f7a8b9c4d5e6f7a8b9c4d5e6f7a8b9c4d5e6f7a8b9c4d5",
312+
),
313+
),
303314
)
304315
}

0 commit comments

Comments
 (0)