Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Added greeter contract and terminal auto setup
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoSnap committed Jan 22, 2021
1 parent 7dec3b2 commit 2d1bd48
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 42 deletions.
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"multiCommand.commands": [

{
"command": "multiCommand.watch",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "yarn watch"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "yarn run watch\u000D" // \u000D is a return so it runs
}
}
]
},
{
"command": "multiCommand.node",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "yarn node"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "yarn run node\u000D" // \u000D is a return so it runs
}
}
]
},
{
"command": "multiCommand.frontend",
"sequence": [
"workbench.action.terminal.new",
{
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "yarn frontend"
}
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "yarn run frontend\u000D" // \u000D is a return so it runs
}
}
]
},
]
}
33 changes: 33 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [

{
"label": "Run 4 terminals on startup",
"runOptions": {"runOn": "folderOpen"},

"dependsOrder": "sequence", // or parallel

"dependsOn": [
"terminal1",
"terminal2",
"terminal3"
]
},

{
"label": "terminal1",
"command": "${command:multiCommand.watch}"
},
{
"label": "terminal2",
"command": "${command:multiCommand.node}",
},
{
"label": "terminal3",
"command": "${command:multiCommand.frontend}"
},
]
}
22 changes: 22 additions & 0 deletions packages/hardhat-demo/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.6.0;

import "hardhat/console.sol";

contract Greeter {
string greeting;

constructor(string memory _greeting) public {
console.log("Deploying a Greeter with greeting:", _greeting);
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
greeting = _greeting;
}
}
18 changes: 18 additions & 0 deletions packages/hardhat-demo/deploy/Greeter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();

await deploy("Greeter", {
from: deployer,
args: ["Hello from Hardhat"],
log: true,
});
};
export default func;
// func.tags = ['Greeter'];
// func.dependencies = ['GreeterElse'];
17 changes: 0 additions & 17 deletions packages/hardhat-demo/deploy/SimpleStorage.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
// module.exports = async ({
// getNamedAccounts,
// deployments,
// getChainId,
// getUnnamedAccounts,
// }) => {
// const { deploy } = deployments;
// const { deployer } = await getNamedAccounts();

// // the following will only deploy "GenericMetaTxProcessor" if the contract was never deployed or if the code changed since last deployment
// const deploy1 = await deploy("SimpleStorage", {
// from: deployer,
// // gas: 4000000,
// args: [],
// });
// };

import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

Expand Down
47 changes: 23 additions & 24 deletions packages/hardhat-demo/frontend/src/hardhat/SymfoniContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import Web3Modal, { IProviderOptions } from "web3modal";
import SimpleStorageADeployment from "./deployments/hardhat/SimpleStorageA.json";
import SimpleStorageBDeployment from "./deployments/hardhat/SimpleStorageB.json";
import SimpleStorageCDeployment from "./deployments/hardhat/SimpleStorageC.json";
import { SimpleStorage } from "./typechain/SimpleStorage";
import { SimpleStorage__factory } from "./typechain/factories/SimpleStorage__factory";
import { SimpleStorage2 } from "./typechain/SimpleStorage2";
import { SimpleStorage2__factory } from "./typechain/factories/SimpleStorage2__factory";
import { SimpleStorage } from "./typechain/SimpleStorage";
import { SimpleStorage__factory } from "./typechain/factories/SimpleStorage__factory";
import WalletConnectProvider from "@walletconnect/web3-provider";

const emptyContract = {
Expand All @@ -34,8 +34,8 @@ export const SymfoniContext = React.createContext<SymfoniContextInterface>(defau
export const SimpleStorageAContext = React.createContext<SymfoniSimpleStorage>(emptyContract);
export const SimpleStorageBContext = React.createContext<SymfoniSimpleStorage>(emptyContract);
export const SimpleStorageCContext = React.createContext<SymfoniSimpleStorage>(emptyContract);
export const SimpleStorageContext = React.createContext<SymfoniSimpleStorage>(emptyContract);
export const SimpleStorage2Context = React.createContext<SymfoniSimpleStorage2>(emptyContract);
export const SimpleStorageContext = React.createContext<SymfoniSimpleStorage>(emptyContract);

export interface SymfoniContextInterface {
init: (provider?: string) => void;
Expand Down Expand Up @@ -66,16 +66,16 @@ export interface SymfoniSimpleStorage {
factory?: SimpleStorage__factory;
}

export interface SymfoniSimpleStorage {
instance?: SimpleStorage;
factory?: SimpleStorage__factory;
}

export interface SymfoniSimpleStorage2 {
instance?: SimpleStorage2;
factory?: SimpleStorage2__factory;
}

export interface SymfoniSimpleStorage {
instance?: SimpleStorage;
factory?: SimpleStorage__factory;
}

export const Symfoni: React.FC<SymfoniProps> = ({
showLoading = true,
autoInit = true,
Expand All @@ -93,8 +93,8 @@ export const Symfoni: React.FC<SymfoniProps> = ({
const [SimpleStorageA, setSimpleStorageA] = useState<SymfoniSimpleStorage>(emptyContract);
const [SimpleStorageB, setSimpleStorageB] = useState<SymfoniSimpleStorage>(emptyContract);
const [SimpleStorageC, setSimpleStorageC] = useState<SymfoniSimpleStorage>(emptyContract);
const [SimpleStorage, setSimpleStorage] = useState<SymfoniSimpleStorage>(emptyContract);
const [SimpleStorage2, setSimpleStorage2] = useState<SymfoniSimpleStorage2>(emptyContract);
const [SimpleStorage, setSimpleStorage] = useState<SymfoniSimpleStorage>(emptyContract);
useEffect(() => {
if (messages.length > 0)
console.debug(messages.pop())
Expand Down Expand Up @@ -180,7 +180,7 @@ export const Symfoni: React.FC<SymfoniProps> = ({
};
const web3Modal = new Web3Modal({
// network: "mainnet",
cacheProvider: true,
cacheProvider: false,
providerOptions, // required
});
return await web3Modal.connect();
Expand All @@ -197,8 +197,8 @@ export const Symfoni: React.FC<SymfoniProps> = ({
setSimpleStorageA(getSimpleStorageA(_provider, _signer))
setSimpleStorageB(getSimpleStorageB(_provider, _signer))
setSimpleStorageC(getSimpleStorageC(_provider, _signer))
setSimpleStorage(getSimpleStorage(_provider, _signer))
setSimpleStorage2(getSimpleStorage2(_provider, _signer))
setSimpleStorage(getSimpleStorage(_provider, _signer))
finish(text)
}
if (!autoInit && initializeCounter === 0) return finish("Auto init turned off.")
Expand Down Expand Up @@ -260,27 +260,26 @@ export const Symfoni: React.FC<SymfoniProps> = ({
return contract
}
;
const getSimpleStorage = (_provider: providers.Provider, _signer?: Signer) => {
let instance = _signer ? SimpleStorage__factory.connect(ethers.constants.AddressZero, _signer) : SimpleStorage__factory.connect(ethers.constants.AddressZero, _provider)
const contract: SymfoniSimpleStorage = {
const getSimpleStorage2 = (_provider: providers.Provider, _signer?: Signer) => {
let instance = _signer ? SimpleStorage2__factory.connect(ethers.constants.AddressZero, _signer) : SimpleStorage2__factory.connect(ethers.constants.AddressZero, _provider)
const contract: SymfoniSimpleStorage2 = {
instance: instance,
factory: _signer ? new SimpleStorage__factory(_signer) : undefined,
factory: _signer ? new SimpleStorage2__factory(_signer) : undefined,
}
return contract
}
;
const getSimpleStorage2 = (_provider: providers.Provider, _signer?: Signer) => {
let instance = _signer ? SimpleStorage2__factory.connect(ethers.constants.AddressZero, _signer) : SimpleStorage2__factory.connect(ethers.constants.AddressZero, _provider)
const contract: SymfoniSimpleStorage2 = {
const getSimpleStorage = (_provider: providers.Provider, _signer?: Signer) => {
let instance = _signer ? SimpleStorage__factory.connect(ethers.constants.AddressZero, _signer) : SimpleStorage__factory.connect(ethers.constants.AddressZero, _provider)
const contract: SymfoniSimpleStorage = {
instance: instance,
factory: _signer ? new SimpleStorage2__factory(_signer) : undefined,
factory: _signer ? new SimpleStorage__factory(_signer) : undefined,
}
return contract
}
;

const handleInitProvider = (provider?: string) => {
console.log("running")
if (provider) {
setProviderPriority(old => old.sort((a, b) => {
return a === provider ? -1 : b === provider ? 1 : 0;
Expand All @@ -296,8 +295,8 @@ export const Symfoni: React.FC<SymfoniProps> = ({
<SimpleStorageAContext.Provider value={SimpleStorageA}>
<SimpleStorageBContext.Provider value={SimpleStorageB}>
<SimpleStorageCContext.Provider value={SimpleStorageC}>
<SimpleStorageContext.Provider value={SimpleStorage}>
<SimpleStorage2Context.Provider value={SimpleStorage2}>
<SimpleStorage2Context.Provider value={SimpleStorage2}>
<SimpleStorageContext.Provider value={SimpleStorage}>
{showLoading && loading ?
props.loadingComponent
? props.loadingComponent
Expand All @@ -308,8 +307,8 @@ export const Symfoni: React.FC<SymfoniProps> = ({
</div>
: props.children
}
</SimpleStorage2Context.Provider >
</SimpleStorageContext.Provider >
</SimpleStorageContext.Provider >
</SimpleStorage2Context.Provider >
</SimpleStorageCContext.Provider >
</SimpleStorageBContext.Provider >
</SimpleStorageAContext.Provider >
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-react/src/ReactComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export class ReactComponent {
};
const web3Modal = new Web3Modal({
// network: "mainnet",
cacheProvider: true,
cacheProvider: false,
providerOptions, // required
});
return await web3Modal.connect();
Expand Down

0 comments on commit 2d1bd48

Please sign in to comment.