From db226e68c80c77adac2d3649ff083f9be5ae332c Mon Sep 17 00:00:00 2001 From: John <139219226+akhil-deriv@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:31:51 +0400 Subject: [PATCH 1/3] akhil/1396/multi_user_level_authentication_poc (#330) --- .../get_account_status_response_result.dart | 13 +++++++++---- .../response/p2p_advert_create_response_result.dart | 7 +++++-- .../response/p2p_advert_list_response_result.dart | 6 ++++-- .../methods/get_account_status_receive_methods.json | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/api/response/get_account_status_response_result.dart b/lib/api/response/get_account_status_response_result.dart index d6b31c9dbc..9d3e59b8f3 100644 --- a/lib/api/response/get_account_status_response_result.dart +++ b/lib/api/response/get_account_status_response_result.dart @@ -55,9 +55,11 @@ class GetAccountStatusResponse extends GetAccountStatusResponseModel { /// /// For parameters information refer to [GetAccountStatusRequest]. /// Throws an [BaseAPIException] if API response contains an error. - static Future fetchAccountStatusRaw() async { + static Future fetchAccountStatusRaw({ + String? loginId, + }) async { final GetAccountStatusReceive response = await _api.call( - request: const GetAccountStatusRequest(), + request: GetAccountStatusRequest(loginid: loginId), ); checkException( @@ -73,8 +75,11 @@ class GetAccountStatusResponse extends GetAccountStatusResponseModel { /// /// For parameters information refer to [GetAccountStatusRequest]. /// Throws an [BaseAPIException] if API response contains an error. - static Future fetchAccountStatus() async { - final GetAccountStatusReceive response = await fetchAccountStatusRaw(); + static Future fetchAccountStatus({ + String? loginId, + }) async { + final GetAccountStatusReceive response = + await fetchAccountStatusRaw(loginId: loginId); return GetAccountStatusResponse.fromJson(response.getAccountStatus); } diff --git a/lib/api/response/p2p_advert_create_response_result.dart b/lib/api/response/p2p_advert_create_response_result.dart index c9aa066cdd..84fc17d7af 100644 --- a/lib/api/response/p2p_advert_create_response_result.dart +++ b/lib/api/response/p2p_advert_create_response_result.dart @@ -1,8 +1,7 @@ // ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import import 'package:equatable/equatable.dart'; - -import 'package:flutter_deriv_api/api/exceptions/p2p_advert_exception.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_create_receive.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_create_send.dart'; @@ -239,6 +238,7 @@ enum VisibilityStatusItemEnum { /// advertiser_temp_ban. advertiserTempBan, } + /// P2p advert create model class. abstract class P2pAdvertCreateModel { /// Initializes P2p advert create model class . @@ -742,6 +742,7 @@ class P2pAdvertCreate extends P2pAdvertCreateModel { visibilityStatus: visibilityStatus ?? this.visibilityStatus, ); } + /// Advertiser details model class. abstract class AdvertiserDetailsModel { /// Initializes Advertiser details model class . @@ -892,6 +893,7 @@ class AdvertiserDetails extends AdvertiserDetailsModel { totalCompletionRate: totalCompletionRate ?? this.totalCompletionRate, ); } + /// Payment method details property model class. abstract class PaymentMethodDetailsPropertyModel { /// Initializes Payment method details property model class . @@ -1020,6 +1022,7 @@ class PaymentMethodDetailsProperty extends PaymentMethodDetailsPropertyModel { usedByOrders: usedByOrders ?? this.usedByOrders, ); } + /// Fields property model class. abstract class FieldsPropertyModel { /// Initializes Fields property model class . diff --git a/lib/api/response/p2p_advert_list_response_result.dart b/lib/api/response/p2p_advert_list_response_result.dart index 6d63631006..af9e4b5688 100644 --- a/lib/api/response/p2p_advert_list_response_result.dart +++ b/lib/api/response/p2p_advert_list_response_result.dart @@ -1,8 +1,7 @@ // ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import import 'package:equatable/equatable.dart'; - -import 'package:flutter_deriv_api/api/exceptions/p2p_advert_exception.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_list_receive.dart'; import 'package:flutter_deriv_api/basic_api/generated/p2p_advert_list_send.dart'; @@ -226,6 +225,7 @@ enum VisibilityStatusItemEnum { /// advertiser_temp_ban. advertiserTempBan, } + /// P2p advert list model class. abstract class P2pAdvertListModel { /// Initializes P2p advert list model class . @@ -274,6 +274,7 @@ class P2pAdvertList extends P2pAdvertListModel { list: list ?? this.list, ); } + /// List item model class. abstract class ListItemModel { /// Initializes List item model class . @@ -817,6 +818,7 @@ class ListItem extends ListItemModel { visibilityStatus: visibilityStatus ?? this.visibilityStatus, ); } + /// Advertiser details model class. abstract class AdvertiserDetailsModel { /// Initializes Advertiser details model class . diff --git a/lib/basic_api/generated/methods/get_account_status_receive_methods.json b/lib/basic_api/generated/methods/get_account_status_receive_methods.json index 712a34feba..dfab51945d 100644 --- a/lib/basic_api/generated/methods/get_account_status_receive_methods.json +++ b/lib/basic_api/generated/methods/get_account_status_receive_methods.json @@ -1,4 +1,4 @@ { - "methods": "static final BaseAPI _api = Injector()(); \n \n /// Gets the account's status. \n /// \n /// For parameters information refer to [GetAccountStatusRequest]. \n /// Throws an [BaseAPIException] if API response contains an error. \n static Future fetchAccountStatusRaw() async { \n final GetAccountStatusReceive response = await _api.call( \n request: const GetAccountStatusRequest(), \n ); \n \n checkException( \n response: response, \n exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => \n BaseAPIException(baseExceptionModel: baseExceptionModel), \n ); \n \n return response; \n } \n \n /// Gets the account's status. \n /// \n /// For parameters information refer to [GetAccountStatusRequest]. \n /// Throws an [BaseAPIException] if API response contains an error. \n static Future fetchAccountStatus() async { \n final GetAccountStatusReceive response = await fetchAccountStatusRaw(); \n \n return GetAccountStatusResponse.fromJson(response.getAccountStatus); \n }", + "methods": "static final BaseAPI _api = Injector()(); \n \n /// Gets the account's status. \n /// \n /// For parameters information refer to [GetAccountStatusRequest]. \n /// Throws an [BaseAPIException] if API response contains an error. \n static Future fetchAccountStatusRaw({String? loginId,}) async { \n final GetAccountStatusReceive response = await _api.call( \n request: GetAccountStatusRequest(loginid: loginId), \n ); \n \n checkException( \n response: response, \n exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => \n BaseAPIException(baseExceptionModel: baseExceptionModel), \n ); \n \n return response; \n } \n \n /// Gets the account's status. \n /// \n /// For parameters information refer to [GetAccountStatusRequest]. \n /// Throws an [BaseAPIException] if API response contains an error. \n static Future fetchAccountStatus({String? loginId,}) async { \n final GetAccountStatusReceive response = await fetchAccountStatusRaw(loginId: loginId); \n \n return GetAccountStatusResponse.fromJson(response.getAccountStatus); \n }", "imports": "import 'package:flutter_deriv_api/api/exceptions/exceptions.dart';\nimport 'package:flutter_deriv_api/api/models/base_exception_model.dart';\nimport 'package:flutter_deriv_api/basic_api/generated/get_account_status_receive.dart';\nimport 'package:flutter_deriv_api/basic_api/generated/get_account_status_send.dart';\nimport 'package:flutter_deriv_api/helpers/helpers.dart';\nimport 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';\nimport 'package:deriv_dependency_injector/dependency_injector.dart';\n" } From 9c45e8386e765e4507c29c7f52780d3e40674cac Mon Sep 17 00:00:00 2001 From: ayaan-deriv Date: Tue, 29 Oct 2024 16:01:59 +0400 Subject: [PATCH 2/3] Create crypto_estimations_response_extended.dart --- .../crypto_estimations_response_extended.dart | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/api/response/crypto_estimations_response_extended.dart diff --git a/lib/api/response/crypto_estimations_response_extended.dart b/lib/api/response/crypto_estimations_response_extended.dart new file mode 100644 index 0000000000..a1feb36927 --- /dev/null +++ b/lib/api/response/crypto_estimations_response_extended.dart @@ -0,0 +1,56 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/base_api_exception.dart'; +import 'package:flutter_deriv_api/api/models/base_exception_model.dart'; +import 'package:flutter_deriv_api/api/response/crypto_estimations_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/crypto_estimations_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/crypto_estimations_send.dart'; +import 'package:flutter_deriv_api/basic_api/generated/forget_receive.dart'; +import 'package:flutter_deriv_api/basic_api/response.dart'; +import 'package:flutter_deriv_api/helpers/miscellaneous_helper.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; +import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart'; + +/// Extended functionality for [CryptoEstimationsResponse] class. +class CryptoEstimationsResponseExtended extends CryptoEstimationsResponse { + static final BaseAPI _api = Injector()(); + + /// This will subscribe to crypto estimations.
+ /// Inside [CryptoEstimationsRequest] class: + /// Incase of error, It will throw [BaseAPIException]. + static Stream subscribeToCryptoEstimates( + CryptoEstimationsRequest request, { + RequestCompareFunction? comparePredicate, + }) => + _api + .subscribe(request: request, comparePredicate: comparePredicate)! + .map( + (Response response) { + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + if (response is CryptoEstimationsReceive) { + return CryptoEstimationsResponse.fromJson( + response.cryptoEstimations, response.subscription); + } else { + throw Exception('Bad response received'); + } + }, + ); + + /// unsubscribe from the subscribed Crypto Estimates
+ /// In case of error, It will throw [BaseAPIException]. + static Future unsubscribeFromCryptoEstimates( + String subscriptionId) async { + final ForgetReceive response = + await _api.unsubscribe(subscriptionId: subscriptionId); + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + return response.forget!; + } +} \ No newline at end of file From dc18d04cb35568e659f9ae770a6c748366e1c897 Mon Sep 17 00:00:00 2001 From: ayaan-deriv Date: Fri, 1 Nov 2024 09:38:31 +0400 Subject: [PATCH 3/3] format crypto_estimations_response_extended.dart --- lib/api/response/crypto_estimations_response_extended.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/api/response/crypto_estimations_response_extended.dart b/lib/api/response/crypto_estimations_response_extended.dart index a1feb36927..1e97dea783 100644 --- a/lib/api/response/crypto_estimations_response_extended.dart +++ b/lib/api/response/crypto_estimations_response_extended.dart @@ -43,7 +43,8 @@ class CryptoEstimationsResponseExtended extends CryptoEstimationsResponse { /// unsubscribe from the subscribed Crypto Estimates
/// In case of error, It will throw [BaseAPIException]. static Future unsubscribeFromCryptoEstimates( - String subscriptionId) async { + String subscriptionId, + ) async { final ForgetReceive response = await _api.unsubscribe(subscriptionId: subscriptionId); checkException( @@ -53,4 +54,4 @@ class CryptoEstimationsResponseExtended extends CryptoEstimationsResponse { ); return response.forget!; } -} \ No newline at end of file +}