@cosmwasm/ts-codegen 0.31.2 → 0.31.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,6 +36,8 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
36
36
  - [React Query](#react-query)
37
37
  - [Recoil](#recoil)
38
38
  - [Message Composer](#message-composer)
39
+ - [Message Builder](#message-builder)
40
+ - [Use Contracts Hooks](#use-contracts-hooks)
39
41
  - [Bundles](#bundles)
40
42
  - [CLI Usage and Examples](#cli-usage-and-examples)
41
43
  - [Advanced Usage](#advanced-usage)
@@ -256,13 +258,13 @@ cosmwasm-ts-codegen generate \
256
258
  | ------------------------------ | ------------------------------------------------------------------- |
257
259
  | `messageComposer.enabled` | enable the messageComposer plugin |
258
260
 
259
- ### Msg Builder
261
+ ### Message Builder
260
262
 
261
263
  Generate raw message jsons for use in your application with the `msg-builder` command.
262
264
 
263
265
  [see example output code](https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26)
264
266
 
265
- #### Msg Builder via CLI
267
+ #### Message Builder via CLI
266
268
 
267
269
  ```sh
268
270
  cosmwasm-ts-codegen generate \
@@ -271,12 +273,66 @@ cosmwasm-ts-codegen generate \
271
273
  --out ./ts \
272
274
  --name MyContractName
273
275
  ```
274
- #### Message Composer Options
276
+ #### Message Builder Options
275
277
 
276
278
  | option | description |
277
279
  |------------ | ------------------------------ | ------------------------------------------------------------------- |
278
- | `msgBuilder.enabled` | enable the msgBilder plugin |
280
+ | `msgBuilder.enabled` | enable the msgBuilder plugin |
281
+
282
+
283
+ ### Use Contracts Hooks
284
+
285
+ | option | description |
286
+ | -------------------------------- | --------------------------------------- |
287
+ | `useContractsHooks.enabled` | enable the `useContracts` plugin |
288
+
289
+ #### Use Contracts Provider Usage
290
+
291
+ ```tsx
292
+ import { useChain } from '@cosmos-kit/react';
293
+ import { ContractsProvider } from '../path/to/codegen/contracts-context';
294
+
295
+ export default function YourComponent() {
296
+
297
+ const {
298
+ address,
299
+ getCosmWasmClient,
300
+ getSigningCosmWasmClient
301
+ } = useChain(chainName);
302
+
303
+ return (
304
+ <ContractsProvider
305
+ contractsConfig={{
306
+ address,
307
+ getCosmWasmClient,
308
+ getSigningCosmWasmClient,
309
+ }}
310
+ >
311
+ <SomeCoolComponent />
312
+ </ContractsProvider>
313
+ )
314
+ };
315
+ ```
316
+
317
+ #### Use Contracts Hooks Usage
318
+
319
+ Once enabled, you can get contracts very simply:
320
+
321
+ ```ts
322
+ const { marketplace } = useContracts();
323
+ ```
279
324
 
325
+ ```ts
326
+ const marketplaceClient = marketplace.signingClient(marketplaceContract);
327
+ await marketplaceClient.updateAskPrice({
328
+ collection: token.collectionAddr,
329
+ price: {
330
+ amount,
331
+ denom,
332
+ },
333
+ tokenId,
334
+ });
335
+ ```
280
336
 
281
337
  ### Bundles
282
338
 
@@ -29,7 +29,7 @@ var write = function write(outPath, file, content) {
29
29
  var createHelpers = function createHelpers(input, builderContext) {
30
30
  var _input$options, _input$options$useCon, _Object$keys;
31
31
 
32
- if ((_input$options = input.options) !== null && _input$options !== void 0 && (_input$options$useCon = _input$options.useContracts) !== null && _input$options$useCon !== void 0 && _input$options$useCon.enabled && (_Object$keys = Object.keys(builderContext.providers)) !== null && _Object$keys !== void 0 && _Object$keys.length) {
32
+ if ((_input$options = input.options) !== null && _input$options !== void 0 && (_input$options$useCon = _input$options.useContractsHooks) !== null && _input$options$useCon !== void 0 && _input$options$useCon.enabled && (_Object$keys = Object.keys(builderContext.providers)) !== null && _Object$keys !== void 0 && _Object$keys.length) {
33
33
  write(input.outPath, "contractContextBase.ts", _helpers.contractContextBase);
34
34
  write(input.outPath, "contracts-context.tsx", _helpers.contractsContextTSX);
35
35
  }
@@ -76,7 +76,7 @@ var ContractsProviderBundlePlugin = /*#__PURE__*/function (_BuilderPluginBase) {
76
76
  while (1) {
77
77
  switch (_context.prev = _context.next) {
78
78
  case 0:
79
- if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.useContracts) !== null && _this$option$useContr !== void 0 && _this$option$useContr.enabled) {
79
+ if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.useContractsHooks) !== null && _this$option$useContr !== void 0 && _this$option$useContr.enabled) {
80
80
  _context.next = 2;
81
81
  break;
82
82
  }
@@ -83,7 +83,7 @@ var ContractsContextProviderPlugin = /*#__PURE__*/function (_BuilderPluginBase)
83
83
  while (1) {
84
84
  switch (_context.prev = _context.next) {
85
85
  case 0:
86
- if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.useContracts) !== null && _this$option$useContr !== void 0 && _this$option$useContr.enabled) {
86
+ if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.useContractsHooks) !== null && _this$option$useContr !== void 0 && _this$option$useContr.enabled) {
87
87
  _context.next = 2;
88
88
  break;
89
89
  }
@@ -18,7 +18,7 @@ const write = (outPath, file, content) => {
18
18
  };
19
19
 
20
20
  export const createHelpers = (input, builderContext) => {
21
- if (input.options?.useContracts?.enabled && Object.keys(builderContext.providers)?.length) {
21
+ if (input.options?.useContractsHooks?.enabled && Object.keys(builderContext.providers)?.length) {
22
22
  write(input.outPath, "contractContextBase.ts", contractContextBase);
23
23
  write(input.outPath, "contracts-context.tsx", contractsContextTSX);
24
24
  }
@@ -20,7 +20,7 @@ export class ContractsProviderBundlePlugin extends BuilderPluginBase {
20
20
  }
21
21
 
22
22
  async doRender(name, context) {
23
- if (!this.option?.useContracts?.enabled) {
23
+ if (!this.option?.useContractsHooks?.enabled) {
24
24
  return;
25
25
  }
26
26
 
@@ -19,7 +19,7 @@ export class ContractsContextProviderPlugin extends BuilderPluginBase {
19
19
  }
20
20
 
21
21
  async doRender(name, context) {
22
- if (!this.option?.useContracts?.enabled) {
22
+ if (!this.option?.useContractsHooks?.enabled) {
23
23
  return;
24
24
  }
25
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "0.31.2",
3
+ "version": "0.31.4",
4
4
  "description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmwasm/ts-codegen",
@@ -98,5 +98,5 @@
98
98
  "shelljs": "0.8.5",
99
99
  "wasm-ast-types": "^0.24.0"
100
100
  },
101
- "gitHead": "ac5ac9a874b56929f76b052a6a719f5c1015ccab"
101
+ "gitHead": "4c207bade9c6e542e9fc4d29b60866f4d7ff1627"
102
102
  }
@@ -1,4 +1,4 @@
1
- import { RenderOptions, defaultOptions, RenderContext, ContractInfo, MessageComposerOptions, BuilderContext} from "wasm-ast-types";
1
+ import { RenderOptions, defaultOptions, RenderContext, ContractInfo, MessageComposerOptions, BuilderContext } from "wasm-ast-types";
2
2
 
3
3
  import { header } from '../utils/header';
4
4
  import { join } from "path";
@@ -48,13 +48,13 @@ export interface BundleOptions {
48
48
  };
49
49
 
50
50
  export interface UseContractsOptions {
51
- enabled?: boolean;
52
- filename?: string;
51
+ enabled?: boolean;
52
+ filename?: string;
53
53
  };
54
54
 
55
55
  export type TSBuilderOptions = {
56
56
  bundle?: BundleOptions;
57
- useContracts?: UseContractsOptions;
57
+ useContractsHooks?: UseContractsOptions;
58
58
  } & RenderOptions;
59
59
 
60
60
  export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder' | 'plugin';
@@ -125,7 +125,7 @@ export class TSBuilder {
125
125
  [].push.apply(this.plugins, plugins);
126
126
  }
127
127
 
128
- this.plugins.forEach(plugin=> plugin.setBuilder(this))
128
+ this.plugins.forEach(plugin => plugin.setBuilder(this))
129
129
  }
130
130
 
131
131
  async build() {
@@ -134,7 +134,7 @@ export class TSBuilder {
134
134
  }
135
135
 
136
136
  // lifecycle functions
137
- private async process(){
137
+ private async process() {
138
138
  for (const contractOpt of this.contracts) {
139
139
  const contract = getContract(contractOpt);
140
140
  //resolve contract schema.
@@ -147,16 +147,16 @@ export class TSBuilder {
147
147
  }
148
148
  }
149
149
 
150
- private async render(name: string, contractInfo: ContractInfo){
151
- for (const plugin of this.plugins) {
152
- let files = await plugin.render(name, contractInfo, this.outPath);
153
- if(files && files.length){
154
- [].push.apply(this.files, files);
155
- }
156
- }
150
+ private async render(name: string, contractInfo: ContractInfo) {
151
+ for (const plugin of this.plugins) {
152
+ let files = await plugin.render(name, contractInfo, this.outPath);
153
+ if (files && files.length) {
154
+ [].push.apply(this.files, files);
155
+ }
156
+ }
157
157
  }
158
158
 
159
- private async after(){
159
+ private async after() {
160
160
  if (this.options.bundle.enabled) {
161
161
  this.bundle();
162
162
  }
@@ -166,21 +166,21 @@ export class TSBuilder {
166
166
  contractsProviderBundlePlugin.setBuilder(this);
167
167
 
168
168
  let files = await contractsProviderBundlePlugin.render(
169
- "",
170
- {
171
- schemas: [],
172
- },
173
- this.outPath
169
+ "",
170
+ {
171
+ schemas: [],
172
+ },
173
+ this.outPath
174
174
  );
175
- if(files && files.length){
176
- [].push.apply(this.files, files);
175
+ if (files && files.length) {
176
+ [].push.apply(this.files, files);
177
177
  }
178
178
 
179
179
  createHelpers({
180
- outPath: this.outPath,
181
- contracts: this.contracts,
182
- options: this.options,
183
- plugins: this.plugins,
180
+ outPath: this.outPath,
181
+ contracts: this.contracts,
182
+ options: this.options,
183
+ plugins: this.plugins,
184
184
  }, this.builderContext);
185
185
  }
186
186
 
@@ -190,8 +190,8 @@ export class TSBuilder {
190
190
 
191
191
  const bundleFile = this.options.bundle.bundleFile;
192
192
  const bundlePath = join(
193
- this.options?.bundle?.bundlePath ?? this.outPath,
194
- bundleFile
193
+ this.options?.bundle?.bundlePath ?? this.outPath,
194
+ bundleFile
195
195
  );
196
196
  const bundleVariables = {};
197
197
  const importPaths = [];
@@ -215,7 +215,7 @@ export class TSBuilder {
215
215
  ]
216
216
  )).code;
217
217
 
218
- if(this.options?.bundle?.bundlePath){
218
+ if (this.options?.bundle?.bundlePath) {
219
219
  mkdirp(this.options?.bundle?.bundlePath);
220
220
  }
221
221
 
@@ -21,7 +21,7 @@ const write = (outPath: string, file: string, content: string) => {
21
21
  };
22
22
 
23
23
  export const createHelpers = (input: TSBuilderInput, builderContext: BuilderContext) => {
24
- if (input.options?.useContracts?.enabled && Object.keys(builderContext.providers)?.length) {
24
+ if (input.options?.useContractsHooks?.enabled && Object.keys(builderContext.providers)?.length) {
25
25
  write(input.outPath, "contractContextBase.ts", contractContextBase);
26
26
  write(input.outPath, "contracts-context.tsx", contractsContextTSX);
27
27
  }
@@ -36,7 +36,7 @@ export class ContractsProviderBundlePlugin extends BuilderPluginBase<TSBuilderOp
36
36
  body: any[];
37
37
  }[]
38
38
  > {
39
- if (!this.option?.useContracts?.enabled) {
39
+ if (!this.option?.useContractsHooks?.enabled) {
40
40
  return;
41
41
  }
42
42
 
@@ -39,7 +39,7 @@ export class ContractsContextProviderPlugin extends BuilderPluginBase<TSBuilderO
39
39
  body: any[];
40
40
  }[]
41
41
  > {
42
- if (!this.option?.useContracts?.enabled) {
42
+ if (!this.option?.useContractsHooks?.enabled) {
43
43
  return;
44
44
  }
45
45
 
@@ -18,7 +18,7 @@ export interface UseContractsOptions {
18
18
  }
19
19
  export type TSBuilderOptions = {
20
20
  bundle?: BundleOptions;
21
- useContracts?: UseContractsOptions;
21
+ useContractsHooks?: UseContractsOptions;
22
22
  } & RenderOptions;
23
23
  export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder' | 'plugin';
24
24
  export interface BuilderFile {