Skip to content

Commit

Permalink
Wallet team feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo Guijarro committed Oct 5, 2023
1 parent e4d99f9 commit 3fd9de7
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 60 deletions.
3 changes: 2 additions & 1 deletion lib/ui/profile/components/profile_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';
import 'package:hypha_wallet/core/network/models/dao_data_model.dart';
import 'package:hypha_wallet/design/avatar_image/hypha_avatar_image.dart';
import 'package:hypha_wallet/design/background/hypha_half_background.dart';
Expand Down Expand Up @@ -84,7 +85,7 @@ class ProfileView extends StatelessWidget {
const SizedBox(height: 4),
Center(
child: Text(
'@${state.profileData?.account ?? ''}',
'@${state.profileData?.account ?? ''} - ${state.profileData?.network.name.capitalizeFirst}',
style: context.hyphaTextTheme.regular.copyWith(color: HyphaColors.lightBlue),
),
),
Expand Down
54 changes: 33 additions & 21 deletions lib/ui/sign_transaction/failed/sign_transaction_failed_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart';
import 'package:hypha_wallet/design/background/hypha_half_background.dart';
import 'package:hypha_wallet/design/background/hypha_page_background.dart';
import 'package:hypha_wallet/design/bottom_component/hypha_safe_bottom_navigation_bar.dart';
Expand All @@ -10,7 +11,9 @@ import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.d
import 'package:hypha_wallet/ui/bottom_navigation/hypha_bottom_navigation.dart';

class SignTransactionFailedPage extends StatelessWidget {
const SignTransactionFailedPage({super.key});
final HyphaError error;

const SignTransactionFailedPage(this.error, {super.key});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -47,27 +50,36 @@ class SignTransactionFailedPage extends StatelessWidget {
body: Stack(
children: [
const HyphaHalfBackground(backgroundColor: HyphaColors.error, showTopBar: false),
Column(
children: [
const SizedBox(height: 80),
Image.asset('assets/images/warning.png', width: 240, height: 240),
Padding(
padding: const EdgeInsets.only(left: 45, right: 45, top: 24),
child: Text('Sorry...', textAlign: TextAlign.center, style: context.hyphaTextTheme.mediumTitles),
),
const SizedBox(height: 16),
Padding(padding: const EdgeInsets.only(left: 45, right: 45), child: failedText),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 45, right: 45),
child: Text(
'Please try again by triggering the transaction from the website or app. Sorry for the inconvenience.',
style: context.hyphaTextTheme.ralMediumBody.copyWith(color: HyphaColors.midGrey),
textAlign: TextAlign.center,
),
SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 45),
child: Column(
children: [
const SizedBox(height: 80),
Image.asset('assets/images/warning.png', width: 240, height: 240),
const SizedBox(height: 24),
Text('Sorry...', textAlign: TextAlign.center, style: context.hyphaTextTheme.mediumTitles),
const SizedBox(height: 16),
failedText,
const SizedBox(height: 16),
Text(
'Please try again by triggering the transaction from the website or app. Sorry for the inconvenience.',
style: context.hyphaTextTheme.ralMediumBody.copyWith(color: HyphaColors.midGrey),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
ExpansionTile(
title: const Text('Tap to see full error'),
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(error.message, style: context.hyphaTextTheme.ralMediumBody),
)
],
),
],
),
const SizedBox(height: 16),
],
),
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/sign_transaction/interactor/page_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ part of 'sign_transaction_bloc.dart';
class PageCommand with _$PageCommand {
const factory PageCommand.navigateToTransactionSuccess(SignSuccessTransactionType type) =
_NavigateToTransactionSuccess;
const factory PageCommand.navigateToTransactionFailed() = _NavigateToTransactionFailed;
const factory PageCommand.navigateToTransactionFailed(ErrorResult<String, HyphaError> errorResult) = _NavigateToTransactionFailed;
const factory PageCommand.navigateAway() = _NavigateAway;
}
10 changes: 8 additions & 2 deletions lib/ui/sign_transaction/interactor/sign_transaction_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hypha_wallet/core/crypto/seeds_esr/scan_qr_code_result_data.dart';
import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart';
import 'package:hypha_wallet/core/logging/log_helper.dart';
import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart';
import 'package:hypha_wallet/ui/architecture/result/result.dart';
import 'package:hypha_wallet/ui/sign_transaction/interactor/data/transaction_action_data.dart';
import 'package:hypha_wallet/ui/sign_transaction/success/sign_transaction_success_page.dart';
import 'package:hypha_wallet/ui/sign_transaction/usecases/sign_transaction_use_case.dart';

part 'page_command.dart';

part 'sign_transaction_bloc.freezed.dart';

part 'sign_transaction_event.dart';

part 'sign_transaction_state.dart';

class SignTransactionBloc extends Bloc<SignTransactionEvent, SignTransactionState> {
Expand Down Expand Up @@ -41,10 +46,11 @@ class SignTransactionBloc extends Bloc<SignTransactionEvent, SignTransactionStat
));
if (result.isValue) {
emit(
state.copyWith(command: const PageCommand.navigateToTransactionSuccess(SignSuccessTransactionType.approved)));
state.copyWith(command: const PageCommand.navigateToTransactionSuccess(SignSuccessTransactionType.approved)),
);
} else {
LogHelper.e('Transaction error: ${result.asError?.error.message}');
emit(state.copyWith(command: const PageCommand.navigateToTransactionFailed()));
emit(state.copyWith(command: PageCommand.navigateToTransactionFailed(result.asError!)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@ mixin _$PageCommand {
TResult when<TResult extends Object?>({
required TResult Function(SignSuccessTransactionType type)
navigateToTransactionSuccess,
required TResult Function() navigateToTransactionFailed,
required TResult Function(ErrorResult<String, HyphaError> errorResult)
navigateToTransactionFailed,
required TResult Function() navigateAway,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult? Function()? navigateToTransactionFailed,
TResult? Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult? Function()? navigateAway,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult Function()? navigateToTransactionFailed,
TResult Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult Function()? navigateAway,
required TResult orElse(),
}) =>
Expand Down Expand Up @@ -158,7 +161,8 @@ class _$_NavigateToTransactionSuccess implements _NavigateToTransactionSuccess {
TResult when<TResult extends Object?>({
required TResult Function(SignSuccessTransactionType type)
navigateToTransactionSuccess,
required TResult Function() navigateToTransactionFailed,
required TResult Function(ErrorResult<String, HyphaError> errorResult)
navigateToTransactionFailed,
required TResult Function() navigateAway,
}) {
return navigateToTransactionSuccess(type);
Expand All @@ -169,7 +173,8 @@ class _$_NavigateToTransactionSuccess implements _NavigateToTransactionSuccess {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult? Function()? navigateToTransactionFailed,
TResult? Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult? Function()? navigateAway,
}) {
return navigateToTransactionSuccess?.call(type);
Expand All @@ -180,7 +185,8 @@ class _$_NavigateToTransactionSuccess implements _NavigateToTransactionSuccess {
TResult maybeWhen<TResult extends Object?>({
TResult Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult Function()? navigateToTransactionFailed,
TResult Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult Function()? navigateAway,
required TResult orElse(),
}) {
Expand Down Expand Up @@ -247,6 +253,8 @@ abstract class _$$_NavigateToTransactionFailedCopyWith<$Res> {
_$_NavigateToTransactionFailed value,
$Res Function(_$_NavigateToTransactionFailed) then) =
__$$_NavigateToTransactionFailedCopyWithImpl<$Res>;
@useResult
$Res call({ErrorResult<String, HyphaError> errorResult});
}

/// @nodoc
Expand All @@ -257,61 +265,89 @@ class __$$_NavigateToTransactionFailedCopyWithImpl<$Res>
_$_NavigateToTransactionFailed _value,
$Res Function(_$_NavigateToTransactionFailed) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? errorResult = null,
}) {
return _then(_$_NavigateToTransactionFailed(
null == errorResult
? _value.errorResult
: errorResult // ignore: cast_nullable_to_non_nullable
as ErrorResult<String, HyphaError>,
));
}
}

/// @nodoc
class _$_NavigateToTransactionFailed implements _NavigateToTransactionFailed {
const _$_NavigateToTransactionFailed();
const _$_NavigateToTransactionFailed(this.errorResult);

@override
final ErrorResult<String, HyphaError> errorResult;

@override
String toString() {
return 'PageCommand.navigateToTransactionFailed()';
return 'PageCommand.navigateToTransactionFailed(errorResult: $errorResult)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_NavigateToTransactionFailed);
other is _$_NavigateToTransactionFailed &&
(identical(other.errorResult, errorResult) ||
other.errorResult == errorResult));
}

@override
int get hashCode => runtimeType.hashCode;
int get hashCode => Object.hash(runtimeType, errorResult);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_NavigateToTransactionFailedCopyWith<_$_NavigateToTransactionFailed>
get copyWith => __$$_NavigateToTransactionFailedCopyWithImpl<
_$_NavigateToTransactionFailed>(this, _$identity);

@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(SignSuccessTransactionType type)
navigateToTransactionSuccess,
required TResult Function() navigateToTransactionFailed,
required TResult Function(ErrorResult<String, HyphaError> errorResult)
navigateToTransactionFailed,
required TResult Function() navigateAway,
}) {
return navigateToTransactionFailed();
return navigateToTransactionFailed(errorResult);
}

@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult? Function()? navigateToTransactionFailed,
TResult? Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult? Function()? navigateAway,
}) {
return navigateToTransactionFailed?.call();
return navigateToTransactionFailed?.call(errorResult);
}

@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult Function()? navigateToTransactionFailed,
TResult Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult Function()? navigateAway,
required TResult orElse(),
}) {
if (navigateToTransactionFailed != null) {
return navigateToTransactionFailed();
return navigateToTransactionFailed(errorResult);
}
return orElse();
}
Expand Down Expand Up @@ -358,7 +394,14 @@ class _$_NavigateToTransactionFailed implements _NavigateToTransactionFailed {
}

abstract class _NavigateToTransactionFailed implements PageCommand {
const factory _NavigateToTransactionFailed() = _$_NavigateToTransactionFailed;
const factory _NavigateToTransactionFailed(
final ErrorResult<String, HyphaError> errorResult) =
_$_NavigateToTransactionFailed;

ErrorResult<String, HyphaError> get errorResult;
@JsonKey(ignore: true)
_$$_NavigateToTransactionFailedCopyWith<_$_NavigateToTransactionFailed>
get copyWith => throw _privateConstructorUsedError;
}

/// @nodoc
Expand Down Expand Up @@ -401,7 +444,8 @@ class _$_NavigateAway implements _NavigateAway {
TResult when<TResult extends Object?>({
required TResult Function(SignSuccessTransactionType type)
navigateToTransactionSuccess,
required TResult Function() navigateToTransactionFailed,
required TResult Function(ErrorResult<String, HyphaError> errorResult)
navigateToTransactionFailed,
required TResult Function() navigateAway,
}) {
return navigateAway();
Expand All @@ -412,7 +456,8 @@ class _$_NavigateAway implements _NavigateAway {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult? Function()? navigateToTransactionFailed,
TResult? Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult? Function()? navigateAway,
}) {
return navigateAway?.call();
Expand All @@ -423,7 +468,8 @@ class _$_NavigateAway implements _NavigateAway {
TResult maybeWhen<TResult extends Object?>({
TResult Function(SignSuccessTransactionType type)?
navigateToTransactionSuccess,
TResult Function()? navigateToTransactionFailed,
TResult Function(ErrorResult<String, HyphaError> errorResult)?
navigateToTransactionFailed,
TResult Function()? navigateAway,
required TResult orElse(),
}) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/sign_transaction/sign_transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class SignTransactionPage extends StatelessWidget {
() => SignTransactionSuccessPage(transactionType: type),
transition: GetX.Transition.downToUp,
);
}, navigateToTransactionFailed: () {
GetX.Get.off(() => const SignTransactionFailedPage(), transition: GetX.Transition.downToUp);
}, navigateToTransactionFailed: (error) {
GetX.Get.off(() => SignTransactionFailedPage(error.error), transition: GetX.Transition.downToUp);
}, navigateAway: () {
GetX.Get.back();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class SignTransactionUseCase extends InputUseCase<HResult.Result<String, HyphaEr
Future<HResult.Result<String, HyphaError>> run(SignTransactionInput input) async {
final userData = _authRepository.authDataOrCrash;
if (input.eOSTransaction.network != userData.userProfileData.network) {
return HResult.Result.error(HyphaError.api(
'Wrong network. Transaction on ${input.eOSTransaction.network} cannot be signed by user on ${userData.userProfileData.network}'));
return HResult.Result.error(
HyphaError.api(
'Wrong network. Transaction on ${input.eOSTransaction.network} cannot be signed by user on ${userData.userProfileData.network}'),
);
}
final Result<dynamic> result;
try {
Expand Down
Loading

0 comments on commit 3fd9de7

Please sign in to comment.