Skip to content

Commit 8cbb46c

Browse files
committed
Merge branch 'dev' into flutter-version-3
2 parents ddc27f4 + 2985260 commit 8cbb46c

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

lib/api/response/p2p_ping_response_result.dart

+41
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import 'package:equatable/equatable.dart';
44

5+
import 'package:deriv_dependency_injector/dependency_injector.dart';
6+
import 'package:flutter_deriv_api/api/exceptions/exceptions.dart';
7+
import 'package:flutter_deriv_api/api/models/base_exception_model.dart';
8+
import 'package:flutter_deriv_api/basic_api/generated/p2p_ping_receive.dart';
9+
import 'package:flutter_deriv_api/basic_api/generated/p2p_ping_send.dart';
10+
511
import 'package:flutter_deriv_api/helpers/helpers.dart';
12+
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
613

714
/// P2p ping response model class.
815
abstract class P2pPingResponseModel {
@@ -44,6 +51,40 @@ class P2pPingResponse extends P2pPingResponseModel {
4451
return resultMap;
4552
}
4653

54+
static final BaseAPI _api = Injector()<BaseAPI>();
55+
56+
/// Requests the p2p ping request to the server.
57+
///
58+
/// Mostly used to test the connection or to keep it alive.
59+
/// Throws a [APIBaseException] if API response contains an error.
60+
static Future<P2pPingReceive> p2pPingMethodRaw([
61+
P2pPingRequest? request,
62+
]) async {
63+
final P2pPingReceive response = await _api.call(
64+
request: request ?? const P2pPingRequest(),
65+
);
66+
67+
checkException(
68+
response: response,
69+
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
70+
APIBaseException(baseExceptionModel: baseExceptionModel),
71+
);
72+
73+
return response;
74+
}
75+
76+
/// Requests the p2p ping request to the server.
77+
///
78+
/// Mostly used to test the connection or to keep it alive.
79+
/// Throws a [APIBaseException] if API response contains an error.
80+
static Future<P2pPingResponse> p2pPingMethod([
81+
P2pPingRequest? request,
82+
]) async {
83+
final P2pPingReceive response = await p2pPingMethodRaw(request);
84+
85+
return P2pPingResponse.fromJson(response.p2pPing);
86+
}
87+
4788
/// Creates a copy of instance with given parameters.
4889
P2pPingResponse copyWith({
4990
P2pPingEnum? p2pPing,
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"methods": "",
3-
"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n"
2+
"methods": "static final BaseAPI _api = Injector()<BaseAPI>(); \n \n /// Requests the p2p ping request to the server. \n /// \n /// Mostly used to test the connection or to keep it alive. \n /// Throws a [APIBaseException] if API response contains an error. \n static Future<P2pPingReceive> p2pPingMethodRaw([ \n P2pPingRequest? request, \n ]) async { \n final P2pPingReceive response = await _api.call( \n request: request ?? const P2pPingRequest(), \n ); \n \n checkException( \n response: response, \n exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) => \n APIBaseException(baseExceptionModel: baseExceptionModel), \n ); \n \n return response; \n } \n \n /// Requests the p2p ping request to the server. \n /// \n /// Mostly used to test the connection or to keep it alive. \n /// Throws a [APIBaseException] if API response contains an error. \n static Future<P2pPingResponse> p2pPingMethod([ \n P2pPingRequest? request, \n ]) async { \n final P2pPingReceive response = await p2pPingMethodRaw(request); \n \n return P2pPingResponse.fromJson(response.p2pPing); \n }",
3+
"imports": "import 'package:deriv_dependency_injector/dependency_injector.dart'; \nimport 'package:flutter_deriv_api/api/exceptions/exceptions.dart'; \nimport 'package:flutter_deriv_api/api/models/base_exception_model.dart'; \nimport 'package:flutter_deriv_api/basic_api/generated/p2p_ping_receive.dart'; \nimport 'package:flutter_deriv_api/basic_api/generated/p2p_ping_send.dart'; \n \nimport 'package:flutter_deriv_api/helpers/helpers.dart'; \nimport 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';\n"
44
}

lib/state/connection/connection_cubit.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,9 @@ class ConnectionCubit extends Cubit<ConnectionState> {
111111
emit(const ConnectionConnectedState());
112112
}
113113
},
114-
onDone: (String key) async {
114+
onDone: (String key) {
115115
if (_key == key) {
116-
await _api!.disconnect();
117-
118-
emit(const ConnectionDisconnectedState());
116+
unawaited(reconnect());
119117
}
120118
},
121119
onError: (String key) {

lib/state/server_time/server_time_cubit.dart

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class ServerTimeCubit extends Cubit<ServerTimeState> {
2727
void _connectionListener(ConnectionState state) {
2828
_fetchServerTime(state);
2929

30+
if (_serverTimeInterval != null && _serverTimeInterval!.isActive) {
31+
_serverTimeInterval!.cancel();
32+
}
3033
_serverTimeInterval = Timer.periodic(
3134
_fetchServerTimeDuration,
3235
(Timer timer) => _fetchServerTime(state),

0 commit comments

Comments
 (0)