Skip to content

Commit 88db3be

Browse files
authored
Merge pull request #126 from Zetazzz/main
change default useShorthandCtor to true
2 parents eaefa24 + 374c302 commit 88db3be

File tree

7 files changed

+71
-44
lines changed

7 files changed

+71
-44
lines changed

Diff for: README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@ export default function YourComponent() {
317317
};
318318
```
319319

320+
If you're using Babel, please make sure include '@babel/preset-react' in devDeps and presets in .babelrc.js:
321+
322+
```js
323+
presets: [
324+
'@babel/typescript',
325+
'@babel/env',
326+
'@babel/preset-react',
327+
]
328+
```
329+
320330
#### Use Contracts Hooks Usage
321331

322332
Once enabled, you can get contracts very simply:
@@ -361,7 +371,7 @@ const { CwAdminFactoryClient } = contracts.CwAdminFactory;
361371

362372
| option | description |
363373
| --------------------- | -------------------------------------------------------------------------------- |
364-
| `useShorthandCtor` | Enable using shorthand constructor. Default: false |
374+
| `useShorthandCtor` | Enable using shorthand constructor. Default: true |
365375

366376
Using shorthand constructor(Might not be transpiled correctly with babel):
367377

Diff for: __output__/builder/bundler_test/contracts/contractContextBase.ts

+7-32
Original file line numberDiff line numberDiff line change
@@ -53,49 +53,24 @@ export class ContractBase<
5353
TQuery = IEmptyClient,
5454
TMsgComposer = IEmptyClient
5555
> {
56-
57-
address: string | undefined;
58-
cosmWasmClient: CosmWasmClient | undefined;
59-
signingCosmWasmClient: SigningCosmWasmClient | undefined;
60-
TSign?: new (
61-
client: SigningCosmWasmClient,
62-
sender: string,
63-
contractAddress: string
64-
) => TSign;
65-
TQuery?: new (
66-
client: CosmWasmClient,
67-
contractAddress: string
68-
) => TQuery;
69-
TMsgComposer?: new (
70-
sender: string,
71-
contractAddress: string
72-
) => TMsgComposer;
73-
7456
constructor(
75-
address: string | undefined,
76-
cosmWasmClient: CosmWasmClient | undefined,
77-
signingCosmWasmClient: SigningCosmWasmClient | undefined,
78-
TSign?: new (
57+
protected address: string | undefined,
58+
protected cosmWasmClient: CosmWasmClient | undefined,
59+
protected signingCosmWasmClient: SigningCosmWasmClient | undefined,
60+
private TSign?: new (
7961
client: SigningCosmWasmClient,
8062
sender: string,
8163
contractAddress: string
8264
) => TSign,
83-
TQuery?: new (
65+
private TQuery?: new (
8466
client: CosmWasmClient,
8567
contractAddress: string
8668
) => TQuery,
87-
TMsgComposer?: new (
69+
private TMsgComposer?: new (
8870
sender: string,
8971
contractAddress: string
9072
) => TMsgComposer
91-
) {
92-
this.address = address;
93-
this.cosmWasmClient = cosmWasmClient;
94-
this.signingCosmWasmClient = signingCosmWasmClient;
95-
this.TSign = TSign;
96-
this.TQuery = TQuery;
97-
this.TMsgComposer = TMsgComposer;
98-
}
73+
) {}
9974

10075
public getSigningClient(contractAddr: string): TSign {
10176
if (!this.signingCosmWasmClient) throw new Error(NO_SINGING_ERROR_MESSAGE);

Diff for: __output__/builder/default/contractContextBase.ts

+32-7
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,49 @@ export class ContractBase<
5353
TQuery = IEmptyClient,
5454
TMsgComposer = IEmptyClient
5555
> {
56+
57+
address: string | undefined;
58+
cosmWasmClient: CosmWasmClient | undefined;
59+
signingCosmWasmClient: SigningCosmWasmClient | undefined;
60+
TSign?: new (
61+
client: SigningCosmWasmClient,
62+
sender: string,
63+
contractAddress: string
64+
) => TSign;
65+
TQuery?: new (
66+
client: CosmWasmClient,
67+
contractAddress: string
68+
) => TQuery;
69+
TMsgComposer?: new (
70+
sender: string,
71+
contractAddress: string
72+
) => TMsgComposer;
73+
5674
constructor(
57-
protected address: string | undefined,
58-
protected cosmWasmClient: CosmWasmClient | undefined,
59-
protected signingCosmWasmClient: SigningCosmWasmClient | undefined,
60-
private TSign?: new (
75+
address: string | undefined,
76+
cosmWasmClient: CosmWasmClient | undefined,
77+
signingCosmWasmClient: SigningCosmWasmClient | undefined,
78+
TSign?: new (
6179
client: SigningCosmWasmClient,
6280
sender: string,
6381
contractAddress: string
6482
) => TSign,
65-
private TQuery?: new (
83+
TQuery?: new (
6684
client: CosmWasmClient,
6785
contractAddress: string
6886
) => TQuery,
69-
private TMsgComposer?: new (
87+
TMsgComposer?: new (
7088
sender: string,
7189
contractAddress: string
7290
) => TMsgComposer
73-
) {}
91+
) {
92+
this.address = address;
93+
this.cosmWasmClient = cosmWasmClient;
94+
this.signingCosmWasmClient = signingCosmWasmClient;
95+
this.TSign = TSign;
96+
this.TQuery = TQuery;
97+
this.TMsgComposer = TMsgComposer;
98+
}
7499

75100
public getSigningClient(contractAddr: string): TSign {
76101
if (!this.signingCosmWasmClient) throw new Error(NO_SINGING_ERROR_MESSAGE);

Diff for: packages/ts-codegen/__tests__/__snapshots__/builder.test.ts.snap

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ TSBuilder {
3939
"aliasExecuteMsg": false,
4040
"enabled": true,
4141
},
42+
"useShorthandCtor": true,
4243
},
4344
"plugins": Array [
4445
TypesPlugin {
@@ -76,6 +77,7 @@ TSBuilder {
7677
"aliasExecuteMsg": false,
7778
"enabled": true,
7879
},
80+
"useShorthandCtor": true,
7981
},
8082
"utils": undefined,
8183
},
@@ -114,6 +116,7 @@ TSBuilder {
114116
"aliasExecuteMsg": false,
115117
"enabled": true,
116118
},
119+
"useShorthandCtor": true,
117120
},
118121
"utils": undefined,
119122
},
@@ -152,6 +155,7 @@ TSBuilder {
152155
"aliasExecuteMsg": false,
153156
"enabled": true,
154157
},
158+
"useShorthandCtor": true,
155159
},
156160
"utils": undefined,
157161
},
@@ -190,6 +194,7 @@ TSBuilder {
190194
"aliasExecuteMsg": false,
191195
"enabled": true,
192196
},
197+
"useShorthandCtor": true,
193198
},
194199
"utils": undefined,
195200
},
@@ -228,6 +233,7 @@ TSBuilder {
228233
"aliasExecuteMsg": false,
229234
"enabled": true,
230235
},
236+
"useShorthandCtor": true,
231237
},
232238
"utils": Object {
233239
"selectorFamily": "recoil",
@@ -268,6 +274,7 @@ TSBuilder {
268274
"aliasExecuteMsg": false,
269275
"enabled": true,
270276
},
277+
"useShorthandCtor": true,
271278
},
272279
"utils": undefined,
273280
},
@@ -306,6 +313,7 @@ TSBuilder {
306313
"aliasExecuteMsg": false,
307314
"enabled": true,
308315
},
316+
"useShorthandCtor": true,
309317
},
310318
"utils": Object {
311319
"ContractBase": "__contractContextBase__",
@@ -356,6 +364,7 @@ TSBuilder {
356364
"aliasExecuteMsg": false,
357365
"enabled": true,
358366
},
367+
"useShorthandCtor": true,
359368
},
360369
"plugins": Array [
361370
TypesPlugin {
@@ -393,6 +402,7 @@ TSBuilder {
393402
"aliasExecuteMsg": false,
394403
"enabled": true,
395404
},
405+
"useShorthandCtor": true,
396406
},
397407
"utils": undefined,
398408
},
@@ -431,6 +441,7 @@ TSBuilder {
431441
"aliasExecuteMsg": false,
432442
"enabled": true,
433443
},
444+
"useShorthandCtor": true,
434445
},
435446
"utils": undefined,
436447
},
@@ -469,6 +480,7 @@ TSBuilder {
469480
"aliasExecuteMsg": false,
470481
"enabled": true,
471482
},
483+
"useShorthandCtor": true,
472484
},
473485
"utils": undefined,
474486
},
@@ -507,6 +519,7 @@ TSBuilder {
507519
"aliasExecuteMsg": false,
508520
"enabled": true,
509521
},
522+
"useShorthandCtor": true,
510523
},
511524
"utils": undefined,
512525
},
@@ -545,6 +558,7 @@ TSBuilder {
545558
"aliasExecuteMsg": false,
546559
"enabled": true,
547560
},
561+
"useShorthandCtor": true,
548562
},
549563
"utils": Object {
550564
"selectorFamily": "recoil",
@@ -585,6 +599,7 @@ TSBuilder {
585599
"aliasExecuteMsg": false,
586600
"enabled": true,
587601
},
602+
"useShorthandCtor": true,
588603
},
589604
"utils": undefined,
590605
},
@@ -623,6 +638,7 @@ TSBuilder {
623638
"aliasExecuteMsg": false,
624639
"enabled": true,
625640
},
641+
"useShorthandCtor": true,
626642
},
627643
"utils": Object {
628644
"ContractBase": "__contractContextBase__",

Diff for: packages/ts-codegen/__tests__/builder.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ it('builder default', async () => {
9494
bundleFile: 'index.ts',
9595
scope: 'smart.contracts'
9696
},
97-
useShorthandCtor: true,
97+
useShorthandCtor: false,
9898
types: {
9999
enabled: true
100100
},

Diff for: packages/ts-codegen/src/builder/builder.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const defaultOpts: TSBuilderOptions = {
3030
enabled: true,
3131
scope: 'contracts',
3232
bundleFile: 'bundle.ts'
33-
}
33+
},
34+
useShorthandCtor: true
3435
}
3536

3637
export interface TSBuilderInput {
@@ -55,7 +56,7 @@ export type TSBuilderOptions = {
5556
bundle?: BundleOptions;
5657
/**
5758
* Enable using shorthand constructor.
58-
* Default: false
59+
* Default: true
5960
*/
6061
useShorthandCtor?: boolean;
6162
useContractsHooks?: UseContractsOptions;

Diff for: packages/ts-codegen/types/src/builder/builder.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type TSBuilderOptions = {
1919
bundle?: BundleOptions;
2020
/**
2121
* Enable using shorthand constructor.
22-
* Default: false
22+
* Default: true
2323
*/
2424
useShorthandCtor?: boolean;
2525
useContractsHooks?: UseContractsOptions;

0 commit comments

Comments
 (0)