Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(highlight): add highlight boolean to factory contracts #536

Merged
merged 3 commits into from
Oct 26, 2023
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
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"]