From 3e7cd61188d17815945359fa301f95b5a14c35fc Mon Sep 17 00:00:00 2001 From: Ian He <39037239+ianhe8x@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:40:07 +1300 Subject: [PATCH] fix missing indexer to context make score accurate (#205) --- packages/apollo-links/src/core/clusterAuthLink.ts | 14 ++++++++------ packages/network-config/src/config.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/apollo-links/src/core/clusterAuthLink.ts b/packages/apollo-links/src/core/clusterAuthLink.ts index 61dd6a9b..3acbea73 100644 --- a/packages/apollo-links/src/core/clusterAuthLink.ts +++ b/packages/apollo-links/src/core/clusterAuthLink.ts @@ -4,7 +4,7 @@ import { ApolloLink, FetchResult, NextLink, Observable, Operation } from '@apollo/client/core'; import { Subscription } from 'zen-observable-ts'; -import { isTokenExpired } from '../auth/authHelper'; +import { isTokenExpired } from '../auth'; import { ChannelAuth, OrderType } from '../types'; import { Logger } from '../utils/logger'; import OrderMananger from '../utils/orderManager'; @@ -22,6 +22,7 @@ type ParamsResponse = { url: string; authorization: string; type: OrderType; + indexer: string; }; error?: { indexer: string; @@ -50,9 +51,9 @@ export class ClusterAuthLink extends ApolloLink { this.getRequestParams() .then((params) => { if (params?.data) { - const { authorization, url, type } = params.data; + const { authorization, url, type, indexer } = params.data; const headers = { authorization }; - operation.setContext({ url, headers, type }); + operation.setContext({ url, headers, type, indexer }); sub = forward(operation).subscribe(observer); } else if (params?.error) { @@ -98,7 +99,8 @@ export class ClusterAuthLink extends ApolloLink { const type = OrderType.agreement; const { token, id, url, indexer } = nextAgreement; - if (!isTokenExpired(token)) return { data: { url, type, ...this.tokenToAuthHeader(token) } }; + if (!isTokenExpired(token)) + return { data: { url, type, indexer, ...this.tokenToAuthHeader(token) } }; try { this.logger?.debug(`request new token for indexer ${indexer}`); @@ -112,7 +114,7 @@ export class ClusterAuthLink extends ApolloLink { this.orderManager.updateTokenById(id, res.token); this.logger?.debug(`request new token for indexer ${indexer} success`); - return { data: { url, type, ...this.tokenToAuthHeader(res.token) } }; + return { data: { url, type, indexer, ...this.tokenToAuthHeader(res.token) } }; } catch (error) { this.logger?.debug( `request new token for indexer ${indexer} and url: ${nextAgreement.url} failed` @@ -140,7 +142,7 @@ export class ClusterAuthLink extends ApolloLink { this.logger?.debug(`request new state signature for indexer ${indexer} success`); const { authorization } = signedState; - return { data: { authorization, url, type } }; + return { data: { authorization, url, type, indexer } }; } catch (error) { this.logger?.debug(`request new state signature for indexer ${indexer} failed`); return { error: { indexer: nextPlan.indexer, message: (error as Error).message } }; diff --git a/packages/network-config/src/config.ts b/packages/network-config/src/config.ts index 88efc3fb..77fbc69b 100644 --- a/packages/network-config/src/config.ts +++ b/packages/network-config/src/config.ts @@ -30,7 +30,7 @@ export const NETWORK_CONFIGS: Record = { gql: gqlEndpoints(SQNetworks.KEPLER), }, [SQNetworks.TESTNET]: { - defaultEndpoint: RPC_ENDPOINTS.testnet, + defaultEndpoint: undefined, sdkOptions: { network: 'testnet', deploymentDetails: testnetDeploymentDetails }, gql: gqlEndpoints(SQNetworks.TESTNET), },