From 216f93a44233872cd53ed8d3677571ecc8b67837 Mon Sep 17 00:00:00 2001 From: reasje Date: Fri, 22 Mar 2024 21:18:40 +0330 Subject: [PATCH] feat: Add graphql to axs client --- .../lib/src/data/api/client/web3_client.dart | 28 +++++++++++++++++++ logic/lib/src/domain/const/config.dart | 9 ++++-- logic/pubspec.yaml | 1 + 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/logic/lib/src/data/api/client/web3_client.dart b/logic/lib/src/data/api/client/web3_client.dart index 55101e5..412f92a 100644 --- a/logic/lib/src/data/api/client/web3_client.dart +++ b/logic/lib/src/data/api/client/web3_client.dart @@ -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'; @@ -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; + } } diff --git a/logic/lib/src/domain/const/config.dart b/logic/lib/src/domain/const/config.dart index 5d1c8da..1ab8d4c 100644 --- a/logic/lib/src/domain/const/config.dart +++ b/logic/lib/src/domain/const/config.dart @@ -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) => @@ -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; diff --git a/logic/pubspec.yaml b/logic/pubspec.yaml index 28fc0d3..39ecefd 100644 --- a/logic/pubspec.yaml +++ b/logic/pubspec.yaml @@ -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