Skip to content

Commit aa85095

Browse files
committed
chore: rm constructor and add client getter
1 parent 4445957 commit aa85095

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+99
-258
lines changed

packages/sdk-ts/src/client/abacus/grpc/AbacusGrpcApi.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import * as PointsSvcPb from '@injectivelabs/abacus-proto-ts-v2/generated/points
33
import { PointsSvcClient } from '@injectivelabs/abacus-proto-ts-v2/generated/points_svc_pb.client'
44
import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
55
import { AbacusGrpcTransformer } from './transformers/index.js'
6-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
76

87
export class AbacusGrpcApi extends BaseGrpcConsumer {
98
protected module: string = IndexerErrorModule.Abacus
10-
private client: PointsSvcClient
119

12-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
13-
super(endpoint, options)
14-
this.client = new PointsSvcClient(this.transport)
10+
private get client() {
11+
return this.initClient(PointsSvcClient)
1512
}
1613

1714
async fetchAccountLatestPoints(address: string) {

packages/sdk-ts/src/client/base/BaseGrpcConsumer.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class BaseGrpcConsumer {
1919
protected metadata?: Record<string, string>
2020
protected endpoint: string
2121
protected options?: GrpcWebTransportAdditionalOptions
22+
private _client: unknown
2223

2324
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
2425
this.endpoint = endpoint
@@ -44,6 +45,24 @@ export default class BaseGrpcConsumer {
4445
return this.transport
4546
}
4647

48+
/**
49+
* Lazily initializes and returns the gRPC client.
50+
* Call this from a getter in subclasses to avoid constructor boilerplate.
51+
*
52+
* @example
53+
* private get client() {
54+
* return this.initClient(MyGrpcClient)
55+
* }
56+
*/
57+
protected initClient<TClient>(
58+
ClientClass: new (transport: GrpcWebRpcTransport) => TClient,
59+
): TClient {
60+
if (!this._client) {
61+
this._client = new ClientClass(this.transport)
62+
}
63+
return this._client as TClient
64+
}
65+
4766
/**
4867
* Builds RpcOptions with metadata
4968
*/

packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuctionApi.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ import { QueryClient as InjectiveAuctionV1Beta1QueryClient } from '@injectivelab
33
import { ChainModule } from '../types/index.js'
44
import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
55
import { ChainGrpcAuctionTransformer } from '../transformers/index.js'
6-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
7-
86
/**
97
* @category Chain Grpc API
108
*/
119
export class ChainGrpcAuctionApi extends BaseGrpcConsumer {
1210
protected module: string = ChainModule.Auction
1311

14-
private client: InjectiveAuctionV1Beta1QueryClient
15-
16-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
17-
super(endpoint, options)
18-
19-
this.client = new InjectiveAuctionV1Beta1QueryClient(this.transport)
12+
private get client() {
13+
return this.initClient(InjectiveAuctionV1Beta1QueryClient)
2014
}
2115

2216
async fetchModuleParams() {

packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuthApi.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
55
import { ChainGrpcAuthTransformer } from '../transformers/ChainGrpcAuthTransformer.js'
66
import { ChainGrpcCommonTransformer } from '../transformers/ChainGrpcCommonTransformer.js'
77
import type { PaginationOption } from '../../../types/pagination.js'
8-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
9-
108
/**
119
* @category Chain Grpc API
1210
*/
1311
export class ChainGrpcAuthApi extends BaseGrpcConsumer {
1412
protected module: string = ChainModule.Auth
15-
private client: CosmosAuthV1BetaQueryClient
1613

17-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
18-
super(endpoint, options)
19-
this.client = new CosmosAuthV1BetaQueryClient(this.transport)
14+
private get client() {
15+
return this.initClient(CosmosAuthV1BetaQueryClient)
2016
}
2117

2218
async fetchModuleParams() {

packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuthZApi.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
55
import { ChainGrpcAuthZTransformer } from '../transformers/ChainGrpcAuthZTransformer.js'
66
import { ChainGrpcCommonTransformer } from '../transformers/ChainGrpcCommonTransformer.js'
77
import type { PaginationOption } from '../../../types/pagination.js'
8-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
9-
108
/**
119
* @category Chain Grpc API
1210
*/
1311
export class ChainGrpcAuthZApi extends BaseGrpcConsumer {
1412
protected module: string = ChainModule.Authz
15-
private client: CosmosAuthzV1BetaQueryClient
1613

17-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
18-
super(endpoint, options)
19-
this.client = new CosmosAuthzV1BetaQueryClient(this.transport)
14+
private get client() {
15+
return this.initClient(CosmosAuthzV1BetaQueryClient)
2016
}
2117

2218
async fetchGrants({

packages/sdk-ts/src/client/chain/grpc/ChainGrpcBankApi.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ import { ChainGrpcBankTransformer } from '../transformers/index.js'
66
import { fetchAllWithPagination } from '../../../utils/pagination.js'
77
import { ChainGrpcCommonTransformer } from '../transformers/ChainGrpcCommonTransformer.js'
88
import type { PaginationOption } from '../../../types/pagination.js'
9-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
10-
119
const MAX_LIMIT_FOR_SUPPLY = 10000
1210

1311
/**
1412
* @category Chain Grpc API
1513
*/
1614
export class ChainGrpcBankApi extends BaseGrpcConsumer {
1715
protected module: string = ChainModule.Bank
18-
private client: CosmosBankV1BetaQueryClient
1916

20-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
21-
super(endpoint, options)
22-
this.client = new CosmosBankV1BetaQueryClient(this.transport)
17+
private get client() {
18+
return this.initClient(CosmosBankV1BetaQueryClient)
2319
}
2420

2521
async fetchModuleParams() {

packages/sdk-ts/src/client/chain/grpc/ChainGrpcDistributionApi.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
55
import { ChainGrpcDistributionTransformer } from '../transformers/index.js'
66
import type { Coin } from '@injectivelabs/ts-types'
77
import type { ValidatorRewards } from '../types/index.js'
8-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
9-
108
/**
119
* @category Chain Grpc API
1210
*/
1311
export class ChainGrpcDistributionApi extends BaseGrpcConsumer {
1412
protected module: string = ChainModule.Distribution
15-
private client: CosmosDistributionV1Beta1QueryClient
1613

17-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
18-
super(endpoint, options)
19-
this.client = new CosmosDistributionV1Beta1QueryClient(this.transport)
14+
private get client() {
15+
return this.initClient(CosmosDistributionV1Beta1QueryClient)
2016
}
2117

2218
async fetchModuleParams() {

packages/sdk-ts/src/client/chain/grpc/ChainGrpcErc20Api.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import {
88
ChainGrpcCommonTransformer,
99
} from '../transformers/index.js'
1010
import type { PaginationOption } from '../../../types/pagination.js'
11-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
12-
1311
const MAX_LIMIT_FOR_SUPPLY = 10000
1412

1513
/**
@@ -18,12 +16,8 @@ const MAX_LIMIT_FOR_SUPPLY = 10000
1816
export class ChainGrpcErc20Api extends BaseGrpcConsumer {
1917
protected module: string = ChainModule.Erc20
2018

21-
private client: InjectiveErc20V1Beta1QueryClient
22-
23-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
24-
super(endpoint, options)
25-
26-
this.client = new InjectiveErc20V1Beta1QueryClient(this.transport)
19+
private get client() {
20+
return this.initClient(InjectiveErc20V1Beta1QueryClient)
2721
}
2822

2923
async fetchModuleParams() {

packages/sdk-ts/src/client/chain/grpc/ChainGrpcEvmApi.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ import { QueryClient as InjectiveEvmV1QueryClient } from '@injectivelabs/core-pr
33
import { ChainModule } from '../types/index.js'
44
import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
55
import { ChainGrpcEvmTransformer } from '../transformers/index.js'
6-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
7-
86
/**
97
* @category Chain Grpc API
108
*/
119
export class ChainGrpcEvmApi extends BaseGrpcConsumer {
1210
protected module: string = ChainModule.Evm
1311

14-
private client: InjectiveEvmV1QueryClient
15-
16-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
17-
super(endpoint, options)
18-
19-
this.client = new InjectiveEvmV1QueryClient(this.transport)
12+
private get client() {
13+
return this.initClient(InjectiveEvmV1QueryClient)
2014
}
2115

2216
async fetchAccount(ethAddress: string) {

packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import BaseGrpcConsumer from '../../base/BaseGrpcConsumer.js'
55
import { ChainGrpcExchangeTransformer } from '../transformers/index.js'
66
import type * as InjectiveExchangeV1Beta1GenesisPb from '@injectivelabs/core-proto-ts-v2/generated/injective/exchange/v1beta1/genesis_pb'
77
import type * as InjectiveExchangeV1Beta1ExchangePb from '@injectivelabs/core-proto-ts-v2/generated/injective/exchange/v1beta1/exchange_pb'
8-
import type { GrpcWebTransportAdditionalOptions } from '../../../types'
9-
108
/**
119
* @category Chain Grpc API
1210
*/
1311
export class ChainGrpcExchangeApi extends BaseGrpcConsumer {
1412
protected module: string = ChainModule.Exchange
15-
private client: InjectiveExchangeV1Beta1QueryClient
1613

17-
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
18-
super(endpoint, options)
19-
this.client = new InjectiveExchangeV1Beta1QueryClient(this.transport)
14+
private get client() {
15+
return this.initClient(InjectiveExchangeV1Beta1QueryClient)
2016
}
2117

2218
async fetchModuleParams() {

0 commit comments

Comments
 (0)