Skip to content

Commit

Permalink
Merge pull request #263 from hypha-dao/feature/show_dao_name
Browse files Browse the repository at this point in the history
Show DAO name on invite
  • Loading branch information
n13 authored Sep 30, 2023
2 parents 6e8649d + be5d44e commit 2d88737
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 108 deletions.
8 changes: 4 additions & 4 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class HyphaAppView extends StatelessWidget {
navigateToSignTransaction: (ScanQrCodeResultData data) {
_showSignTransactionBottomSheet(data);
},
showJoinDaoRationale: (daoName, secret) {
_showJoinDaoRationale(daoName, secret, context);
showJoinDaoRationale: (inviteLinkData) {
_showJoinDaoRationale(inviteLinkData, context);
},
);
context.read<DeeplinkBloc>().add(const DeeplinkEvent.clearPageCommand());
Expand Down Expand Up @@ -226,9 +226,9 @@ class HyphaAppView extends StatelessWidget {
);
}

void _showJoinDaoRationale(String daoName, String secret, BuildContext context) {
void _showJoinDaoRationale(InviteLinkData inviteLinkData, BuildContext context) {
Get.Get.bottomSheet(
JoinDaoRationaleBottomSheet(daoName: daoName, secret: secret),
JoinDaoRationaleBottomSheet(inviteLinkData: inviteLinkData),
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(30)),
Expand Down
7 changes: 4 additions & 3 deletions lib/core/di/bloc_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ void _registerBlocsModule() {
),
);

_registerFactoryWithParams<JoinDaoBloc, String, void>(
(secret, _) => JoinDaoBloc(
_registerFactoryWithParams<JoinDaoBloc, InviteLinkData, void>(
(inviteLinkData, _) => JoinDaoBloc(
_getIt<AuthRepository>(),
_getIt<InviteService>(),
_getIt<ErrorHandlerManager>(),
secret,
_getIt<GetDaoNameUseCase>(),
inviteLinkData,
),
);

Expand Down
1 change: 1 addition & 0 deletions lib/core/di/di_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import 'package:hypha_wallet/ui/history/details/interactor/transaction_detail_bl
import 'package:hypha_wallet/ui/history/transactions/interactor/transactions_bloc.dart';
import 'package:hypha_wallet/ui/history/transactions/usecases/get_transaction_history_use_case.dart';
import 'package:hypha_wallet/ui/home_page/interactor/home_bloc.dart';
import 'package:hypha_wallet/ui/home_page/usecases/get_dao_name_use_case.dart';
import 'package:hypha_wallet/ui/home_page/usecases/parse_qr_code_use_case.dart';
import 'package:hypha_wallet/ui/onboarding/create_account/interactor/create_account_bloc.dart';
import 'package:hypha_wallet/ui/onboarding/edit_account/edit_account_page.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/core/di/usecases_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ void _registerUseCasesModule() {
_getIt<FirebaseDatabaseService>(),
_getIt<AuthRepository>(),
));

_registerFactory(() => GetDaoNameUseCase(_getIt<DaoService>()));
}
5 changes: 0 additions & 5 deletions lib/core/network/api/services/dao_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart';
import 'package:hypha_wallet/core/logging/log_helper.dart';
Expand Down Expand Up @@ -60,9 +58,6 @@ class DaoService {
try {
final res = await _networkingManager.post(url, data: query);
final Map<String, dynamic> response = res.data;

print("response: ${response}");

final List<dynamic> daos = response['data']['queryDao'];
return Result.value(daos.isNotEmpty ? DaoData.fromJson(daos[0]) : null);
} catch (error, stackTrace) {
Expand Down
20 changes: 11 additions & 9 deletions lib/ui/blocs/deeplink/deeplink_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,28 @@ class DeeplinkBloc extends Bloc<DeeplinkEvent, DeeplinkState> {
if (queryParams.isNotEmpty && queryParams.containsKey('code') && queryParams.containsKey('chain')) {
final code = queryParams['code']!;
final chain = queryParams['chain']!;
final network = Network.fromString(chain);
final dao = queryParams['dao']!;

final String enrollSecret = queryParams['enroll_secret']!;

final inviteLinkData = InviteLinkData(
code: code,
network: network,
dao: dao,
enrollSecret: enrollSecret,
);

final PageCommand command;
if(_authRepository.currentAuthStatus is Authenticated) {
command = PageCommand.showJoinDaoRationale(dao, enrollSecret);
if (_authRepository.currentAuthStatus is Authenticated) {
command = PageCommand.showJoinDaoRationale(inviteLinkData);
} else {
command = const PageCommand.navigateToCreateAccount();
}

/// Emit new state with data from link
emit(
state.copyWith(
inviteLinkData: InviteLinkData(
code: code,
network: Network.fromString(chain),
dao: dao,
enrollSecret: enrollSecret,
),
inviteLinkData: inviteLinkData,
command: command,
),
);
Expand Down
68 changes: 30 additions & 38 deletions lib/ui/blocs/deeplink/deeplink_bloc.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ mixin _$PageCommand {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() navigateToCreateAccount,
required TResult Function(String daoName, String secret)
required TResult Function(InviteLinkData inviteLinkData)
showJoinDaoRationale,
required TResult Function(ScanQrCodeResultData data)
navigateToSignTransaction,
Expand All @@ -784,14 +784,14 @@ mixin _$PageCommand {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? navigateToCreateAccount,
TResult? Function(String daoName, String secret)? showJoinDaoRationale,
TResult? Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult? Function(ScanQrCodeResultData data)? navigateToSignTransaction,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? navigateToCreateAccount,
TResult Function(String daoName, String secret)? showJoinDaoRationale,
TResult Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult Function(ScanQrCodeResultData data)? navigateToSignTransaction,
required TResult orElse(),
}) =>
Expand Down Expand Up @@ -882,7 +882,7 @@ class _$_NavigateToCreateAccount implements _NavigateToCreateAccount {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() navigateToCreateAccount,
required TResult Function(String daoName, String secret)
required TResult Function(InviteLinkData inviteLinkData)
showJoinDaoRationale,
required TResult Function(ScanQrCodeResultData data)
navigateToSignTransaction,
Expand All @@ -894,7 +894,7 @@ class _$_NavigateToCreateAccount implements _NavigateToCreateAccount {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? navigateToCreateAccount,
TResult? Function(String daoName, String secret)? showJoinDaoRationale,
TResult? Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult? Function(ScanQrCodeResultData data)? navigateToSignTransaction,
}) {
return navigateToCreateAccount?.call();
Expand All @@ -904,7 +904,7 @@ class _$_NavigateToCreateAccount implements _NavigateToCreateAccount {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? navigateToCreateAccount,
TResult Function(String daoName, String secret)? showJoinDaoRationale,
TResult Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult Function(ScanQrCodeResultData data)? navigateToSignTransaction,
required TResult orElse(),
}) {
Expand Down Expand Up @@ -963,7 +963,7 @@ abstract class _$$_ShowJoinDaoRationaleCopyWith<$Res> {
$Res Function(_$_ShowJoinDaoRationale) then) =
__$$_ShowJoinDaoRationaleCopyWithImpl<$Res>;
@useResult
$Res call({String daoName, String secret});
$Res call({InviteLinkData inviteLinkData});
}

/// @nodoc
Expand All @@ -977,48 +977,41 @@ class __$$_ShowJoinDaoRationaleCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? daoName = null,
Object? secret = null,
Object? inviteLinkData = null,
}) {
return _then(_$_ShowJoinDaoRationale(
null == daoName
? _value.daoName
: daoName // ignore: cast_nullable_to_non_nullable
as String,
null == secret
? _value.secret
: secret // ignore: cast_nullable_to_non_nullable
as String,
null == inviteLinkData
? _value.inviteLinkData
: inviteLinkData // ignore: cast_nullable_to_non_nullable
as InviteLinkData,
));
}
}

/// @nodoc
class _$_ShowJoinDaoRationale implements _ShowJoinDaoRationale {
const _$_ShowJoinDaoRationale(this.daoName, this.secret);
const _$_ShowJoinDaoRationale(this.inviteLinkData);

@override
final String daoName;
@override
final String secret;
final InviteLinkData inviteLinkData;

@override
String toString() {
return 'PageCommand.showJoinDaoRationale(daoName: $daoName, secret: $secret)';
return 'PageCommand.showJoinDaoRationale(inviteLinkData: $inviteLinkData)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_ShowJoinDaoRationale &&
(identical(other.daoName, daoName) || other.daoName == daoName) &&
(identical(other.secret, secret) || other.secret == secret));
(identical(other.inviteLinkData, inviteLinkData) ||
other.inviteLinkData == inviteLinkData));
}

@override
int get hashCode => Object.hash(runtimeType, daoName, secret);
int get hashCode => Object.hash(runtimeType, inviteLinkData);

@JsonKey(ignore: true)
@override
Expand All @@ -1031,34 +1024,34 @@ class _$_ShowJoinDaoRationale implements _ShowJoinDaoRationale {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() navigateToCreateAccount,
required TResult Function(String daoName, String secret)
required TResult Function(InviteLinkData inviteLinkData)
showJoinDaoRationale,
required TResult Function(ScanQrCodeResultData data)
navigateToSignTransaction,
}) {
return showJoinDaoRationale(daoName, secret);
return showJoinDaoRationale(inviteLinkData);
}

@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? navigateToCreateAccount,
TResult? Function(String daoName, String secret)? showJoinDaoRationale,
TResult? Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult? Function(ScanQrCodeResultData data)? navigateToSignTransaction,
}) {
return showJoinDaoRationale?.call(daoName, secret);
return showJoinDaoRationale?.call(inviteLinkData);
}

@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? navigateToCreateAccount,
TResult Function(String daoName, String secret)? showJoinDaoRationale,
TResult Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult Function(ScanQrCodeResultData data)? navigateToSignTransaction,
required TResult orElse(),
}) {
if (showJoinDaoRationale != null) {
return showJoinDaoRationale(daoName, secret);
return showJoinDaoRationale(inviteLinkData);
}
return orElse();
}
Expand Down Expand Up @@ -1103,11 +1096,10 @@ class _$_ShowJoinDaoRationale implements _ShowJoinDaoRationale {
}

abstract class _ShowJoinDaoRationale implements PageCommand {
const factory _ShowJoinDaoRationale(
final String daoName, final String secret) = _$_ShowJoinDaoRationale;
const factory _ShowJoinDaoRationale(final InviteLinkData inviteLinkData) =
_$_ShowJoinDaoRationale;

String get daoName;
String get secret;
InviteLinkData get inviteLinkData;
@JsonKey(ignore: true)
_$$_ShowJoinDaoRationaleCopyWith<_$_ShowJoinDaoRationale> get copyWith =>
throw _privateConstructorUsedError;
Expand Down Expand Up @@ -1183,7 +1175,7 @@ class _$_ESRLinkNavigateToSignTransaction
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() navigateToCreateAccount,
required TResult Function(String daoName, String secret)
required TResult Function(InviteLinkData inviteLinkData)
showJoinDaoRationale,
required TResult Function(ScanQrCodeResultData data)
navigateToSignTransaction,
Expand All @@ -1195,7 +1187,7 @@ class _$_ESRLinkNavigateToSignTransaction
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? navigateToCreateAccount,
TResult? Function(String daoName, String secret)? showJoinDaoRationale,
TResult? Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult? Function(ScanQrCodeResultData data)? navigateToSignTransaction,
}) {
return navigateToSignTransaction?.call(data);
Expand All @@ -1205,7 +1197,7 @@ class _$_ESRLinkNavigateToSignTransaction
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? navigateToCreateAccount,
TResult Function(String daoName, String secret)? showJoinDaoRationale,
TResult Function(InviteLinkData inviteLinkData)? showJoinDaoRationale,
TResult Function(ScanQrCodeResultData data)? navigateToSignTransaction,
required TResult orElse(),
}) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/blocs/deeplink/page_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ part of 'deeplink_bloc.dart';
@freezed
class PageCommand with _$PageCommand {
const factory PageCommand.navigateToCreateAccount() = _NavigateToCreateAccount;
const factory PageCommand.showJoinDaoRationale(String daoName, String secret) = _ShowJoinDaoRationale;
const factory PageCommand.showJoinDaoRationale(InviteLinkData inviteLinkData) = _ShowJoinDaoRationale;
const factory PageCommand.navigateToSignTransaction(ScanQrCodeResultData data) = _ESRLinkNavigateToSignTransaction;
}
24 changes: 24 additions & 0 deletions lib/ui/home_page/usecases/get_dao_name_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart';
import 'package:hypha_wallet/core/network/api/services/dao_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/ui/architecture/result/result.dart' as HResult;

class GetDaoNameUseCase {
final DaoService _daoService;

GetDaoNameUseCase(this._daoService);

Future<HResult.Result<String, HyphaError>> run(String daoId, Network network) async {
final HResult.Result<DaoData?, HyphaError> data = await _daoService.getDaoById(daoId: daoId, network: network);
final daoName = data.asValue?.value?.settingsDaoTitle;

if (daoName != null) {
return HResult.Result.value(daoName);
} else if (data.isError) {
return HResult.Result.error(data.asError!.error);
} else {
return HResult.Result.error(HyphaError.generic('Could not find dao with ID: $daoId'));
}
}
}
20 changes: 15 additions & 5 deletions lib/ui/onboarding/join_dao/interactor/join_dao_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:hypha_wallet/core/error_handler/error_handler_manager.dart';
import 'package:hypha_wallet/core/network/api/services/invite_service.dart';
import 'package:hypha_wallet/core/network/repository/auth_repository.dart';
import 'package:hypha_wallet/ui/architecture/interactor/page_states.dart';
import 'package:hypha_wallet/ui/blocs/deeplink/deeplink_bloc.dart';
import 'package:hypha_wallet/ui/home_page/usecases/get_dao_name_use_case.dart';

part 'join_dao_bloc.freezed.dart';

Expand All @@ -18,30 +20,38 @@ class JoinDaoBloc extends Bloc<JoinDaoEvent, JoinDaoState> {
final AuthRepository _authRepository;
final InviteService _inviteService;
final ErrorHandlerManager _errorHandlerManager;
final String secret;
final GetDaoNameUseCase _getDaoNameUseCase;
final InviteLinkData _inviteLinkData;

JoinDaoBloc(
this._authRepository,
this._inviteService,
this._errorHandlerManager,
this.secret,
this._getDaoNameUseCase,
this._inviteLinkData,
) : super(const JoinDaoState()) {
on<_Initial>(_initial);
on<_OnYesTapped>(_onYesTapped);
}

Future<void> _initial(_Initial event, Emitter<JoinDaoState> emit) async {
emit(state.copyWith(pageState: PageState.success));
emit(state.copyWith(pageState: PageState.loading));
final result = await _getDaoNameUseCase.run(_inviteLinkData.dao!, _inviteLinkData.network);
if (result.isValue) {
emit(state.copyWith(pageState: PageState.success, daoName: result.asValue!.value));
} else {
emit(state.copyWith(pageState: PageState.failure));
}
}

FutureOr<void> _onYesTapped(_OnYesTapped event, Emitter<JoinDaoState> emit) async {
emit(state.copyWith(isButtonLoading: true));
final result = await _inviteService.redeemInvite(
user: _authRepository.authDataOrCrash.userProfileData,
secret: secret,
secret: _inviteLinkData.enrollSecret!,
);

if(result.isValue) {
if (result.isValue) {
emit(state.copyWith(isButtonLoading: false));
Get.back();
} else {
Expand Down
Loading

0 comments on commit 2d88737

Please sign in to comment.