diff --git a/changelog.md b/changelog.md index d39fb01b74..6781ecdc75 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ ## Unreleased +### Changes + +- [#3444](https://github.com/ignite/cli/pull/3444) Add support for ICS chains in ts-client generation + ## [`v0.26.1`](https://github.com/ignite/cli/releases/tag/v0.26.1) ### Features diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 0651ab1a2b..fa2ea2f7af 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -29,8 +29,9 @@ type tsGenerator struct { } type generatePayload struct { - Modules []module.Module - PackageNS string + Modules []module.Module + PackageNS string + IsConsumerChain bool } func newTSGenerator(g *generator) *tsGenerator { @@ -45,8 +46,9 @@ func (g *generator) generateTS() error { appModulePath := gomodulepath.ExtractAppPath(chainPath.RawPath) data := generatePayload{ - Modules: g.appModules, - PackageNS: strings.ReplaceAll(appModulePath, "/", "-"), + Modules: g.appModules, + PackageNS: strings.ReplaceAll(appModulePath, "/", "-"), + IsConsumerChain: false, } // Third party modules are always required to generate the root @@ -55,8 +57,12 @@ func (g *generator) generateTS() error { // modules when the root templates are re-generated. for _, modules := range g.thirdModules { data.Modules = append(data.Modules, modules...) + for _, m := range modules { + if strings.HasPrefix(m.Pkg.Name, "interchain_security.ccv.consumer") { + data.IsConsumerChain = true + } + } } - // Make sure the modules are always sorted to keep the import // and module registration order consistent so the generated // files are not changed. diff --git a/ignite/pkg/cosmosgen/templates/root/client.ts.tpl b/ignite/pkg/cosmosgen/templates/root/client.ts.tpl index 0c8e21d47c..fe54755d5a 100644 --- a/ignite/pkg/cosmosgen/templates/root/client.ts.tpl +++ b/ignite/pkg/cosmosgen/templates/root/client.ts.tpl @@ -77,28 +77,22 @@ export class IgniteClient extends EventEmitter { const queryClient = ( await import("./cosmos.base.tendermint.v1beta1/module") ).queryClient; - const stakingQueryClient = ( - await import("./cosmos.staking.v1beta1/module") - ).queryClient; const bankQueryClient = (await import("./cosmos.bank.v1beta1/module")) .queryClient; - + {{ if eq .IsConsumerChain false }} + const stakingQueryClient = (await import("./cosmos.staking.v1beta1/module")).queryClient; const stakingqc = stakingQueryClient({ addr: this.env.apiURL }); + const staking = await (await stakingqc.queryParams()).data; + {{ end }} const qc = queryClient({ addr: this.env.apiURL }); const node_info = await (await qc.serviceGetNodeInfo()).data; const chainId = node_info.default_node_info?.network ?? ""; const chainName = chainId?.toUpperCase() + " Network"; - const staking = await (await stakingqc.queryParams()).data; const bankqc = bankQueryClient({ addr: this.env.apiURL }); const tokens = await (await bankqc.queryTotalSupply()).data; const addrPrefix = this.env.prefix ?? "cosmos"; const rpc = this.env.rpcURL; const rest = this.env.apiURL; - let stakeCurrency = { - coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "", - coinMinimalDenom: staking.params?.bond_denom ?? "", - coinDecimals: 0, - }; let bip44 = { coinType: 118, @@ -123,6 +117,15 @@ export class IgniteClient extends EventEmitter { return y; }) ?? []; + {{ if eq .IsConsumerChain true -}} + let stakeCurrency = currencies.find((x) => !x.coinDenom.startsWith("ibc/")); + {{ else }} + let stakeCurrency = { + coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "", + coinMinimalDenom: staking.params?.bond_denom ?? "", + coinDecimals: 0, + }; + {{ end }} let feeCurrencies = tokens.supply?.map((x) => { const y = {