forked from deriv-com/flutter-deriv-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request deriv-com#290 from akhil-deriv/akhil/1340/fetching…
…_the_list_of_wallets_available_to_create akhil/1340/fetching_the_list_of_wallets_available_to_create
- Loading branch information
Showing
7 changed files
with
364 additions
and
4 deletions.
There are no files selected for viewing
Submodule binary-websocket-api
updated
from 815af0 to 4a2ead
28 changes: 28 additions & 0 deletions
28
lib/api/response/available_accounts_response_extended.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()<BaseAPI>(); | ||
|
||
/// Fetches the available wallets that can be created | ||
static Future<AvailableAccountsResponse> 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); | ||
} | ||
} |
191 changes: 191 additions & 0 deletions
191
lib/api/response/available_accounts_response_result.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> toJson() { | ||
final Map<String, dynamic> resultMap = <String, dynamic>{}; | ||
|
||
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<String, AccountTypeEnum> accountTypeEnumMapper = | ||
<String, AccountTypeEnum>{ | ||
"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<WalletsItem> 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<String, dynamic> json) => | ||
AvailableAccounts( | ||
wallets: List<WalletsItem>.from( | ||
json['wallets'].map( | ||
(dynamic item) => WalletsItem.fromJson(item), | ||
), | ||
), | ||
); | ||
|
||
/// Converts an instance to JSON. | ||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> resultMap = <String, dynamic>{}; | ||
|
||
resultMap['wallets'] = wallets | ||
.map<dynamic>( | ||
(WalletsItem item) => item.toJson(), | ||
) | ||
.toList(); | ||
|
||
return resultMap; | ||
} | ||
|
||
/// Creates a copy of instance with given parameters. | ||
AvailableAccounts copyWith({ | ||
List<WalletsItem>? 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<String, dynamic> json) => WalletsItem( | ||
accountType: accountTypeEnumMapper[json['account_type']]!, | ||
currency: json['currency'], | ||
landingCompany: json['landing_company'], | ||
); | ||
|
||
/// Converts an instance to JSON. | ||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> resultMap = <String, dynamic>{}; | ||
|
||
resultMap['account_type'] = accountTypeEnumMapper.entries | ||
.firstWhere((MapEntry<String, AccountTypeEnum> 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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json) => | ||
AvailableAccountsReceive( | ||
availableAccounts: json['available_accounts'] as Map<String, dynamic>?, | ||
echoReq: json['echo_req'] as Map<String, dynamic>?, | ||
error: json['error'] as Map<String, dynamic>?, | ||
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<String, dynamic>? availableAccounts; | ||
|
||
/// Converts this instance to JSON | ||
@override | ||
Map<String, dynamic> toJson() => <String, dynamic>{ | ||
'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<String, dynamic>? availableAccounts, | ||
Map<String, dynamic>? echoReq, | ||
Map<String, dynamic>? 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<Object?> get props => <Object?>[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json) => | ||
AvailableAccountsRequest( | ||
availableAccounts: json['available_accounts'] == null | ||
? null | ||
: json['available_accounts'] == 1, | ||
categories: (json['categories'] as List<dynamic>?) | ||
?.map<String>((dynamic item) => item as String) | ||
.toList(), | ||
loginid: json['loginid'] as String?, | ||
passthrough: json['passthrough'] as Map<String, dynamic>?, | ||
reqId: json['req_id'] as int?, | ||
); | ||
|
||
/// Must be `true` | ||
final bool? availableAccounts; | ||
|
||
/// List of account categories that needs to received. | ||
final List<String>? 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<String, dynamic> toJson() => <String, dynamic>{ | ||
'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<String>? categories, | ||
String? loginid, | ||
Map<String, dynamic>? 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<Object?> get props => <Object?>[]; | ||
} |
4 changes: 4 additions & 0 deletions
4
lib/basic_api/generated/methods/available_accounts_receive_methods.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"methods": "", | ||
"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" | ||
} |
Oops, something went wrong.