Skip to content

Commit e0dae85

Browse files
committed
New exchange api errors file
1 parent 45aed0d commit e0dae85

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'package:bb_mobile/generated/l10n/localization.dart';
2+
3+
class FundExchangeApiErrorCopy {
4+
FundExchangeApiErrorCopy._();
5+
6+
static String? title(String? code, AppLocalizations loc) => switch (code) {
7+
'ERR_ORD_PO404' => loc.fundExchangeErrorTitleOrdPo404,
8+
'ERR_RCP_PO404' => loc.fundExchangeErrorTitleRcpPo404,
9+
'ERR_RCP_POSINPE404' => loc.fundExchangeErrorTitleRcpPosinpe404,
10+
'ERR_ORD_KYC400' => loc.fundExchangeErrorTitleOrdKyc400,
11+
'ERR_ORD_COP400' => loc.fundExchangeErrorTitleOrdCop400,
12+
'ERR_ORD_CSRCP400' => loc.fundExchangeErrorTitleOrdCsrcp400,
13+
'ERR_RCP_400' => loc.fundExchangeErrorTitleRcp400,
14+
_ => null,
15+
};
16+
17+
static String message({
18+
required String? code,
19+
required String backendMessage,
20+
required Map<String, String>? messageData,
21+
required AppLocalizations loc,
22+
}) {
23+
if (code == 'ERR_RCP_400') {
24+
return backendMessage.isNotEmpty
25+
? backendMessage
26+
: loc.fundExchangeErrorRcp400;
27+
}
28+
29+
return switch (code) {
30+
'ERR_ORD_PO404' => loc.fundExchangeErrorOrdPo404,
31+
'ERR_RCP_PO404' => loc.fundExchangeErrorRcpPo404,
32+
'ERR_RCP_POSINPE404' => loc.fundExchangeErrorRcpPosinpe404,
33+
'ERR_ORD_KYC400' => loc.fundExchangeErrorOrdKyc400(
34+
messageData?['missingFields'] ?? '',
35+
),
36+
'ERR_ORD_COP400' => loc.fundExchangeErrorOrdCop400(
37+
messageData?['error'] ?? backendMessage,
38+
),
39+
'ERR_ORD_CSRCP400' => loc.fundExchangeErrorOrdCsrcp400(
40+
messageData?['iban'] ?? '',
41+
),
42+
_ => loc.fundExchangeErrorLoadingDetails,
43+
};
44+
}
45+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'package:bb_mobile/core/themes/app_theme.dart';
2+
import 'package:bb_mobile/core/utils/build_context_x.dart';
3+
import 'package:bb_mobile/core/widgets/text/text.dart';
4+
import 'package:bb_mobile/features/fund_exchange/presentation/fund_exchange_presentation_error.dart';
5+
import 'package:flutter/material.dart';
6+
7+
class FundExchangeErrorText extends StatelessWidget {
8+
const FundExchangeErrorText({
9+
super.key,
10+
required this.error,
11+
this.textAlign = TextAlign.center,
12+
});
13+
14+
final FundExchangePresentationError error;
15+
final TextAlign textAlign;
16+
17+
@override
18+
Widget build(BuildContext context) {
19+
final title = error.displayTitle(context.loc);
20+
final message = error.displayMessage(context.loc);
21+
22+
if (title == null) {
23+
return BBText(
24+
message,
25+
style: context.font.bodyMedium,
26+
color: Theme.of(context).colorScheme.error,
27+
textAlign: textAlign,
28+
);
29+
}
30+
31+
return Column(
32+
crossAxisAlignment: CrossAxisAlignment.stretch,
33+
children: [
34+
BBText(
35+
title,
36+
style: context.font.bodyLarge?.copyWith(
37+
fontWeight: FontWeight.bold,
38+
color: Theme.of(context).colorScheme.error,
39+
),
40+
textAlign: textAlign,
41+
),
42+
const SizedBox(height: 4),
43+
BBText(
44+
message,
45+
style: context.font.bodyMedium,
46+
color: Theme.of(context).colorScheme.error,
47+
textAlign: textAlign,
48+
),
49+
],
50+
);
51+
}
52+
}

0 commit comments

Comments
 (0)