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

Fix transactions #259

Merged
merged 5 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions lib/core/network/models/transaction_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ sealed class TransactionModel extends Equatable {
required Map<String, dynamic> data,
}) {
return switch (actionName) {
'transfer'
when account == _hyphaTokenAccount || account == _hyphaWrapTokenAccount || account == _systemTokenAccount =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when account == _hyphaTokenAccount || account == _hyphaWrapTokenAccount || account == _systemTokenAccount

Is this needed??

Basically this is never true when it call it for my account.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah because we recognize our own wrap token accounts

This is only identifying a transaction as a transfer

system token = TLOS or EOS
hypha token = hypha.hypha
wrap token = this isn't working yet but I think we should keep it there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so a transfer is any actions that includes 'transfer' as the action name

Later on we decide which one to show or not. But the model is not the one dictating this, the UI is.

The models just models data.

TransactionTransfer(
'transfer' => TransactionTransfer(
account: account,
actionName: actionName,
blockNumber: blockNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ class TransactionHistoryRepository {

TransactionHistoryRepository({required this.service});

Future<Result<List<TransactionModel>, HyphaError>> getTransactions(UserProfileData user, bool transferOnly,
{useV1History = false}) async {
Future<Result<List<TransactionModel>, HyphaError>> getTransactions(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

UserProfileData user,
bool transferOnly, {
useV1History = false,
}) async {
try {
final Response response = useV1History
? await service.getAllTransactionsV1History(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BottomNavigationBloc extends Bloc<BottomNavigationEvent, BottomNavigationS
BottomNavigationState(
allPages: [
BottomNavigationPage.home,
if (_remoteConfigService.isWalletEnabled) BottomNavigationPage.wallet,
if (true) BottomNavigationPage.wallet,
BottomNavigationPage.transactions,
BottomNavigationPage.profile,
BottomNavigationPage.settings,
Expand Down
19 changes: 16 additions & 3 deletions lib/ui/wallet/components/recent_transactions_widget.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';
import 'package:hypha_wallet/design/buttons/hypha_app_button.dart';
import 'package:hypha_wallet/design/hypha_card.dart';
import 'package:hypha_wallet/design/hypha_colors.dart';
import 'package:hypha_wallet/design/progress_indicator/hypha_progress_indicator.dart';
import 'package:hypha_wallet/design/themes/extensions/theme_extension_provider.dart';
import 'package:hypha_wallet/ui/shared/listview_with_all_separators.dart';
import 'package:hypha_wallet/ui/wallet/components/wallet_transaction_tile.dart';
import 'package:hypha_wallet/ui/wallet/interactor/wallet_bloc.dart';

class RecentTransactionsWidget extends StatelessWidget {
final bool loadingTransaction;
Expand Down Expand Up @@ -49,9 +52,19 @@ class RecentTransactionsWidget extends StatelessWidget {
child: HyphaCard(
child: Padding(
padding: const EdgeInsets.all(24),
child: Text(
'You haven’t done any transaction yet',
style: context.hyphaTextTheme.ralMediumSmallNote,
child: Column(
children: [
Text(
'You haven’t done any transaction yet',
style: context.hyphaTextTheme.ralMediumSmallNote,
),
HyphaAppButton(
title: 'Refresh',
onPressed: () {
context.read<WalletBloc>().add(const WalletEvent.onRefresh());
},
)
],
),
),
),
Expand Down
38 changes: 27 additions & 11 deletions lib/ui/wallet/interactor/wallet_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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/ui/architecture/interactor/page_states.dart';
import 'package:hypha_wallet/ui/architecture/result/result.dart';
import 'package:hypha_wallet/ui/wallet/components/wallet_transaction_tile.dart';
Expand All @@ -26,26 +27,24 @@ class WalletBloc extends Bloc<WalletEvent, WalletState> {
WalletBloc(
this._errorHandlerManager,
this._getUserTokensUseCase,
this._getTransactionHistoryDataUseCase,
this._getTransactionHistoryDataUseCase,
) : super(const WalletState()) {
on<_Initial>(_initial);
on<_OnTransactionsChanged>(_onTransactionsChanged);
on<_OnRefresh>(_onRefresh);
on<_ClearPageCommand>((_, emit) => emit(state.copyWith(command: null)));
}

Future<void> _initial(_Initial event, Emitter<WalletState> emit) async {
emit(state.copyWith(pageState: PageState.success, loadingTransaction: true));

unawaited(_getTransactionHistoryDataUseCase.run(true).then((result) {
if (result.isValue && !isClosed) {
emit(state.copyWith(
pageState: PageState.success,
recentTransactions: result.valueOrCrash,
loadingTransaction: false,
));
} else if (!isClosed){
// ignore: unawaited_futures
_errorHandlerManager.handlerError(result.asError!.error);
emit(state.copyWith(loadingTransaction: false));
if (isClosed) {
return;
}

if (result.isValue) {
add(WalletEvent.onTransactionsChanged(result));
}
}));

Expand All @@ -54,4 +53,21 @@ class WalletBloc extends Bloc<WalletEvent, WalletState> {
return state.copyWith(pageState: PageState.success, tokens: data);
});
}

FutureOr<void> _onTransactionsChanged(_OnTransactionsChanged event, Emitter<WalletState> emit) {
if (event.value.isValue) {
emit(state.copyWith(
pageState: PageState.success,
recentTransactions: event.value.asValue!.value,
loadingTransaction: false,
));
} else {
_errorHandlerManager.handlerError(event.value.asError!.error);
emit(state.copyWith(loadingTransaction: false));
}
}

FutureOr<void> _onRefresh(_OnRefresh event, Emitter<WalletState> emit) {
add(const WalletEvent.initial());
}
}
Loading
Loading