diff --git a/lib/core/network/api/services/token_service.dart b/lib/core/network/api/services/token_service.dart index 98bd5a48..688b0d7d 100644 --- a/lib/core/network/api/services/token_service.dart +++ b/lib/core/network/api/services/token_service.dart @@ -16,6 +16,7 @@ class TokenSymbolScope { final String symbol; final String scope; final String tokenContract; + TokenSymbolScope({required this.symbol, required this.scope, required this.tokenContract}); } @@ -31,12 +32,12 @@ class TokenService { }) async { LogHelper.d('getTokenBalance: $tokenContract'); try { - final requestBody = ''' - { - "account": "${user.accountName}", - "code": "$tokenContract", - "symbol": "$symbol", - }'''; + final requestBody = { + 'account': user.accountName, + 'code': tokenContract, + 'symbol': symbol, + }; + final Response res = await user.network.manager.post( Endpoints.getCurrencyBalance, data: requestBody, @@ -64,15 +65,15 @@ class TokenService { required String tokenContract, }) async { try { - final requestBody = ''' - { - "code": "$tokenContract", - "table": "stat", - "lower_bound": "", - "upper_bound": "", - "limit": 1000, - "reverse": false, - }'''; + final requestBody = { + 'code': tokenContract, + 'table': 'stat', + 'lower_bound': '', + 'upper_bound': '', + 'limit': 1000, + 'reverse': false, + }; + final res = await networkingManager.post(Endpoints.getTableScopes, data: requestBody); final List> list = List>.from(res.data['rows']); final tokenSymbolScopes = List.from(list.map((e) { @@ -96,12 +97,12 @@ class TokenService { required String symbol, }) async { try { - final requestBody = ''' - { - "json": true, - "code": "$tokenContract", - "symbol": "$symbol" - }'''; + final requestBody = { + 'json': true, + 'code': tokenContract, + 'symbol': symbol + }; + final res = await networkingManager.post(Endpoints.getCurrencyStats, data: requestBody); final json = res.data; // flutter: res: {HYPHA: {supply: 47738747.41 HYPHA, max_supply: -1.00 HYPHA, issuer: dao.hypha}} diff --git a/lib/core/network/api/services/user_account_service.dart b/lib/core/network/api/services/user_account_service.dart index 7722fa1e..f8b5ade3 100644 --- a/lib/core/network/api/services/user_account_service.dart +++ b/lib/core/network/api/services/user_account_service.dart @@ -18,13 +18,13 @@ class UserAccountService { required String publicKey, required String network, }) async { - final requestBody = ''' - { - "code": "$code", - "accountName": "$accountName", - "publicKey": "$publicKey", - "network": "$network" - }'''; + final requestBody = { + 'code': code, + 'accountName': accountName, + 'publicKey': publicKey, + 'network': network + }; + final url = remoteConfigService.accountCreatorEndpoint + Endpoints.createAccount; try { // ignore: unused_local_variable @@ -46,7 +46,9 @@ class UserAccountService { } Future isUserAccountAvailable(String accountName, Network network) async { - final requestBody = '{ "account_name": "$accountName" }'; + final requestBody = { + 'account_name': accountName + }; try { // ignore: unused_local_variable final res = await network.manager.post(Endpoints.getAccount, data: requestBody); diff --git a/lib/core/network/models/transaction_model.dart b/lib/core/network/models/transaction_model.dart index 866c89d7..38b75667 100644 --- a/lib/core/network/models/transaction_model.dart +++ b/lib/core/network/models/transaction_model.dart @@ -1,9 +1,6 @@ import 'package:equatable/equatable.dart'; const _daoAccount = 'dao.hypha'; -const _systemTokenAccount = 'eosio.token'; -const _hyphaTokenAccount = 'hypha.hypha'; -const _hyphaWrapTokenAccount = 'whypha.hypha'; const _eosioLoginAccount = 'eosio.login'; sealed class TransactionModel extends Equatable { @@ -26,7 +23,7 @@ sealed class TransactionModel extends Equatable { }); @override - List get props => [actionName, data, account, timestamp, blockNumber]; + List get props => [actionName, data, account, timestamp, blockNumber, actor, transactionId]; factory TransactionModel.parseFromParams({ required timestamp, @@ -38,9 +35,7 @@ sealed class TransactionModel extends Equatable { required Map data, }) { return switch (actionName) { - 'transfer' - when account == _hyphaTokenAccount || account == _hyphaWrapTokenAccount || account == _systemTokenAccount => - TransactionTransfer( + 'transfer' => TransactionTransfer( account: account, actionName: actionName, blockNumber: blockNumber, @@ -187,10 +182,10 @@ class TransactionTransfer extends TransactionModel { String get to => data['to']; /// 3175.00 - num get amount => data['amount']; + String get amount => (data['quantity'] as String).split(' ').first; /// HUSD - String get symbol => data['symbol']; + String get symbol => (data['quantity'] as String).split(' ').last; const TransactionTransfer({ required super.data, @@ -208,10 +203,11 @@ class TransactionRedeem extends TransactionModel { String get requestor => data['requestor']; - /// 3175.00 HUSD Beware of this... - String get amount => (data['amount'] as String).split(' ').first; + /// 3175.00 + String get amount => (data['quantity'] as String).split(' ').first; - String get symbol => (data['amount'] as String).split(' ')[1]; + /// HUSD + String get symbol => (data['quantity'] as String).split(' ').last; const TransactionRedeem({ required super.data, diff --git a/lib/core/network/repository/transaction_history_repository.dart b/lib/core/network/repository/transaction_history_repository.dart index bcae1430..8490533d 100644 --- a/lib/core/network/repository/transaction_history_repository.dart +++ b/lib/core/network/repository/transaction_history_repository.dart @@ -12,8 +12,11 @@ class TransactionHistoryRepository { TransactionHistoryRepository({required this.service}); - Future, HyphaError>> getTransactions(UserProfileData user, bool transferOnly, - {useV1History = false}) async { + Future, HyphaError>> getTransactions( + UserProfileData user, + bool transferOnly, { + useV1History = false, + }) async { try { final Response response = useV1History ? await service.getAllTransactionsV1History(user) diff --git a/lib/ui/token/token_details/interactor/token_details_bloc.dart b/lib/ui/token/token_details/interactor/token_details_bloc.dart index 025c1e47..3716f516 100644 --- a/lib/ui/token/token_details/interactor/token_details_bloc.dart +++ b/lib/ui/token/token_details/interactor/token_details_bloc.dart @@ -14,8 +14,11 @@ import 'package:hypha_wallet/ui/wallet/data/wallet_token_data.dart'; import 'package:hypha_wallet/ui/wallet/usecases/get_transaction_history_data_use_case.dart'; part 'page_command.dart'; + part 'token_details_bloc.freezed.dart'; + part 'token_details_event.dart'; + part 'token_details_state.dart'; class TokenDetailsBloc extends Bloc { @@ -44,8 +47,9 @@ class TokenDetailsBloc extends Bloc { FutureOr _initial(_Initial event, Emitter emit) async { emit(state.copyWith(loadingTransaction: true, loadingTokenBalance: true)); - - await _getTransactionHistoryDataUseCase.run(true).then((result) { + await _getTransactionHistoryDataUseCase + .getTransferTransactionsForToken(contract: state.token.contract, symbol: state.token.symbol) + .then((result) { if (result.isValue) { emit(state.copyWith( pageState: PageState.success, diff --git a/lib/ui/wallet/components/recent_transactions_widget.dart b/lib/ui/wallet/components/recent_transactions_widget.dart index 1367b994..6fb86f71 100644 --- a/lib/ui/wallet/components/recent_transactions_widget.dart +++ b/lib/ui/wallet/components/recent_transactions_widget.dart @@ -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; @@ -49,9 +52,20 @@ 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, + ), + const SizedBox(height: 8), + HyphaAppButton( + title: 'Refresh', + onPressed: () { + context.read().add(const WalletEvent.onRefresh()); + }, + ) + ], ), ), ), diff --git a/lib/ui/wallet/interactor/wallet_bloc.dart b/lib/ui/wallet/interactor/wallet_bloc.dart index 83afeac1..82034759 100644 --- a/lib/ui/wallet/interactor/wallet_bloc.dart +++ b/lib/ui/wallet/interactor/wallet_bloc.dart @@ -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'; @@ -26,26 +27,24 @@ class WalletBloc extends Bloc { 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 _initial(_Initial event, Emitter 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)); + unawaited(_getTransactionHistoryDataUseCase.getTransferTransactionsForTokens().then((result) { + if (isClosed) { + return; + } + + if (result.isValue) { + add(WalletEvent.onTransactionsChanged(result)); } })); @@ -54,4 +53,21 @@ class WalletBloc extends Bloc { return state.copyWith(pageState: PageState.success, tokens: data); }); } + + FutureOr _onTransactionsChanged(_OnTransactionsChanged event, Emitter 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 _onRefresh(_OnRefresh event, Emitter emit) { + add(const WalletEvent.initial()); + } } diff --git a/lib/ui/wallet/interactor/wallet_bloc.freezed.dart b/lib/ui/wallet/interactor/wallet_bloc.freezed.dart index baec5b6d..bc447886 100644 --- a/lib/ui/wallet/interactor/wallet_bloc.freezed.dart +++ b/lib/ui/wallet/interactor/wallet_bloc.freezed.dart @@ -171,6 +171,9 @@ mixin _$WalletEvent { required TResult Function() initial, required TResult Function() onRefresh, required TResult Function() clearPageCommand, + required TResult Function( + Result, HyphaError> value) + onTransactionsChanged, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -178,6 +181,9 @@ mixin _$WalletEvent { TResult? Function()? initial, TResult? Function()? onRefresh, TResult? Function()? clearPageCommand, + TResult? Function( + Result, HyphaError> value)? + onTransactionsChanged, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -185,6 +191,8 @@ mixin _$WalletEvent { TResult Function()? initial, TResult Function()? onRefresh, TResult Function()? clearPageCommand, + TResult Function(Result, HyphaError> value)? + onTransactionsChanged, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -193,6 +201,8 @@ mixin _$WalletEvent { required TResult Function(_Initial value) initial, required TResult Function(_OnRefresh value) onRefresh, required TResult Function(_ClearPageCommand value) clearPageCommand, + required TResult Function(_OnTransactionsChanged value) + onTransactionsChanged, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -200,6 +210,7 @@ mixin _$WalletEvent { TResult? Function(_Initial value)? initial, TResult? Function(_OnRefresh value)? onRefresh, TResult? Function(_ClearPageCommand value)? clearPageCommand, + TResult? Function(_OnTransactionsChanged value)? onTransactionsChanged, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -207,6 +218,7 @@ mixin _$WalletEvent { TResult Function(_Initial value)? initial, TResult Function(_OnRefresh value)? onRefresh, TResult Function(_ClearPageCommand value)? clearPageCommand, + TResult Function(_OnTransactionsChanged value)? onTransactionsChanged, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -270,6 +282,9 @@ class _$_Initial implements _Initial { required TResult Function() initial, required TResult Function() onRefresh, required TResult Function() clearPageCommand, + required TResult Function( + Result, HyphaError> value) + onTransactionsChanged, }) { return initial(); } @@ -280,6 +295,9 @@ class _$_Initial implements _Initial { TResult? Function()? initial, TResult? Function()? onRefresh, TResult? Function()? clearPageCommand, + TResult? Function( + Result, HyphaError> value)? + onTransactionsChanged, }) { return initial?.call(); } @@ -290,6 +308,8 @@ class _$_Initial implements _Initial { TResult Function()? initial, TResult Function()? onRefresh, TResult Function()? clearPageCommand, + TResult Function(Result, HyphaError> value)? + onTransactionsChanged, required TResult orElse(), }) { if (initial != null) { @@ -304,6 +324,8 @@ class _$_Initial implements _Initial { required TResult Function(_Initial value) initial, required TResult Function(_OnRefresh value) onRefresh, required TResult Function(_ClearPageCommand value) clearPageCommand, + required TResult Function(_OnTransactionsChanged value) + onTransactionsChanged, }) { return initial(this); } @@ -314,6 +336,7 @@ class _$_Initial implements _Initial { TResult? Function(_Initial value)? initial, TResult? Function(_OnRefresh value)? onRefresh, TResult? Function(_ClearPageCommand value)? clearPageCommand, + TResult? Function(_OnTransactionsChanged value)? onTransactionsChanged, }) { return initial?.call(this); } @@ -324,6 +347,7 @@ class _$_Initial implements _Initial { TResult Function(_Initial value)? initial, TResult Function(_OnRefresh value)? onRefresh, TResult Function(_ClearPageCommand value)? clearPageCommand, + TResult Function(_OnTransactionsChanged value)? onTransactionsChanged, required TResult orElse(), }) { if (initial != null) { @@ -378,6 +402,9 @@ class _$_OnRefresh implements _OnRefresh { required TResult Function() initial, required TResult Function() onRefresh, required TResult Function() clearPageCommand, + required TResult Function( + Result, HyphaError> value) + onTransactionsChanged, }) { return onRefresh(); } @@ -388,6 +415,9 @@ class _$_OnRefresh implements _OnRefresh { TResult? Function()? initial, TResult? Function()? onRefresh, TResult? Function()? clearPageCommand, + TResult? Function( + Result, HyphaError> value)? + onTransactionsChanged, }) { return onRefresh?.call(); } @@ -398,6 +428,8 @@ class _$_OnRefresh implements _OnRefresh { TResult Function()? initial, TResult Function()? onRefresh, TResult Function()? clearPageCommand, + TResult Function(Result, HyphaError> value)? + onTransactionsChanged, required TResult orElse(), }) { if (onRefresh != null) { @@ -412,6 +444,8 @@ class _$_OnRefresh implements _OnRefresh { required TResult Function(_Initial value) initial, required TResult Function(_OnRefresh value) onRefresh, required TResult Function(_ClearPageCommand value) clearPageCommand, + required TResult Function(_OnTransactionsChanged value) + onTransactionsChanged, }) { return onRefresh(this); } @@ -422,6 +456,7 @@ class _$_OnRefresh implements _OnRefresh { TResult? Function(_Initial value)? initial, TResult? Function(_OnRefresh value)? onRefresh, TResult? Function(_ClearPageCommand value)? clearPageCommand, + TResult? Function(_OnTransactionsChanged value)? onTransactionsChanged, }) { return onRefresh?.call(this); } @@ -432,6 +467,7 @@ class _$_OnRefresh implements _OnRefresh { TResult Function(_Initial value)? initial, TResult Function(_OnRefresh value)? onRefresh, TResult Function(_ClearPageCommand value)? clearPageCommand, + TResult Function(_OnTransactionsChanged value)? onTransactionsChanged, required TResult orElse(), }) { if (onRefresh != null) { @@ -486,6 +522,9 @@ class _$_ClearPageCommand implements _ClearPageCommand { required TResult Function() initial, required TResult Function() onRefresh, required TResult Function() clearPageCommand, + required TResult Function( + Result, HyphaError> value) + onTransactionsChanged, }) { return clearPageCommand(); } @@ -496,6 +535,9 @@ class _$_ClearPageCommand implements _ClearPageCommand { TResult? Function()? initial, TResult? Function()? onRefresh, TResult? Function()? clearPageCommand, + TResult? Function( + Result, HyphaError> value)? + onTransactionsChanged, }) { return clearPageCommand?.call(); } @@ -506,6 +548,8 @@ class _$_ClearPageCommand implements _ClearPageCommand { TResult Function()? initial, TResult Function()? onRefresh, TResult Function()? clearPageCommand, + TResult Function(Result, HyphaError> value)? + onTransactionsChanged, required TResult orElse(), }) { if (clearPageCommand != null) { @@ -520,6 +564,8 @@ class _$_ClearPageCommand implements _ClearPageCommand { required TResult Function(_Initial value) initial, required TResult Function(_OnRefresh value) onRefresh, required TResult Function(_ClearPageCommand value) clearPageCommand, + required TResult Function(_OnTransactionsChanged value) + onTransactionsChanged, }) { return clearPageCommand(this); } @@ -530,6 +576,7 @@ class _$_ClearPageCommand implements _ClearPageCommand { TResult? Function(_Initial value)? initial, TResult? Function(_OnRefresh value)? onRefresh, TResult? Function(_ClearPageCommand value)? clearPageCommand, + TResult? Function(_OnTransactionsChanged value)? onTransactionsChanged, }) { return clearPageCommand?.call(this); } @@ -540,6 +587,7 @@ class _$_ClearPageCommand implements _ClearPageCommand { TResult Function(_Initial value)? initial, TResult Function(_OnRefresh value)? onRefresh, TResult Function(_ClearPageCommand value)? clearPageCommand, + TResult Function(_OnTransactionsChanged value)? onTransactionsChanged, required TResult orElse(), }) { if (clearPageCommand != null) { @@ -553,6 +601,160 @@ abstract class _ClearPageCommand implements WalletEvent { const factory _ClearPageCommand() = _$_ClearPageCommand; } +/// @nodoc +abstract class _$$_OnTransactionsChangedCopyWith<$Res> { + factory _$$_OnTransactionsChangedCopyWith(_$_OnTransactionsChanged value, + $Res Function(_$_OnTransactionsChanged) then) = + __$$_OnTransactionsChangedCopyWithImpl<$Res>; + @useResult + $Res call({Result, HyphaError> value}); +} + +/// @nodoc +class __$$_OnTransactionsChangedCopyWithImpl<$Res> + extends _$WalletEventCopyWithImpl<$Res, _$_OnTransactionsChanged> + implements _$$_OnTransactionsChangedCopyWith<$Res> { + __$$_OnTransactionsChangedCopyWithImpl(_$_OnTransactionsChanged _value, + $Res Function(_$_OnTransactionsChanged) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? value = null, + }) { + return _then(_$_OnTransactionsChanged( + null == value + ? _value.value + : value // ignore: cast_nullable_to_non_nullable + as Result, HyphaError>, + )); + } +} + +/// @nodoc + +class _$_OnTransactionsChanged implements _OnTransactionsChanged { + const _$_OnTransactionsChanged(this.value); + + @override + final Result, HyphaError> value; + + @override + String toString() { + return 'WalletEvent.onTransactionsChanged(value: $value)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_OnTransactionsChanged && + (identical(other.value, value) || other.value == value)); + } + + @override + int get hashCode => Object.hash(runtimeType, value); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_OnTransactionsChangedCopyWith<_$_OnTransactionsChanged> get copyWith => + __$$_OnTransactionsChangedCopyWithImpl<_$_OnTransactionsChanged>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() onRefresh, + required TResult Function() clearPageCommand, + required TResult Function( + Result, HyphaError> value) + onTransactionsChanged, + }) { + return onTransactionsChanged(value); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? onRefresh, + TResult? Function()? clearPageCommand, + TResult? Function( + Result, HyphaError> value)? + onTransactionsChanged, + }) { + return onTransactionsChanged?.call(value); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? onRefresh, + TResult Function()? clearPageCommand, + TResult Function(Result, HyphaError> value)? + onTransactionsChanged, + required TResult orElse(), + }) { + if (onTransactionsChanged != null) { + return onTransactionsChanged(value); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_OnRefresh value) onRefresh, + required TResult Function(_ClearPageCommand value) clearPageCommand, + required TResult Function(_OnTransactionsChanged value) + onTransactionsChanged, + }) { + return onTransactionsChanged(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_OnRefresh value)? onRefresh, + TResult? Function(_ClearPageCommand value)? clearPageCommand, + TResult? Function(_OnTransactionsChanged value)? onTransactionsChanged, + }) { + return onTransactionsChanged?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_OnRefresh value)? onRefresh, + TResult Function(_ClearPageCommand value)? clearPageCommand, + TResult Function(_OnTransactionsChanged value)? onTransactionsChanged, + required TResult orElse(), + }) { + if (onTransactionsChanged != null) { + return onTransactionsChanged(this); + } + return orElse(); + } +} + +abstract class _OnTransactionsChanged implements WalletEvent { + const factory _OnTransactionsChanged( + final Result, HyphaError> value) = + _$_OnTransactionsChanged; + + Result, HyphaError> get value; + @JsonKey(ignore: true) + _$$_OnTransactionsChangedCopyWith<_$_OnTransactionsChanged> get copyWith => + throw _privateConstructorUsedError; +} + /// @nodoc mixin _$WalletState { PageState get pageState => throw _privateConstructorUsedError; diff --git a/lib/ui/wallet/interactor/wallet_event.dart b/lib/ui/wallet/interactor/wallet_event.dart index 0bbfd9e3..7e1924b1 100644 --- a/lib/ui/wallet/interactor/wallet_event.dart +++ b/lib/ui/wallet/interactor/wallet_event.dart @@ -5,5 +5,7 @@ class WalletEvent with _$WalletEvent { const factory WalletEvent.initial() = _Initial; const factory WalletEvent.onRefresh() = _OnRefresh; const factory WalletEvent.clearPageCommand() = _ClearPageCommand; + const factory WalletEvent.onTransactionsChanged(Result, HyphaError> value) = _OnTransactionsChanged; + } diff --git a/lib/ui/wallet/usecases/get_transaction_history_data_use_case.dart b/lib/ui/wallet/usecases/get_transaction_history_data_use_case.dart index 93ace70c..c4569087 100644 --- a/lib/ui/wallet/usecases/get_transaction_history_data_use_case.dart +++ b/lib/ui/wallet/usecases/get_transaction_history_data_use_case.dart @@ -1,3 +1,4 @@ +import 'package:get/get.dart'; import 'package:hypha_wallet/core/error_handler/model/hypha_error.dart'; import 'package:hypha_wallet/core/firebase/firebase_database_service.dart'; import 'package:hypha_wallet/core/firebase/firebase_token_data.dart'; @@ -19,14 +20,41 @@ class GetTransactionHistoryDataUseCase { this._authRepository, ); - Future, HyphaError>> run(bool transferOnly) async { + Future, HyphaError>> getTransferTransactionsForTokens() async { final List allTokens = await _firebaseDatabaseService.getAllTokens(); final user = _authRepository.authDataOrCrash; - final result = await _getTransactionHistoryUseCase.run(transferOnly); + final result = await _getTransactionHistoryUseCase.run(true); if (result.isValue) { return Result.value(result.valueOrCrash - .where((TransactionModel element) => element is TransactionRedeem || element is TransactionTransfer) + .where( + (TransactionModel element) => + element is TransactionRedeem || + element is TransactionTransfer && + allTokens.firstWhereOrNull( + (token) => token.contract == element.account && token.symbol == element.symbol) != + null, + ) + .toList() + .mapRecentTransactionsTileData(allTokens, user.userProfileData.accountName)); + } else { + return Result.error(result.asError!.error); + } + } + + Future, HyphaError>> getTransferTransactionsForToken({ + required String contract, + required String symbol, + }) async { + final List allTokens = await _firebaseDatabaseService.getAllTokens(); + final user = _authRepository.authDataOrCrash; + + final result = await _getTransactionHistoryUseCase.run(true); + if (result.isValue) { + return Result.value(result.valueOrCrash + .where((TransactionModel element) => + element is TransactionRedeem || + element is TransactionTransfer && contract == element.account && symbol == element.symbol) .toList() .mapRecentTransactionsTileData(allTokens, user.userProfileData.accountName)); } else {