Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/core/exchange/domain/errors/buy_error.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'buy_error.freezed.dart';
Expand All @@ -15,4 +17,17 @@ sealed class BuyError with _$BuyError {
OrderAlreadyConfirmedBuyError;
const factory BuyError.unexpected({required String message}) =
UnexpectedBuyError;

const BuyError._();

/// Returns the localized error message.
String toTranslated(BuildContext context) => when(
unauthenticated: () => context.loc.buyUnauthenticatedError,
belowMinAmount: (_) => context.loc.buyBelowMinAmountError,
aboveMaxAmount: (_) => context.loc.buyAboveMaxAmountError,
insufficientFunds: () => context.loc.buyInsufficientFundsError,
orderNotFound: () => context.loc.buyOrderNotFoundError,
orderAlreadyConfirmed: () => context.loc.buyOrderAlreadyConfirmedError,
unexpected: (message) => message,
);
}
15 changes: 15 additions & 0 deletions lib/core/exchange/domain/errors/pay_error.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'pay_error.freezed.dart';
Expand All @@ -15,4 +17,17 @@ sealed class PayError with _$PayError {
OrderAlreadyConfirmedPayError;
const factory PayError.unexpected({required String message}) =
UnexpectedPayError;

const PayError._();

/// Returns the localized error message.
String toTranslated(BuildContext context) => when(
unauthenticated: () => context.loc.payNotAuthenticated,
belowMinAmount: (_) => context.loc.payBelowMinAmount,
aboveMaxAmount: (_) => context.loc.payAboveMaxAmount,
insufficientBalance: () => context.loc.payInsufficientBalance,
orderNotFound: () => context.loc.payOrderNotFound,
orderAlreadyConfirmed: () => context.loc.payOrderAlreadyConfirmed,
unexpected: (message) => message,
);
}
15 changes: 15 additions & 0 deletions lib/core/exchange/domain/errors/sell_error.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'sell_error.freezed.dart';
Expand All @@ -17,4 +19,17 @@ sealed class SellError with _$SellError {
const factory SellError.insufficientBalance({
required int requiredAmountSat,
}) = InsufficientBalanceSellError;

const SellError._();

/// Returns the localized error message.
String toTranslated(BuildContext context) => when(
unauthenticated: () => context.loc.sellUnauthenticatedError,
belowMinAmount: (_) => context.loc.sellBelowMinAmountError,
aboveMaxAmount: (_) => context.loc.sellAboveMaxAmountError,
orderNotFound: () => context.loc.sellOrderNotFoundError,
orderAlreadyConfirmed: () => context.loc.sellOrderAlreadyConfirmedError,
unexpected: (message) => message,
insufficientBalance: (_) => context.loc.sellInsufficientBalanceError,
);
}
14 changes: 14 additions & 0 deletions lib/core/exchange/domain/errors/withdraw_error.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'withdraw_error.freezed.dart';
Expand All @@ -14,4 +16,16 @@ sealed class WithdrawError with _$WithdrawError {
OrderAlreadyConfirmedWithdrawError;
const factory WithdrawError.unexpected({required String message}) =
UnexpectedWithdrawError;

const WithdrawError._();

/// Returns the localized error message.
String toTranslated(BuildContext context) => when(
unauthenticated: () => context.loc.withdrawUnauthenticatedError,
belowMinAmount: (_) => context.loc.withdrawBelowMinAmountError,
aboveMaxAmount: (_) => context.loc.withdrawAboveMaxAmountError,
orderNotFound: () => context.loc.withdrawOrderNotFoundError,
orderAlreadyConfirmed: () => context.loc.withdrawOrderAlreadyConfirmedError,
unexpected: (message) => message,
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:bb_mobile/core/exchange/domain/entity/order.dart';
import 'package:bb_mobile/core/exchange/domain/errors/pay_error.dart';
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
Expand Down Expand Up @@ -110,52 +109,16 @@ class _PayError extends StatelessWidget {
: null,
);

if (payError == null) return const SizedBox.shrink();

return Center(
child: switch (payError) {
AboveMaxAmountPayError _ => Text(
context.loc.payAboveMaxAmount,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
BelowMinAmountPayError _ => Text(
context.loc.payBelowMinAmount,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
UnauthenticatedPayError _ => Text(
context.loc.payNotAuthenticated,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
OrderNotFoundPayError _ => Text(
context.loc.payOrderNotFound,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
child: Text(
payError.toTranslated(context),
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
OrderAlreadyConfirmedPayError _ => Text(
context.loc.payOrderAlreadyConfirmed,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
UnexpectedPayError _ => Text(
payError.message,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
_ => const SizedBox.shrink(),
},
textAlign: TextAlign.center,
),
);
}
}
52 changes: 10 additions & 42 deletions lib/features/pay/ui/screens/pay_send_payment_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:bb_mobile/core/exchange/domain/errors/pay_error.dart';
import 'package:bb_mobile/core/fees/domain/fees_entity.dart';
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/amount_conversions.dart';
Expand Down Expand Up @@ -449,50 +448,19 @@ class _PayError extends StatelessWidget {
: null,
);

if (payError == null) return const SizedBox.shrink();

return Center(
child: switch (payError) {
AboveMaxAmountPayError _ => Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: Text(
context.loc.payAboveMaxAmount,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
),
BelowMinAmountPayError _ => Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: Text(
context.loc.payBelowMinAmount,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
),
InsufficientBalancePayError _ => Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: Text(
context.loc.payInsufficientBalance,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
),
UnexpectedPayError(:final message) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: Text(
message,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: Text(
payError.toTranslated(context),
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: TextAlign.center,
),
_ => const SizedBox.shrink(),
},
),
);
}
}
60 changes: 8 additions & 52 deletions lib/features/pay/ui/screens/pay_wallet_selection_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:bb_mobile/core/exchange/domain/errors/pay_error.dart';
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
Expand Down Expand Up @@ -104,59 +103,16 @@ class _PayError extends StatelessWidget {
: null,
);

if (payError == null) return const SizedBox.shrink();

return Center(
child: switch (payError) {
AboveMaxAmountPayError _ => Text(
context.loc.payAboveMaxAmount,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
BelowMinAmountPayError _ => Text(
context.loc.payBelowMinAmount,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
InsufficientBalancePayError _ => Text(
context.loc.payInsufficientBalance,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
UnauthenticatedPayError _ => Text(
context.loc.payNotAuthenticated,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
child: Text(
payError.toTranslated(context),
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
OrderNotFoundPayError _ => Text(
context.loc.payOrderNotFound,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
OrderAlreadyConfirmedPayError _ => Text(
context.loc.payOrderAlreadyConfirmed,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
UnexpectedPayError _ => Text(
payError.message,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
_ => const SizedBox.shrink(),
},
textAlign: TextAlign.center,
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:bb_mobile/core/exchange/domain/entity/order.dart';
import 'package:bb_mobile/core/exchange/domain/errors/sell_error.dart';
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
Expand Down Expand Up @@ -110,53 +109,16 @@ class _SellError extends StatelessWidget {
: null,
);

return Center(
child: switch (sellError) {
AboveMaxAmountSellError _ => Text(
context.loc.sellAboveMaxAmountError,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
BelowMinAmountSellError _ => Text(
context.loc.sellBelowMinAmountError,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
if (sellError == null) return const SizedBox.shrink();

UnauthenticatedSellError _ => Text(
context.loc.sellUnauthenticatedError,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
OrderNotFoundSellError _ => Text(
context.loc.sellOrderNotFoundError,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
OrderAlreadyConfirmedSellError _ => Text(
context.loc.sellOrderAlreadyConfirmedError,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
),
UnexpectedSellError _ => Text(
sellError.message,
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
textAlign: .center,
return Center(
child: Text(
sellError.toTranslated(context),
style: context.font.bodyMedium?.copyWith(
color: context.appColors.error,
),
_ => const SizedBox.shrink(),
},
textAlign: TextAlign.center,
),
);
}
}
Loading