Skip to content

Commit

Permalink
fix(highlight): add highlight boolean to factory contracts (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano authored and StuartGavidia committed Oct 28, 2023
1 parent 0483057 commit bd55b09
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/builder/src/schemas.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,19 @@ export const invokeSchema = z
.optional(),

/**
*
* Constructor or initializer args
*/
constructorArgs: z.array(argsUnion).optional(),

/**
* Bypass error messages if an event is expected in the invoke action but none are emitted in the transaction.
*/
allowEmptyEvents: z.boolean().optional(),

/**
* Determines whether contract should get priority in displays
*/
highlight: z.boolean().optional(),
})
)
.optional(),
Expand Down
4 changes: 4 additions & 0 deletions packages/builder/src/steps/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ ${getAllContractPaths(ctx).join('\n')}`);
contractName: contractName,
deployedOn: packageState.currentLabel,
};

if (factoryInfo.highlight) {
contracts[k].highlight = true;
}
}
}

Expand Down
22 changes: 19 additions & 3 deletions packages/cli/src/commands/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { red, bold, gray, green, yellow, cyan } = chalk;
import prompts, { Choice } from 'prompts';
import Wei, { wei } from '@synthetixio/wei';
import { PackageSpecification } from '../types';
import { CannonWrapperGenericProvider, ChainArtifacts } from '@usecannon/builder';
import { CannonWrapperGenericProvider, ChainArtifacts, ContractMap } from '@usecannon/builder';

const PROMPT_BACK_OPTION = { title: '↩ BACK' };

Expand Down Expand Up @@ -51,6 +51,7 @@ export async function interact(ctx: InteractTaskArgs) {
} else if (!pickedContract) {
pickedContract = await pickContract({
contractNames: Object.keys(ctx.contracts[pickedPackage]),
contractArtifacts: ctx.packagesArtifacts?.[pickedPackage]?.contracts,
});

if (!pickedContract) {
Expand Down Expand Up @@ -186,8 +187,23 @@ async function pickPackage(packages: PackageSpecification[]) {
return typeof pickedPackage === 'number' ? pickedPackage : -1;
}

async function pickContract({ contractNames }: { contractNames: string[] }) {
const choices = contractNames.sort().map((s) => ({ title: s }));
async function pickContract({
contractNames,
contractArtifacts,
}: {
contractNames: string[];
contractArtifacts?: ContractMap;
}) {
const isHighlighted = (n: string) => !!contractArtifacts?.[n].highlight;

const choices: Choice[] = _.sortBy(contractNames, [
(contractName) => !isHighlighted(contractName),
(contractName) => contractName,
]).map((contractName) => ({
title: isHighlighted(contractName) ? bold(contractName) : contractName,
value: contractName,
}));

choices.unshift(PROMPT_BACK_OPTION);

const { pickedContract } = await prompts.prompt([
Expand Down
1 change: 1 addition & 0 deletions packages/registry/cannonfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ fromCall.func = "owner"
factory.Proxy.abiOf = ["Implementation"]
factory.Proxy.event = "Upgraded"
factory.Proxy.arg = 0
factory.Proxy.highlight = true

depends = ["contract.InitialProxy", "contract.Implementation"]

0 comments on commit bd55b09

Please sign in to comment.