Skip to content
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ jobs:
- name: 📦 Install Dependencies
run: flutter pub get

# Setup Node.js to ensure Node.js 20 is used
- name: ⚡ Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

Comment on lines +35 to +39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check if there is another reason for this issue? anyways, we should use actions from the approved list https://security.deriv.dev/github-action-scanner/exceptions/approved_actions.txt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @abedelaziz-deriv
Will check on this.

# do not fail if the analyze issue is info level
- name: 🕵️ Analyze
run: |
Expand Down
57 changes: 57 additions & 0 deletions lib/api/response/crypto_estimations_response_extended.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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()<BaseAPI>();

/// This will subscribe to crypto estimations.<br>
/// Inside [CryptoEstimationsRequest] class:
/// Incase of error, It will throw [BaseAPIException].
static Stream<CryptoEstimationsResponse?> subscribeToCryptoEstimates(
CryptoEstimationsRequest request, {
RequestCompareFunction? comparePredicate,
}) =>
_api
.subscribe(request: request, comparePredicate: comparePredicate)!
.map<CryptoEstimationsResponse?>(
(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 <br>
/// In case of error, It will throw [BaseAPIException].
static Future<bool> unsubscribeFromCryptoEstimates(
String subscriptionId) async {
final ForgetReceive response =
await _api.unsubscribe(subscriptionId: subscriptionId);
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
return response.forget!;
}
}