2024-06-18 10:36:24 +05:30
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
2024-04-08 15:05:50 +05:30
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
|
|
|
|
|
|
import '../../Utils/api_urls.dart';
|
2024-06-18 10:36:24 +05:30
|
|
|
import '../../Utils/base_manager.dart';
|
|
|
|
|
import '../../data/network/network_api_services.dart';
|
2024-04-08 15:05:50 +05:30
|
|
|
|
|
|
|
|
// void openDashboardPage(BuildContext context) {
|
|
|
|
|
// Navigator.pushReplacement(
|
|
|
|
|
// context, MaterialPageRoute(builder: ((context) => PortfolioMainUI())));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// void openEquityPage(BuildContext context, Map<String, dynamic> holdings) {
|
|
|
|
|
// Navigator.push(
|
|
|
|
|
// context,
|
|
|
|
|
// MaterialPageRoute(
|
|
|
|
|
// builder: ((context) => Equityinner(holdings: holdings))));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//broker account table
|
|
|
|
|
|
|
|
|
|
//delete broker account
|
|
|
|
|
Future<bool> deleteBrokerAccount(int id) async {
|
|
|
|
|
final response = await http.Client()
|
2024-06-18 10:36:24 +05:30
|
|
|
.get(Uri.parse('${ApiUrls.base}api/delete_brokerage_account/$id'));
|
2024-04-08 15:05:50 +05:30
|
|
|
if (response.statusCode == 200) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//post broker account
|
|
|
|
|
Future<bool> postBrokerAccount({
|
|
|
|
|
required String brokerName,
|
|
|
|
|
required String authToken,
|
|
|
|
|
required String txnId,
|
|
|
|
|
}) async {
|
2024-06-18 10:36:24 +05:30
|
|
|
final response = await NetworkApiServices().postApi(
|
|
|
|
|
FormData.fromMap({
|
2024-04-08 15:05:50 +05:30
|
|
|
"broker_name": brokerName,
|
|
|
|
|
"auth_token": authToken,
|
|
|
|
|
"transaction_id": txnId,
|
2024-06-18 10:36:24 +05:30
|
|
|
}),
|
|
|
|
|
'${ApiUrls.base}add-broker-account',
|
2024-04-08 15:05:50 +05:30
|
|
|
);
|
2024-06-18 10:36:24 +05:30
|
|
|
|
|
|
|
|
if (response.status == ResponseStatus.SUCCESS) {
|
|
|
|
|
Map<String, dynamic> responseData =
|
|
|
|
|
Map<String, dynamic>.from(response.data);
|
|
|
|
|
if (responseData['status'] == "success") {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-08 15:05:50 +05:30
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 10:36:24 +05:30
|
|
|
//fetch broker accounts
|
2024-06-19 17:47:24 +05:30
|
|
|
|
|
|
|
|
Future<String> fetchAuthToken() async {
|
2024-06-18 10:36:24 +05:30
|
|
|
final response = await NetworkApiServices().getApi(
|
2024-06-19 17:47:24 +05:30
|
|
|
'${ApiUrls.base}get-small-case-auth-token',
|
2024-06-18 10:36:24 +05:30
|
|
|
);
|
|
|
|
|
// log(response.data.toString());
|
|
|
|
|
if (response.status == ResponseStatus.SUCCESS) {
|
|
|
|
|
Map<String, dynamic> responseData =
|
|
|
|
|
Map<String, dynamic>.from(response.data);
|
|
|
|
|
if (responseData['status'] == "success") {
|
2024-06-19 17:47:24 +05:30
|
|
|
return response.data['data'];
|
2024-06-18 10:36:24 +05:30
|
|
|
} else {
|
2024-06-19 17:47:24 +05:30
|
|
|
return "Failed";
|
2024-06-18 10:36:24 +05:30
|
|
|
}
|
|
|
|
|
}
|
2024-06-19 17:47:24 +05:30
|
|
|
return "Failed";
|
2024-06-18 10:36:24 +05:30
|
|
|
}
|
|
|
|
|
|
2024-06-19 17:47:24 +05:30
|
|
|
Future<ResponseData<dynamic>> fetchBrokerAccounts() async {
|
2024-06-18 10:36:24 +05:30
|
|
|
final response = await NetworkApiServices().getApi(
|
2024-06-19 17:47:24 +05:30
|
|
|
'${ApiUrls.base}get-broker-account-data',
|
2024-04-08 15:05:50 +05:30
|
|
|
);
|
2024-06-19 17:47:24 +05:30
|
|
|
log(response.data.toString());
|
|
|
|
|
|
2024-06-18 10:36:24 +05:30
|
|
|
if (response.status == ResponseStatus.SUCCESS) {
|
|
|
|
|
Map<String, dynamic> responseData =
|
|
|
|
|
Map<String, dynamic>.from(response.data);
|
|
|
|
|
if (responseData['status'] == "success") {
|
2024-06-19 17:47:24 +05:30
|
|
|
return response;
|
2024-06-18 10:36:24 +05:30
|
|
|
} else {
|
2024-06-19 17:47:24 +05:30
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
responseData['message'], ResponseStatus.FAILED);
|
2024-06-18 10:36:24 +05:30
|
|
|
}
|
|
|
|
|
}
|
2024-06-19 17:47:24 +05:30
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<ResponseData<dynamic>> fetchHoldingForDB(String brokerName) async {
|
|
|
|
|
final response = await NetworkApiServices().postApi(
|
|
|
|
|
FormData.fromMap({"broker_name": brokerName}),
|
|
|
|
|
'${ApiUrls.base}get-all-details-of-my-portfolio',
|
|
|
|
|
);
|
|
|
|
|
log(response.data.toString());
|
|
|
|
|
|
|
|
|
|
if (response.status == ResponseStatus.SUCCESS) {
|
|
|
|
|
Map<String, dynamic> responseData =
|
|
|
|
|
Map<String, dynamic>.from(response.data);
|
|
|
|
|
if (responseData['status'] == "success") {
|
|
|
|
|
return response;
|
|
|
|
|
} else {
|
|
|
|
|
return ResponseData<dynamic>(
|
|
|
|
|
responseData['message'], ResponseStatus.FAILED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return response;
|
2024-04-08 15:05:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<String> fetchBrokerConnectTxnId({required String authToken}) async {
|
2024-06-18 10:36:24 +05:30
|
|
|
final response = await NetworkApiServices().postApi(
|
|
|
|
|
FormData.fromMap({"auth_token": authToken}),
|
|
|
|
|
'${ApiUrls.base}get-transaction-id',
|
2024-04-08 15:05:50 +05:30
|
|
|
);
|
2024-06-18 10:36:24 +05:30
|
|
|
log(response.data.toString());
|
|
|
|
|
if (response.status == ResponseStatus.SUCCESS) {
|
|
|
|
|
Map<String, dynamic> responseData =
|
|
|
|
|
Map<String, dynamic>.from(response.data);
|
|
|
|
|
if (responseData['status'] == "success") {
|
|
|
|
|
return response.data['data']["data"]
|
|
|
|
|
['transactionId']; // jsonDecode(response.body)
|
|
|
|
|
} else {
|
|
|
|
|
return "Failed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "Failed";
|
2024-04-08 15:05:50 +05:30
|
|
|
}
|
|
|
|
|
|
2024-06-18 10:36:24 +05:30
|
|
|
Future<String> fetchHoldingsImportTxnId(String authToken) async {
|
|
|
|
|
log(authToken);
|
|
|
|
|
final response = await NetworkApiServices().postApi(
|
|
|
|
|
FormData.fromMap({"auth_token": authToken}),
|
|
|
|
|
'${ApiUrls.base}create-transaction-holdings-import',
|
2024-04-08 15:05:50 +05:30
|
|
|
);
|
2024-06-18 10:36:24 +05:30
|
|
|
log(response.data.toString());
|
|
|
|
|
if (response.status == ResponseStatus.SUCCESS) {
|
|
|
|
|
Map<String, dynamic> responseData =
|
|
|
|
|
Map<String, dynamic>.from(response.data);
|
|
|
|
|
if (responseData['status'] == "success" &&
|
|
|
|
|
!responseData.toString().contains(
|
|
|
|
|
"{status: error, status_code: 500, message: Something went wrong.}")) {
|
2024-06-19 11:17:03 +05:30
|
|
|
log("Transaction id --> ${response.data['data']["data"]['transactionId']}");
|
2024-06-18 10:36:24 +05:30
|
|
|
return response.data['data']["data"]
|
|
|
|
|
['transactionId']; // jsonDecode(response.body)
|
|
|
|
|
} else {
|
|
|
|
|
return "Failed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "Failed";
|
2024-04-08 15:05:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<Map<String, dynamic>> fetchHoldings(String authToken) async {
|
2024-06-18 10:36:24 +05:30
|
|
|
final response = await NetworkApiServices().postApi(
|
|
|
|
|
FormData.fromMap({"auth_token": authToken}),
|
|
|
|
|
'${ApiUrls.base}fetch-holdings',
|
2024-04-08 15:05:50 +05:30
|
|
|
);
|
2024-06-18 10:36:24 +05:30
|
|
|
log(response.data.toString());
|
|
|
|
|
if (response.status == ResponseStatus.SUCCESS) {
|
|
|
|
|
Map<String, dynamic> responseData =
|
|
|
|
|
Map<String, dynamic>.from(response.data);
|
|
|
|
|
if (responseData['status'] == "success") {
|
|
|
|
|
return responseData;
|
|
|
|
|
} else {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
2024-04-08 15:05:50 +05:30
|
|
|
}
|