Skip to content

Commit e4e0341

Browse files
authored
Merge pull request #1638 from gluneau/localization/core-exchange
feat: localization of core/exchange
2 parents 1a31c96 + 66e12e2 commit e4e0341

13 files changed

Lines changed: 243 additions & 279 deletions

lib/core/exchange/domain/errors/buy_error.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:bb_mobile/core/utils/build_context_x.dart';
2+
import 'package:flutter/material.dart';
13
import 'package:freezed_annotation/freezed_annotation.dart';
24

35
part 'buy_error.freezed.dart';
@@ -15,4 +17,17 @@ sealed class BuyError with _$BuyError {
1517
OrderAlreadyConfirmedBuyError;
1618
const factory BuyError.unexpected({required String message}) =
1719
UnexpectedBuyError;
20+
21+
const BuyError._();
22+
23+
/// Returns the localized error message.
24+
String toTranslated(BuildContext context) => when(
25+
unauthenticated: () => context.loc.buyUnauthenticatedError,
26+
belowMinAmount: (_) => context.loc.buyBelowMinAmountError,
27+
aboveMaxAmount: (_) => context.loc.buyAboveMaxAmountError,
28+
insufficientFunds: () => context.loc.buyInsufficientFundsError,
29+
orderNotFound: () => context.loc.buyOrderNotFoundError,
30+
orderAlreadyConfirmed: () => context.loc.buyOrderAlreadyConfirmedError,
31+
unexpected: (message) => message,
32+
);
1833
}

lib/core/exchange/domain/errors/pay_error.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:bb_mobile/core/utils/build_context_x.dart';
2+
import 'package:flutter/material.dart';
13
import 'package:freezed_annotation/freezed_annotation.dart';
24

35
part 'pay_error.freezed.dart';
@@ -15,4 +17,17 @@ sealed class PayError with _$PayError {
1517
OrderAlreadyConfirmedPayError;
1618
const factory PayError.unexpected({required String message}) =
1719
UnexpectedPayError;
20+
21+
const PayError._();
22+
23+
/// Returns the localized error message.
24+
String toTranslated(BuildContext context) => when(
25+
unauthenticated: () => context.loc.payNotAuthenticated,
26+
belowMinAmount: (_) => context.loc.payBelowMinAmount,
27+
aboveMaxAmount: (_) => context.loc.payAboveMaxAmount,
28+
insufficientBalance: () => context.loc.payInsufficientBalance,
29+
orderNotFound: () => context.loc.payOrderNotFound,
30+
orderAlreadyConfirmed: () => context.loc.payOrderAlreadyConfirmed,
31+
unexpected: (message) => message,
32+
);
1833
}

lib/core/exchange/domain/errors/sell_error.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:bb_mobile/core/utils/build_context_x.dart';
2+
import 'package:flutter/material.dart';
13
import 'package:freezed_annotation/freezed_annotation.dart';
24

35
part 'sell_error.freezed.dart';
@@ -17,4 +19,17 @@ sealed class SellError with _$SellError {
1719
const factory SellError.insufficientBalance({
1820
required int requiredAmountSat,
1921
}) = InsufficientBalanceSellError;
22+
23+
const SellError._();
24+
25+
/// Returns the localized error message.
26+
String toTranslated(BuildContext context) => when(
27+
unauthenticated: () => context.loc.sellUnauthenticatedError,
28+
belowMinAmount: (_) => context.loc.sellBelowMinAmountError,
29+
aboveMaxAmount: (_) => context.loc.sellAboveMaxAmountError,
30+
orderNotFound: () => context.loc.sellOrderNotFoundError,
31+
orderAlreadyConfirmed: () => context.loc.sellOrderAlreadyConfirmedError,
32+
unexpected: (message) => message,
33+
insufficientBalance: (_) => context.loc.sellInsufficientBalanceError,
34+
);
2035
}

lib/core/exchange/domain/errors/withdraw_error.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:bb_mobile/core/utils/build_context_x.dart';
2+
import 'package:flutter/material.dart';
13
import 'package:freezed_annotation/freezed_annotation.dart';
24

35
part 'withdraw_error.freezed.dart';
@@ -14,4 +16,16 @@ sealed class WithdrawError with _$WithdrawError {
1416
OrderAlreadyConfirmedWithdrawError;
1517
const factory WithdrawError.unexpected({required String message}) =
1618
UnexpectedWithdrawError;
19+
20+
const WithdrawError._();
21+
22+
/// Returns the localized error message.
23+
String toTranslated(BuildContext context) => when(
24+
unauthenticated: () => context.loc.withdrawUnauthenticatedError,
25+
belowMinAmount: (_) => context.loc.withdrawBelowMinAmountError,
26+
aboveMaxAmount: (_) => context.loc.withdrawAboveMaxAmountError,
27+
orderNotFound: () => context.loc.withdrawOrderNotFoundError,
28+
orderAlreadyConfirmed: () => context.loc.withdrawOrderAlreadyConfirmedError,
29+
unexpected: (message) => message,
30+
);
1731
}

lib/features/pay/ui/screens/pay_external_wallet_network_selection_screen.dart

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:bb_mobile/core/exchange/domain/entity/order.dart';
2-
import 'package:bb_mobile/core/exchange/domain/errors/pay_error.dart';
32
import 'package:bb_mobile/core/themes/app_theme.dart';
43
import 'package:bb_mobile/core/utils/build_context_x.dart';
54
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
@@ -110,52 +109,16 @@ class _PayError extends StatelessWidget {
110109
: null,
111110
);
112111

112+
if (payError == null) return const SizedBox.shrink();
113+
113114
return Center(
114-
child: switch (payError) {
115-
AboveMaxAmountPayError _ => Text(
116-
context.loc.payAboveMaxAmount,
117-
style: context.font.bodyMedium?.copyWith(
118-
color: context.appColors.error,
119-
),
120-
textAlign: .center,
121-
),
122-
BelowMinAmountPayError _ => Text(
123-
context.loc.payBelowMinAmount,
124-
style: context.font.bodyMedium?.copyWith(
125-
color: context.appColors.error,
126-
),
127-
textAlign: .center,
128-
),
129-
UnauthenticatedPayError _ => Text(
130-
context.loc.payNotAuthenticated,
131-
style: context.font.bodyMedium?.copyWith(
132-
color: context.appColors.error,
133-
),
134-
textAlign: .center,
135-
),
136-
OrderNotFoundPayError _ => Text(
137-
context.loc.payOrderNotFound,
138-
style: context.font.bodyMedium?.copyWith(
139-
color: context.appColors.error,
140-
),
141-
textAlign: .center,
115+
child: Text(
116+
payError.toTranslated(context),
117+
style: context.font.bodyMedium?.copyWith(
118+
color: context.appColors.error,
142119
),
143-
OrderAlreadyConfirmedPayError _ => Text(
144-
context.loc.payOrderAlreadyConfirmed,
145-
style: context.font.bodyMedium?.copyWith(
146-
color: context.appColors.error,
147-
),
148-
textAlign: .center,
149-
),
150-
UnexpectedPayError _ => Text(
151-
payError.message,
152-
style: context.font.bodyMedium?.copyWith(
153-
color: context.appColors.error,
154-
),
155-
textAlign: .center,
156-
),
157-
_ => const SizedBox.shrink(),
158-
},
120+
textAlign: TextAlign.center,
121+
),
159122
);
160123
}
161124
}

lib/features/pay/ui/screens/pay_send_payment_screen.dart

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:bb_mobile/core/exchange/domain/errors/pay_error.dart';
21
import 'package:bb_mobile/core/fees/domain/fees_entity.dart';
32
import 'package:bb_mobile/core/themes/app_theme.dart';
43
import 'package:bb_mobile/core/utils/amount_conversions.dart';
@@ -449,50 +448,19 @@ class _PayError extends StatelessWidget {
449448
: null,
450449
);
451450

451+
if (payError == null) return const SizedBox.shrink();
452+
452453
return Center(
453-
child: switch (payError) {
454-
AboveMaxAmountPayError _ => Padding(
455-
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
456-
child: Text(
457-
context.loc.payAboveMaxAmount,
458-
style: context.font.bodyMedium?.copyWith(
459-
color: context.appColors.error,
460-
),
461-
textAlign: .center,
462-
),
463-
),
464-
BelowMinAmountPayError _ => Padding(
465-
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
466-
child: Text(
467-
context.loc.payBelowMinAmount,
468-
style: context.font.bodyMedium?.copyWith(
469-
color: context.appColors.error,
470-
),
471-
textAlign: .center,
472-
),
473-
),
474-
InsufficientBalancePayError _ => Padding(
475-
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
476-
child: Text(
477-
context.loc.payInsufficientBalance,
478-
style: context.font.bodyMedium?.copyWith(
479-
color: context.appColors.error,
480-
),
481-
textAlign: .center,
482-
),
483-
),
484-
UnexpectedPayError(:final message) => Padding(
485-
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
486-
child: Text(
487-
message,
488-
style: context.font.bodyMedium?.copyWith(
489-
color: context.appColors.error,
490-
),
491-
textAlign: .center,
454+
child: Padding(
455+
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
456+
child: Text(
457+
payError.toTranslated(context),
458+
style: context.font.bodyMedium?.copyWith(
459+
color: context.appColors.error,
492460
),
461+
textAlign: TextAlign.center,
493462
),
494-
_ => const SizedBox.shrink(),
495-
},
463+
),
496464
);
497465
}
498466
}

lib/features/pay/ui/screens/pay_wallet_selection_screen.dart

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:bb_mobile/core/exchange/domain/errors/pay_error.dart';
21
import 'package:bb_mobile/core/themes/app_theme.dart';
32
import 'package:bb_mobile/core/utils/build_context_x.dart';
43
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
@@ -104,59 +103,16 @@ class _PayError extends StatelessWidget {
104103
: null,
105104
);
106105

106+
if (payError == null) return const SizedBox.shrink();
107+
107108
return Center(
108-
child: switch (payError) {
109-
AboveMaxAmountPayError _ => Text(
110-
context.loc.payAboveMaxAmount,
111-
style: context.font.bodyMedium?.copyWith(
112-
color: context.appColors.error,
113-
),
114-
textAlign: .center,
115-
),
116-
BelowMinAmountPayError _ => Text(
117-
context.loc.payBelowMinAmount,
118-
style: context.font.bodyMedium?.copyWith(
119-
color: context.appColors.error,
120-
),
121-
textAlign: .center,
122-
),
123-
InsufficientBalancePayError _ => Text(
124-
context.loc.payInsufficientBalance,
125-
style: context.font.bodyMedium?.copyWith(
126-
color: context.appColors.error,
127-
),
128-
textAlign: .center,
129-
),
130-
UnauthenticatedPayError _ => Text(
131-
context.loc.payNotAuthenticated,
132-
style: context.font.bodyMedium?.copyWith(
133-
color: context.appColors.error,
134-
),
135-
textAlign: .center,
109+
child: Text(
110+
payError.toTranslated(context),
111+
style: context.font.bodyMedium?.copyWith(
112+
color: context.appColors.error,
136113
),
137-
OrderNotFoundPayError _ => Text(
138-
context.loc.payOrderNotFound,
139-
style: context.font.bodyMedium?.copyWith(
140-
color: context.appColors.error,
141-
),
142-
textAlign: .center,
143-
),
144-
OrderAlreadyConfirmedPayError _ => Text(
145-
context.loc.payOrderAlreadyConfirmed,
146-
style: context.font.bodyMedium?.copyWith(
147-
color: context.appColors.error,
148-
),
149-
textAlign: .center,
150-
),
151-
UnexpectedPayError _ => Text(
152-
payError.message,
153-
style: context.font.bodyMedium?.copyWith(
154-
color: context.appColors.error,
155-
),
156-
textAlign: .center,
157-
),
158-
_ => const SizedBox.shrink(),
159-
},
114+
textAlign: TextAlign.center,
115+
),
160116
);
161117
}
162118
}

lib/features/sell/ui/screens/sell_external_wallet_network_selection_screen.dart

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:bb_mobile/core/exchange/domain/entity/order.dart';
2-
import 'package:bb_mobile/core/exchange/domain/errors/sell_error.dart';
32
import 'package:bb_mobile/core/themes/app_theme.dart';
43
import 'package:bb_mobile/core/utils/build_context_x.dart';
54
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
@@ -110,53 +109,16 @@ class _SellError extends StatelessWidget {
110109
: null,
111110
);
112111

113-
return Center(
114-
child: switch (sellError) {
115-
AboveMaxAmountSellError _ => Text(
116-
context.loc.sellAboveMaxAmountError,
117-
style: context.font.bodyMedium?.copyWith(
118-
color: context.appColors.error,
119-
),
120-
textAlign: .center,
121-
),
122-
BelowMinAmountSellError _ => Text(
123-
context.loc.sellBelowMinAmountError,
124-
style: context.font.bodyMedium?.copyWith(
125-
color: context.appColors.error,
126-
),
127-
textAlign: .center,
128-
),
112+
if (sellError == null) return const SizedBox.shrink();
129113

130-
UnauthenticatedSellError _ => Text(
131-
context.loc.sellUnauthenticatedError,
132-
style: context.font.bodyMedium?.copyWith(
133-
color: context.appColors.error,
134-
),
135-
textAlign: .center,
136-
),
137-
OrderNotFoundSellError _ => Text(
138-
context.loc.sellOrderNotFoundError,
139-
style: context.font.bodyMedium?.copyWith(
140-
color: context.appColors.error,
141-
),
142-
textAlign: .center,
143-
),
144-
OrderAlreadyConfirmedSellError _ => Text(
145-
context.loc.sellOrderAlreadyConfirmedError,
146-
style: context.font.bodyMedium?.copyWith(
147-
color: context.appColors.error,
148-
),
149-
textAlign: .center,
150-
),
151-
UnexpectedSellError _ => Text(
152-
sellError.message,
153-
style: context.font.bodyMedium?.copyWith(
154-
color: context.appColors.error,
155-
),
156-
textAlign: .center,
114+
return Center(
115+
child: Text(
116+
sellError.toTranslated(context),
117+
style: context.font.bodyMedium?.copyWith(
118+
color: context.appColors.error,
157119
),
158-
_ => const SizedBox.shrink(),
159-
},
120+
textAlign: TextAlign.center,
121+
),
160122
);
161123
}
162124
}

0 commit comments

Comments
 (0)