Skip to content

Commit aa4628d

Browse files
authored
Merge pull request #130 from AbstractSDK/adair/abstractappnamespace
Ensure cli generates chainname param
2 parents 378db9b + 83a66c2 commit aa4628d

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

.changeset/giant-rats-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@abstract-money/cli": minor
3+
---
4+
5+
Add chainName to code generation

packages/cli/src/plugins/react.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,25 @@ export function react(options: ReactOptions = {}): ReactResult {
5656

5757
const cosmwasmCodegenDirPath = join(out, 'cosmwasm-codegen')
5858

59-
// Guard speicfic contracts to not have the abstract app generated
60-
const contractsWithoutAbstractApp = contracts.filter(({ namespace }) =>
61-
disableAbstractAppFor.includes(namespace),
59+
// Guard specific contracts to not have the abstract app generated
60+
const contractsWithoutAbstractApp = contracts.filter(({ name }) =>
61+
disableAbstractAppFor.includes(name),
6262
)
6363

64+
const absContracts = contracts
65+
.filter(
66+
({ name }) =>
67+
!disableAbstractAppFor.includes(name) &&
68+
contractsWithoutAbstractApp.every(
69+
(guardedContract) => guardedContract.name !== name,
70+
),
71+
)
72+
.map(({ name, path }) => ({ name, dir: path }))
73+
console.log('absContracts', absContracts)
74+
6475
await codegen({
6576
options: codegenOptions,
66-
contracts: contracts
67-
.filter(
68-
({ namespace }) =>
69-
!disableAbstractAppFor.includes(namespace) &&
70-
contractsWithoutAbstractApp.every(
71-
(guardedContract) => guardedContract.namespace !== namespace,
72-
),
73-
)
74-
.map(({ name, path }) => ({ name, dir: path })),
77+
contracts: absContracts,
7578
outPath: cosmwasmCodegenDirPath,
7679
})
7780

@@ -80,8 +83,8 @@ export function react(options: ReactOptions = {}): ReactResult {
8083
options: { ...codegenOptions, abstractApp: { enabled: false } },
8184
contracts: [
8285
...contractsWithoutAbstractApp,
83-
...contracts.filter(({ namespace }) =>
84-
disableAbstractAppFor.includes(namespace),
86+
...contracts.filter(({ name }) =>
87+
disableAbstractAppFor.includes(name),
8588
),
8689
].map(({ name, path }) => ({ name, dir: path })),
8790
outPath: cosmwasmCodegenDirPath,
@@ -242,12 +245,14 @@ export function react(options: ReactOptions = {}): ReactResult {
242245
cosmwasmCodegenDirPath,
243246
`${contractNamePascalCase}.types.ts`,
244247
)
245-
imports.push(
246-
`import * as ${contractNamePascalCase}Types from './${relative(
247-
out,
248-
typesFilePath.slice(0, -3),
249-
)}'`,
250-
)
248+
if (hasAbstractApp) {
249+
imports.push(
250+
`import * as ${contractNamePascalCase}Types from './${relative(
251+
out,
252+
typesFilePath.slice(0, -3),
253+
)}'`,
254+
)
255+
}
251256
}
252257

253258
imports.push(
@@ -293,7 +298,7 @@ export function react(options: ReactOptions = {}): ReactResult {
293298
)}>>[0], 'client'> & { ${
294299
hasAbstractApp
295300
? 'accountId: AccountId | undefined; chainName: string | undefined;'
296-
: 'contractAddress: string | undefined;'
301+
: 'contractAddress: string | undefined; chainName: string | undefined'
297302
}}) => {
298303
const {
299304
data: ${queryClientCamelCase},
@@ -346,11 +351,11 @@ export function react(options: ReactOptions = {}): ReactResult {
346351
{ ${
347352
hasAbstractApp
348353
? 'accountId, chainName, sender'
349-
: 'contractAddress, sender'
354+
: 'contractAddress, chainName, sender'
350355
} }: { ${
351356
hasAbstractApp
352357
? 'accountId: AccountId | undefined; chainName: string | undefined; sender?: string | undefined;'
353-
: 'contractAddress: string | undefined; sender?: string | undefined;'
358+
: 'contractAddress: string | undefined; chainName: string | undefined; sender?: string | undefined;'
354359
} },
355360
options?: Omit<
356361
UseMutationOptions<
@@ -377,7 +382,7 @@ export function react(options: ReactOptions = {}): ReactResult {
377382
chainName,
378383
sender,
379384
`
380-
: 'contractAddress,'
385+
: 'contractAddress, chainName,'
381386
}
382387
Module: ${clientPascalCase},
383388
}

0 commit comments

Comments
 (0)