diff --git a/packages/hardhat/hardhat.config.js b/packages/hardhat/hardhat.config.js index dd8a0b59..28d3a413 100644 --- a/packages/hardhat/hardhat.config.js +++ b/packages/hardhat/hardhat.config.js @@ -73,7 +73,7 @@ module.exports = { gasPrice: 1000000000, accounts: [`${process.env.XDAI_DEPLOYER_PRIV_KEY}`], }, - polygon: { + matic: { url: `https://polygon-mainnet.infura.io/v3/${process.env.POLYGON_INFURA_KEY}`, // <---- YOUR MORALIS ID! (not limited to infura) gasPrice: 1000000000, accounts: [`${process.env.POLYGON_DEPLOYER_PRIV_KEY}`], @@ -81,9 +81,7 @@ module.exports = { // matic: { // url: "https://rpc-mainnet.maticvigil.com/", // gasPrice: 1000000000, - // accounts: { - // mnemonic: mnemonic(), - // }, + // accounts: [`${process.env.POLYGON_DEPLOYER_PRIV_KEY}`], // }, // rinkebyArbitrum: { // url: "https://rinkeby.arbitrum.io/rpc", diff --git a/packages/react-app/src/components/Cards/SideCard.jsx b/packages/react-app/src/components/Cards/SideCard.jsx index c1be78b1..017547ac 100644 --- a/packages/react-app/src/components/Cards/SideCard.jsx +++ b/packages/react-app/src/components/Cards/SideCard.jsx @@ -26,6 +26,7 @@ function ElectionCard({ function goBack() { routeHistory.push("/"); } + // console.log({electionState}) return ( diff --git a/packages/react-app/src/contracts/external_contracts.js b/packages/react-app/src/contracts/external_contracts.js index 166b1753..4edfe0c1 100644 --- a/packages/react-app/src/contracts/external_contracts.js +++ b/packages/react-app/src/contracts/external_contracts.js @@ -801,7 +801,7 @@ module.exports = { 4: { contracts: { DAI: { - address: "0x6B175474E89094C44Da98b954EedeAC495271d0F", + address: "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea", abi: DAIABI, }, UNI: { @@ -824,6 +824,10 @@ module.exports = { address: "0xdb95f9188479575F3F718a245EcA1B3BF74567EC", abi: ERC20ABI, }, + DAI: { + address: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063", + abi: ERC20ABI, + }, }, }, }; diff --git a/packages/react-app/src/contracts/hardhat_contracts.json b/packages/react-app/src/contracts/hardhat_contracts.json index 18b8e84f..4eb23721 100644 --- a/packages/react-app/src/contracts/hardhat_contracts.json +++ b/packages/react-app/src/contracts/hardhat_contracts.json @@ -504,7 +504,7 @@ "chainId": "4", "contracts": { "Diplomat": { - "address": "0x057d7CFaC1FA6D1CEd591A448DA94525c5289f2F", + "address": "0x7658Eac3D619B0c141937ddEeC0E5a638F961427", "abi": [ { "inputs": [], @@ -998,12 +998,12 @@ } }, "137": { - "polygon": { - "name": "polygon", + "matic": { + "name": "matic", "chainId": "137", "contracts": { "Diplomat": { - "address": "0xea99c58645f897ac8bf530538e36e6d651ff8bf7", + "address": "0x8486D6959d4e01aAd3d3D14A0e679160239FE463", "abi": [ { "inputs": [], diff --git a/packages/react-app/src/dips/ceramicHandler.js b/packages/react-app/src/dips/ceramicHandler.js index 688d25be..1ff88955 100644 --- a/packages/react-app/src/dips/ceramicHandler.js +++ b/packages/react-app/src/dips/ceramicHandler.js @@ -73,6 +73,8 @@ export default function CeramicHandler( const electionId = electionDoc.id.toUrl(); + // console.log({ targetNetwork }); + /* CREATE ELECTION ON-CHAIN (push the ceramic commitId to elections array) */ let contract = new ethers.Contract( Diplomat[targetNetwork.chainId][targetNetwork.name].contracts.Diplomat.address, diff --git a/packages/react-app/src/dips/helpers.js b/packages/react-app/src/dips/helpers.js index a6ce057e..a283a152 100644 --- a/packages/react-app/src/dips/helpers.js +++ b/packages/react-app/src/dips/helpers.js @@ -7,9 +7,11 @@ import { makeCeramicClient } from "../helpers"; export const CERAMIC_PREFIX = "ceramic://"; -const CURRENCY = "ETH"; +const CURRENCY = process.env.REACT_APP_NETWORK_SYMBOL; const TOKEN = process.env.REACT_APP_TOKEN_SYMBOL; const TOKEN_ADR = process.env.REACT_APP_TOKEN_ADDRESS; +const STABLE = process.env.REACT_APP_STABLE_TOKEN_SYMBOL; +const STABLE_ADR = process.env.REACT_APP_STABLE_TOKEN_ADDRESS; //// PASTE HERE export const getAllCeramicElections = async (contract, ceramic) => { @@ -137,10 +139,13 @@ export const newSerializeCeramicElection = async ({ id, electionDoc, address, ce }); } } - let tokenSymbol = "ETH"; + let tokenSymbol = CURRENCY; if (electionDoc.content.tokenAddress == TOKEN_ADR) { tokenSymbol = TOKEN; } + if (electionDoc.content.tokenAddress == STABLE_ADR) { + tokenSymbol = STABLE; + } console.log({ content: electionDoc.content, tags }); const serializedElection = { id, @@ -187,24 +192,24 @@ export const getCeramicElectionIds = async diplomatContract => { return elections; }; -// export const getNetwork = async () => { -// const web3Modal = new Web3Modal(); -// const connection = await web3Modal.connect(); -// const provider = new ethers.providers.Web3Provider(connection); -// const signer = provider.getSigner(); -// let network = await provider.getNetwork(); -// // console.log(network); -// if (network.chainId === 31337 || network.chainId === 1337) { -// network = { name: "localhost", chainId: 31337 }; -// } -// if (network.name === "homestead") { -// network = { name: "mainnet", chainId: 1 }; -// } -// if (network.chainId === 137) { -// network = { name: "polygon", chainId: 137 }; -// } -// return { network, signer, provider }; -// }; +export const getNetwork = async () => { + const web3Modal = new Web3Modal(); + const connection = await web3Modal.connect(); + const provider = new ethers.providers.Web3Provider(connection); + const signer = provider.getSigner(); + let network = await provider.getNetwork(); + // console.log(network); + if (network.chainId === 31337 || network.chainId === 1337) { + network = { name: "localhost", chainId: 31337 }; + } + if (network.name === "homestead") { + network = { name: "mainnet", chainId: 1 }; + } + if (network.chainId === 137) { + network = { name: "polygon", chainId: 137 }; + } + return { network, signer, provider }; +}; export const toCeramicId = id => (id.startsWith(CERAMIC_PREFIX) ? id : CERAMIC_PREFIX + id); @@ -333,10 +338,13 @@ export const serializeCeramicElection = async (ceramicElectionId, address, ceram }); } } - let tokenSymbol = "ETH"; + let tokenSymbol = CURRENCY; if (electionDoc.content.tokenAddress == TOKEN_ADR) { tokenSymbol = TOKEN; } + if (electionDoc.content.tokenAddress == STABLE_ADR) { + tokenSymbol = STABLE; + } console.log({ content: electionDoc.content, tags }); const serializedElection = { id, diff --git a/packages/react-app/src/views/Create.jsx b/packages/react-app/src/views/Create.jsx index 4d5394e2..07f0c85a 100644 --- a/packages/react-app/src/views/Create.jsx +++ b/packages/react-app/src/views/Create.jsx @@ -46,9 +46,11 @@ import { ethers } from "ethers"; import { CERAMIC_PREFIX } from "../dips/helpers"; -const CURRENCY = "ETH"; +const CURRENCY = process.env.REACT_APP_NETWORK_SYMBOL; const TOKEN = process.env.REACT_APP_TOKEN_SYMBOL; const TOKEN_ADR = process.env.REACT_APP_TOKEN_ADDRESS; +const STABLE = process.env.REACT_APP_STABLE_TOKEN_SYMBOL; +const STABLE_ADR = process.env.REACT_APP_STABLE_TOKEN_ADDRESS; const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, writeContracts, targetNetwork }) => { /***** Routes *****/ @@ -67,7 +69,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write const [newElection, setNewElection] = useState({ name: "", description: "", - tokenSym: "ETH", + tokenSym: CURRENCY, tokenAdr: "0x0000000000000000000000000000000000000000", fundAmount: 0.1, fundAmountInWei: toWei("0.1"), @@ -176,7 +178,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write setNewElection({ name: "", description: "", - tokenSym: "ETH", + tokenSym: CURRENCY, fundAmount: 0.1, fundAmountInWei: toWei("0.1"), voteAllocation: 1, @@ -228,6 +230,12 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write tokenAdr: TOKEN_ADR, })); } + if (e.target.value === STABLE) { + setNewElection(prevState => ({ + ...prevState, + tokenAdr: STABLE_ADR, + })); + } }; const updateFundAmount = e => { @@ -390,7 +398,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write - + + @@ -430,7 +439,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write Vote Allocation (number of votes for each voter)
- + )} - {!electionState.isPaid && !electionState.active && electionState.isAdmin && ( + {address && spender && electionState && !electionState.isPaid && !electionState.active && electionState.isAdmin && (