Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into ramin/test_proxy_awa…
Browse files Browse the repository at this point in the history
…re_ws_connection
  • Loading branch information
ramin-deriv committed Feb 19, 2024
2 parents 0fde7cf + 3729f1f commit 3630991
Show file tree
Hide file tree
Showing 452 changed files with 12,595 additions and 5,295 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "binary-websocket-api"]
path = binary-websocket-api
url = https://github.com/regentmarkets/binary-websocket-api.git
url = git@github.com:regentmarkets/binary-websocket-api.git
branch = master
2 changes: 1 addition & 1 deletion binary-websocket-api
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.deriv.flutter_deriv_api_example"
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: flutter_deriv_api_example
description: Demonstrates how to use the flutter_deriv_api plugin.
publish_to: "none"
version: 0.0.1

environment:
sdk: ">=3.0.0"
Expand Down
6 changes: 2 additions & 4 deletions lib/api/response/account_closure_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ abstract class AccountClosureResponseModel {
class AccountClosureResponse extends AccountClosureResponseModel {
/// Initializes Account closure response class.
const AccountClosureResponse({
bool? accountClosure,
}) : super(
accountClosure: accountClosure,
);
super.accountClosure,
});

/// Creates an instance from JSON.
factory AccountClosureResponse.fromJson(
Expand Down
296 changes: 296 additions & 0 deletions lib/api/response/account_list_response_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import

import 'package:equatable/equatable.dart';

import 'package:flutter_deriv_api/helpers/helpers.dart';

/// Account list response model class.
abstract class AccountListResponseModel {
/// Initializes Account list response model class .
const AccountListResponseModel({
this.accountList,
});

/// List of accounts for current user. This is also available from the `authroize` call.
final List<AccountListItem>? accountList;
}

/// Account list response class.
class AccountListResponse extends AccountListResponseModel {
/// Initializes Account list response class.
const AccountListResponse({
super.accountList,
});

/// Creates an instance from JSON.
factory AccountListResponse.fromJson(
dynamic accountListJson,
) =>
AccountListResponse(
accountList: accountListJson == null
? null
: List<AccountListItem>.from(
accountListJson?.map(
(dynamic item) => AccountListItem.fromJson(item),
),
),
);

/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};

if (accountList != null) {
resultMap['account_list'] = accountList!
.map<dynamic>(
(AccountListItem item) => item.toJson(),
)
.toList();
}

return resultMap;
}

/// Creates a copy of instance with given parameters.
AccountListResponse copyWith({
List<AccountListItem>? accountList,
}) =>
AccountListResponse(
accountList: accountList ?? this.accountList,
);
}

/// AccountCategoryEnum mapper.
final Map<String, AccountCategoryEnum> accountCategoryEnumMapper =
<String, AccountCategoryEnum>{
"trading": AccountCategoryEnum.trading,
"wallet": AccountCategoryEnum.wallet,
};

/// AccountCategory Enum.
enum AccountCategoryEnum {
/// trading.
trading,

/// wallet.
wallet,
}

/// PlatformEnum mapper.
final Map<String, PlatformEnum> platformEnumMapper = <String, PlatformEnum>{
"ctrader": PlatformEnum.ctrader,
"derivez": PlatformEnum.derivez,
"dtrade": PlatformEnum.dtrade,
"dwallet": PlatformEnum.dwallet,
"dxtrade": PlatformEnum.dxtrade,
"mt5": PlatformEnum.mt5,
};

/// Platform Enum.
enum PlatformEnum {
/// ctrader.
ctrader,

/// derivez.
derivez,

/// dtrade.
dtrade,

/// dwallet.
dwallet,

/// dxtrade.
dxtrade,

/// mt5.
mt5,
}
/// Account list item model class.
abstract class AccountListItemModel {
/// Initializes Account list item model class .
const AccountListItemModel({
required this.loginid,
required this.linkedTo,
required this.landingCompanyName,
required this.isVirtual,
required this.isDisabled,
required this.currency,
required this.createdAt,
required this.accountType,
required this.accountCategory,
this.broker,
});

/// The account ID of specified account.
final String loginid;

/// Details of the list of Trading accounts linked to the Wallet account.
final List<LinkedToItem> linkedTo;

/// Landing company shortcode the account belongs to.
final String landingCompanyName;

/// Boolean value: `true` or `false`, indicating whether the account is a virtual-money account.
final bool isVirtual;

/// Boolean value: `true` or `false`, indicating whether the account is marked as disabled or not.
final bool isDisabled;

/// Currency of specified account.
final String currency;

/// Creation time of the account as epoch.
final DateTime createdAt;

/// Account type.
final String accountType;

/// Account category.
final AccountCategoryEnum accountCategory;

/// 2 letter broker code.
final String? broker;
}

/// Account list item class.
class AccountListItem extends AccountListItemModel {
/// Initializes Account list item class.
const AccountListItem({
required super.accountCategory,
required super.accountType,
required super.createdAt,
required super.currency,
required super.isDisabled,
required super.isVirtual,
required super.landingCompanyName,
required super.linkedTo,
required super.loginid,
super.broker,
});

/// Creates an instance from JSON.
factory AccountListItem.fromJson(Map<String, dynamic> json) =>
AccountListItem(
accountCategory: accountCategoryEnumMapper[json['account_category']]!,
accountType: json['account_type'],
createdAt: getDateTime(json['created_at'])!,
currency: json['currency'],
isDisabled: getBool(json['is_disabled'])!,
isVirtual: getBool(json['is_virtual'])!,
landingCompanyName: json['landing_company_name'],
linkedTo: List<LinkedToItem>.from(
json['linked_to'].map(
(dynamic item) => LinkedToItem.fromJson(item),
),
),
loginid: json['loginid'],
broker: json['broker'],
);

/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};

resultMap['account_category'] = accountCategoryEnumMapper.entries
.firstWhere((MapEntry<String, AccountCategoryEnum> entry) =>
entry.value == accountCategory)
.key;
resultMap['account_type'] = accountType;
resultMap['created_at'] = getSecondsSinceEpochDateTime(createdAt);
resultMap['currency'] = currency;
resultMap['is_disabled'] = isDisabled;
resultMap['is_virtual'] = isVirtual;
resultMap['landing_company_name'] = landingCompanyName;
resultMap['linked_to'] = linkedTo
.map<dynamic>(
(LinkedToItem item) => item.toJson(),
)
.toList();

resultMap['loginid'] = loginid;
resultMap['broker'] = broker;

return resultMap;
}

/// Creates a copy of instance with given parameters.
AccountListItem copyWith({
AccountCategoryEnum? accountCategory,
String? accountType,
DateTime? createdAt,
String? currency,
bool? isDisabled,
bool? isVirtual,
String? landingCompanyName,
List<LinkedToItem>? linkedTo,
String? loginid,
String? broker,
}) =>
AccountListItem(
accountCategory: accountCategory ?? this.accountCategory,
accountType: accountType ?? this.accountType,
createdAt: createdAt ?? this.createdAt,
currency: currency ?? this.currency,
isDisabled: isDisabled ?? this.isDisabled,
isVirtual: isVirtual ?? this.isVirtual,
landingCompanyName: landingCompanyName ?? this.landingCompanyName,
linkedTo: linkedTo ?? this.linkedTo,
loginid: loginid ?? this.loginid,
broker: broker ?? this.broker,
);
}
/// Linked to item model class.
abstract class LinkedToItemModel {
/// Initializes Linked to item model class .
const LinkedToItemModel({
this.loginid,
this.platform,
});

/// Account ID.
final String? loginid;

/// Account platform name.
final PlatformEnum? platform;
}

/// Linked to item class.
class LinkedToItem extends LinkedToItemModel {
/// Initializes Linked to item class.
const LinkedToItem({
super.loginid,
super.platform,
});

/// Creates an instance from JSON.
factory LinkedToItem.fromJson(Map<String, dynamic> json) => LinkedToItem(
loginid: json['loginid'],
platform: json['platform'] == null
? null
: platformEnumMapper[json['platform']],
);

/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};

resultMap['loginid'] = loginid;
resultMap['platform'] = platformEnumMapper.entries
.firstWhere(
(MapEntry<String, PlatformEnum> entry) => entry.value == platform)
.key;

return resultMap;
}

/// Creates a copy of instance with given parameters.
LinkedToItem copyWith({
String? loginid,
PlatformEnum? platform,
}) =>
LinkedToItem(
loginid: loginid ?? this.loginid,
platform: platform ?? this.platform,
);
}
21 changes: 7 additions & 14 deletions lib/api/response/account_security_response_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ abstract class AccountSecurityResponseModel {
class AccountSecurityResponse extends AccountSecurityResponseModel {
/// Initializes Account security response class.
const AccountSecurityResponse({
AccountSecurity? accountSecurity,
}) : super(
accountSecurity: accountSecurity,
);
super.accountSecurity,
});

/// Creates an instance from JSON.
factory AccountSecurityResponse.fromJson(
Expand Down Expand Up @@ -68,10 +66,8 @@ abstract class AccountSecurityModel {
class AccountSecurity extends AccountSecurityModel {
/// Initializes Account security class.
const AccountSecurity({
Totp? totp,
}) : super(
totp: totp,
);
super.totp,
});

/// Creates an instance from JSON.
factory AccountSecurity.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -117,12 +113,9 @@ abstract class TotpModel {
class Totp extends TotpModel {
/// Initializes Totp class.
const Totp({
bool? isEnabled,
String? secretKey,
}) : super(
isEnabled: isEnabled,
secretKey: secretKey,
);
super.isEnabled,
super.secretKey,
});

/// Creates an instance from JSON.
factory Totp.fromJson(Map<String, dynamic> json) => Totp(
Expand Down
Loading

0 comments on commit 3630991

Please sign in to comment.