From 9534e905d5de6338a7675c812076f1836db7acc4 Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Fri, 25 Oct 2024 04:20:50 -0400 Subject: [PATCH 1/2] Add chainName to generation --- packages/cli/src/plugins/react.ts | 53 +++++++++++++++++-------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/cli/src/plugins/react.ts b/packages/cli/src/plugins/react.ts index 1b1ac62d..8cb0476f 100644 --- a/packages/cli/src/plugins/react.ts +++ b/packages/cli/src/plugins/react.ts @@ -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, }) @@ -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, @@ -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( @@ -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}, @@ -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< @@ -377,7 +382,7 @@ export function react(options: ReactOptions = {}): ReactResult { chainName, sender, ` - : 'contractAddress,' + : 'contractAddress, chainName,' } Module: ${clientPascalCase}, } From 83a66c2bf962c4533baa6a584895c0d3e3758a6f Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Fri, 25 Oct 2024 04:22:05 -0400 Subject: [PATCH 2/2] Changeset --- .changeset/giant-rats-protect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/giant-rats-protect.md diff --git a/.changeset/giant-rats-protect.md b/.changeset/giant-rats-protect.md new file mode 100644 index 00000000..eeed989d --- /dev/null +++ b/.changeset/giant-rats-protect.md @@ -0,0 +1,5 @@ +--- +"@abstract-money/cli": minor +--- + +Add chainName to code generation