Skip to content

Commit f090c3f

Browse files
author
jeronimoalbi
committed
Merge branch 'develop' into ilgooz/migration-refactor
2 parents 0435812 + 505f7d5 commit f090c3f

27 files changed

+1219
-577
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
## Unreleased
44

5+
- Updated `nodetime`: `ts-proto` to `v1.126.0`, `protobufjs` to `v7.1.1`, `swagger-typescript-api` to `v9.2.0`
6+
- Switched codegen client to use `axios` instead of `fetch`
7+
58
### Fixes
69

10+
- Change vuex generation to use a default TS client path.
711
- Fix cli action org in templates.
812
- Seal the capability keeper in the `app.go` template
913

docs/docs/clients/01-typescript.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ ignite generate ts-client
3535

3636
To prevent regenerating the client, remove the `client:typescript` property from `config.yml`.
3737

38+
## Setup
39+
40+
The best way to get started building with the TypeScript client is by using a [Vite](https://vitejs.dev/) boilerplate. Vite provides boilerplates for vanilla TS projects as well as react, vue, lit, svelte and preact frameworks.
41+
You can find additional information at the [Vite Getting Started guide](https://vitejs.dev/guide/).
42+
43+
You will also need to polyfill the client's dependencies. The following is an example of setting up a vanilla TS project with the necessary polyfills.
44+
45+
```bash
46+
npm create vite@latest my-frontend-app -- --template vanilla-ts
47+
npm install --save-dev buffer @rollup/plugin-node-resolve
48+
```
49+
50+
You must then create the necessary `vite.config.ts` file.
51+
52+
```typescript
53+
import { nodeResolve } from '@rollup/plugin-node-resolve'
54+
import { Buffer } from 'buffer'
55+
import { defineConfig } from 'vite'
56+
57+
export default defineConfig({
58+
define: {
59+
global: {
60+
Buffer: Buffer
61+
}
62+
},
63+
plugins: [nodeResolve()],
64+
})
65+
```
66+
67+
You are then ready to use the generated client code inside this project directly or by publishing the client and installing it as any other npm package.
68+
3869
## Usage
3970

4071
The code generated in `ts-client` comes with a `package.json` file ready to publish which you can modify to suit your needs.
@@ -178,4 +209,4 @@ const tx_result = await client.sendMsgSend(
178209
memo
179210
}
180211
);
181-
```
212+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ require (
5050
github.com/stretchr/testify v1.8.0
5151
github.com/takuoki/gocase v1.0.0
5252
github.com/tendermint/flutter/v2 v2.0.4
53-
github.com/tendermint/spn v0.2.1-0.20220907161743-aab4d3df1f2b
53+
github.com/tendermint/spn v0.2.1-0.20220921200247-8bafad876bdd
5454
github.com/tendermint/tendermint v0.34.21
5555
github.com/tendermint/tm-db v0.6.7
5656
github.com/vektra/mockery/v2 v2.14.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,10 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l
17131713
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
17141714
github.com/tendermint/spn v0.2.1-0.20220907161743-aab4d3df1f2b h1:QqEBIiWRC+uPM8FCXuxcvzTS6isR/lycQJDRHgsmg2c=
17151715
github.com/tendermint/spn v0.2.1-0.20220907161743-aab4d3df1f2b/go.mod h1:CMzd3oBkjR9I1h/BEaU1K2V78XqARFWGjxPP9Xy/FIE=
1716+
github.com/tendermint/spn v0.2.1-0.20220921185243-142531a50099 h1:vXANQeYDrMkzAKz1EP7GSccY6KuLniZ+2pn9kHuzqpw=
1717+
github.com/tendermint/spn v0.2.1-0.20220921185243-142531a50099/go.mod h1:p4b3ZAVTgLGxIpXZsXVeQuOxVUk1/kcwBIIlOMTZtsE=
1718+
github.com/tendermint/spn v0.2.1-0.20220921200247-8bafad876bdd h1:Sp1MgPWq73/a8WVJvE/B6/xOt7cXEzLFT/+KBtIiuk8=
1719+
github.com/tendermint/spn v0.2.1-0.20220921200247-8bafad876bdd/go.mod h1:p4b3ZAVTgLGxIpXZsXVeQuOxVUk1/kcwBIIlOMTZtsE=
17161720
github.com/tendermint/tendermint v0.34.21 h1:UiGGnBFHVrZhoQVQ7EfwSOLuCtarqCSsRf8VrklqB7s=
17171721
github.com/tendermint/tendermint v0.34.21/go.mod h1:XDvfg6U7grcFTDx7VkzxnhazQ/bspGJAn4DZ6DcLLjQ=
17181722
github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8=

ignite/chainconfig/chainconfig.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package chainconfig
22

33
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
49
"github.com/ignite/cli/ignite/chainconfig/config"
510
v0 "github.com/ignite/cli/ignite/chainconfig/v0"
611
v1 "github.com/ignite/cli/ignite/chainconfig/v1"
@@ -14,6 +19,10 @@ var (
1419
// ConfigFileNames is a list of recognized names as for Ignite's config file.
1520
ConfigFileNames = []string{"config.yml", "config.yaml"}
1621

22+
// DefaultTSClientPath defines the default relative path to use when generating the TS client.
23+
// The path is relative to the app's directory.
24+
DefaultTSClientPath = "ts-client"
25+
1726
// LatestVersion defines the latest version of the config.
1827
LatestVersion config.Version = 1
1928

@@ -31,3 +40,50 @@ type Config = v1.Config
3140
func DefaultConfig() *Config {
3241
return v1.DefaultConfig()
3342
}
43+
44+
// FaucetHost returns the faucet host to use.
45+
func FaucetHost(cfg *Config) string {
46+
// We keep supporting Port option for backward compatibility
47+
// TODO: drop this option in the future
48+
host := cfg.Faucet.Host
49+
if cfg.Faucet.Port != 0 {
50+
host = fmt.Sprintf(":%d", cfg.Faucet.Port)
51+
}
52+
53+
return host
54+
}
55+
56+
// TSClientPath returns the relative path to the Typescript client directory.
57+
// Path is relative to the app's directory.
58+
func TSClientPath(conf *Config) string {
59+
if path := strings.TrimSpace(conf.Client.Typescript.Path); path != "" {
60+
return filepath.Clean(path)
61+
}
62+
63+
return DefaultTSClientPath
64+
}
65+
66+
// CreateConfigDir creates config directory if it is not created yet.
67+
func CreateConfigDir() error {
68+
path, err := ConfigDirPath()
69+
if err != nil {
70+
return err
71+
}
72+
73+
return os.MkdirAll(path, 0o755)
74+
}
75+
76+
// LocateDefault locates the default path for the config file.
77+
// Returns ErrConfigNotFound when no config file found.
78+
func LocateDefault(root string) (path string, err error) {
79+
for _, name := range ConfigFileNames {
80+
path = filepath.Join(root, name)
81+
if _, err := os.Stat(path); err == nil {
82+
return path, nil
83+
} else if !os.IsNotExist(err) {
84+
return "", err
85+
}
86+
}
87+
88+
return "", ErrConfigNotFound
89+
}

ignite/chainconfig/parser.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package chainconfig
22

33
import (
44
"bytes"
5-
"fmt"
65
"io"
76
"os"
8-
"path/filepath"
97

108
"gopkg.in/yaml.v2"
119

@@ -69,43 +67,6 @@ func ReadConfigVersion(configFile io.Reader) (config.Version, error) {
6967
return c.Version, err
7068
}
7169

72-
// LocateDefault locates the default path for the config file.
73-
// Returns ErrConfigNotFound when no config file found.
74-
func LocateDefault(root string) (path string, err error) {
75-
for _, name := range ConfigFileNames {
76-
path = filepath.Join(root, name)
77-
if _, err := os.Stat(path); err == nil {
78-
return path, nil
79-
} else if !os.IsNotExist(err) {
80-
return "", err
81-
}
82-
}
83-
84-
return "", ErrConfigNotFound
85-
}
86-
87-
// FaucetHost returns the faucet host to use.
88-
func FaucetHost(cfg *Config) string {
89-
// We keep supporting Port option for backward compatibility
90-
// TODO: drop this option in the future
91-
host := cfg.Faucet.Host
92-
if cfg.Faucet.Port != 0 {
93-
host = fmt.Sprintf(":%d", cfg.Faucet.Port)
94-
}
95-
96-
return host
97-
}
98-
99-
// CreateConfigDir creates config directory if it is not created yet.
100-
func CreateConfigDir() error {
101-
path, err := ConfigDirPath()
102-
if err != nil {
103-
return err
104-
}
105-
106-
return os.MkdirAll(path, 0755)
107-
}
108-
10970
func decodeConfig(r io.Reader, version config.Version) (config.Converter, error) {
11071
c, ok := Versions[version]
11172
if !ok {

ignite/cmd/generate_typescript_client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ignitecmd
33
import (
44
"github.com/spf13/cobra"
55

6+
"github.com/ignite/cli/ignite/chainconfig"
67
"github.com/ignite/cli/ignite/pkg/cliui"
78
"github.com/ignite/cli/ignite/services/chain"
89
)
@@ -13,7 +14,10 @@ func NewGenerateTSClient() *cobra.Command {
1314
Short: "Generate Typescript client for your chain's frontend",
1415
RunE: generateTSClientHandler,
1516
}
17+
1618
c.Flags().AddFlagSet(flagSetProto3rdParty(""))
19+
c.Flags().StringP(flagOutput, "o", chainconfig.DefaultTSClientPath, "typescript client output path")
20+
1721
return c
1822
}
1923

@@ -33,7 +37,13 @@ func generateTSClientHandler(cmd *cobra.Command, args []string) error {
3337
return err
3438
}
3539

36-
if err := c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient()); err != nil {
40+
output, err := cmd.Flags().GetString(flagOutput)
41+
if err != nil {
42+
return err
43+
}
44+
45+
err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output))
46+
if err != nil {
3747
return err
3848
}
3949

ignite/cmd/network_chain_list.go

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package ignitecmd
22

33
import (
4+
"errors"
45
"fmt"
6+
"time"
57

8+
"github.com/cosmos/cosmos-sdk/types/query"
69
"github.com/spf13/cobra"
710

811
"github.com/ignite/cli/ignite/pkg/cliui"
@@ -11,7 +14,18 @@ import (
1114
"github.com/ignite/cli/ignite/services/network/networktypes"
1215
)
1316

14-
var LaunchSummaryHeader = []string{"launch ID", "chain ID", "source", "campaign ID", "network", "reward"}
17+
var LaunchSummaryHeader = []string{
18+
"launch ID",
19+
"chain ID",
20+
"source",
21+
"phase",
22+
}
23+
24+
var LaunchSummaryAdvancedHeader = []string{
25+
"campaign ID",
26+
"network",
27+
"reward",
28+
}
1529

1630
// NewNetworkChainList returns a new command to list all published chains on Ignite
1731
func NewNetworkChainList() *cobra.Command {
@@ -21,13 +35,27 @@ func NewNetworkChainList() *cobra.Command {
2135
Args: cobra.NoArgs,
2236
RunE: networkChainListHandler,
2337
}
38+
c.Flags().Bool(flagAdvanced, false, "Show advanced information about the chains")
39+
c.Flags().Uint64(flagLimit, 100, "Limit of results per page")
40+
c.Flags().Uint64(flagPage, 1, "Page for chain list result")
41+
2442
return c
2543
}
2644

2745
func networkChainListHandler(cmd *cobra.Command, _ []string) error {
46+
var (
47+
advanced, _ = cmd.Flags().GetBool(flagAdvanced)
48+
limit, _ = cmd.Flags().GetUint64(flagLimit)
49+
page, _ = cmd.Flags().GetUint64(flagPage)
50+
)
51+
2852
session := cliui.New()
2953
defer session.Cleanup()
3054

55+
if page == 0 {
56+
return errors.New("invalid page value")
57+
}
58+
3159
nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
3260
if err != nil {
3361
return err
@@ -36,40 +64,70 @@ func networkChainListHandler(cmd *cobra.Command, _ []string) error {
3664
if err != nil {
3765
return err
3866
}
39-
chainLaunches, err := n.ChainLaunchesWithReward(cmd.Context())
67+
chainLaunches, err := n.ChainLaunchesWithReward(cmd.Context(), &query.PageRequest{
68+
Offset: limit * (page - 1),
69+
Limit: limit,
70+
})
4071
if err != nil {
4172
return err
4273
}
4374

4475
session.StopSpinner()
4576

46-
return renderLaunchSummaries(chainLaunches, session)
77+
return renderLaunchSummaries(chainLaunches, session, advanced)
4778
}
4879

4980
// renderLaunchSummaries writes into the provided out, the list of summarized launches
50-
func renderLaunchSummaries(chainLaunches []networktypes.ChainLaunch, session cliui.Session) error {
81+
func renderLaunchSummaries(chainLaunches []networktypes.ChainLaunch, session cliui.Session, advanced bool) error {
82+
header := LaunchSummaryHeader
83+
if advanced {
84+
// advanced information show the campaign ID, type of network and rewards for incentivized testnet
85+
header = append(header, LaunchSummaryAdvancedHeader...)
86+
}
87+
5188
var launchEntries [][]string
5289

90+
// iterate and fetch summary for chains
5391
for _, c := range chainLaunches {
54-
campaign := "no campaign"
55-
if c.CampaignID > 0 {
56-
campaign = fmt.Sprintf("%d", c.CampaignID)
57-
}
5892

59-
reward := entrywriter.None
60-
if len(c.Reward) > 0 {
61-
reward = c.Reward
93+
// get the current phase of the chain
94+
var phase string
95+
switch {
96+
case !c.LaunchTriggered:
97+
phase = "coordinating"
98+
case time.Now().Before(c.LaunchTime):
99+
phase = "launching"
100+
default:
101+
phase = "launched"
62102
}
63103

64-
launchEntries = append(launchEntries, []string{
104+
entry := []string{
65105
fmt.Sprintf("%d", c.ID),
66106
c.ChainID,
67107
c.SourceURL,
68-
campaign,
69-
c.Network.String(),
70-
reward,
71-
})
108+
phase,
109+
}
110+
111+
// add advanced information
112+
if advanced {
113+
campaign := "no campaign"
114+
if c.CampaignID > 0 {
115+
campaign = fmt.Sprintf("%d", c.CampaignID)
116+
}
117+
118+
reward := entrywriter.None
119+
if len(c.Reward) > 0 {
120+
reward = c.Reward
121+
}
122+
123+
entry = append(entry,
124+
campaign,
125+
c.Network.String(),
126+
reward)
127+
}
128+
129+
launchEntries = append(launchEntries, entry)
72130
}
73131

74-
return session.PrintTable(LaunchSummaryHeader, launchEntries...)
132+
return session.PrintTable(header, launchEntries...)
75133
}

ignite/pkg/cosmosgen/generate_typescript.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (g *tsGenerator) generateModuleTemplate(
164164
m.Pkg.Path,
165165
includePaths,
166166
tsOut,
167-
protoc.Plugin(tsprotoPluginPath, "--ts_proto_opt=snakeToCamel=true"),
167+
protoc.Plugin(tsprotoPluginPath, "--ts_proto_opt=snakeToCamel=true --ts_proto_opt=esModuleInterop=true "),
168168
protoc.Env("NODE_OPTIONS="), // unset nodejs options to avoid unexpected issues with vercel "pkg"
169169
protoc.WithCommand(protocCmd),
170170
)

0 commit comments

Comments
 (0)