@cosmwasm/ts-codegen 0.30.1 → 0.31.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +36 -30
- package/main/builder/builder.js +41 -4
- package/main/generators/create-helpers.js +38 -0
- package/main/helpers/contractContextBase.js +8 -0
- package/main/helpers/contractsContextTSX.js +8 -0
- package/main/helpers/index.js +31 -0
- package/main/plugins/client.js +11 -6
- package/main/plugins/message-composer.js +10 -6
- package/main/plugins/msg-builder.js +1 -1
- package/main/plugins/plugin-base.js +9 -2
- package/main/plugins/provider-bundle.js +146 -0
- package/main/plugins/provider.js +170 -0
- package/main/plugins/react-query.js +1 -1
- package/main/plugins/recoil.js +1 -1
- package/main/plugins/types.js +1 -1
- package/main/utils/files.js +77 -0
- package/main/utils/unused.js +68 -0
- package/module/builder/builder.js +28 -2
- package/module/generators/create-helpers.js +25 -0
- package/module/helpers/contractContextBase.js +92 -0
- package/module/helpers/contractsContextTSX.js +73 -0
- package/module/helpers/index.js +2 -0
- package/module/plugins/client.js +13 -10
- package/module/plugins/message-composer.js +12 -10
- package/module/plugins/msg-builder.js +1 -1
- package/module/plugins/plugin-base.js +15 -8
- package/module/plugins/provider-bundle.js +65 -0
- package/module/plugins/provider.js +81 -0
- package/module/plugins/react-query.js +1 -1
- package/module/plugins/recoil.js +1 -1
- package/module/plugins/types.js +1 -1
- package/module/utils/files.js +44 -0
- package/module/utils/unused.js +45 -0
- package/package.json +3 -3
- package/src/builder/builder.ts +36 -1
- package/src/generators/create-helpers.ts +28 -0
- package/src/helpers/contractContextBase.ts +92 -0
- package/src/helpers/contractsContextTSX.ts +73 -0
- package/src/helpers/index.ts +2 -0
- package/src/plugins/client.ts +30 -14
- package/src/plugins/message-composer.ts +23 -14
- package/src/plugins/msg-builder.ts +1 -1
- package/src/plugins/plugin-base.ts +30 -20
- package/src/plugins/provider-bundle.ts +97 -0
- package/src/plugins/provider.ts +114 -0
- package/src/plugins/react-query.ts +1 -1
- package/src/plugins/recoil.ts +1 -1
- package/src/plugins/types.ts +1 -1
- package/src/utils/files.ts +73 -0
- package/src/utils/unused.ts +52 -0
- package/types/src/builder/builder.d.ts +7 -1
- package/types/src/generators/create-helpers.d.ts +3 -0
- package/types/src/helpers/contractContextBase.d.ts +1 -0
- package/types/src/helpers/contractsContextTSX.d.ts +1 -0
- package/types/src/helpers/index.d.ts +2 -0
- package/types/src/plugins/client.d.ts +4 -3
- package/types/src/plugins/message-composer.d.ts +4 -3
- package/types/src/plugins/plugin-base.d.ts +7 -3
- package/types/src/plugins/provider-bundle.d.ts +13 -0
- package/types/src/plugins/provider.d.ts +15 -0
- package/types/src/plugins/use-contracts.d.ts +12 -0
- package/types/src/utils/files.d.ts +3 -0
- package/types/src/utils/unused.d.ts +5 -0
package/README.md
CHANGED
@@ -36,7 +36,6 @@ 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
|
-
- [Msg Builder](#msg-builder)
|
40
39
|
- [Bundles](#bundles)
|
41
40
|
- [CLI Usage and Examples](#cli-usage-and-examples)
|
42
41
|
- [Advanced Usage](#advanced-usage)
|
@@ -121,7 +120,7 @@ codegen({
|
|
121
120
|
messageComposer: {
|
122
121
|
enabled: false
|
123
122
|
},
|
124
|
-
msgBuilder: {
|
123
|
+
msgBuilder: {
|
125
124
|
enabled: false
|
126
125
|
}
|
127
126
|
}
|
@@ -137,11 +136,11 @@ Typescript types and interfaces are generated in separate files so they can be i
|
|
137
136
|
|
138
137
|
#### Types Options
|
139
138
|
|
140
|
-
| option
|
141
|
-
|
|
142
|
-
| `types.enabled`
|
143
|
-
| `types.aliasExecuteMsg`
|
144
|
-
| `types.aliasEntryPoints`
|
139
|
+
| option | description |
|
140
|
+
| ------------------------ | ---------------------------------------------------- |
|
141
|
+
| `types.enabled` | enable type generation |
|
142
|
+
| `types.aliasExecuteMsg` | generate a type alias based on the contract name |
|
143
|
+
| `types.aliasEntryPoints` | generate type aliases for the entry points based on the contract name |
|
145
144
|
|
146
145
|
### Client
|
147
146
|
|
@@ -174,15 +173,15 @@ Generate [react-query v3](https://react-query-v3.tanstack.com/) or [react-query
|
|
174
173
|
|
175
174
|
#### React Query Options
|
176
175
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
176
|
+
| option | description |
|
177
|
+
| --------------------------- | --------------------------------------------------------------------------- |
|
178
|
+
| `reactQuery.enabled` | enable the react-query plugin |
|
179
|
+
| `reactQuery.optionalClient` | allows contract client to be undefined as the component renders |
|
180
|
+
| `reactQuery.queryKeys` | generates a const queryKeys object for use with invalidations and set values |
|
181
|
+
| `reactQuery.queryFactory` | generates a const queryFactory object for useQueries and prefetchQueries use |
|
182
|
+
| `reactQuery.version` | `v4` uses `@tanstack/react-query` and `v3` uses `react-query` |
|
183
|
+
| `reactQuery.mutations` | also generate mutations |
|
184
|
+
| `reactQuery.camelize` | use camelCase style for property names |
|
186
185
|
|
187
186
|
|
188
187
|
#### React Query via CLI
|
@@ -232,9 +231,9 @@ cosmwasm-ts-codegen generate \
|
|
232
231
|
|
233
232
|
#### Recoil Options
|
234
233
|
|
235
|
-
|
236
|
-
|
237
|
-
|
234
|
+
| option | description |
|
235
|
+
| ------------------------------ | ------------------------------------------------------------------- |
|
236
|
+
| `recoil.enabled` | enable the recoil plugin |
|
238
237
|
|
239
238
|
### Message Composer
|
240
239
|
|
@@ -253,9 +252,9 @@ cosmwasm-ts-codegen generate \
|
|
253
252
|
```
|
254
253
|
#### Message Composer Options
|
255
254
|
|
256
|
-
|
257
|
-
|
258
|
-
|
255
|
+
| option | description |
|
256
|
+
| ------------------------------ | ------------------------------------------------------------------- |
|
257
|
+
| `messageComposer.enabled` | enable the messageComposer plugin |
|
259
258
|
|
260
259
|
### Msg Builder
|
261
260
|
|
@@ -275,7 +274,7 @@ cosmwasm-ts-codegen generate \
|
|
275
274
|
#### Message Composer Options
|
276
275
|
|
277
276
|
| option | description |
|
278
|
-
|
277
|
+
|------------ | ------------------------------ | ------------------------------------------------------------------- |
|
279
278
|
| `msgBuilder.enabled` | enable the msgBilder plugin |
|
280
279
|
|
281
280
|
|
@@ -293,11 +292,11 @@ const { CwAdminFactoryClient } = contracts.CwAdminFactory;
|
|
293
292
|
```
|
294
293
|
#### Bundler Options
|
295
294
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
295
|
+
| option | description |
|
296
|
+
| --------------------- | -------------------------------------------------------------------------------- |
|
297
|
+
| `bundle.enabled` | enable the bundler plugin |
|
298
|
+
| `bundle.scope` | name of the scope, defaults to `contracts` (you can use `.` to make more scopes) |
|
299
|
+
| `bundle.bundleFile` | name of the bundle file |
|
301
300
|
|
302
301
|
### CLI Usage and Examples
|
303
302
|
|
@@ -416,6 +415,10 @@ https://gist.github.com/pyramation/a9520ccf131177b1841e02a97d7d3731
|
|
416
415
|
|
417
416
|
https://gist.github.com/pyramation/43320e8b952751a0bd5a77dbc5b601f4
|
418
417
|
|
418
|
+
- `cosmwasm-ts-codegen generate --plugin msg-builder`
|
419
|
+
|
420
|
+
https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26
|
421
|
+
|
419
422
|
|
420
423
|
### JSON Schema
|
421
424
|
|
@@ -507,8 +510,11 @@ See the [docs](https://github.com/CosmWasm/ts-codegen/blob/main/packages/wasm-as
|
|
507
510
|
Checkout these related projects:
|
508
511
|
|
509
512
|
* [@osmonauts/telescope](https://github.com/osmosis-labs/telescope) a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.
|
510
|
-
* [chain-registry](https://github.com/cosmology-tech/chain-registry)
|
511
|
-
* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) A wallet connector for the Cosmos
|
513
|
+
* [chain-registry](https://github.com/cosmology-tech/chain-registry) an npm module for the official Cosmos chain-registry.
|
514
|
+
* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) A wallet connector for the Cosmos ⚛️
|
515
|
+
* [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) set up a modern Cosmos app by running one command.
|
516
|
+
* [starship](https://github.com/cosmology-tech/starship) a k8s-based unified development environment for Cosmos Ecosystem
|
517
|
+
|
512
518
|
## Credits
|
513
519
|
|
514
520
|
🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.tech/validator)
|
package/main/builder/builder.js
CHANGED
@@ -55,6 +55,12 @@ var _client = require("../plugins/client");
|
|
55
55
|
|
56
56
|
var _types2 = require("../plugins/types");
|
57
57
|
|
58
|
+
var _provider = require("../plugins/provider");
|
59
|
+
|
60
|
+
var _createHelpers = require("../generators/create-helpers");
|
61
|
+
|
62
|
+
var _providerBundle = require("../plugins/provider-bundle");
|
63
|
+
|
58
64
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
59
65
|
|
60
66
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -75,6 +81,7 @@ var defaultOpts = {
|
|
75
81
|
;
|
76
82
|
;
|
77
83
|
;
|
84
|
+
;
|
78
85
|
|
79
86
|
function getContract(contractOpt) {
|
80
87
|
if (typeof contractOpt === 'string') {
|
@@ -94,6 +101,8 @@ function getContract(contractOpt) {
|
|
94
101
|
|
95
102
|
var TSBuilder = /*#__PURE__*/function () {
|
96
103
|
function TSBuilder(_ref) {
|
104
|
+
var _this = this;
|
105
|
+
|
97
106
|
var contracts = _ref.contracts,
|
98
107
|
outPath = _ref.outPath,
|
99
108
|
options = _ref.options,
|
@@ -103,6 +112,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
103
112
|
(0, _defineProperty2["default"])(this, "outPath", void 0);
|
104
113
|
(0, _defineProperty2["default"])(this, "options", void 0);
|
105
114
|
(0, _defineProperty2["default"])(this, "plugins", []);
|
115
|
+
(0, _defineProperty2["default"])(this, "builderContext", new _wasmAstTypes.BuilderContext());
|
106
116
|
(0, _defineProperty2["default"])(this, "files", []);
|
107
117
|
this.contracts = contracts;
|
108
118
|
this.outPath = outPath;
|
@@ -112,12 +122,16 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
112
122
|
if (plugins && plugins.length) {
|
113
123
|
[].push.apply(this.plugins, plugins);
|
114
124
|
}
|
125
|
+
|
126
|
+
this.plugins.forEach(function (plugin) {
|
127
|
+
return plugin.setBuilder(_this);
|
128
|
+
});
|
115
129
|
}
|
116
130
|
|
117
131
|
(0, _createClass2["default"])(TSBuilder, [{
|
118
132
|
key: "loadDefaultPlugins",
|
119
133
|
value: function loadDefaultPlugins() {
|
120
|
-
[].push.apply(this.plugins, [new _types2.TypesPlugin(this.options), new _client.ClientPlugin(this.options), new _messageComposer.MessageComposerPlugin(this.options), new _reactQuery.ReactQueryPlugin(this.options), new _recoil.RecoilPlugin(this.options), new _msgBuilder.MsgBuilderPlugin(this.options)]);
|
134
|
+
[].push.apply(this.plugins, [new _types2.TypesPlugin(this.options), new _client.ClientPlugin(this.options), new _messageComposer.MessageComposerPlugin(this.options), new _reactQuery.ReactQueryPlugin(this.options), new _recoil.RecoilPlugin(this.options), new _msgBuilder.MsgBuilderPlugin(this.options), new _provider.ContractsContextProviderPlugin(this.options)]);
|
121
135
|
}
|
122
136
|
}, {
|
123
137
|
key: "build",
|
@@ -289,15 +303,38 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
289
303
|
key: "after",
|
290
304
|
value: function () {
|
291
305
|
var _after = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
306
|
+
var contractsProviderBundlePlugin, files;
|
292
307
|
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
293
308
|
while (1) {
|
294
309
|
switch (_context4.prev = _context4.next) {
|
295
310
|
case 0:
|
296
311
|
if (this.options.bundle.enabled) {
|
297
312
|
this.bundle();
|
313
|
+
} //create useContracts bundle file
|
314
|
+
|
315
|
+
|
316
|
+
contractsProviderBundlePlugin = new _providerBundle.ContractsProviderBundlePlugin(this.options);
|
317
|
+
contractsProviderBundlePlugin.setBuilder(this);
|
318
|
+
_context4.next = 5;
|
319
|
+
return contractsProviderBundlePlugin.render("", {
|
320
|
+
schemas: []
|
321
|
+
}, this.outPath);
|
322
|
+
|
323
|
+
case 5:
|
324
|
+
files = _context4.sent;
|
325
|
+
|
326
|
+
if (files && files.length) {
|
327
|
+
[].push.apply(this.files, files);
|
298
328
|
}
|
299
329
|
|
300
|
-
|
330
|
+
(0, _createHelpers.createHelpers)({
|
331
|
+
outPath: this.outPath,
|
332
|
+
contracts: this.contracts,
|
333
|
+
options: this.options,
|
334
|
+
plugins: this.plugins
|
335
|
+
}, this.builderContext);
|
336
|
+
|
337
|
+
case 8:
|
301
338
|
case "end":
|
302
339
|
return _context4.stop();
|
303
340
|
}
|
@@ -318,7 +355,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
318
355
|
var _this$options$bundle$,
|
319
356
|
_this$options,
|
320
357
|
_this$options$bundle,
|
321
|
-
|
358
|
+
_this2 = this,
|
322
359
|
_this$options2,
|
323
360
|
_this$options2$bundle;
|
324
361
|
|
@@ -334,7 +371,7 @@ var TSBuilder = /*#__PURE__*/function () {
|
|
334
371
|
bundleVariables = {};
|
335
372
|
importPaths = [];
|
336
373
|
allFiles.forEach(function (file) {
|
337
|
-
(0, _bundler.createFileBundle)("".concat(
|
374
|
+
(0, _bundler.createFileBundle)("".concat(_this2.options.bundle.scope, ".").concat(file.contract), file.filename, bundlePath, importPaths, bundleVariables);
|
338
375
|
});
|
339
376
|
ast = (0, _bundler.recursiveModuleBundle)(bundleVariables);
|
340
377
|
code = (0, _generator["default"])(t.program([].concat(importPaths, (0, _toConsumableArray2["default"])(ast)))).code;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.createHelpers = void 0;
|
9
|
+
|
10
|
+
var _path = require("path");
|
11
|
+
|
12
|
+
var _mkdirp = require("mkdirp");
|
13
|
+
|
14
|
+
var _package = _interopRequireDefault(require("../../package.json"));
|
15
|
+
|
16
|
+
var _files = require("../utils/files");
|
17
|
+
|
18
|
+
var _helpers = require("../helpers");
|
19
|
+
|
20
|
+
var version = process.env.NODE_ENV === "test" ? "latest" : _package["default"].version;
|
21
|
+
var header = "/**\n* This file and any referenced files were automatically generated by ".concat(_package["default"].name, "@").concat(version, "\n* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain\n* and run the transpile command or yarn proto command to regenerate this bundle.\n*/\n\n");
|
22
|
+
|
23
|
+
var write = function write(outPath, file, content) {
|
24
|
+
var outFile = (0, _path.join)(outPath, file);
|
25
|
+
(0, _mkdirp.sync)((0, _path.dirname)(outFile));
|
26
|
+
(0, _files.writeContentToFile)(outPath, header + content, outFile);
|
27
|
+
};
|
28
|
+
|
29
|
+
var createHelpers = function createHelpers(input, builderContext) {
|
30
|
+
var _input$options, _input$options$useCon, _Object$keys;
|
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) {
|
33
|
+
write(input.outPath, "contractContextBase.ts", _helpers.contractContextBase);
|
34
|
+
write(input.outPath, "contracts-context.tsx", _helpers.contractsContextTSX);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
exports.createHelpers = createHelpers;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.contractContextBase = void 0;
|
7
|
+
var contractContextBase = "\nimport {\n CosmWasmClient,\n SigningCosmWasmClient,\n} from '@cosmjs/cosmwasm-stargate';\n\nexport interface IContractConstructor {\n address: string | undefined;\n cosmWasmClient: CosmWasmClient | undefined;\n signingCosmWasmClient: SigningCosmWasmClient | undefined;\n}\n\nexport const NO_SINGING_ERROR_MESSAGE = 'signingCosmWasmClient not connected';\n\nexport const NO_COSMWASW_CLIENT_ERROR_MESSAGE = 'cosmWasmClient not connected';\n\nexport const NO_ADDRESS_ERROR_MESSAGE = \"address doesn't exist\";\n\nexport const NO_SIGNING_CLIENT_ERROR_MESSAGE =\n 'Signing client is not generated. Please check ts-codegen config';\n\nexport const NO_QUERY_CLIENT_ERROR_MESSAGE =\n 'Query client is not generated. Please check ts-codegen config';\n\nexport const NO_MESSAGE_COMPOSER_ERROR_MESSAGE =\n 'Message composer client is not generated. Please check ts-codegen config';\n\n/**\n * a placeholder for non-generated classes\n */\nexport interface IEmptyClient {}\n\nexport interface ISigningClientProvider<T> {\n getSigningClient(contractAddr: string): T;\n}\n\nexport interface IQueryClientProvider<T> {\n getQueryClient(contractAddr: string): T;\n}\n\nexport interface IMessageComposerProvider<T> {\n getMessageComposer(contractAddr: string): T;\n}\n\nexport class ContractBase<\n TSign = IEmptyClient,\n TQuery = IEmptyClient,\n TMsgComposer = IEmptyClient\n> {\n constructor(\n protected address: string | undefined,\n protected cosmWasmClient: CosmWasmClient | undefined,\n protected signingCosmWasmClient: SigningCosmWasmClient | undefined,\n private TSign?: new (\n client: SigningCosmWasmClient,\n sender: string,\n contractAddress: string\n ) => TSign,\n private TQuery?: new (\n client: CosmWasmClient,\n contractAddress: string\n ) => TQuery,\n private TMsgComposer?: new (\n sender: string,\n contractAddress: string\n ) => TMsgComposer\n ) {}\n\n public getSigningClient(contractAddr: string): TSign {\n if (!this.signingCosmWasmClient) throw new Error(NO_SINGING_ERROR_MESSAGE);\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TSign) throw new Error(NO_SIGNING_CLIENT_ERROR_MESSAGE);\n return new this.TSign(\n this.signingCosmWasmClient,\n this.address,\n contractAddr\n );\n }\n\n public getQueryClient(contractAddr: string): TQuery {\n if (!this.cosmWasmClient) throw new Error(NO_COSMWASW_CLIENT_ERROR_MESSAGE);\n if (!this.TQuery) throw new Error(NO_QUERY_CLIENT_ERROR_MESSAGE);\n return new this.TQuery(this.cosmWasmClient, contractAddr);\n }\n\n public getMessageComposer(contractAddr: string): TMsgComposer {\n if (!this.address) throw new Error(NO_ADDRESS_ERROR_MESSAGE);\n if (!this.TMsgComposer) throw new Error(NO_MESSAGE_COMPOSER_ERROR_MESSAGE);\n return new this.TMsgComposer(this.address, contractAddr);\n }\n}\n";
|
8
|
+
exports.contractContextBase = contractContextBase;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.contractsContextTSX = void 0;
|
7
|
+
var contractsContextTSX = "\nimport React, { useEffect, useMemo, useRef, useState, useContext } from 'react';\nimport {\n CosmWasmClient,\n SigningCosmWasmClient,\n} from '@cosmjs/cosmwasm-stargate';\n\nimport { IContractsContext, getProviders } from './contractContextProviders';\n\ninterface ContractsConfig {\n address: string | undefined;\n getCosmWasmClient: () => Promise<CosmWasmClient>;\n getSigningCosmWasmClient: () => Promise<SigningCosmWasmClient>;\n}\n\nconst ContractsContext = React.createContext<IContractsContext | null>(null);\n\nexport const ContractsProvider = ({\n children,\n contractsConfig,\n}: {\n children: React.ReactNode;\n contractsConfig: ContractsConfig;\n}) => {\n const [cosmWasmClient, setCosmWasmClient] = useState<CosmWasmClient>();\n const [signingCosmWasmClient, setSigningCosmWasmClient] =\n useState<SigningCosmWasmClient>();\n\n const { address, getCosmWasmClient, getSigningCosmWasmClient } =\n contractsConfig;\n\n const prevAddressRef = useRef<string | undefined>(address);\n\n const contracts: IContractsContext = useMemo(() => {\n return getProviders(address, cosmWasmClient, signingCosmWasmClient);\n }, [address, cosmWasmClient, signingCosmWasmClient]);\n\n useEffect(() => {\n const connectSigningCwClient = async () => {\n if (address && prevAddressRef.current !== address) {\n const signingCosmWasmClient = await getSigningCosmWasmClient();\n setSigningCosmWasmClient(signingCosmWasmClient);\n } else if (!address) {\n setSigningCosmWasmClient(undefined);\n }\n prevAddressRef.current = address;\n };\n connectSigningCwClient();\n }, [address, getSigningCosmWasmClient]);\n\n useEffect(() => {\n const connectCosmWasmClient = async () => {\n const cosmWasmClient = await getCosmWasmClient();\n setCosmWasmClient(cosmWasmClient);\n };\n connectCosmWasmClient();\n }, [getCosmWasmClient]);\n\n return (\n <ContractsContext.Provider value={contracts}>\n {children}\n </ContractsContext.Provider>\n );\n};\n\nexport const useContracts = () => {\n const contracts = useContext(ContractsContext);\n if (contracts === null) {\n throw new Error('useContracts must be used within a ContractsProvider');\n }\n return contracts;\n};\n";
|
8
|
+
exports.contractsContextTSX = contractsContextTSX;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _contractContextBase = require("./contractContextBase");
|
8
|
+
|
9
|
+
Object.keys(_contractContextBase).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _contractContextBase[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function get() {
|
15
|
+
return _contractContextBase[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
19
|
+
|
20
|
+
var _contractsContextTSX = require("./contractsContextTSX");
|
21
|
+
|
22
|
+
Object.keys(_contractsContextTSX).forEach(function (key) {
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
24
|
+
if (key in exports && exports[key] === _contractsContextTSX[key]) return;
|
25
|
+
Object.defineProperty(exports, key, {
|
26
|
+
enumerable: true,
|
27
|
+
get: function get() {
|
28
|
+
return _contractsContextTSX[key];
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
package/main/plugins/client.js
CHANGED
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
8
8
|
value: true
|
9
9
|
});
|
10
|
-
exports.ClientPlugin = void 0;
|
10
|
+
exports.TYPE = exports.ClientPlugin = void 0;
|
11
11
|
|
12
12
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
13
13
|
|
@@ -39,6 +39,9 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
39
39
|
|
40
40
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
41
41
|
|
42
|
+
var TYPE = "client";
|
43
|
+
exports.TYPE = TYPE;
|
44
|
+
|
42
45
|
var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
43
46
|
(0, _inherits2["default"])(ClientPlugin, _BuilderPluginBase);
|
44
47
|
|
@@ -52,7 +55,7 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
52
55
|
(0, _createClass2["default"])(ClientPlugin, [{
|
53
56
|
key: "initContext",
|
54
57
|
value: function initContext(contract, options) {
|
55
|
-
return new w.RenderContext(contract, options);
|
58
|
+
return new w.RenderContext(contract, options, this.builder.builderContext);
|
56
59
|
}
|
57
60
|
}, {
|
58
61
|
key: "doRender",
|
@@ -74,8 +77,8 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
74
77
|
|
75
78
|
case 3:
|
76
79
|
schemas = context.contract.schemas;
|
77
|
-
localname = (0, _case.pascal)(name) +
|
78
|
-
TypesFile = (0, _case.pascal)(name) +
|
80
|
+
localname = (0, _case.pascal)(name) + ".client.ts";
|
81
|
+
TypesFile = (0, _case.pascal)(name) + ".types";
|
79
82
|
QueryMsg = (0, _utils.findQueryMsg)(schemas);
|
80
83
|
ExecuteMsg = (0, _utils.findExecuteMsg)(schemas);
|
81
84
|
_context.next = 10;
|
@@ -95,6 +98,7 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
95
98
|
ReadOnlyInstance = (0, _case.pascal)("".concat(name, "ReadOnlyInterface"));
|
96
99
|
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
97
100
|
body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
|
101
|
+
context.addProviderInfo(name, w.PROVIDER_TYPES.QUERY_CLIENT_TYPE, QueryClient, localname);
|
98
102
|
} // execute messages
|
99
103
|
|
100
104
|
|
@@ -106,16 +110,17 @@ var ClientPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
106
110
|
Instance = (0, _case.pascal)("".concat(name, "Interface"));
|
107
111
|
body.push(w.createExecuteInterface(context, Instance, this.option.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
|
108
112
|
body.push(w.createExecuteClass(context, Client, Instance, this.option.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
|
113
|
+
context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
|
109
114
|
}
|
110
115
|
}
|
111
116
|
|
112
|
-
if (typeHash.hasOwnProperty(
|
117
|
+
if (typeHash.hasOwnProperty("Coin")) {
|
113
118
|
// @ts-ignore
|
114
119
|
delete context.utils.Coin;
|
115
120
|
}
|
116
121
|
|
117
122
|
return _context.abrupt("return", [{
|
118
|
-
type:
|
123
|
+
type: TYPE,
|
119
124
|
localname: localname,
|
120
125
|
body: body
|
121
126
|
}]);
|
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
8
8
|
value: true
|
9
9
|
});
|
10
|
-
exports.MessageComposerPlugin = void 0;
|
10
|
+
exports.TYPE = exports.MessageComposerPlugin = void 0;
|
11
11
|
|
12
12
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
13
13
|
|
@@ -39,6 +39,9 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
39
39
|
|
40
40
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
41
41
|
|
42
|
+
var TYPE = "message-composer";
|
43
|
+
exports.TYPE = TYPE;
|
44
|
+
|
42
45
|
var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
43
46
|
(0, _inherits2["default"])(MessageComposerPlugin, _BuilderPluginBase);
|
44
47
|
|
@@ -52,7 +55,7 @@ var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
52
55
|
(0, _createClass2["default"])(MessageComposerPlugin, [{
|
53
56
|
key: "initContext",
|
54
57
|
value: function initContext(contract, options) {
|
55
|
-
return new w.RenderContext(contract, options);
|
58
|
+
return new w.RenderContext(contract, options, this.builder.builderContext);
|
56
59
|
}
|
57
60
|
}, {
|
58
61
|
key: "doRender",
|
@@ -74,8 +77,8 @@ var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
74
77
|
|
75
78
|
case 3:
|
76
79
|
schemas = context.contract.schemas;
|
77
|
-
localname = (0, _case.pascal)(name) +
|
78
|
-
TypesFile = (0, _case.pascal)(name) +
|
80
|
+
localname = (0, _case.pascal)(name) + ".message-composer.ts";
|
81
|
+
TypesFile = (0, _case.pascal)(name) + ".types";
|
79
82
|
ExecuteMsg = (0, _utils.findExecuteMsg)(schemas);
|
80
83
|
_context.next = 9;
|
81
84
|
return (0, _utils.findAndParseTypes)(schemas);
|
@@ -93,16 +96,17 @@ var MessageComposerPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
93
96
|
Interface = (0, _case.pascal)("".concat(name, "Message"));
|
94
97
|
body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
|
95
98
|
body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
|
99
|
+
context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
|
96
100
|
}
|
97
101
|
}
|
98
102
|
|
99
|
-
if (typeHash.hasOwnProperty(
|
103
|
+
if (typeHash.hasOwnProperty("Coin")) {
|
100
104
|
// @ts-ignore
|
101
105
|
delete context.utils.Coin;
|
102
106
|
}
|
103
107
|
|
104
108
|
return _context.abrupt("return", [{
|
105
|
-
type:
|
109
|
+
type: TYPE,
|
106
110
|
localname: localname,
|
107
111
|
body: body
|
108
112
|
}]);
|
@@ -52,7 +52,7 @@ var MsgBuilderPlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
52
52
|
(0, _createClass2["default"])(MsgBuilderPlugin, [{
|
53
53
|
key: "initContext",
|
54
54
|
value: function initContext(contract, options) {
|
55
|
-
return new w.RenderContext(contract, options);
|
55
|
+
return new w.RenderContext(contract, options, this.builder.builderContext);
|
56
56
|
}
|
57
57
|
}, {
|
58
58
|
key: "doRender",
|
@@ -41,14 +41,21 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
41
41
|
* BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
|
42
42
|
*/
|
43
43
|
var BuilderPluginBase = /*#__PURE__*/function () {
|
44
|
-
function BuilderPluginBase(opt) {
|
44
|
+
function BuilderPluginBase(opt, builder) {
|
45
45
|
(0, _classCallCheck2["default"])(this, BuilderPluginBase);
|
46
|
+
(0, _defineProperty2["default"])(this, "builder", void 0);
|
46
47
|
(0, _defineProperty2["default"])(this, "option", void 0);
|
47
48
|
(0, _defineProperty2["default"])(this, "utils", void 0);
|
48
49
|
this.option = opt;
|
50
|
+
this.builder = builder;
|
49
51
|
}
|
50
52
|
|
51
53
|
(0, _createClass2["default"])(BuilderPluginBase, [{
|
54
|
+
key: "setBuilder",
|
55
|
+
value: function setBuilder(builder) {
|
56
|
+
this.builder = builder;
|
57
|
+
}
|
58
|
+
}, {
|
52
59
|
key: "render",
|
53
60
|
value: function () {
|
54
61
|
var _render = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, contractInfo, outPath) {
|
@@ -85,7 +92,7 @@ var BuilderPluginBase = /*#__PURE__*/function () {
|
|
85
92
|
|
86
93
|
case 9:
|
87
94
|
return _context.abrupt("return", results.map(function (result) {
|
88
|
-
var imports = context.getImports(_this.utils);
|
95
|
+
var imports = context.getImports(_this.utils, result.localname);
|
89
96
|
var code = _header.header + (0, _generator["default"])(t.program([].concat((0, _toConsumableArray2["default"])(imports), (0, _toConsumableArray2["default"])(result.body)))).code;
|
90
97
|
(0, _mkdirp.sync)(outPath);
|
91
98
|
var filename = (0, _path.join)(outPath, result.localname);
|