Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-rats-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@abstract-money/cli": minor
---

Add chainName to code generation
53 changes: 29 additions & 24 deletions packages/cli/src/plugins/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,25 @@ export function react(options: ReactOptions = {}): ReactResult {

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

// Guard speicfic contracts to not have the abstract app generated
const contractsWithoutAbstractApp = contracts.filter(({ namespace }) =>
disableAbstractAppFor.includes(namespace),
// Guard specific contracts to not have the abstract app generated
const contractsWithoutAbstractApp = contracts.filter(({ name }) =>
disableAbstractAppFor.includes(name),
)

const absContracts = contracts
.filter(
({ name }) =>
!disableAbstractAppFor.includes(name) &&
contractsWithoutAbstractApp.every(
(guardedContract) => guardedContract.name !== name,
),
)
.map(({ name, path }) => ({ name, dir: path }))
console.log('absContracts', absContracts)

await codegen({
options: codegenOptions,
contracts: contracts
.filter(
({ namespace }) =>
!disableAbstractAppFor.includes(namespace) &&
contractsWithoutAbstractApp.every(
(guardedContract) => guardedContract.namespace !== namespace,
),
)
.map(({ name, path }) => ({ name, dir: path })),
contracts: absContracts,
outPath: cosmwasmCodegenDirPath,
})

Expand All @@ -80,8 +83,8 @@ export function react(options: ReactOptions = {}): ReactResult {
options: { ...codegenOptions, abstractApp: { enabled: false } },
contracts: [
...contractsWithoutAbstractApp,
...contracts.filter(({ namespace }) =>
disableAbstractAppFor.includes(namespace),
...contracts.filter(({ name }) =>
disableAbstractAppFor.includes(name),
),
].map(({ name, path }) => ({ name, dir: path })),
outPath: cosmwasmCodegenDirPath,
Expand Down Expand Up @@ -242,12 +245,14 @@ export function react(options: ReactOptions = {}): ReactResult {
cosmwasmCodegenDirPath,
`${contractNamePascalCase}.types.ts`,
)
imports.push(
`import * as ${contractNamePascalCase}Types from './${relative(
out,
typesFilePath.slice(0, -3),
)}'`,
)
if (hasAbstractApp) {
imports.push(
`import * as ${contractNamePascalCase}Types from './${relative(
out,
typesFilePath.slice(0, -3),
)}'`,
)
}
}

imports.push(
Expand Down Expand Up @@ -293,7 +298,7 @@ export function react(options: ReactOptions = {}): ReactResult {
)}>>[0], 'client'> & { ${
hasAbstractApp
? 'accountId: AccountId | undefined; chainName: string | undefined;'
: 'contractAddress: string | undefined;'
: 'contractAddress: string | undefined; chainName: string | undefined'
}}) => {
const {
data: ${queryClientCamelCase},
Expand Down Expand Up @@ -346,11 +351,11 @@ export function react(options: ReactOptions = {}): ReactResult {
{ ${
hasAbstractApp
? 'accountId, chainName, sender'
: 'contractAddress, sender'
: 'contractAddress, chainName, sender'
} }: { ${
hasAbstractApp
? 'accountId: AccountId | undefined; chainName: string | undefined; sender?: string | undefined;'
: 'contractAddress: string | undefined; sender?: string | undefined;'
: 'contractAddress: string | undefined; chainName: string | undefined; sender?: string | undefined;'
} },
options?: Omit<
UseMutationOptions<
Expand All @@ -377,7 +382,7 @@ export function react(options: ReactOptions = {}): ReactResult {
chainName,
sender,
`
: 'contractAddress,'
: 'contractAddress, chainName,'
}
Module: ${clientPascalCase},
}
Expand Down
Loading