feat(App): update Finlytic Flutter app UI and blocs
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'asset_trades_event.dart';
|
||||
import 'asset_trades_state.dart';
|
||||
import '../../repositories/asset_repository.dart';
|
||||
|
||||
class AssetTradesBloc extends Bloc<AssetTradesEvent, AssetTradesState> {
|
||||
final AssetRepository repository;
|
||||
|
||||
AssetTradesBloc({required this.repository}) : super(AssetTradesInitial()) {
|
||||
on<LoadAssetTrades>((event, emit) async {
|
||||
emit(AssetTradesLoading());
|
||||
try {
|
||||
final data = await repository.getAssetTrades(event.isin, event.status);
|
||||
emit(AssetTradesLoaded(data));
|
||||
} catch (e) {
|
||||
emit(AssetTradesError(e.toString()));
|
||||
}
|
||||
});
|
||||
on<TriggerManualAnalysis>((event, emit) async {
|
||||
try {
|
||||
await repository.triggerManualAnalysis(event.isin, payload: event.payload);
|
||||
add(LoadAssetTrades(event.isin));
|
||||
} catch (e) {
|
||||
emit(AssetTradesError("Failed to trigger manual analysis: $e"));
|
||||
}
|
||||
});
|
||||
on<RejectTradeEvent>((event, emit) async {
|
||||
try {
|
||||
await repository.rejectTrade(event.tradeId);
|
||||
add(LoadAssetTrades(event.isin));
|
||||
} catch (e) {
|
||||
emit(AssetTradesError("Failed to reject trade: $e"));
|
||||
}
|
||||
});
|
||||
on<AcceptTradeEvent>((event, emit) async {
|
||||
try {
|
||||
await repository.acceptTrade(event.tradeAcceptanceDto);
|
||||
add(LoadAssetTrades(event.isin));
|
||||
} catch (e) {
|
||||
emit(AssetTradesError("Failed to accept trade: $e"));
|
||||
}
|
||||
});
|
||||
on<CloseTradeEvent>((event, emit) async {
|
||||
try {
|
||||
await repository.closeTrade(event.tradeId, event.exitPrice);
|
||||
add(LoadAssetTrades(event.isin));
|
||||
} catch (e) {
|
||||
emit(AssetTradesError("Failed to close trade: $e"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:finlytic_app/features/trades/models/trade_acceptance_dto.dart';
|
||||
|
||||
import 'package:finlytic_app/features/asset_detail/models/manual_analysis_request_dto.dart';
|
||||
|
||||
abstract class AssetTradesEvent {}
|
||||
class LoadAssetTrades extends AssetTradesEvent {
|
||||
final String isin;
|
||||
final String? status;
|
||||
LoadAssetTrades(this.isin, {this.status});
|
||||
}
|
||||
class TriggerManualAnalysis extends AssetTradesEvent {
|
||||
final String isin;
|
||||
final ManualAnalysisRequestDto? payload;
|
||||
TriggerManualAnalysis(this.isin, {this.payload});
|
||||
}
|
||||
class RejectTradeEvent extends AssetTradesEvent {
|
||||
final String tradeId;
|
||||
final String isin;
|
||||
RejectTradeEvent(this.tradeId, this.isin);
|
||||
}
|
||||
class AcceptTradeEvent extends AssetTradesEvent {
|
||||
final TradeAcceptanceDto tradeAcceptanceDto;
|
||||
final String isin;
|
||||
AcceptTradeEvent(this.tradeAcceptanceDto, this.isin);
|
||||
}
|
||||
class CloseTradeEvent extends AssetTradesEvent {
|
||||
final String tradeId;
|
||||
final String isin;
|
||||
final double exitPrice;
|
||||
CloseTradeEvent(this.tradeId, this.isin, this.exitPrice);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import '../../../trades/models/trade_model.dart';
|
||||
|
||||
abstract class AssetTradesState {}
|
||||
class AssetTradesInitial extends AssetTradesState {}
|
||||
class AssetTradesLoading extends AssetTradesState {}
|
||||
class AssetTradesLoaded extends AssetTradesState {
|
||||
final List<TradeModel> data;
|
||||
AssetTradesLoaded(this.data);
|
||||
}
|
||||
class AssetTradesError extends AssetTradesState {
|
||||
final String message;
|
||||
AssetTradesError(this.message);
|
||||
}
|
||||
Reference in New Issue
Block a user