Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: implement sign transaction pages #378

Merged
merged 1 commit into from
Nov 29, 2024
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
9 changes: 9 additions & 0 deletions lib/core/di/bloc_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ void _registerBlocsModule() {
(daos, _) => ProposalCreationBloc(
daos,
_getIt<PublishProposalUseCase>(),
_getIt<ErrorHandlerManager>(),
),
);

_registerFactoryWithParams<ProposalDetailsBloc, String, void>(
(proposalId, _) => ProposalDetailsBloc(
_getIt<GetProposalDetailsUseCase>(),
_getIt<CastVoteUseCase>(),
_getIt<ErrorHandlerManager>(),
proposalId
),
);
}
2 changes: 2 additions & 0 deletions lib/core/di/di_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion lib/core/di/repositories_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ void _registerRepositoriesModule() {

_registerLazySingleton(() => TransactionHistoryRepository(service: _getIt<TransactionHistoryService>()));

_registerLazySingleton(() => ProposalRepository(_getIt<RemoteConfigService>(),_getIt<EOSService>(),_getIt<DaoService>(),_getIt<ProposalService>(),_getIt<ProfileService>()));
_registerLazySingleton(() => ProposalRepository(_getIt<DaoService>(),_getIt<ProposalService>(),_getIt<ProfileService>()));
}
2 changes: 2 additions & 0 deletions lib/core/di/usecases_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void _registerUseCasesModule() {

_registerFactory(() => GetProposalDetailsUseCase(_getIt<AuthRepository>(), _getIt<ProposalRepository>()));

_registerFactory(() => CastVoteUseCase(_getIt<AuthRepository>(), _getIt<EOSService>(), _getIt<RemoteConfigService>()));

_registerFactory(() => AggregateDaoProposalCountsUseCase());

_registerFactory(() => PublishProposalUseCase(_getIt<AuthRepository>(), _getIt<EOSService>(), _getIt<RemoteConfigService>()));
Expand Down
35 changes: 2 additions & 33 deletions lib/core/network/repository/proposal_repository.dart
Original file line number Diff line number Diff line change
@@ -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<Result<List<ProposalModel>, HyphaError>> getProposals(UserProfileData user, GetProposalsUseCaseInput input) async {
final List<Future<Result<Map<String, dynamic>, HyphaError>>> futures = input.daos.map((DaoData dao) {
Expand Down Expand Up @@ -153,24 +142,4 @@ class ProposalRepository {
return Result.error(result.asError!.error);
}
}

Future<Result<String, HyphaError>> 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'));
}
}
}
14 changes: 10 additions & 4 deletions lib/ui/proposals/creation/proposal_creation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProposalCreationBloc>(),
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<ProposalCreationBloc>().add(const ProposalCreationEvent.publishProposal());
}
)
);
},
);
Expand Down
18 changes: 13 additions & 5 deletions lib/ui/proposals/details/components/proposal_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ 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';
import 'package:hypha_wallet/ui/proposals/components/proposal_expiration_timer.dart';
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 {
Expand Down Expand Up @@ -63,7 +64,7 @@ class _ProposalDetailsViewState extends State<ProposalDetailsView> {
scrolledUnderElevation: 0,
title: const Text('Proposal Details'),
),
body: BlocBuilder<ProposalDetailBloc, ProposalDetailState>(
body: BlocBuilder<ProposalDetailsBloc, ProposalDetailsState>(
builder: (context, state) {
return HyphaBodyWidget(
pageState: state.pageState,
Expand Down Expand Up @@ -255,7 +256,14 @@ class _ProposalDetailsViewState extends State<ProposalDetailsView> {
}[userVote.voteStatus] ??
'You chose to abstain',
)
: _buildVoteWidget(context),
: BlocBuilder<ProposalDetailsBloc, ProposalDetailsState>(
builder: (context, state) {
return state.votingState == PageState.loading ? const Padding(
padding: EdgeInsets.only(top: 20),
child: Center(child: CircularProgressIndicator.adaptive()),
) : _buildVoteWidget(context);
},
),
),
],
),
Expand Down Expand Up @@ -299,9 +307,9 @@ Widget _buildVoteWidget(BuildContext context) => Column(
}

// Get the bloc instances
final proposalDetailBloc = context.read<ProposalDetailBloc>();
final proposalDetailBloc = context.read<ProposalDetailsBloc>();
// Dispatch the castVote event
proposalDetailBloc.add(ProposalDetailEvent.castVote(voteStatus));
proposalDetailBloc.add(ProposalDetailsEvent.castVote(voteStatus));
},
buttonType: ButtonType.danger,
buttonColor: index == 0
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/proposals/details/interactor/page_command.dart
Original file line number Diff line number Diff line change
@@ -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;
}
64 changes: 0 additions & 64 deletions lib/ui/proposals/details/interactor/proposal_detail_bloc.dart

This file was deleted.

Loading
Loading