Skip to content

Commit

Permalink
Merge branch 'master' into release/2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo Guijarro authored Dec 8, 2021
2 parents 2db163f + 1bc1220 commit 96d5902
Show file tree
Hide file tree
Showing 110 changed files with 1,613 additions and 1,135 deletions.
7 changes: 7 additions & 0 deletions lib/blocs/authentication/viewmodels/authentication_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class AuthenticationBloc extends Bloc<AuthenticationEvent, AuthenticationState>
}

Future<void> _onImportAccount(OnImportAccount event, Emitter<AuthenticationState> emit) async {
/// Cancel recover should not be executed on switch account (app unlocked).
/// Since cancel recover removes preferences and secure storage.
if (state.authStatus != AuthStatus.unlocked) {
/// In case there was a recovery in place. We cancel it.
/// This will clean all data
await StopRecoveryUseCase().run();
}
await SaveAccountUseCase().run(accountName: event.account, authData: event.authData);
// New account --> re-start auth status
add(const InitAuthStatus());
Expand Down
20 changes: 15 additions & 5 deletions lib/blocs/rates/mappers/rates_state_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:seeds/blocs/rates/viewmodels/rates_bloc.dart';
import 'package:seeds/datasource/remote/model/fiat_rate_model.dart';
import 'package:seeds/datasource/remote/model/rate_model.dart';
import 'package:seeds/datasource/remote/model/token_model.dart';
import 'package:seeds/domain-shared/page_state.dart';
import 'package:seeds/domain-shared/result_to_state_mapper.dart';

Expand All @@ -9,11 +10,20 @@ class RatesStateMapper extends StateMapper {
if (areAllResultsError(results)) {
return currentState.copyWith(pageState: PageState.failure, errorMessage: 'Cannot fetch balance...');
} else {
results.retainWhere((Result i) => i.isValue);
final values = results.map((Result i) => i.asValue!.value).toList();
final RateModel? rate = values.firstWhere((i) => i is RateModel, orElse: () => null);
final FiatRateModel? fiatRate = values.firstWhere((i) => i is FiatRateModel, orElse: () => null);
return currentState.copyWith(rate: rate, fiatRate: fiatRate);
/// note: we re-use existing conversion rates if we can't load new ones
final RateModel? seedsRateModel = results[0].asValue?.value ?? currentState.rates?[seedsToken.symbol];
final RateModel? telosRateModel = results[1].asValue?.value ?? currentState.rates?[telosToken.symbol];
final rates = {
husdToken.symbol: RateModel(husdToken.symbol, 1),
};
if (seedsRateModel != null) {
rates[seedsToken.symbol] = seedsRateModel;
}
if (telosRateModel != null) {
rates[telosToken.symbol] = telosRateModel;
}
final FiatRateModel? fiatRate = results[2].asValue?.value;
return currentState.copyWith(rates: rates, fiatRate: fiatRate);
}
}
}
3 changes: 2 additions & 1 deletion lib/blocs/rates/usecases/get_rates_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class GetRatesUseCase {

Future<List<Result>> run() {
final futures = [
_ratesRepository.getUSDRate(),
_ratesRepository.getSeedsRate(),
_ratesRepository.getTelosRate(),
_ratesRepository.getFiatRates(),
];
return Future.wait(futures);
Expand Down
10 changes: 5 additions & 5 deletions lib/blocs/rates/viewmodels/rates_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ part of 'rates_bloc.dart';
class RatesState extends Equatable {
final PageState pageState;
final String? errorMessage;
final RateModel? rate;
final Map<String, RateModel>? rates;
final FiatRateModel? fiatRate;

const RatesState({
required this.pageState,
this.errorMessage,
this.rate,
this.rates,
this.fiatRate,
});

@override
List<Object?> get props => [
pageState,
errorMessage,
rate,
rates,
fiatRate,
];

RatesState copyWith({
PageState? pageState,
String? errorMessage,
RateModel? rate,
Map<String, RateModel>? rates,
FiatRateModel? fiatRate,
}) {
return RatesState(
pageState: pageState ?? this.pageState,
errorMessage: errorMessage,
rate: rate ?? this.rate,
rates: rates ?? this.rates,
fiatRate: fiatRate ?? this.fiatRate,
);
}
Expand Down
46 changes: 25 additions & 21 deletions lib/components/search_result_row.dart
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:seeds/components/profile_avatar.dart';
import 'package:seeds/datasource/remote/model/member_model.dart';
import 'package:seeds/design/app_theme.dart';
import 'package:seeds/utils/cap_utils.dart';

class SearchResultRow extends StatelessWidget {
final String? imageUrl;
final String account;
final String? name;
final GestureTapCallback? resultCallBack;
final MemberModel member;
final GestureTapCallback? onTap;

const SearchResultRow({
Key? key,
this.imageUrl,
required this.account,
this.name,
this.resultCallBack,
}) : super(key: key);
const SearchResultRow({Key? key, required this.member, this.onTap}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10, left: 16, right: 16),
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
child: InkWell(
onTap: resultCallBack,
onTap: onTap,
child: Row(
children: [
ProfileAvatar(
size: 60,
image: imageUrl,
account: account,
nickname: name,
image: member.image,
account: member.account,
nickname: member.nickname,
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 16, right: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
(name != null && name?.isNotEmpty == true) ? name! : account,
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.button,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
member.nickname.isNotEmpty ? member.nickname : member.account,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.button,
),
Text(
describeEnum(member.userCitizenshipStatus).inCaps,
style: Theme.of(context).textTheme.button,
),
],
),
const SizedBox(height: 8),
Text(account, style: Theme.of(context).textTheme.subtitle2OpacityEmphasis)
Text(member.account, style: Theme.of(context).textTheme.subtitle2OpacityEmphasis)
],
),
),
Expand Down
34 changes: 0 additions & 34 deletions lib/components/search_user/components/search_result_list.dart

This file was deleted.

65 changes: 65 additions & 0 deletions lib/components/search_user/components/search_user_text_field.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:seeds/components/search_user/interactor/search_user_bloc.dart';
import 'package:seeds/components/search_user/interactor/viewmodels/search_user_events.dart';
import 'package:seeds/components/search_user/interactor/viewmodels/search_user_state.dart';
import 'package:seeds/constants/app_colors.dart';
import 'package:seeds/domain-shared/page_state.dart';
import 'package:seeds/i18n/components/components.i18n.dart';

class SearchUserTextField extends StatefulWidget {
const SearchUserTextField({Key? key}) : super(key: key);

@override
_SearchUserTextFieldState createState() => _SearchUserTextFieldState();
}

class _SearchUserTextFieldState extends State<SearchUserTextField> {
final TextEditingController _controller = TextEditingController();
final _searchBorder = const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
borderSide: BorderSide(color: AppColors.darkGreen2, width: 2.0),
);

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return TextField(
autofocus: true,
autocorrect: false,
controller: _controller,
onChanged: (value) {
BlocProvider.of<SearchUserBloc>(context).add(OnSearchChange(searchQuery: value));
},
decoration: InputDecoration(
suffixIcon: BlocBuilder<SearchUserBloc, SearchUserState>(
builder: (context, state) {
return state.pageState == PageState.loading
? Transform.scale(
scale: 0.5,
child: const CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(AppColors.green)),
)
: IconButton(
icon: Icon(state.searchBarIcon, color: AppColors.white, size: 26),
onPressed: () {
if (state.searchBarIcon == Icons.clear) {
BlocProvider.of<SearchUserBloc>(context).add(ClearIconTapped());
_controller.clear();
}
},
);
},
),
enabledBorder: _searchBorder,
focusedBorder: _searchBorder,
border: const OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(8))),
hintText: 'Search...'.i18n,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SearchUserStateMapper extends StateMapper {
}

if (currentState.showOnlyCitizenshipStatus != null) {
uniqueUsers.removeWhere((element) => element.citizenshipStatus != currentState.showOnlyCitizenshipStatus);
uniqueUsers.removeWhere((element) => element.userCitizenshipStatus != currentState.showOnlyCitizenshipStatus);
}

return currentState.copyWith(pageState: PageState.success, users: uniqueUsers);
Expand Down
Loading

0 comments on commit 96d5902

Please sign in to comment.