diff --git a/lib/core/di/bloc_module.dart b/lib/core/di/bloc_module.dart index 7217ce11..0b9275bf 100644 --- a/lib/core/di/bloc_module.dart +++ b/lib/core/di/bloc_module.dart @@ -152,7 +152,16 @@ void _registerBlocsModule() { (daos, _) => ProposalCreationBloc( daos, _getIt(), + _getIt(), + ), + ); + + _registerFactoryWithParams( + (proposalId, _) => ProposalDetailsBloc( + _getIt(), + _getIt(), _getIt(), + proposalId ), ); } diff --git a/lib/core/di/di_setup.dart b/lib/core/di/di_setup.dart index 52d91963..77c05f7c 100644 --- a/lib/core/di/di_setup.dart +++ b/lib/core/di/di_setup.dart @@ -75,6 +75,8 @@ import 'package:hypha_wallet/ui/profile/usecases/set_image_use_case.dart'; import 'package:hypha_wallet/ui/profile/usecases/set_name_use_case.dart'; import 'package:hypha_wallet/ui/proposals/creation/interactor/proposal_creation_bloc.dart'; import 'package:hypha_wallet/ui/proposals/creation/usecases/publish_proposal_use_case.dart'; +import 'package:hypha_wallet/ui/proposals/details/interactor/proposal_details_bloc.dart'; +import 'package:hypha_wallet/ui/proposals/details/usecases/cast_vote_use_case.dart'; import 'package:hypha_wallet/ui/proposals/details/usecases/get_proposal_details_use_case.dart'; import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_proposals_bloc.dart'; import 'package:hypha_wallet/ui/proposals/filter/usecases/aggregate_dao_proposal_counts_use_case.dart'; diff --git a/lib/core/di/repositories_module.dart b/lib/core/di/repositories_module.dart index 96eb65b4..a52ca0de 100644 --- a/lib/core/di/repositories_module.dart +++ b/lib/core/di/repositories_module.dart @@ -23,5 +23,5 @@ void _registerRepositoriesModule() { _registerLazySingleton(() => TransactionHistoryRepository(service: _getIt())); - _registerLazySingleton(() => ProposalRepository(_getIt(),_getIt(),_getIt(),_getIt(),_getIt())); + _registerLazySingleton(() => ProposalRepository(_getIt(),_getIt(),_getIt())); } \ No newline at end of file diff --git a/lib/core/di/usecases_module.dart b/lib/core/di/usecases_module.dart index 9c1937ed..42e311db 100644 --- a/lib/core/di/usecases_module.dart +++ b/lib/core/di/usecases_module.dart @@ -87,6 +87,8 @@ void _registerUseCasesModule() { _registerFactory(() => GetProposalDetailsUseCase(_getIt(), _getIt())); + _registerFactory(() => CastVoteUseCase(_getIt(), _getIt(), _getIt())); + _registerFactory(() => AggregateDaoProposalCountsUseCase()); _registerFactory(() => PublishProposalUseCase(_getIt(), _getIt(), _getIt())); diff --git a/lib/core/network/repository/proposal_repository.dart b/lib/core/network/repository/proposal_repository.dart index a1525c68..641309d2 100644 --- a/lib/core/network/repository/proposal_repository.dart +++ b/lib/core/network/repository/proposal_repository.dart @@ -1,36 +1,25 @@ -import 'package:hypha_wallet/core/crypto/seeds_esr/eos_action.dart'; import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart'; import 'package:hypha_wallet/core/extension/base_proposal_model_extension.dart'; import 'package:hypha_wallet/core/logging/log_helper.dart'; -import 'package:hypha_wallet/core/network/api/actions/vote_action_factory.dart'; -import 'package:hypha_wallet/core/network/api/eos_service.dart'; import 'package:hypha_wallet/core/network/api/services/dao_service.dart'; import 'package:hypha_wallet/core/network/api/services/proposal_service.dart'; -import 'package:hypha_wallet/core/network/api/services/remote_config_service.dart'; import 'package:hypha_wallet/core/network/models/dao_data_model.dart'; import 'package:hypha_wallet/core/network/models/network.dart'; import 'package:hypha_wallet/core/network/models/proposal_details_model.dart'; import 'package:hypha_wallet/core/network/models/proposal_model.dart'; import 'package:hypha_wallet/core/network/models/user_profile_data.dart'; -import 'package:hypha_wallet/core/network/models/vote_model.dart'; import 'package:hypha_wallet/core/network/repository/profile_repository.dart'; import 'package:hypha_wallet/ui/architecture/result/result.dart'; import 'package:hypha_wallet/ui/profile/interactor/profile_data.dart'; import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_status.dart'; -import 'package:hypha_wallet/ui/proposals/list/interactor/get_proposals_use_case_input.dart'; +import 'package:hypha_wallet/ui/proposals/list/usecases/get_proposals_use_case_input.dart'; class ProposalRepository { final ProposalService _proposalService; final ProfileService _profileService; final DaoService _daoService; - final EOSService _eosService; - final RemoteConfigService _remoteConfigService; - ProposalRepository( - this._remoteConfigService, - this._eosService, - this._daoService, - this._proposalService, this._profileService); + ProposalRepository(this._daoService, this._proposalService, this._profileService); Future, HyphaError>> getProposals(UserProfileData user, GetProposalsUseCaseInput input) async { final List, HyphaError>>> futures = input.daos.map((DaoData dao) { @@ -153,24 +142,4 @@ class ProposalRepository { return Result.error(result.asError!.error); } } - - Future> castVote( - String proposalId, - VoteStatus vote, - UserProfileData user - ) async { - // Get the DAO contract for the user's network - final String daoContract = _remoteConfigService.daoContract(network: user.network); - // Create the EOS action for casting the vote - final EOSAction eosAction = VoteActionFactory.voteAction(daoContract, user.accountName, proposalId, vote); - - try { - // Execute the action using EOS service and get the result - final castVoteResult = await _eosService.runAction(signer: user, action: eosAction); - return Result.value(castVoteResult.asValue!.value); - } catch (e, stackTrace) { - LogHelper.e('Error casting vote', error: e, stacktrace: stackTrace); - return Result.error(HyphaError.generic('Failed to cast vote')); - } - } } diff --git a/lib/ui/proposals/creation/proposal_creation_page.dart b/lib/ui/proposals/creation/proposal_creation_page.dart index c859a47e..1dbd1c05 100644 --- a/lib/ui/proposals/creation/proposal_creation_page.dart +++ b/lib/ui/proposals/creation/proposal_creation_page.dart @@ -29,12 +29,18 @@ class ProposalCreationPage extends StatelessWidget { Get.back(); }, navigateToSuccessPage: () { - Get.to(() => SignTransactionSuccessPage(transactionType: SignSuccessTransactionType.published, proposalId: state.proposal.id)); + Get.to(() => const SignTransactionSuccessPage(transactionType: SignSuccessTransactionType.published)); }, navigateToFailurePage: (HyphaError hyphaError) { - Get.to(() => BlocProvider.value( - value: context.read(), - child: SignTransactionFailedPage(hyphaError, text1: 'Publishing Proposal', text2: 'An error occurred while publishing your proposal. Click the button below if you want to see the full error, or click the close button to go back to your proposal publishing step and try again')) + Get.to(() => SignTransactionFailedPage( + hyphaError, + text1: 'Publishing proposal', + text2: 'An error occurred while publishing your proposal. Click the button below if you want to see the full error, or click the close button to go back to your proposal publishing step and try again.', + callBack: () { + Get.back(); + context.read().add(const ProposalCreationEvent.publishProposal()); + } + ) ); }, ); diff --git a/lib/ui/proposals/details/components/proposal_details_view.dart b/lib/ui/proposals/details/components/proposal_details_view.dart index 013b0963..485c039c 100644 --- a/lib/ui/proposals/details/components/proposal_details_view.dart +++ b/lib/ui/proposals/details/components/proposal_details_view.dart @@ -9,6 +9,7 @@ import 'package:hypha_wallet/design/buttons/hypha_app_button.dart'; import 'package:hypha_wallet/design/dividers/hypha_divider.dart'; import 'package:hypha_wallet/design/hypha_colors.dart'; import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart'; +import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart'; import 'package:hypha_wallet/ui/blocs/authentication/authentication_bloc.dart'; import 'package:hypha_wallet/ui/proposals/components/proposal_button.dart'; import 'package:hypha_wallet/ui/proposals/components/proposal_creator.dart'; @@ -16,7 +17,7 @@ import 'package:hypha_wallet/ui/proposals/components/proposal_expiration_timer.d import 'package:hypha_wallet/ui/proposals/components/proposal_header.dart'; import 'package:hypha_wallet/ui/proposals/components/proposal_percentage_indicator.dart'; import 'package:hypha_wallet/ui/proposals/details/components/proposal_voters.dart'; -import 'package:hypha_wallet/ui/proposals/details/interactor/proposal_detail_bloc.dart'; +import 'package:hypha_wallet/ui/proposals/details/interactor/proposal_details_bloc.dart'; import 'package:hypha_wallet/ui/shared/hypha_body_widget.dart'; class ProposalDetailsView extends StatefulWidget { @@ -63,7 +64,7 @@ class _ProposalDetailsViewState extends State { scrolledUnderElevation: 0, title: const Text('Proposal Details'), ), - body: BlocBuilder( + body: BlocBuilder( builder: (context, state) { return HyphaBodyWidget( pageState: state.pageState, @@ -255,7 +256,14 @@ class _ProposalDetailsViewState extends State { }[userVote.voteStatus] ?? 'You chose to abstain', ) - : _buildVoteWidget(context), + : BlocBuilder( + builder: (context, state) { + return state.votingState == PageState.loading ? const Padding( + padding: EdgeInsets.only(top: 20), + child: Center(child: CircularProgressIndicator.adaptive()), + ) : _buildVoteWidget(context); + }, + ), ), ], ), @@ -299,9 +307,9 @@ Widget _buildVoteWidget(BuildContext context) => Column( } // Get the bloc instances - final proposalDetailBloc = context.read(); + final proposalDetailBloc = context.read(); // Dispatch the castVote event - proposalDetailBloc.add(ProposalDetailEvent.castVote(voteStatus)); + proposalDetailBloc.add(ProposalDetailsEvent.castVote(voteStatus)); }, buttonType: ButtonType.danger, buttonColor: index == 0 diff --git a/lib/ui/proposals/details/interactor/page_command.dart b/lib/ui/proposals/details/interactor/page_command.dart new file mode 100644 index 00000000..dcfb4eda --- /dev/null +++ b/lib/ui/proposals/details/interactor/page_command.dart @@ -0,0 +1,7 @@ +part of 'proposal_details_bloc.dart'; + +@freezed +class PageCommand with _$PageCommand { + const factory PageCommand.navigateToSuccessPage() = _NavigateToSuccessPage; + const factory PageCommand.navigateToFailurePage(HyphaError hyphaError) = _NavigateToFailurePage; +} diff --git a/lib/ui/proposals/details/interactor/proposal_detail_bloc.dart b/lib/ui/proposals/details/interactor/proposal_detail_bloc.dart deleted file mode 100644 index 41a0b148..00000000 --- a/lib/ui/proposals/details/interactor/proposal_detail_bloc.dart +++ /dev/null @@ -1,64 +0,0 @@ -import 'dart:async'; -import 'package:bloc/bloc.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:get/get.dart' as Get; -import 'package:get_it/get_it.dart'; -import 'package:hypha_wallet/core/error_handler/error_handler_manager.dart'; -import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart'; -import 'package:hypha_wallet/core/network/models/proposal_details_model.dart'; -import 'package:hypha_wallet/core/network/models/vote_model.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/proposals/details/usecases/get_proposal_details_use_case.dart'; -import 'package:hypha_wallet/ui/proposals/list/interactor/proposals_bloc.dart'; - -part 'proposal_detail_bloc.freezed.dart'; - -part 'proposal_detail_event.dart'; - -part 'proposal_detail_state.dart'; - -class ProposalDetailBloc - extends Bloc { - final GetProposalDetailsUseCase _getProposalDetailsUseCase; - final ErrorHandlerManager _errorHandlerManager; - final String _proposalId; - - ProposalDetailBloc(this._proposalId, this._getProposalDetailsUseCase, - this._errorHandlerManager) - : super(const ProposalDetailState()) { - on<_Initial>(_initial); - on<_CastVote>(_castVote); - } - - Future _initial( - _Initial event, Emitter emit) async { - emit(state.copyWith(pageState: PageState.loading)); - - final Result result = - await _getProposalDetailsUseCase.run(_proposalId); - if (result.isValue) { - emit(state.copyWith( - pageState: PageState.success, - proposalDetailsModel: result.asValue!.value)); - } else { - await _errorHandlerManager.handlerError(result.asError!.error); - emit(state.copyWith(pageState: PageState.failure)); - } - } - - Future _castVote( - _CastVote event, Emitter emit) async { - emit(state.copyWith(pageState: PageState.loading)); - final Result result = - await _getProposalDetailsUseCase.castVote(_proposalId, event.vote); - if (result.isValue) { - GetIt.I.get().add(const ProposalsEvent.initial()); - Get.Get.back(); - emit(state.copyWith(pageState: PageState.success)); - } else { - await _errorHandlerManager.handlerError(result.asError!.error); - emit(state.copyWith(pageState: PageState.failure)); - } - } -} diff --git a/lib/ui/proposals/details/interactor/proposal_detail_bloc.freezed.dart b/lib/ui/proposals/details/interactor/proposal_detail_bloc.freezed.dart deleted file mode 100644 index b2a093ba..00000000 --- a/lib/ui/proposals/details/interactor/proposal_detail_bloc.freezed.dart +++ /dev/null @@ -1,476 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'proposal_detail_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$ProposalDetailEvent { - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function(VoteStatus vote) castVote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function(VoteStatus vote)? castVote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function(VoteStatus vote)? castVote, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_CastVote value) castVote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_CastVote value)? castVote, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_CastVote value)? castVote, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $ProposalDetailEventCopyWith<$Res> { - factory $ProposalDetailEventCopyWith( - ProposalDetailEvent value, $Res Function(ProposalDetailEvent) then) = - _$ProposalDetailEventCopyWithImpl<$Res, ProposalDetailEvent>; -} - -/// @nodoc -class _$ProposalDetailEventCopyWithImpl<$Res, $Val extends ProposalDetailEvent> - implements $ProposalDetailEventCopyWith<$Res> { - _$ProposalDetailEventCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of ProposalDetailEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$InitialImplCopyWith<$Res> { - factory _$$InitialImplCopyWith( - _$InitialImpl value, $Res Function(_$InitialImpl) then) = - __$$InitialImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$InitialImplCopyWithImpl<$Res> - extends _$ProposalDetailEventCopyWithImpl<$Res, _$InitialImpl> - implements _$$InitialImplCopyWith<$Res> { - __$$InitialImplCopyWithImpl( - _$InitialImpl _value, $Res Function(_$InitialImpl) _then) - : super(_value, _then); - - /// Create a copy of ProposalDetailEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$InitialImpl implements _Initial { - const _$InitialImpl(); - - @override - String toString() { - return 'ProposalDetailEvent.initial()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$InitialImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function(VoteStatus vote) castVote, - }) { - return initial(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function(VoteStatus vote)? castVote, - }) { - return initial?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function(VoteStatus vote)? castVote, - required TResult orElse(), - }) { - if (initial != null) { - return initial(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_CastVote value) castVote, - }) { - return initial(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_CastVote value)? castVote, - }) { - return initial?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_CastVote value)? castVote, - required TResult orElse(), - }) { - if (initial != null) { - return initial(this); - } - return orElse(); - } -} - -abstract class _Initial implements ProposalDetailEvent { - const factory _Initial() = _$InitialImpl; -} - -/// @nodoc -abstract class _$$CastVoteImplCopyWith<$Res> { - factory _$$CastVoteImplCopyWith( - _$CastVoteImpl value, $Res Function(_$CastVoteImpl) then) = - __$$CastVoteImplCopyWithImpl<$Res>; - @useResult - $Res call({VoteStatus vote}); -} - -/// @nodoc -class __$$CastVoteImplCopyWithImpl<$Res> - extends _$ProposalDetailEventCopyWithImpl<$Res, _$CastVoteImpl> - implements _$$CastVoteImplCopyWith<$Res> { - __$$CastVoteImplCopyWithImpl( - _$CastVoteImpl _value, $Res Function(_$CastVoteImpl) _then) - : super(_value, _then); - - /// Create a copy of ProposalDetailEvent - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? vote = null, - }) { - return _then(_$CastVoteImpl( - null == vote - ? _value.vote - : vote // ignore: cast_nullable_to_non_nullable - as VoteStatus, - )); - } -} - -/// @nodoc - -class _$CastVoteImpl implements _CastVote { - const _$CastVoteImpl(this.vote); - - @override - final VoteStatus vote; - - @override - String toString() { - return 'ProposalDetailEvent.castVote(vote: $vote)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$CastVoteImpl && - (identical(other.vote, vote) || other.vote == vote)); - } - - @override - int get hashCode => Object.hash(runtimeType, vote); - - /// Create a copy of ProposalDetailEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$CastVoteImplCopyWith<_$CastVoteImpl> get copyWith => - __$$CastVoteImplCopyWithImpl<_$CastVoteImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function(VoteStatus vote) castVote, - }) { - return castVote(vote); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function(VoteStatus vote)? castVote, - }) { - return castVote?.call(vote); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function(VoteStatus vote)? castVote, - required TResult orElse(), - }) { - if (castVote != null) { - return castVote(vote); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_CastVote value) castVote, - }) { - return castVote(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_CastVote value)? castVote, - }) { - return castVote?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_CastVote value)? castVote, - required TResult orElse(), - }) { - if (castVote != null) { - return castVote(this); - } - return orElse(); - } -} - -abstract class _CastVote implements ProposalDetailEvent { - const factory _CastVote(final VoteStatus vote) = _$CastVoteImpl; - - VoteStatus get vote; - - /// Create a copy of ProposalDetailEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$CastVoteImplCopyWith<_$CastVoteImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$ProposalDetailState { - PageState get pageState => throw _privateConstructorUsedError; - ProposalDetailsModel? get proposalDetailsModel => - throw _privateConstructorUsedError; - - /// Create a copy of ProposalDetailState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $ProposalDetailStateCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $ProposalDetailStateCopyWith<$Res> { - factory $ProposalDetailStateCopyWith( - ProposalDetailState value, $Res Function(ProposalDetailState) then) = - _$ProposalDetailStateCopyWithImpl<$Res, ProposalDetailState>; - @useResult - $Res call({PageState pageState, ProposalDetailsModel? proposalDetailsModel}); -} - -/// @nodoc -class _$ProposalDetailStateCopyWithImpl<$Res, $Val extends ProposalDetailState> - implements $ProposalDetailStateCopyWith<$Res> { - _$ProposalDetailStateCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of ProposalDetailState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? pageState = null, - Object? proposalDetailsModel = freezed, - }) { - return _then(_value.copyWith( - pageState: null == pageState - ? _value.pageState - : pageState // ignore: cast_nullable_to_non_nullable - as PageState, - proposalDetailsModel: freezed == proposalDetailsModel - ? _value.proposalDetailsModel - : proposalDetailsModel // ignore: cast_nullable_to_non_nullable - as ProposalDetailsModel?, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$ProposalDetailStateImplCopyWith<$Res> - implements $ProposalDetailStateCopyWith<$Res> { - factory _$$ProposalDetailStateImplCopyWith(_$ProposalDetailStateImpl value, - $Res Function(_$ProposalDetailStateImpl) then) = - __$$ProposalDetailStateImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({PageState pageState, ProposalDetailsModel? proposalDetailsModel}); -} - -/// @nodoc -class __$$ProposalDetailStateImplCopyWithImpl<$Res> - extends _$ProposalDetailStateCopyWithImpl<$Res, _$ProposalDetailStateImpl> - implements _$$ProposalDetailStateImplCopyWith<$Res> { - __$$ProposalDetailStateImplCopyWithImpl(_$ProposalDetailStateImpl _value, - $Res Function(_$ProposalDetailStateImpl) _then) - : super(_value, _then); - - /// Create a copy of ProposalDetailState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? pageState = null, - Object? proposalDetailsModel = freezed, - }) { - return _then(_$ProposalDetailStateImpl( - pageState: null == pageState - ? _value.pageState - : pageState // ignore: cast_nullable_to_non_nullable - as PageState, - proposalDetailsModel: freezed == proposalDetailsModel - ? _value.proposalDetailsModel - : proposalDetailsModel // ignore: cast_nullable_to_non_nullable - as ProposalDetailsModel?, - )); - } -} - -/// @nodoc - -class _$ProposalDetailStateImpl implements _ProposalDetailState { - const _$ProposalDetailStateImpl( - {this.pageState = PageState.initial, this.proposalDetailsModel}); - - @override - @JsonKey() - final PageState pageState; - @override - final ProposalDetailsModel? proposalDetailsModel; - - @override - String toString() { - return 'ProposalDetailState(pageState: $pageState, proposalDetailsModel: $proposalDetailsModel)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ProposalDetailStateImpl && - (identical(other.pageState, pageState) || - other.pageState == pageState) && - (identical(other.proposalDetailsModel, proposalDetailsModel) || - other.proposalDetailsModel == proposalDetailsModel)); - } - - @override - int get hashCode => Object.hash(runtimeType, pageState, proposalDetailsModel); - - /// Create a copy of ProposalDetailState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$ProposalDetailStateImplCopyWith<_$ProposalDetailStateImpl> get copyWith => - __$$ProposalDetailStateImplCopyWithImpl<_$ProposalDetailStateImpl>( - this, _$identity); -} - -abstract class _ProposalDetailState implements ProposalDetailState { - const factory _ProposalDetailState( - {final PageState pageState, - final ProposalDetailsModel? proposalDetailsModel}) = - _$ProposalDetailStateImpl; - - @override - PageState get pageState; - @override - ProposalDetailsModel? get proposalDetailsModel; - - /// Create a copy of ProposalDetailState - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$ProposalDetailStateImplCopyWith<_$ProposalDetailStateImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/ui/proposals/details/interactor/proposal_detail_event.dart b/lib/ui/proposals/details/interactor/proposal_detail_event.dart deleted file mode 100644 index f0b20531..00000000 --- a/lib/ui/proposals/details/interactor/proposal_detail_event.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of 'proposal_detail_bloc.dart'; - -@freezed -class ProposalDetailEvent with _$ProposalDetailEvent { - const factory ProposalDetailEvent.initial() = _Initial; - const factory ProposalDetailEvent.castVote(VoteStatus vote) = _CastVote; -} diff --git a/lib/ui/proposals/details/interactor/proposal_detail_state.dart b/lib/ui/proposals/details/interactor/proposal_detail_state.dart deleted file mode 100644 index cc5dfd44..00000000 --- a/lib/ui/proposals/details/interactor/proposal_detail_state.dart +++ /dev/null @@ -1,9 +0,0 @@ -part of 'proposal_detail_bloc.dart'; - -@freezed -class ProposalDetailState with _$ProposalDetailState { - const factory ProposalDetailState({ - @Default(PageState.initial) PageState pageState, - ProposalDetailsModel? proposalDetailsModel, - }) = _ProposalDetailState; -} diff --git a/lib/ui/proposals/details/interactor/proposal_details_bloc.dart b/lib/ui/proposals/details/interactor/proposal_details_bloc.dart new file mode 100644 index 00000000..dae4a0e0 --- /dev/null +++ b/lib/ui/proposals/details/interactor/proposal_details_bloc.dart @@ -0,0 +1,56 @@ +import 'dart:async'; +import 'package:bloc/bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:hypha_wallet/core/error_handler/error_handler_manager.dart'; +import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart'; +import 'package:hypha_wallet/core/network/models/proposal_details_model.dart'; +import 'package:hypha_wallet/core/network/models/vote_model.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/proposals/details/usecases/cast_vote_use_case.dart'; +import 'package:hypha_wallet/ui/proposals/details/usecases/cast_vote_use_case_input.dart'; +import 'package:hypha_wallet/ui/proposals/details/usecases/get_proposal_details_use_case.dart'; + +part 'page_command.dart'; +part 'proposal_details_bloc.freezed.dart'; +part 'proposal_details_event.dart'; +part 'proposal_details_state.dart'; + +class ProposalDetailsBloc extends Bloc { + final GetProposalDetailsUseCase _getProposalDetailsUseCase; + final CastVoteUseCase _castVoteUseCase; + final ErrorHandlerManager _errorHandlerManager; + final String _proposalId; + + ProposalDetailsBloc(this._getProposalDetailsUseCase, this._castVoteUseCase, this._errorHandlerManager, this._proposalId) : super(const ProposalDetailsState()) { + on<_Initial>(_initial); + on<_CastVote>(_castVote); + on<_ClearPageCommand>((_, emit) => emit(state.copyWith(command: null))); + } + + Future _initial(_Initial event, Emitter emit) async { + emit(state.copyWith(pageState: PageState.loading)); + + final Result result = await _getProposalDetailsUseCase.run(_proposalId); + + if (result.isValue) { + emit(state.copyWith(pageState: PageState.success, proposalDetailsModel: result.asValue!.value)); + } else { + await _errorHandlerManager.handlerError(result.asError!.error); + emit(state.copyWith(pageState: PageState.failure)); + } + } + + Future _castVote(_CastVote event, Emitter emit) async { + emit(state.copyWith(votingState: PageState.loading)); + + final Result result = await _castVoteUseCase.run(CastVoteUseCaseInput(_proposalId, event.voteStatus)); + + if (result.isValue) { + emit(state.copyWith(votingState: PageState.success, command: const PageCommand.navigateToSuccessPage())); + } else { + await _errorHandlerManager.handlerError(result.asError!.error); + emit(state.copyWith(votingState: PageState.failure, command: PageCommand.navigateToFailurePage(result.asError!.error))); + } + } +} diff --git a/lib/ui/proposals/details/interactor/proposal_details_bloc.freezed.dart b/lib/ui/proposals/details/interactor/proposal_details_bloc.freezed.dart new file mode 100644 index 00000000..ef5d2090 --- /dev/null +++ b/lib/ui/proposals/details/interactor/proposal_details_bloc.freezed.dart @@ -0,0 +1,995 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'proposal_details_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +/// @nodoc +mixin _$PageCommand { + @optionalTypeArgs + TResult when({ + required TResult Function() navigateToSuccessPage, + required TResult Function(HyphaError hyphaError) navigateToFailurePage, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? navigateToSuccessPage, + TResult? Function(HyphaError hyphaError)? navigateToFailurePage, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? navigateToSuccessPage, + TResult Function(HyphaError hyphaError)? navigateToFailurePage, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_NavigateToSuccessPage value) + navigateToSuccessPage, + required TResult Function(_NavigateToFailurePage value) + navigateToFailurePage, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_NavigateToSuccessPage value)? navigateToSuccessPage, + TResult? Function(_NavigateToFailurePage value)? navigateToFailurePage, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_NavigateToSuccessPage value)? navigateToSuccessPage, + TResult Function(_NavigateToFailurePage value)? navigateToFailurePage, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PageCommandCopyWith<$Res> { + factory $PageCommandCopyWith( + PageCommand value, $Res Function(PageCommand) then) = + _$PageCommandCopyWithImpl<$Res, PageCommand>; +} + +/// @nodoc +class _$PageCommandCopyWithImpl<$Res, $Val extends PageCommand> + implements $PageCommandCopyWith<$Res> { + _$PageCommandCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PageCommand + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$NavigateToSuccessPageImplCopyWith<$Res> { + factory _$$NavigateToSuccessPageImplCopyWith( + _$NavigateToSuccessPageImpl value, + $Res Function(_$NavigateToSuccessPageImpl) then) = + __$$NavigateToSuccessPageImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$NavigateToSuccessPageImplCopyWithImpl<$Res> + extends _$PageCommandCopyWithImpl<$Res, _$NavigateToSuccessPageImpl> + implements _$$NavigateToSuccessPageImplCopyWith<$Res> { + __$$NavigateToSuccessPageImplCopyWithImpl(_$NavigateToSuccessPageImpl _value, + $Res Function(_$NavigateToSuccessPageImpl) _then) + : super(_value, _then); + + /// Create a copy of PageCommand + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$NavigateToSuccessPageImpl implements _NavigateToSuccessPage { + const _$NavigateToSuccessPageImpl(); + + @override + String toString() { + return 'PageCommand.navigateToSuccessPage()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$NavigateToSuccessPageImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() navigateToSuccessPage, + required TResult Function(HyphaError hyphaError) navigateToFailurePage, + }) { + return navigateToSuccessPage(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? navigateToSuccessPage, + TResult? Function(HyphaError hyphaError)? navigateToFailurePage, + }) { + return navigateToSuccessPage?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? navigateToSuccessPage, + TResult Function(HyphaError hyphaError)? navigateToFailurePage, + required TResult orElse(), + }) { + if (navigateToSuccessPage != null) { + return navigateToSuccessPage(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_NavigateToSuccessPage value) + navigateToSuccessPage, + required TResult Function(_NavigateToFailurePage value) + navigateToFailurePage, + }) { + return navigateToSuccessPage(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_NavigateToSuccessPage value)? navigateToSuccessPage, + TResult? Function(_NavigateToFailurePage value)? navigateToFailurePage, + }) { + return navigateToSuccessPage?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_NavigateToSuccessPage value)? navigateToSuccessPage, + TResult Function(_NavigateToFailurePage value)? navigateToFailurePage, + required TResult orElse(), + }) { + if (navigateToSuccessPage != null) { + return navigateToSuccessPage(this); + } + return orElse(); + } +} + +abstract class _NavigateToSuccessPage implements PageCommand { + const factory _NavigateToSuccessPage() = _$NavigateToSuccessPageImpl; +} + +/// @nodoc +abstract class _$$NavigateToFailurePageImplCopyWith<$Res> { + factory _$$NavigateToFailurePageImplCopyWith( + _$NavigateToFailurePageImpl value, + $Res Function(_$NavigateToFailurePageImpl) then) = + __$$NavigateToFailurePageImplCopyWithImpl<$Res>; + @useResult + $Res call({HyphaError hyphaError}); +} + +/// @nodoc +class __$$NavigateToFailurePageImplCopyWithImpl<$Res> + extends _$PageCommandCopyWithImpl<$Res, _$NavigateToFailurePageImpl> + implements _$$NavigateToFailurePageImplCopyWith<$Res> { + __$$NavigateToFailurePageImplCopyWithImpl(_$NavigateToFailurePageImpl _value, + $Res Function(_$NavigateToFailurePageImpl) _then) + : super(_value, _then); + + /// Create a copy of PageCommand + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? hyphaError = null, + }) { + return _then(_$NavigateToFailurePageImpl( + null == hyphaError + ? _value.hyphaError + : hyphaError // ignore: cast_nullable_to_non_nullable + as HyphaError, + )); + } +} + +/// @nodoc + +class _$NavigateToFailurePageImpl implements _NavigateToFailurePage { + const _$NavigateToFailurePageImpl(this.hyphaError); + + @override + final HyphaError hyphaError; + + @override + String toString() { + return 'PageCommand.navigateToFailurePage(hyphaError: $hyphaError)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$NavigateToFailurePageImpl && + (identical(other.hyphaError, hyphaError) || + other.hyphaError == hyphaError)); + } + + @override + int get hashCode => Object.hash(runtimeType, hyphaError); + + /// Create a copy of PageCommand + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$NavigateToFailurePageImplCopyWith<_$NavigateToFailurePageImpl> + get copyWith => __$$NavigateToFailurePageImplCopyWithImpl< + _$NavigateToFailurePageImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() navigateToSuccessPage, + required TResult Function(HyphaError hyphaError) navigateToFailurePage, + }) { + return navigateToFailurePage(hyphaError); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? navigateToSuccessPage, + TResult? Function(HyphaError hyphaError)? navigateToFailurePage, + }) { + return navigateToFailurePage?.call(hyphaError); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? navigateToSuccessPage, + TResult Function(HyphaError hyphaError)? navigateToFailurePage, + required TResult orElse(), + }) { + if (navigateToFailurePage != null) { + return navigateToFailurePage(hyphaError); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_NavigateToSuccessPage value) + navigateToSuccessPage, + required TResult Function(_NavigateToFailurePage value) + navigateToFailurePage, + }) { + return navigateToFailurePage(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_NavigateToSuccessPage value)? navigateToSuccessPage, + TResult? Function(_NavigateToFailurePage value)? navigateToFailurePage, + }) { + return navigateToFailurePage?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_NavigateToSuccessPage value)? navigateToSuccessPage, + TResult Function(_NavigateToFailurePage value)? navigateToFailurePage, + required TResult orElse(), + }) { + if (navigateToFailurePage != null) { + return navigateToFailurePage(this); + } + return orElse(); + } +} + +abstract class _NavigateToFailurePage implements PageCommand { + const factory _NavigateToFailurePage(final HyphaError hyphaError) = + _$NavigateToFailurePageImpl; + + HyphaError get hyphaError; + + /// Create a copy of PageCommand + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$NavigateToFailurePageImplCopyWith<_$NavigateToFailurePageImpl> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +mixin _$ProposalDetailsEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(VoteStatus voteStatus) castVote, + required TResult Function() clearPageCommand, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(VoteStatus voteStatus)? castVote, + TResult? Function()? clearPageCommand, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(VoteStatus voteStatus)? castVote, + TResult Function()? clearPageCommand, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CastVote value) castVote, + required TResult Function(_ClearPageCommand value) clearPageCommand, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_CastVote value)? castVote, + TResult? Function(_ClearPageCommand value)? clearPageCommand, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CastVote value)? castVote, + TResult Function(_ClearPageCommand value)? clearPageCommand, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ProposalDetailsEventCopyWith<$Res> { + factory $ProposalDetailsEventCopyWith(ProposalDetailsEvent value, + $Res Function(ProposalDetailsEvent) then) = + _$ProposalDetailsEventCopyWithImpl<$Res, ProposalDetailsEvent>; +} + +/// @nodoc +class _$ProposalDetailsEventCopyWithImpl<$Res, + $Val extends ProposalDetailsEvent> + implements $ProposalDetailsEventCopyWith<$Res> { + _$ProposalDetailsEventCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ProposalDetailsEvent + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$InitialImplCopyWith<$Res> { + factory _$$InitialImplCopyWith( + _$InitialImpl value, $Res Function(_$InitialImpl) then) = + __$$InitialImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$InitialImplCopyWithImpl<$Res> + extends _$ProposalDetailsEventCopyWithImpl<$Res, _$InitialImpl> + implements _$$InitialImplCopyWith<$Res> { + __$$InitialImplCopyWithImpl( + _$InitialImpl _value, $Res Function(_$InitialImpl) _then) + : super(_value, _then); + + /// Create a copy of ProposalDetailsEvent + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$InitialImpl implements _Initial { + const _$InitialImpl(); + + @override + String toString() { + return 'ProposalDetailsEvent.initial()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$InitialImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(VoteStatus voteStatus) castVote, + required TResult Function() clearPageCommand, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(VoteStatus voteStatus)? castVote, + TResult? Function()? clearPageCommand, + }) { + return initial?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(VoteStatus voteStatus)? castVote, + TResult Function()? clearPageCommand, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CastVote value) castVote, + required TResult Function(_ClearPageCommand value) clearPageCommand, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_CastVote value)? castVote, + TResult? Function(_ClearPageCommand value)? clearPageCommand, + }) { + return initial?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CastVote value)? castVote, + TResult Function(_ClearPageCommand value)? clearPageCommand, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _Initial implements ProposalDetailsEvent { + const factory _Initial() = _$InitialImpl; +} + +/// @nodoc +abstract class _$$CastVoteImplCopyWith<$Res> { + factory _$$CastVoteImplCopyWith( + _$CastVoteImpl value, $Res Function(_$CastVoteImpl) then) = + __$$CastVoteImplCopyWithImpl<$Res>; + @useResult + $Res call({VoteStatus voteStatus}); +} + +/// @nodoc +class __$$CastVoteImplCopyWithImpl<$Res> + extends _$ProposalDetailsEventCopyWithImpl<$Res, _$CastVoteImpl> + implements _$$CastVoteImplCopyWith<$Res> { + __$$CastVoteImplCopyWithImpl( + _$CastVoteImpl _value, $Res Function(_$CastVoteImpl) _then) + : super(_value, _then); + + /// Create a copy of ProposalDetailsEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? voteStatus = null, + }) { + return _then(_$CastVoteImpl( + null == voteStatus + ? _value.voteStatus + : voteStatus // ignore: cast_nullable_to_non_nullable + as VoteStatus, + )); + } +} + +/// @nodoc + +class _$CastVoteImpl implements _CastVote { + const _$CastVoteImpl(this.voteStatus); + + @override + final VoteStatus voteStatus; + + @override + String toString() { + return 'ProposalDetailsEvent.castVote(voteStatus: $voteStatus)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$CastVoteImpl && + (identical(other.voteStatus, voteStatus) || + other.voteStatus == voteStatus)); + } + + @override + int get hashCode => Object.hash(runtimeType, voteStatus); + + /// Create a copy of ProposalDetailsEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$CastVoteImplCopyWith<_$CastVoteImpl> get copyWith => + __$$CastVoteImplCopyWithImpl<_$CastVoteImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(VoteStatus voteStatus) castVote, + required TResult Function() clearPageCommand, + }) { + return castVote(voteStatus); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(VoteStatus voteStatus)? castVote, + TResult? Function()? clearPageCommand, + }) { + return castVote?.call(voteStatus); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(VoteStatus voteStatus)? castVote, + TResult Function()? clearPageCommand, + required TResult orElse(), + }) { + if (castVote != null) { + return castVote(voteStatus); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CastVote value) castVote, + required TResult Function(_ClearPageCommand value) clearPageCommand, + }) { + return castVote(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_CastVote value)? castVote, + TResult? Function(_ClearPageCommand value)? clearPageCommand, + }) { + return castVote?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CastVote value)? castVote, + TResult Function(_ClearPageCommand value)? clearPageCommand, + required TResult orElse(), + }) { + if (castVote != null) { + return castVote(this); + } + return orElse(); + } +} + +abstract class _CastVote implements ProposalDetailsEvent { + const factory _CastVote(final VoteStatus voteStatus) = _$CastVoteImpl; + + VoteStatus get voteStatus; + + /// Create a copy of ProposalDetailsEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$CastVoteImplCopyWith<_$CastVoteImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$ClearPageCommandImplCopyWith<$Res> { + factory _$$ClearPageCommandImplCopyWith(_$ClearPageCommandImpl value, + $Res Function(_$ClearPageCommandImpl) then) = + __$$ClearPageCommandImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$ClearPageCommandImplCopyWithImpl<$Res> + extends _$ProposalDetailsEventCopyWithImpl<$Res, _$ClearPageCommandImpl> + implements _$$ClearPageCommandImplCopyWith<$Res> { + __$$ClearPageCommandImplCopyWithImpl(_$ClearPageCommandImpl _value, + $Res Function(_$ClearPageCommandImpl) _then) + : super(_value, _then); + + /// Create a copy of ProposalDetailsEvent + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$ClearPageCommandImpl implements _ClearPageCommand { + const _$ClearPageCommandImpl(); + + @override + String toString() { + return 'ProposalDetailsEvent.clearPageCommand()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$ClearPageCommandImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(VoteStatus voteStatus) castVote, + required TResult Function() clearPageCommand, + }) { + return clearPageCommand(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function(VoteStatus voteStatus)? castVote, + TResult? Function()? clearPageCommand, + }) { + return clearPageCommand?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(VoteStatus voteStatus)? castVote, + TResult Function()? clearPageCommand, + required TResult orElse(), + }) { + if (clearPageCommand != null) { + return clearPageCommand(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_CastVote value) castVote, + required TResult Function(_ClearPageCommand value) clearPageCommand, + }) { + return clearPageCommand(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_CastVote value)? castVote, + TResult? Function(_ClearPageCommand value)? clearPageCommand, + }) { + return clearPageCommand?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_CastVote value)? castVote, + TResult Function(_ClearPageCommand value)? clearPageCommand, + required TResult orElse(), + }) { + if (clearPageCommand != null) { + return clearPageCommand(this); + } + return orElse(); + } +} + +abstract class _ClearPageCommand implements ProposalDetailsEvent { + const factory _ClearPageCommand() = _$ClearPageCommandImpl; +} + +/// @nodoc +mixin _$ProposalDetailsState { + PageState get pageState => throw _privateConstructorUsedError; + PageState get votingState => throw _privateConstructorUsedError; + ProposalDetailsModel? get proposalDetailsModel => + throw _privateConstructorUsedError; + PageCommand? get command => throw _privateConstructorUsedError; + + /// Create a copy of ProposalDetailsState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ProposalDetailsStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ProposalDetailsStateCopyWith<$Res> { + factory $ProposalDetailsStateCopyWith(ProposalDetailsState value, + $Res Function(ProposalDetailsState) then) = + _$ProposalDetailsStateCopyWithImpl<$Res, ProposalDetailsState>; + @useResult + $Res call( + {PageState pageState, + PageState votingState, + ProposalDetailsModel? proposalDetailsModel, + PageCommand? command}); + + $PageCommandCopyWith<$Res>? get command; +} + +/// @nodoc +class _$ProposalDetailsStateCopyWithImpl<$Res, + $Val extends ProposalDetailsState> + implements $ProposalDetailsStateCopyWith<$Res> { + _$ProposalDetailsStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ProposalDetailsState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? pageState = null, + Object? votingState = null, + Object? proposalDetailsModel = freezed, + Object? command = freezed, + }) { + return _then(_value.copyWith( + pageState: null == pageState + ? _value.pageState + : pageState // ignore: cast_nullable_to_non_nullable + as PageState, + votingState: null == votingState + ? _value.votingState + : votingState // ignore: cast_nullable_to_non_nullable + as PageState, + proposalDetailsModel: freezed == proposalDetailsModel + ? _value.proposalDetailsModel + : proposalDetailsModel // ignore: cast_nullable_to_non_nullable + as ProposalDetailsModel?, + command: freezed == command + ? _value.command + : command // ignore: cast_nullable_to_non_nullable + as PageCommand?, + ) as $Val); + } + + /// Create a copy of ProposalDetailsState + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $PageCommandCopyWith<$Res>? get command { + if (_value.command == null) { + return null; + } + + return $PageCommandCopyWith<$Res>(_value.command!, (value) { + return _then(_value.copyWith(command: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$ProposalDetailsStateImplCopyWith<$Res> + implements $ProposalDetailsStateCopyWith<$Res> { + factory _$$ProposalDetailsStateImplCopyWith(_$ProposalDetailsStateImpl value, + $Res Function(_$ProposalDetailsStateImpl) then) = + __$$ProposalDetailsStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {PageState pageState, + PageState votingState, + ProposalDetailsModel? proposalDetailsModel, + PageCommand? command}); + + @override + $PageCommandCopyWith<$Res>? get command; +} + +/// @nodoc +class __$$ProposalDetailsStateImplCopyWithImpl<$Res> + extends _$ProposalDetailsStateCopyWithImpl<$Res, _$ProposalDetailsStateImpl> + implements _$$ProposalDetailsStateImplCopyWith<$Res> { + __$$ProposalDetailsStateImplCopyWithImpl(_$ProposalDetailsStateImpl _value, + $Res Function(_$ProposalDetailsStateImpl) _then) + : super(_value, _then); + + /// Create a copy of ProposalDetailsState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? pageState = null, + Object? votingState = null, + Object? proposalDetailsModel = freezed, + Object? command = freezed, + }) { + return _then(_$ProposalDetailsStateImpl( + pageState: null == pageState + ? _value.pageState + : pageState // ignore: cast_nullable_to_non_nullable + as PageState, + votingState: null == votingState + ? _value.votingState + : votingState // ignore: cast_nullable_to_non_nullable + as PageState, + proposalDetailsModel: freezed == proposalDetailsModel + ? _value.proposalDetailsModel + : proposalDetailsModel // ignore: cast_nullable_to_non_nullable + as ProposalDetailsModel?, + command: freezed == command + ? _value.command + : command // ignore: cast_nullable_to_non_nullable + as PageCommand?, + )); + } +} + +/// @nodoc + +class _$ProposalDetailsStateImpl implements _ProposalDetailsState { + const _$ProposalDetailsStateImpl( + {this.pageState = PageState.initial, + this.votingState = PageState.initial, + this.proposalDetailsModel, + this.command}); + + @override + @JsonKey() + final PageState pageState; + @override + @JsonKey() + final PageState votingState; + @override + final ProposalDetailsModel? proposalDetailsModel; + @override + final PageCommand? command; + + @override + String toString() { + return 'ProposalDetailsState(pageState: $pageState, votingState: $votingState, proposalDetailsModel: $proposalDetailsModel, command: $command)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ProposalDetailsStateImpl && + (identical(other.pageState, pageState) || + other.pageState == pageState) && + (identical(other.votingState, votingState) || + other.votingState == votingState) && + (identical(other.proposalDetailsModel, proposalDetailsModel) || + other.proposalDetailsModel == proposalDetailsModel) && + (identical(other.command, command) || other.command == command)); + } + + @override + int get hashCode => Object.hash( + runtimeType, pageState, votingState, proposalDetailsModel, command); + + /// Create a copy of ProposalDetailsState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ProposalDetailsStateImplCopyWith<_$ProposalDetailsStateImpl> + get copyWith => + __$$ProposalDetailsStateImplCopyWithImpl<_$ProposalDetailsStateImpl>( + this, _$identity); +} + +abstract class _ProposalDetailsState implements ProposalDetailsState { + const factory _ProposalDetailsState( + {final PageState pageState, + final PageState votingState, + final ProposalDetailsModel? proposalDetailsModel, + final PageCommand? command}) = _$ProposalDetailsStateImpl; + + @override + PageState get pageState; + @override + PageState get votingState; + @override + ProposalDetailsModel? get proposalDetailsModel; + @override + PageCommand? get command; + + /// Create a copy of ProposalDetailsState + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ProposalDetailsStateImplCopyWith<_$ProposalDetailsStateImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/ui/proposals/details/interactor/proposal_details_event.dart b/lib/ui/proposals/details/interactor/proposal_details_event.dart new file mode 100644 index 00000000..2267f013 --- /dev/null +++ b/lib/ui/proposals/details/interactor/proposal_details_event.dart @@ -0,0 +1,8 @@ +part of 'proposal_details_bloc.dart'; + +@freezed +class ProposalDetailsEvent with _$ProposalDetailsEvent { + const factory ProposalDetailsEvent.initial() = _Initial; + const factory ProposalDetailsEvent.castVote(VoteStatus voteStatus) = _CastVote; + const factory ProposalDetailsEvent.clearPageCommand() = _ClearPageCommand; +} diff --git a/lib/ui/proposals/details/interactor/proposal_details_state.dart b/lib/ui/proposals/details/interactor/proposal_details_state.dart new file mode 100644 index 00000000..fc030257 --- /dev/null +++ b/lib/ui/proposals/details/interactor/proposal_details_state.dart @@ -0,0 +1,11 @@ +part of 'proposal_details_bloc.dart'; + +@freezed +class ProposalDetailsState with _$ProposalDetailsState { + const factory ProposalDetailsState({ + @Default(PageState.initial) PageState pageState, + @Default(PageState.initial) PageState votingState, + ProposalDetailsModel? proposalDetailsModel, + PageCommand? command, + }) = _ProposalDetailsState; +} diff --git a/lib/ui/proposals/details/proposal_details_page.dart b/lib/ui/proposals/details/proposal_details_page.dart index a906fc16..20238477 100644 --- a/lib/ui/proposals/details/proposal_details_page.dart +++ b/lib/ui/proposals/details/proposal_details_page.dart @@ -1,22 +1,39 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:get/get.dart'; import 'package:get_it/get_it.dart'; -import 'package:hypha_wallet/core/error_handler/error_handler_manager.dart'; +import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart'; import 'package:hypha_wallet/ui/proposals/details/components/proposal_details_view.dart'; -import 'package:hypha_wallet/ui/proposals/details/interactor/proposal_detail_bloc.dart'; -import 'package:hypha_wallet/ui/proposals/details/usecases/get_proposal_details_use_case.dart'; +import 'package:hypha_wallet/ui/proposals/details/interactor/proposal_details_bloc.dart'; +import 'package:hypha_wallet/ui/sign_transaction/failed/sign_transaction_failed_page.dart'; +import 'package:hypha_wallet/ui/sign_transaction/success/sign_transaction_success_page.dart'; class ProposalDetailsPage extends StatelessWidget { - final String proposalId; + final String _proposalId; - const ProposalDetailsPage({super.key, required this.proposalId}); + const ProposalDetailsPage(this._proposalId, {super.key}); @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => ProposalDetailBloc(proposalId, GetIt.I.get(), GetIt.I.get()) - ..add(const ProposalDetailEvent.initial()), - child: const ProposalDetailsView() + create: (context) => GetIt.I.get(param1: _proposalId)..add(const ProposalDetailsEvent.initial()), + child: BlocListener( + listenWhen: (previous, current) => previous.command != current.command, + listener: (context, state) { + state.command?.when( + navigateToSuccessPage: () { + Get.to(() => const SignTransactionSuccessPage(transactionType: SignSuccessTransactionType.cast)); + }, + navigateToFailurePage: (HyphaError hyphaError) { + Get.to(() => SignTransactionFailedPage(hyphaError, text1: 'Casting vote', text2: 'An error occurred while casting your vote. Click the button below if you want to see the full error.') + ); + }, + ); + + context.read().add(const ProposalDetailsEvent.clearPageCommand()); + }, + child: const ProposalDetailsView(), + ), ); } } diff --git a/lib/ui/proposals/details/usecases/cast_vote_use_case.dart b/lib/ui/proposals/details/usecases/cast_vote_use_case.dart new file mode 100644 index 00000000..b2ad27e2 --- /dev/null +++ b/lib/ui/proposals/details/usecases/cast_vote_use_case.dart @@ -0,0 +1,35 @@ +import 'package:hypha_wallet/core/crypto/seeds_esr/eos_action.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/core/network/api/actions/vote_action_factory.dart'; +import 'package:hypha_wallet/core/network/api/eos_service.dart'; +import 'package:hypha_wallet/core/network/api/services/remote_config_service.dart'; +import 'package:hypha_wallet/core/network/models/user_profile_data.dart'; +import 'package:hypha_wallet/core/network/repository/auth_repository.dart'; +import 'package:hypha_wallet/ui/architecture/interactor/base_usecase.dart'; +import 'package:hypha_wallet/ui/architecture/result/result.dart'; +import 'package:hypha_wallet/ui/proposals/details/usecases/cast_vote_use_case_input.dart'; + +class CastVoteUseCase extends InputUseCase, CastVoteUseCaseInput> { + final AuthRepository _authRepository; + final EOSService _eosService; + final RemoteConfigService _remoteConfigService; + + CastVoteUseCase(this._authRepository, this._eosService, this._remoteConfigService); + + @override + Future> run(CastVoteUseCaseInput input) async { + final UserProfileData user = _authRepository.authDataOrCrash.userProfileData; + final String daoContract = _remoteConfigService.daoContract(network: user.network); + + final EOSAction eosAction = VoteActionFactory.voteAction(daoContract, user.accountName, input.proposalId, input.voteStatus); + + try { + final castVoteResult = await _eosService.runAction(signer: user, action: eosAction); + return Result.value(castVoteResult.asValue!.value); + } catch (e, stackTrace) { + LogHelper.e('Error casting vote', error: e, stacktrace: stackTrace); + return Result.error(HyphaError.fromError(e)); + } + } +} diff --git a/lib/ui/proposals/details/usecases/cast_vote_use_case_input.dart b/lib/ui/proposals/details/usecases/cast_vote_use_case_input.dart new file mode 100644 index 00000000..189d28ca --- /dev/null +++ b/lib/ui/proposals/details/usecases/cast_vote_use_case_input.dart @@ -0,0 +1,8 @@ +import 'package:hypha_wallet/core/network/models/vote_model.dart'; + +class CastVoteUseCaseInput { + final String proposalId; + final VoteStatus voteStatus; + + CastVoteUseCaseInput(this.proposalId, this.voteStatus); +} \ No newline at end of file diff --git a/lib/ui/proposals/details/usecases/get_proposal_details_use_case.dart b/lib/ui/proposals/details/usecases/get_proposal_details_use_case.dart index 58fc24f7..ffd2394d 100644 --- a/lib/ui/proposals/details/usecases/get_proposal_details_use_case.dart +++ b/lib/ui/proposals/details/usecases/get_proposal_details_use_case.dart @@ -1,6 +1,5 @@ import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart'; import 'package:hypha_wallet/core/network/models/proposal_details_model.dart'; -import 'package:hypha_wallet/core/network/models/vote_model.dart'; import 'package:hypha_wallet/core/network/repository/auth_repository.dart'; import 'package:hypha_wallet/core/network/repository/proposal_repository.dart'; import 'package:hypha_wallet/ui/architecture/result/result.dart'; @@ -11,6 +10,4 @@ class GetProposalDetailsUseCase { GetProposalDetailsUseCase(this._authRepository, this._proposalRepository); Future> run(String proposalId) async => _proposalRepository.getProposalDetails(proposalId,_authRepository.authDataOrCrash.userProfileData); - Future> castVote(String proposalId,VoteStatus vote) async => _proposalRepository.castVote(proposalId,vote,_authRepository.authDataOrCrash.userProfileData); - -} \ No newline at end of file +} diff --git a/lib/ui/proposals/list/components/hypha_proposals_action_card.dart b/lib/ui/proposals/list/components/hypha_proposals_action_card.dart index 83295043..8fe33343 100644 --- a/lib/ui/proposals/list/components/hypha_proposals_action_card.dart +++ b/lib/ui/proposals/list/components/hypha_proposals_action_card.dart @@ -28,7 +28,7 @@ class HyphaProposalsActionCard extends StatelessWidget { onTap: () { Get.Get.to( ProposalDetailsPage( - proposalId: _proposalModel.id ?? '', + _proposalModel.id ?? '', ), transition: Get.Transition.rightToLeft, ); @@ -126,7 +126,7 @@ class HyphaProposalsActionCard extends StatelessWidget { Expanded(child: ProposalCreator(creator)), ProposalButton('Vote', Icons.arrow_forward_ios, () { Get.Get.to( - ProposalDetailsPage(proposalId: _proposalModel.id!), + ProposalDetailsPage(_proposalModel.id!), transition: Get.Transition.rightToLeft, ); }), diff --git a/lib/ui/proposals/list/interactor/proposals_bloc.dart b/lib/ui/proposals/list/interactor/proposals_bloc.dart index 2cf812ae..3b191066 100644 --- a/lib/ui/proposals/list/interactor/proposals_bloc.dart +++ b/lib/ui/proposals/list/interactor/proposals_bloc.dart @@ -9,7 +9,7 @@ import 'package:hypha_wallet/ui/architecture/result/result.dart'; import 'package:hypha_wallet/ui/profile/interactor/profile_data.dart'; import 'package:hypha_wallet/ui/profile/usecases/fetch_profile_use_case.dart'; import 'package:hypha_wallet/ui/proposals/filter/interactor/filter_status.dart'; -import 'package:hypha_wallet/ui/proposals/list/interactor/get_proposals_use_case_input.dart'; +import 'package:hypha_wallet/ui/proposals/list/usecases/get_proposals_use_case_input.dart'; import 'package:hypha_wallet/ui/proposals/list/usecases/get_proposals_use_case.dart'; part 'proposals_bloc.freezed.dart'; diff --git a/lib/ui/proposals/list/usecases/get_proposals_use_case.dart b/lib/ui/proposals/list/usecases/get_proposals_use_case.dart index 67f7e40b..6072f081 100644 --- a/lib/ui/proposals/list/usecases/get_proposals_use_case.dart +++ b/lib/ui/proposals/list/usecases/get_proposals_use_case.dart @@ -4,7 +4,7 @@ import 'package:hypha_wallet/core/network/repository/auth_repository.dart'; import 'package:hypha_wallet/core/network/repository/proposal_repository.dart'; import 'package:hypha_wallet/ui/architecture/interactor/base_usecase.dart'; import 'package:hypha_wallet/ui/architecture/result/result.dart'; -import 'package:hypha_wallet/ui/proposals/list/interactor/get_proposals_use_case_input.dart'; +import 'package:hypha_wallet/ui/proposals/list/usecases/get_proposals_use_case_input.dart'; class GetProposalsUseCase extends InputUseCase, HyphaError>, GetProposalsUseCaseInput> { final AuthRepository _authRepository; diff --git a/lib/ui/proposals/list/interactor/get_proposals_use_case_input.dart b/lib/ui/proposals/list/usecases/get_proposals_use_case_input.dart similarity index 100% rename from lib/ui/proposals/list/interactor/get_proposals_use_case_input.dart rename to lib/ui/proposals/list/usecases/get_proposals_use_case_input.dart diff --git a/lib/ui/sign_transaction/failed/sign_transaction_failed_page.dart b/lib/ui/sign_transaction/failed/sign_transaction_failed_page.dart index b9b66784..ae5775ff 100644 --- a/lib/ui/sign_transaction/failed/sign_transaction_failed_page.dart +++ b/lib/ui/sign_transaction/failed/sign_transaction_failed_page.dart @@ -16,8 +16,9 @@ class SignTransactionFailedPage extends StatelessWidget { final HyphaError error; final String text1; final String text2; + final VoidCallback? callBack; - const SignTransactionFailedPage(this.error, {super.key, this.text1 = 'This transaction ', this.text2 = 'Please try again by triggering the transaction from the website or app. Sorry for the inconvenience.'}); + const SignTransactionFailedPage(this.error, {this.text1 = 'Transaction', this.text2 = 'Please try again by triggering the transaction from the website or app. Sorry for the inconvenience.', this.callBack, super.key}); @override Widget build(BuildContext context) { @@ -46,15 +47,14 @@ class SignTransactionFailedPage extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - HyphaAppButton( - buttonType: ButtonType.secondary, - onPressed: () { - Get.back(); - context.read().add(const ProposalCreationEvent.publishProposal()); - }, - title: 'Retry', - ), - const SizedBox(height: 20), + if(callBack != null) ... [ + HyphaAppButton( + buttonType: ButtonType.secondary, + onPressed: callBack, + title: 'Retry', + ), + const SizedBox(height: 20) + ], HyphaAppButton( buttonType: ButtonType.secondary, onPressed: () { diff --git a/lib/ui/sign_transaction/success/sign_transaction_success_page.dart b/lib/ui/sign_transaction/success/sign_transaction_success_page.dart index 40b8388b..81208312 100644 --- a/lib/ui/sign_transaction/success/sign_transaction_success_page.dart +++ b/lib/ui/sign_transaction/success/sign_transaction_success_page.dart @@ -10,7 +10,8 @@ import 'package:hypha_wallet/ui/bottom_navigation/hypha_bottom_navigation.dart'; enum SignSuccessTransactionType { approved('Approved'), - published('published'); + published('published'), + cast('cast'); const SignSuccessTransactionType(this.value); @@ -24,13 +25,16 @@ enum SignSuccessTransactionType { class SignTransactionSuccessPage extends StatelessWidget { final SignSuccessTransactionType transactionType; - final String? proposalId; - const SignTransactionSuccessPage({super.key, required this.transactionType, this.proposalId}); + const SignTransactionSuccessPage({super.key, required this.transactionType}); @override Widget build(BuildContext context) { - final successText = RichText( + final String textPrefix = transactionType == SignSuccessTransactionType.approved + ? 'Transaction' + : 'Your ${transactionType == SignSuccessTransactionType.published ? 'proposal' : 'vote'} has been\nsuccessfully'; + + final RichText successText = RichText( textAlign: TextAlign.center, text: TextSpan( style: context.hyphaTextTheme.regular.copyWith( @@ -38,7 +42,7 @@ class SignTransactionSuccessPage extends StatelessWidget { ), children: [ TextSpan( - text: proposalId == null ? 'Transaction' : 'Your Proposal has been\nsuccessfully', + text: textPrefix, style: context.hyphaTextTheme.regular.copyWith(color: HyphaColors.primaryBlu), ), const TextSpan(text: ' '), @@ -52,31 +56,11 @@ class SignTransactionSuccessPage extends StatelessWidget { child: Scaffold( backgroundColor: HyphaColors.transparent, bottomNavigationBar: HyphaSafeBottomNavigationBar( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - /// uncomment this (when you get the created proposal ID) - /*if(proposalId != null) ... [ - HyphaAppButton( - buttonType: ButtonType.secondary, - buttonColor: HyphaColors.gradientBlackLight, - onPressed: () { - Get.to( - ProposalDetailsPage(proposalId: proposalId!), - transition: Transition.rightToLeft, - ); - }, - title: 'See Proposal Details', - ), - const SizedBox(height: 20), - ],*/ - HyphaAppButton( - onPressed: () { - Get.offAll(() => const HyphaBottomNavigation()); - }, - title: 'Close', - ), - ], + child: HyphaAppButton( + onPressed: () { + Get.offAll(() => const HyphaBottomNavigation()); + }, + title: 'Close', ), ), body: Stack( diff --git a/pubspec.yaml b/pubspec.yaml index de352f72..62acb392 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 2.0.0+67 +version: 2.0.0+68 environment: sdk: '>=3.0.0 <4.0.0'