Skip to content

Commit 5c2aefd

Browse files
authored
Merge pull request #1631 from gluneau/localization/core-bitbox
feat: localization of core/bitbox
2 parents d5517c2 + 06cadfd commit 5c2aefd

8 files changed

Lines changed: 1146 additions & 115 deletions

File tree

lib/core/bitbox/domain/errors/bitbox_errors.dart

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// lib/core/bitbox/domain/errors/bitbox_errors.dart
2+
import 'package:bb_mobile/core/utils/build_context_x.dart';
3+
import 'package:flutter/material.dart';
24
import 'package:freezed_annotation/freezed_annotation.dart';
35

46
part 'bitbox_errors.freezed.dart';
@@ -23,21 +25,23 @@ sealed class BitBoxError with _$BitBoxError {
2325

2426
const BitBoxError._();
2527

26-
String get message => when(
27-
permissionDenied: () => 'USB permissions are required to connect to BitBox devices.',
28-
noDevicesFound: () => 'No BitBox devices found. Make sure your device is powered on and connected via USB.',
29-
multipleDevicesFound: () => 'Multiple BitBox devices found. Please ensure only one device is connected.',
30-
deviceNotFound: () => 'BitBox device not found.',
31-
connectionTypeNotInitialized: () => 'Connection type not initialized.',
32-
noActiveConnection: () => 'No active connection to BitBox device.',
33-
deviceMismatch: () => 'Device mismatch detected.',
34-
invalidMagicBytes: () => 'Invalid PSBT format detected.',
35-
deviceNotPaired: () => 'Device not paired. Please complete the pairing process first.',
36-
handshakeFailed: () => 'Failed to establish secure connection. Please try again.',
37-
operationTimeout: () => 'Operation timed out. Please try again.',
38-
connectionFailed: () => 'Failed to connect to BitBox device. Please check your connection.',
39-
invalidResponse: () => 'Invalid response from BitBox device. Please try again.',
40-
operationCancelled: () => 'Operation was cancelled. Please try again.',
28+
/// Returns the localized error message.
29+
String toTranslated(BuildContext context) => when(
30+
permissionDenied: () => context.loc.bitboxErrorPermissionDenied,
31+
noDevicesFound: () => context.loc.bitboxErrorNoDevicesFound,
32+
multipleDevicesFound: () => context.loc.bitboxErrorMultipleDevicesFound,
33+
deviceNotFound: () => context.loc.bitboxErrorDeviceNotFound,
34+
connectionTypeNotInitialized: () =>
35+
context.loc.bitboxErrorConnectionTypeNotInitialized,
36+
noActiveConnection: () => context.loc.bitboxErrorNoActiveConnection,
37+
deviceMismatch: () => context.loc.bitboxErrorDeviceMismatch,
38+
invalidMagicBytes: () => context.loc.bitboxErrorInvalidMagicBytes,
39+
deviceNotPaired: () => context.loc.bitboxErrorDeviceNotPaired,
40+
handshakeFailed: () => context.loc.bitboxErrorHandshakeFailed,
41+
operationTimeout: () => context.loc.bitboxErrorOperationTimeout,
42+
connectionFailed: () => context.loc.bitboxErrorConnectionFailed,
43+
invalidResponse: () => context.loc.bitboxErrorInvalidResponse,
44+
operationCancelled: () => context.loc.bitboxErrorOperationCancelled,
4145
operationFailed: (msg) => msg,
4246
);
4347
}
Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
1+
import 'package:bb_mobile/core/utils/build_context_x.dart';
2+
import 'package:flutter/material.dart';
23
import 'package:freezed_annotation/freezed_annotation.dart';
34

45
part 'bitbox_action.freezed.dart';
@@ -13,63 +14,64 @@ sealed class BitBoxAction with _$BitBoxAction {
1314

1415
const BitBoxAction._();
1516

16-
String get title {
17+
String toTitle(BuildContext context) {
1718
return when(
18-
unlockDevice: () => 'Unlock BitBox Device',
19-
pairDevice: () => 'Pair BitBox Device',
20-
importWallet: () => 'Import BitBox Wallet',
21-
signTransaction: () => 'Sign Transaction',
22-
verifyAddress: () => 'Verify Address on BitBox',
19+
unlockDevice: () => context.loc.bitboxActionUnlockDeviceTitle,
20+
pairDevice: () => context.loc.bitboxActionPairDeviceTitle,
21+
importWallet: () => context.loc.bitboxActionImportWalletTitle,
22+
signTransaction: () => context.loc.bitboxActionSignTransactionTitle,
23+
verifyAddress: () => context.loc.bitboxActionVerifyAddressTitle,
2324
);
2425
}
2526

26-
String get buttonText {
27+
String toButtonText(BuildContext context) {
2728
return when(
28-
unlockDevice: () => 'Unlock Device',
29-
pairDevice: () => 'Start Pairing',
30-
importWallet: () => 'Start Import',
31-
signTransaction: () => 'Start Signing',
32-
verifyAddress: () => 'Verify Address',
29+
unlockDevice: () => context.loc.bitboxActionUnlockDeviceButton,
30+
pairDevice: () => context.loc.bitboxActionPairDeviceButton,
31+
importWallet: () => context.loc.bitboxActionImportWalletButton,
32+
signTransaction: () => context.loc.bitboxActionSignTransactionButton,
33+
verifyAddress: () => context.loc.bitboxActionVerifyAddressButton,
3334
);
3435
}
3536

36-
String get processingText {
37+
String toProcessingText(BuildContext context) {
3738
return when(
38-
unlockDevice: () => 'Unlocking Device',
39-
pairDevice: () => 'Pairing Device',
40-
importWallet: () => 'Importing Wallet',
41-
signTransaction: () => 'Signing Transaction',
42-
verifyAddress: () => 'Showing address on BitBox...',
39+
unlockDevice: () => context.loc.bitboxActionUnlockDeviceProcessing,
40+
pairDevice: () => context.loc.bitboxActionPairDeviceProcessing,
41+
importWallet: () => context.loc.bitboxActionImportWalletProcessing,
42+
signTransaction: () => context.loc.bitboxActionSignTransactionProcessing,
43+
verifyAddress: () => context.loc.bitboxActionVerifyAddressProcessing,
4344
);
4445
}
4546

46-
String get successText {
47+
String toSuccessText(BuildContext context) {
4748
return when(
48-
unlockDevice: () => 'Device Unlocked Successfully',
49-
pairDevice: () => 'Device Paired Successfully',
50-
importWallet: () => 'Wallet Imported Successfully',
51-
signTransaction: () => 'Transaction Signed Successfully',
52-
verifyAddress: () => 'Address Verified Successfully',
49+
unlockDevice: () => context.loc.bitboxActionUnlockDeviceSuccess,
50+
pairDevice: () => context.loc.bitboxActionPairDeviceSuccess,
51+
importWallet: () => context.loc.bitboxActionImportWalletSuccess,
52+
signTransaction: () => context.loc.bitboxActionSignTransactionSuccess,
53+
verifyAddress: () => context.loc.bitboxActionVerifyAddressSuccess,
5354
);
5455
}
5556

56-
String get successSubText {
57+
String toSuccessSubText(BuildContext context) {
5758
return when(
58-
unlockDevice: () => 'Your BitBox device is now unlocked and ready to use.',
59-
pairDevice: () => 'Your BitBox device is now paired and ready to use.',
60-
importWallet: () => 'Your BitBox wallet has been imported successfully.',
61-
signTransaction: () => 'Your transaction has been signed successfully.',
62-
verifyAddress: () => 'The address has been verified on your BitBox device.',
59+
unlockDevice: () => context.loc.bitboxActionUnlockDeviceSuccessSubtext,
60+
pairDevice: () => context.loc.bitboxActionPairDeviceSuccessSubtext,
61+
importWallet: () => context.loc.bitboxActionImportWalletSuccessSubtext,
62+
signTransaction: () => context.loc.bitboxActionSignTransactionSuccessSubtext,
63+
verifyAddress: () => context.loc.bitboxActionVerifyAddressSuccessSubtext,
6364
);
6465
}
6566

66-
String get processingSubText {
67+
String toProcessingSubText(BuildContext context) {
6768
return when(
68-
unlockDevice: () => 'Please enter your password on the BitBox device...',
69-
pairDevice: () => 'Please verify the pairing code on your BitBox device...',
70-
importWallet: () => 'Setting up your watch-only wallet...',
71-
signTransaction: () => 'Please confirm the transaction on your BitBox device...',
72-
verifyAddress: () => 'Please confirm the address on your BitBox device.',
69+
unlockDevice: () => context.loc.bitboxActionUnlockDeviceProcessingSubtext,
70+
pairDevice: () => context.loc.bitboxActionPairDeviceProcessingSubtext,
71+
importWallet: () => context.loc.bitboxActionImportWalletProcessingSubtext,
72+
signTransaction: () =>
73+
context.loc.bitboxActionSignTransactionProcessingSubtext,
74+
verifyAddress: () => context.loc.bitboxActionVerifyAddressProcessingSubtext,
7375
);
7476
}
7577
}

lib/features/bitbox/presentation/cubit/bitbox_operation_cubit.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BitBoxOperationCubit extends Cubit<BitBoxOperationState> {
4646
emit(
4747
state.copyWith(
4848
status: BitBoxOperationStatus.waitingForPassword,
49-
errorMessage: null,
49+
error: null,
5050
),
5151
);
5252
}
@@ -55,7 +55,7 @@ class BitBoxOperationCubit extends Cubit<BitBoxOperationState> {
5555
emit(
5656
state.copyWith(
5757
status: BitBoxOperationStatus.processing,
58-
errorMessage: null,
58+
error: null,
5959
),
6060
);
6161
}
@@ -79,7 +79,7 @@ class BitBoxOperationCubit extends Cubit<BitBoxOperationState> {
7979
emit(
8080
state.copyWith(
8181
status: BitBoxOperationStatus.scanning,
82-
errorMessage: null,
82+
error: null,
8383
),
8484
);
8585

@@ -108,12 +108,11 @@ class BitBoxOperationCubit extends Cubit<BitBoxOperationState> {
108108
throw BitBoxError.operationFailed(message: e.toString());
109109
}
110110
} on BitBoxError catch (e) {
111-
final message = e.message;
112-
log.warning('BitBox operation failed: $message');
111+
log.warning('BitBox operation failed: $e');
113112
emit(
114113
state.copyWith(
115114
status: BitBoxOperationStatus.error,
116-
errorMessage: message,
115+
error: e,
117116
),
118117
);
119118
rethrow;
@@ -124,15 +123,15 @@ class BitBoxOperationCubit extends Cubit<BitBoxOperationState> {
124123
emit(
125124
state.copyWith(
126125
status: BitBoxOperationStatus.error,
127-
errorMessage: interpretedMessage,
126+
error: BitBoxError.operationFailed(message: interpretedMessage),
128127
),
129128
);
130129
} else {
131130
log.warning('BitBox operation failed: $e');
132131
emit(
133132
state.copyWith(
134133
status: BitBoxOperationStatus.error,
135-
errorMessage: e.toString(),
134+
error: BitBoxError.operationFailed(message: e.toString()),
136135
),
137136
);
138137
}

lib/features/bitbox/presentation/cubit/bitbox_operation_state.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:bb_mobile/core/bitbox/domain/entities/bitbox_device_entity.dart';
2+
import 'package:bb_mobile/core/bitbox/domain/errors/bitbox_errors.dart';
23
import 'package:freezed_annotation/freezed_annotation.dart';
34

45
part 'bitbox_operation_state.freezed.dart';
@@ -20,7 +21,7 @@ sealed class BitBoxOperationState with _$BitBoxOperationState {
2021
const factory BitBoxOperationState({
2122
@Default(BitBoxOperationStatus.initial) BitBoxOperationStatus status,
2223
BitBoxDeviceEntity? connectedDevice,
23-
String? errorMessage,
24+
BitBoxError? error,
2425
dynamic result,
2526
}) = _BitBoxOperationState;
2627

0 commit comments

Comments
 (0)