Skip to content

Commit

Permalink
Merge pull request #674 from scaffold-eth/cli-backmerge
Browse files Browse the repository at this point in the history
Weekly CLI backmerge
  • Loading branch information
technophile-04 committed Dec 29, 2023
2 parents f9e614b + 8af19db commit 7cbd2be
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 101 deletions.
7 changes: 7 additions & 0 deletions .changeset/quiet-ligers-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-eth": patch
---

- Track hardhat-deploy deployments, except localhost (#666)
- feat: add external flag to external contracts (#647)
- Remove `.github/ISSUE_TEMPLATE` and pull request template when using npx
58 changes: 0 additions & 58 deletions templates/base/.github/ISSUE_TEMPLATE/bug_report.yml

This file was deleted.

8 changes: 0 additions & 8 deletions templates/base/.github/ISSUE_TEMPLATE/config.yml

This file was deleted.

16 changes: 0 additions & 16 deletions templates/base/.github/pull_request_template.md

This file was deleted.

2 changes: 1 addition & 1 deletion templates/base/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged --verbose
yarn lint-staged --verbose
17 changes: 13 additions & 4 deletions templates/base/packages/nextjs/pages/debug.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useEffect } from "react";
import type { NextPage } from "next";
import { useLocalStorage } from "usehooks-ts";
import { BarsArrowUpIcon } from "@heroicons/react/20/solid";
import { MetaHeader } from "~~/components/MetaHeader";
import { ContractUI } from "~~/components/scaffold-eth";
import { ContractName } from "~~/utils/scaffold-eth/contract";
import { getContractNames } from "~~/utils/scaffold-eth/contractNames";
import { getAllContracts } from "~~/utils/scaffold-eth/contractsData";

const selectedContractStorageKey = "scaffoldEth2.selectedContract";
const contractNames = getContractNames();
const contractsData = getAllContracts();
const contractNames = Object.keys(contractsData) as ContractName[];

const Debug: NextPage = () => {
const [selectedContract, setSelectedContract] = useLocalStorage<ContractName>(
Expand Down Expand Up @@ -36,13 +38,20 @@ const Debug: NextPage = () => {
<div className="flex flex-row gap-2 w-full max-w-7xl pb-1 px-6 lg:px-10 flex-wrap">
{contractNames.map(contractName => (
<button
className={`btn btn-secondary btn-sm font-thin ${
contractName === selectedContract ? "bg-base-300" : "bg-base-100"
className={`btn btn-secondary btn-sm font-light hover:border-transparent ${
contractName === selectedContract
? "bg-base-300 hover:bg-base-300 no-animation"
: "bg-base-100 hover:bg-secondary"
}`}
key={contractName}
onClick={() => setSelectedContract(contractName)}
>
{contractName}
{contractsData[contractName].external && (
<span className="tooltip tooltip-top tooltip-accent" data-tip="External contract">
<BarsArrowUpIcon className="h-4 w-4 cursor-pointer" />
</span>
)}
</button>
))}
</div>
Expand Down
30 changes: 24 additions & 6 deletions templates/base/packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,34 @@ import deployedContractsData from "~~/contracts/deployedContracts";
import externalContractsData from "~~/contracts/externalContracts";
import scaffoldConfig from "~~/scaffold.config";

const deepMergeContracts = <D extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(
destination: D,
source: S,
type AddExternalFlag<T> = {
[ChainId in keyof T]: {
[ContractName in keyof T[ChainId]]: T[ChainId][ContractName] & { external?: true };
};
};

const deepMergeContracts = <L extends Record<PropertyKey, any>, E extends Record<PropertyKey, any>>(
local: L,
external: E,
) => {
const result: Record<PropertyKey, any> = {};
const allKeys = Array.from(new Set([...Object.keys(source), ...Object.keys(destination)]));
const allKeys = Array.from(new Set([...Object.keys(external), ...Object.keys(local)]));
for (const key of allKeys) {
result[key] = { ...destination[key], ...source[key] };
if (!external[key]) {
result[key] = local[key];
continue;
}
const amendedExternal = Object.fromEntries(
Object.entries(external[key] as Record<string, Record<string, unknown>>).map(([contractName, declaration]) => [
contractName,
{ ...declaration, external: true },
]),
);
result[key] = { ...local[key], ...amendedExternal };
}
return result as MergeDeepRecord<D, S, { arrayMergeMode: "replace" }>;
return result as MergeDeepRecord<AddExternalFlag<L>, AddExternalFlag<E>, { arrayMergeMode: "replace" }>;
};

const contractsData = deepMergeContracts(deployedContractsData, externalContractsData);

export type InheritedFunctions = { readonly [key: string]: string };
Expand All @@ -42,6 +59,7 @@ export type GenericContract = {
address: Address;
abi: Abi;
inheritedFunctions?: InheritedFunctions;
external?: true;
};

export type GenericContractsDeclaration = {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scaffoldConfig from "~~/scaffold.config";
import { contracts } from "~~/utils/scaffold-eth/contract";

export function getAllContracts() {
const contractsData = contracts?.[scaffoldConfig.targetNetworks[0].id];
return contractsData ? contractsData : {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ artifacts
artifacts-zk
cache-zk
deployments`
deployments/localhost`

export default contents

0 comments on commit 7cbd2be

Please sign in to comment.