Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_crypto_config_api_call #316

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/api/response/crypto_config_response_extended.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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_config_response_result.dart';
import 'package:flutter_deriv_api/basic_api/generated/crypto_config_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/crypto_config_send.dart';
import 'package:flutter_deriv_api/helpers/miscellaneous_helper.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';

/// The extended version of the [CryptoConfigResponseExtended] class to implement
/// the API call methods.
class CryptoConfigResponseExtended extends CryptoConfigResponse {
static final BaseAPI _api = Injector()<BaseAPI>();

/// Fetches the available wallets that can be created
static Future<CryptoConfigResponse> fetchCryptoConfig({
required CryptoConfigRequest request,
}) async {
final CryptoConfigReceive response = await _api.call(request: request);

checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);

return CryptoConfigResponse.fromJson(response.cryptoConfig);
}
}
3 changes: 3 additions & 0 deletions lib/services/connection/api_manager/mock_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter_deriv_api/services/connection/api_manager/connection_inf
import 'package:flutter_deriv_api/services/connection/api_manager/exceptions/api_manager_exception.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/account/new_account_wallet_response.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/cashier/cashier_payments_response.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/common/crypto_config_response.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/base_call_manager.dart';
import 'package:flutter_deriv_api/services/connection/call_manager/exceptions/call_manager_exception.dart';

Expand Down Expand Up @@ -226,6 +227,8 @@ class MockAPI extends BaseAPI {
return copyTradingListResponse;
case 'copytrading_statistics':
return copyTradingStatisticsResponse;
case 'crypto_config':
return cryptoConfigResponse;
// case 'document_upload':
case 'exchange_rates':
return exchangeRatesResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const String cryptoConfigResponse = '''
{
"crypto_config": {
"currencies_config": {
"BTC": {
"minimum_withdrawal": 0.0002968
},
"ETH": {
"minimum_withdrawal": 0.01445239
},
"LTC": {
"minimum_withdrawal": 0.05539552
},
"USDC": {
"minimum_withdrawal": 50
},
"eUSDT": {
"minimum_withdrawal": 49.96
},
"tUSDT": {
"minimum_deposit": 50,
"minimum_withdrawal": 24.98
}
}
},
"echo_req": {
"crypto_config": 1,
"req_id": 2
},
"msg_type": "crypto_config",
}
''';
23 changes: 23 additions & 0 deletions test/api/common/crypto_config/crypto_config_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:deriv_dependency_injector/dependency_injector.dart';
import 'package:flutter_deriv_api/api/api_initializer.dart';
import 'package:flutter_deriv_api/api/response/crypto_config_response_extended.dart';
import 'package:flutter_deriv_api/api/response/crypto_config_response_result.dart';
import 'package:flutter_deriv_api/basic_api/generated/crypto_config_send.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../../services/call_manager/base_call_manager_test.dart';

void main() {
setUp(() => APIInitializer().initialize(api: MockAPI()));

tearDown(() => Injector().dispose());

test('CryptoConfigResponseExtended makes API call.', () async {
final CryptoConfigResponse response =
await CryptoConfigResponseExtended.fetchCryptoConfig(
request: const CryptoConfigRequest(),
);

expect(response, isA<CryptoConfigResponse>());
});
}
Loading