Skip to content

Commit

Permalink
Merge pull request #48 from moonshotcollective/polygon
Browse files Browse the repository at this point in the history
Polygon into staging
  • Loading branch information
hmrtn authored Dec 1, 2021
2 parents c1ae31d + a563132 commit a3c0bc9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 36 deletions.
6 changes: 2 additions & 4 deletions packages/hardhat/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ 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}`],
},
// 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",
Expand Down
1 change: 1 addition & 0 deletions packages/react-app/src/components/Cards/SideCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function ElectionCard({
function goBack() {
routeHistory.push("/");
}
// console.log({electionState})

return (
<Box py="1.5rem" px="2.5rem">
Expand Down
6 changes: 5 additions & 1 deletion packages/react-app/src/contracts/external_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ module.exports = {
4: {
contracts: {
DAI: {
address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
address: "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea",
abi: DAIABI,
},
UNI: {
Expand All @@ -824,6 +824,10 @@ module.exports = {
address: "0xdb95f9188479575F3F718a245EcA1B3BF74567EC",
abi: ERC20ABI,
},
DAI: {
address: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
abi: ERC20ABI,
},
},
},
};
8 changes: 4 additions & 4 deletions packages/react-app/src/contracts/hardhat_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@
"chainId": "4",
"contracts": {
"Diplomat": {
"address": "0x057d7CFaC1FA6D1CEd591A448DA94525c5289f2F",
"address": "0x7658Eac3D619B0c141937ddEeC0E5a638F961427",
"abi": [
{
"inputs": [],
Expand Down Expand Up @@ -998,12 +998,12 @@
}
},
"137": {
"polygon": {
"name": "polygon",
"matic": {
"name": "matic",
"chainId": "137",
"contracts": {
"Diplomat": {
"address": "0xea99c58645f897ac8bf530538e36e6d651ff8bf7",
"address": "0x8486D6959d4e01aAd3d3D14A0e679160239FE463",
"abi": [
{
"inputs": [],
Expand Down
2 changes: 2 additions & 0 deletions packages/react-app/src/dips/ceramicHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 29 additions & 21 deletions packages/react-app/src/dips/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
19 changes: 14 additions & 5 deletions packages/react-app/src/views/Create.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 *****/
Expand All @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -390,7 +398,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write
<HStack pb="1rem" justify="space-between">
<HStack>
<InputGroup w="300px">
<NumberInput max={50} min={0.001} defaultValue={newElection.fundAmount}>
<NumberInput min={0.000000000000000001} defaultValue={newElection.fundAmount}>
<NumberInputField
w="300px"
placeholder="fundAmount"
Expand All @@ -417,6 +425,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write
>
<option value={CURRENCY}>{CURRENCY}</option>
<option value={TOKEN}>{TOKEN}</option>
<option value={STABLE}>{STABLE}</option>
</Select>
</HStack>
</HStack>
Expand All @@ -430,7 +439,7 @@ const Create = ({ address, mainnetProvider, userSigner, tx, readContracts, write
Vote Allocation (number of votes for each voter)
<br />
</FormLabel>
<NumberInput max={1000} min={1} defaultValue={newElection.voteAllocation}>
<NumberInput min={1} defaultValue={newElection.voteAllocation}>
<NumberInputField
placeholder="Vote allocation"
borderColor="purple.500"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/src/views/Election.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default function Election({
</Alert>
)}

{!electionState.isPaid && !electionState.active && electionState.isAdmin && (
{address && spender && electionState && !electionState.isPaid && !electionState.active && electionState.isAdmin && (
<PayButton
token={electionState.tokenSymbol}
tokenAddr={electionState.tokenAdr}
Expand Down

0 comments on commit a3c0bc9

Please sign in to comment.