diff --git a/binary-websocket-api b/binary-websocket-api index 815af08a17..4a2ead83f9 160000 --- a/binary-websocket-api +++ b/binary-websocket-api @@ -1 +1 @@ -Subproject commit 815af08a17a6f3933923fc45d2f0f125721d57ed +Subproject commit 4a2ead83f9323d0b8bfe762710b2898060a9c98f diff --git a/lib/api/response/available_accounts_response_extended.dart b/lib/api/response/available_accounts_response_extended.dart new file mode 100644 index 0000000000..c7faf3c3e8 --- /dev/null +++ b/lib/api/response/available_accounts_response_extended.dart @@ -0,0 +1,28 @@ +import 'package:deriv_dependency_injector/dependency_injector.dart'; +import 'package:flutter_deriv_api/api/exceptions/exceptions.dart'; +import 'package:flutter_deriv_api/api/response/available_accounts_response_result.dart'; +import 'package:flutter_deriv_api/basic_api/generated/available_accounts_receive.dart'; +import 'package:flutter_deriv_api/basic_api/generated/available_accounts_send.dart'; +import 'package:flutter_deriv_api/helpers/helpers.dart'; +import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart'; + +/// The extended version of the [AvailableAccountsResponse] class to implement +/// the API call methods. +class AvailableAccountsResponseExtended extends AvailableAccountsResponse { + static final BaseAPI _api = Injector()(); + + /// Fetches the available wallets that can be created + static Future fetchAvailableWalletsToCreate({ + required AvailableAccountsRequest request, + }) async { + final AvailableAccountsReceive response = await _api.call(request: request); + + checkException( + response: response, + exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => + BaseAPIException(baseExceptionModel: baseExceptionModel), + ); + + return AvailableAccountsResponse.fromJson(response.availableAccounts); + } +} diff --git a/lib/api/response/available_accounts_response_result.dart b/lib/api/response/available_accounts_response_result.dart new file mode 100644 index 0000000000..b02d7c3c86 --- /dev/null +++ b/lib/api/response/available_accounts_response_result.dart @@ -0,0 +1,191 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:equatable/equatable.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; + +/// Available accounts response model class. +abstract class AvailableAccountsResponseModel { + /// Initializes Available accounts response model class . + const AvailableAccountsResponseModel({ + this.availableAccounts, + }); + + /// Returns list of accounts that are available to be created - limited to wallets and can be extended + final AvailableAccounts? availableAccounts; +} + +/// Available accounts response class. +class AvailableAccountsResponse extends AvailableAccountsResponseModel { + /// Initializes Available accounts response class. + const AvailableAccountsResponse({ + super.availableAccounts, + }); + + /// Creates an instance from JSON. + factory AvailableAccountsResponse.fromJson( + dynamic availableAccountsJson, + ) => + AvailableAccountsResponse( + availableAccounts: availableAccountsJson == null + ? null + : AvailableAccounts.fromJson(availableAccountsJson), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + if (availableAccounts != null) { + resultMap['available_accounts'] = availableAccounts!.toJson(); + } + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + AvailableAccountsResponse copyWith({ + AvailableAccounts? availableAccounts, + }) => + AvailableAccountsResponse( + availableAccounts: availableAccounts ?? this.availableAccounts, + ); +} + +/// AccountTypeEnum mapper. +final Map accountTypeEnumMapper = + { + "doughflow": AccountTypeEnum.doughflow, + "crypto": AccountTypeEnum.crypto, + "paymentagent": AccountTypeEnum.paymentagent, + "paymentagent_client": AccountTypeEnum.paymentagentClient, + "p2p": AccountTypeEnum.p2p, +}; + +/// AccountType Enum. +enum AccountTypeEnum { + /// doughflow. + doughflow, + + /// crypto. + crypto, + + /// paymentagent. + paymentagent, + + /// paymentagent_client. + paymentagentClient, + + /// p2p. + p2p, +} +/// Available accounts model class. +abstract class AvailableAccountsModel { + /// Initializes Available accounts model class . + const AvailableAccountsModel({ + required this.wallets, + }); + + /// Wallet account types that are available to be created + final List wallets; +} + +/// Available accounts class. +class AvailableAccounts extends AvailableAccountsModel { + /// Initializes Available accounts class. + const AvailableAccounts({ + required super.wallets, + }); + + /// Creates an instance from JSON. + factory AvailableAccounts.fromJson(Map json) => + AvailableAccounts( + wallets: List.from( + json['wallets'].map( + (dynamic item) => WalletsItem.fromJson(item), + ), + ), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['wallets'] = wallets + .map( + (WalletsItem item) => item.toJson(), + ) + .toList(); + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + AvailableAccounts copyWith({ + List? wallets, + }) => + AvailableAccounts( + wallets: wallets ?? this.wallets, + ); +} +/// Wallets item model class. +abstract class WalletsItemModel { + /// Initializes Wallets item model class . + const WalletsItemModel({ + required this.landingCompany, + required this.currency, + required this.accountType, + }); + + /// Landing Company of wallet. + final String landingCompany; + + /// Currency of wallet + final String currency; + + /// Account type of wallet + final AccountTypeEnum accountType; +} + +/// Wallets item class. +class WalletsItem extends WalletsItemModel { + /// Initializes Wallets item class. + const WalletsItem({ + required super.accountType, + required super.currency, + required super.landingCompany, + }); + + /// Creates an instance from JSON. + factory WalletsItem.fromJson(Map json) => WalletsItem( + accountType: accountTypeEnumMapper[json['account_type']]!, + currency: json['currency'], + landingCompany: json['landing_company'], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['account_type'] = accountTypeEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == accountType) + .key; + resultMap['currency'] = currency; + resultMap['landing_company'] = landingCompany; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + WalletsItem copyWith({ + AccountTypeEnum? accountType, + String? currency, + String? landingCompany, + }) => + WalletsItem( + accountType: accountType ?? this.accountType, + currency: currency ?? this.currency, + landingCompany: landingCompany ?? this.landingCompany, + ); +} diff --git a/lib/basic_api/generated/available_accounts_receive.dart b/lib/basic_api/generated/available_accounts_receive.dart new file mode 100644 index 0000000000..e0d69942b7 --- /dev/null +++ b/lib/basic_api/generated/available_accounts_receive.dart @@ -0,0 +1,61 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/available_accounts_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// Available accounts receive class. +class AvailableAccountsReceive extends Response { + /// Initialize AvailableAccountsReceive. + const AvailableAccountsReceive({ + this.availableAccounts, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory AvailableAccountsReceive.fromJson(Map json) => + AvailableAccountsReceive( + availableAccounts: json['available_accounts'] as Map?, + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// Returns list of accounts that are available to be created - limited to wallets and can be extended + final Map? availableAccounts; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'available_accounts': availableAccounts, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + AvailableAccountsReceive copyWith({ + Map? availableAccounts, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + AvailableAccountsReceive( + availableAccounts: availableAccounts ?? this.availableAccounts, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/available_accounts_send.dart b/lib/basic_api/generated/available_accounts_send.dart new file mode 100644 index 0000000000..a1bfe8fc4a --- /dev/null +++ b/lib/basic_api/generated/available_accounts_send.dart @@ -0,0 +1,76 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/available_accounts_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// Available accounts request class. +class AvailableAccountsRequest extends Request { + /// Initialize AvailableAccountsRequest. + const AvailableAccountsRequest({ + this.availableAccounts = true, + required this.categories, + this.loginid, + super.msgType = 'available_accounts', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory AvailableAccountsRequest.fromJson(Map json) => + AvailableAccountsRequest( + availableAccounts: json['available_accounts'] == null + ? null + : json['available_accounts'] == 1, + categories: (json['categories'] as List?) + ?.map((dynamic item) => item as String) + .toList(), + loginid: json['loginid'] as String?, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// Must be `true` + final bool? availableAccounts; + + /// List of account categories that needs to received. + final List? categories; + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'available_accounts': availableAccounts == null + ? null + : availableAccounts! + ? 1 + : 0, + 'categories': categories, + 'loginid': loginid, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + AvailableAccountsRequest copyWith({ + bool? availableAccounts, + List? categories, + String? loginid, + Map? passthrough, + int? reqId, + }) => + AvailableAccountsRequest( + availableAccounts: availableAccounts ?? this.availableAccounts, + categories: categories ?? this.categories, + loginid: loginid ?? this.loginid, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/methods/available_accounts_receive_methods.json b/lib/basic_api/generated/methods/available_accounts_receive_methods.json new file mode 100644 index 0000000000..640034becf --- /dev/null +++ b/lib/basic_api/generated/methods/available_accounts_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} diff --git a/lib/basic_api/helper/response_mapper.helper.dart b/lib/basic_api/helper/response_mapper.helper.dart index 88237bceb5..75e71d1dc3 100644 --- a/lib/basic_api/helper/response_mapper.helper.dart +++ b/lib/basic_api/helper/response_mapper.helper.dart @@ -17,6 +17,7 @@ import '../generated/app_register_receive.dart'; import '../generated/app_update_receive.dart'; import '../generated/asset_index_receive.dart'; import '../generated/authorize_receive.dart'; +import '../generated/available_accounts_receive.dart'; import '../generated/balance_receive.dart'; import '../generated/buy_contract_for_multiple_accounts_receive.dart'; import '../generated/buy_receive.dart'; @@ -41,7 +42,6 @@ import '../generated/forget_all_receive.dart'; import '../generated/forget_receive.dart'; import '../generated/get_account_status_receive.dart'; import '../generated/get_account_types_receive.dart'; -import '../generated/get_available_accounts_to_transfer_receive.dart'; import '../generated/get_financial_assessment_receive.dart'; import '../generated/get_limits_receive.dart'; import '../generated/get_self_exclusion_receive.dart'; @@ -174,6 +174,8 @@ Response getGeneratedResponse(Map responseMap) { return AssetIndexReceive.fromJson(responseMap); case 'authorize': return AuthorizeReceive.fromJson(responseMap); + case 'available_accounts': + return AvailableAccountsReceive.fromJson(responseMap); case 'balance': return BalanceReceive.fromJson(responseMap); case 'buy_contract_for_multiple_accounts': @@ -222,8 +224,6 @@ Response getGeneratedResponse(Map responseMap) { return GetAccountStatusReceive.fromJson(responseMap); case 'get_account_types': return GetAccountTypesReceive.fromJson(responseMap); - case 'get_available_accounts_to_transfer': - return GetAvailableAccountsToTransferReceive.fromJson(responseMap); case 'get_financial_assessment': return GetFinancialAssessmentReceive.fromJson(responseMap); case 'get_limits':