Skip to content

Commit

Permalink
feat: Add graphql to axs client
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Mar 22, 2024
1 parent 00ff5e0 commit 216f93a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
28 changes: 28 additions & 0 deletions logic/lib/src/data/api/client/web3_client.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -58,4 +59,31 @@ class DatadashClient extends Web3Client {
LoggingInterceptor(),
],
);

GraphQLClient? _graphQLClient;

GraphQLClient get graphQLClient {
final chainId = _getNetwork().chainId;

if (!Config.isMxcChains(chainId)) {
throw 'Accessing graphQL for chains other than MXC chains';
}
final mepUrl = Urls.getMepGraphQlLink(chainId);

late GraphQLClient finalGraphqlClient;

if (_graphQLClient == null ||
((_graphQLClient!.link as HttpLink).uri.toString() == mepUrl)) {
finalGraphqlClient = GraphQLClient(
link: HttpLink(
Urls.getMepGraphQlLink(_getNetwork().chainId),
),
cache: GraphQLCache(),
);
} else {
finalGraphqlClient = _graphQLClient!;
}

return finalGraphqlClient;
}
}
9 changes: 6 additions & 3 deletions logic/lib/src/domain/const/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Config {
);

static EthereumAddress getContractAddress(
MXCContacts contract, int chainId) =>
MXCContacts contract,
int chainId,
) =>
EthereumAddress.fromHex(getContractAddressString(contract, chainId));

static String getContractAddressString(MXCContacts contract, int chainId) =>
Expand Down Expand Up @@ -144,13 +146,14 @@ class Config {
static double dAppDoubleTapLowerBound = 0;
static double dAppDoubleTapUpperBound = 200;

/// The frequency in which background process will be
/// The frequency in which background process will be
/// executed, NOTE : It's in minutes.
static const axsBackgroundServiceInterval = 15;

static const String axsPeriodicalTask = 'com.mxc.axswallet.periodicalTasks';
static const String dappHookTasks = 'com.mxc.axswallet.dappHooksTasks';
static const String minerAutoClaimTask = 'com.mxc.axswallet.minerAutoClaimTask';
static const String minerAutoClaimTask =
'com.mxc.axswallet.minerAutoClaimTask';
// Miner dApp transactions gas limit
static const double minerDAppGasLimit = 750000;

Expand Down
1 change: 1 addition & 0 deletions logic/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
flutter:
sdk: flutter
graphql: ^5.1.3
graphql_flutter: ^5.1.2
hex: ^0.2.0
http: ^0.13.5
http_interceptor: ^1.0.1
Expand Down

0 comments on commit 216f93a

Please sign in to comment.