Skip to content

Commit

Permalink
fix missing indexer to context make score accurate (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhe8x authored Oct 15, 2023
1 parent 721fc64 commit 3e7cd61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions packages/apollo-links/src/core/clusterAuthLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -22,6 +22,7 @@ type ParamsResponse = {
url: string;
authorization: string;
type: OrderType;
indexer: string;
};
error?: {
indexer: string;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`);
Expand All @@ -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`
Expand Down Expand Up @@ -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 } };
Expand Down
2 changes: 1 addition & 1 deletion packages/network-config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const NETWORK_CONFIGS: Record<SQNetworks, NetworkConfig> = {
gql: gqlEndpoints(SQNetworks.KEPLER),
},
[SQNetworks.TESTNET]: {
defaultEndpoint: RPC_ENDPOINTS.testnet,
defaultEndpoint: undefined,
sdkOptions: { network: 'testnet', deploymentDetails: testnetDeploymentDetails },
gql: gqlEndpoints(SQNetworks.TESTNET),
},
Expand Down

0 comments on commit 3e7cd61

Please sign in to comment.