-
+
{
- setToken({
- ...token,
- ...{
- amount: event.target.value.length ? BigNumber.from(event.target.value) : undefined,
- }
- });
- }}
+ onChange={_setAmount}
className="form-control"
+ value={displayAmount}
/>
-
- {tokens.map((tokenItem: Token, index: number) => (
- {
- event.currentTarget.blur();
- event.preventDefault();
-
- setToken({
- ...token,
- ...{
- token: tokenItem
- }
- });
- }}
- >{tokenItem.symbol}
- ))}
+
+ {!tokens && Connect your wallet}
+ {tokens &&
+ Array.from(tokens.values()).map((tokenItem: ITokenData, index: number) => (
+
+ {tokenItem && tokenItem.symbol}
+
+ ))}
{token?.balance && (
- ({
- ...token,
- ...{
- amount: token?.balance
- }
- })}
- >Max: {token.balance.toString()} {token.token?.symbol || ""}
+
+ Max: {displayBalance} {token?.symbol || ""}
+
)}
diff --git a/src/constants/chains.ts b/src/constants/chains.ts
index 6a12e3f..aa9365e 100644
--- a/src/constants/chains.ts
+++ b/src/constants/chains.ts
@@ -1,6 +1,8 @@
+import { ChainId } from "@uniswap/sdk";
+
export enum SupportedChainId {
- MAINNET = 1,
- RINKEBY = 4,
+ MAINNET = ChainId.MAINNET,
+ RINKEBY = ChainId.RINKEBY,
}
export const connectorConfig = {
diff --git a/src/constants/contracts.ts b/src/constants/contracts.ts
deleted file mode 100644
index 8b4b7a5..0000000
--- a/src/constants/contracts.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { SupportedChainId } from "./chains";
-
-export const tokens = {
- gOHM: {
- [SupportedChainId.MAINNET]: "0x0ab87046fBb341D058F17CBC4c1133F25a20a52f",
- [SupportedChainId.RINKEBY]: "0x70699eae51C0068917dE7Ce689C2dC3b2B074C1F",
- },
-};
-
-export const protocols = {
- atlantisSwap: {
- [SupportedChainId.MAINNET]: "0x0",
- [SupportedChainId.RINKEBY]: "0x0",
- },
-};
diff --git a/src/contracts/abis/ERC20.json b/src/contracts/abis/ERC20.json
new file mode 100644
index 0000000..686acac
--- /dev/null
+++ b/src/contracts/abis/ERC20.json
@@ -0,0 +1,224 @@
+{
+ "abi": [
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "name",
+ "outputs": [
+ {
+ "name": "",
+ "type": "string"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "_spender",
+ "type": "address"
+ },
+ {
+ "name": "_value",
+ "type": "uint256"
+ }
+ ],
+ "name": "approve",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "totalSupply",
+ "outputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "_from",
+ "type": "address"
+ },
+ {
+ "name": "_to",
+ "type": "address"
+ },
+ {
+ "name": "_value",
+ "type": "uint256"
+ }
+ ],
+ "name": "transferFrom",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "decimals",
+ "outputs": [
+ {
+ "name": "",
+ "type": "uint8"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "_owner",
+ "type": "address"
+ }
+ ],
+ "name": "balanceOf",
+ "outputs": [
+ {
+ "name": "balance",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "symbol",
+ "outputs": [
+ {
+ "name": "",
+ "type": "string"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "_to",
+ "type": "address"
+ },
+ {
+ "name": "_value",
+ "type": "uint256"
+ }
+ ],
+ "name": "transfer",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "_owner",
+ "type": "address"
+ },
+ {
+ "name": "_spender",
+ "type": "address"
+ }
+ ],
+ "name": "allowance",
+ "outputs": [
+ {
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "payable": true,
+ "stateMutability": "payable",
+ "type": "fallback"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "owner",
+ "type": "address"
+ },
+ {
+ "indexed": true,
+ "name": "spender",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "name": "value",
+ "type": "uint256"
+ }
+ ],
+ "name": "Approval",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "name": "from",
+ "type": "address"
+ },
+ {
+ "indexed": true,
+ "name": "to",
+ "type": "address"
+ },
+ {
+ "indexed": false,
+ "name": "value",
+ "type": "uint256"
+ }
+ ],
+ "name": "Transfer",
+ "type": "event"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/contracts/index.ts b/src/contracts/index.ts
new file mode 100644
index 0000000..ab937e7
--- /dev/null
+++ b/src/contracts/index.ts
@@ -0,0 +1,33 @@
+import { SupportedChainId } from "../constants/chains";
+import { ChainId, Token } from "@uniswap/sdk";
+
+export const protocols = {
+ atlantisSwap: {
+ [SupportedChainId.MAINNET]: "0x0",
+ [SupportedChainId.RINKEBY]: "0x0",
+ },
+};
+
+interface ITokenDef {
+ [key: string]: {
+ [x: number]: string;
+ };
+}
+
+export const tokens: ITokenDef = {
+ gohm: {
+ [SupportedChainId.MAINNET]: "0x0ab87046fBb341D058F17CBC4c1133F25a20a52f",
+ [SupportedChainId.RINKEBY]: "0x70699eae51C0068917dE7Ce689C2dC3b2B074C1F",
+ },
+};
+
+export const tokenName_gohm = "gOHM";
+
+export const allTokens: Token[] = [
+ new Token(ChainId.MAINNET, "0x0ab87046fBb341D058F17CBC4c1133F25a20a52f", 18, tokenName_gohm, "Governance OHM"),
+ new Token(ChainId.RINKEBY, "0x70699eae51C0068917dE7Ce689C2dC3b2B074C1F", 18, tokenName_gohm, "Governance OHM"),
+];
+
+export const getTokensForChainId = (chainId: ChainId, tokens: Token[]) => {
+ return tokens.filter(token => token.chainId == chainId);
+};
diff --git a/src/data/tokens.ts b/src/data/tokens.ts
deleted file mode 100644
index 2a52073..0000000
--- a/src/data/tokens.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { Token } from "@uniswap/sdk";
-
-const TOKENS: Token[] = [
- new Token(1, "0x000000000000000000000000000000000000fafa", 18, "OHM", "OlympusDAO"),
- new Token(1, "0x000000000000000000000000000000000000faaf", 18, "WETH", "Wrapped Ether"),
-];
-
-export default TOKENS;
diff --git a/src/hooks/index.ts b/src/hooks/index.ts
new file mode 100644
index 0000000..ea0873a
--- /dev/null
+++ b/src/hooks/index.ts
@@ -0,0 +1,6 @@
+
+import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
+import { AppDispatch, RootState } from "../state/store";
+
+export const useAppSelector: TypedUseSelectorHook
= useSelector;
+export const useAppDispatch = () => useDispatch();
diff --git a/src/interfaces/TokenData.ts b/src/interfaces/TokenData.ts
index 1838a19..7780aa3 100644
--- a/src/interfaces/TokenData.ts
+++ b/src/interfaces/TokenData.ts
@@ -1,9 +1,8 @@
import { Token } from "@uniswap/sdk";
import { BigNumber } from "ethers";
-
-export interface TokenData {
- token?: Token,
- balance?: BigNumber,
- allowance?: BigNumber,
- amount?: BigNumber
+export interface ITokenData extends Token {
+ balance?: BigNumber;
+ allowance?: BigNumber;
}
+
+export interface ITokenMap extends Map {}
diff --git a/src/pages/Bootstrap/Bootstrap.tsx b/src/pages/Bootstrap/Bootstrap.tsx
index d366120..a897517 100644
--- a/src/pages/Bootstrap/Bootstrap.tsx
+++ b/src/pages/Bootstrap/Bootstrap.tsx
@@ -1,14 +1,30 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
+import { BigNumber, utils } from "ethers";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Modal } from "react-bootstrap";
-import TokenAmountInput from "../../components/TokenAmountInput/TokenAmountInput";
-import { TokenData } from "../../interfaces/TokenData";
import { toast } from "react-toastify";
+import TokenAmountInput from "../../components/TokenAmountInput/TokenAmountInput";
+import { ITokenData } from "../../interfaces/TokenData";
+import { useAppSelector } from "../../hooks";
+import { tokenName_gohm } from "../../contracts";
export default function Bootstrap(): JSX.Element {
// states
- const [inputToken, setInputToken] = useState(null);
+ const [inputToken, setInputToken] = useState(null);
+ const [amount, setAmount] = useState(BigNumber.from(0));
const [showSwapSettingsModal, setShowSwapSettingsModal] = useState(false);
+ const tokens = useAppSelector(state => state.account.tokens);
+
+ // on Load
+ useEffect(() => {
+ // Set initial selected token
+ if (!tokens) return;
+ if (tokens.size == 0) return;
+ const gohm = tokens.get(tokenName_gohm);
+ if (!gohm) return;
+
+ setInputToken(gohm);
+ }, []);
const approve = async () => {
toast("Please confirm transaction");
@@ -31,7 +47,7 @@ export default function Bootstrap(): JSX.Element {
- setInputToken(newToken)}
- />
+
-
- Est. APY
-
-
- 6,420 %
-
+
Est. APY
+
6,420 %
@@ -63,8 +72,8 @@ export default function Bootstrap(): JSX.Element {
+ >
+ Approve
+
+ >
+ Swap
+
@@ -94,20 +109,14 @@ export default function Bootstrap(): JSX.Element {
>
diff --git a/src/pages/Swap/Swap.tsx b/src/pages/Swap/Swap.tsx
index 9db6fd6..766337b 100644
--- a/src/pages/Swap/Swap.tsx
+++ b/src/pages/Swap/Swap.tsx
@@ -1,48 +1,53 @@
import React, { useEffect, useState } from "react";
import { useWeb3React } from "@web3-react/core";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import TOKENS from "../../data/tokens";
import { Modal } from "react-bootstrap";
import TokenAmountInput from "../../components/TokenAmountInput/TokenAmountInput";
-import { TokenData } from "../../interfaces/TokenData";
+import { ITokenData } from "../../interfaces/TokenData";
+import { useAppSelector } from "../../hooks";
import "./styles.scss";
import { toast } from "react-toastify";
+import { BigNumber } from "ethers";
export default function Swap(): JSX.Element {
const { account } = useWeb3React();
// states
- const [inputToken, setInputToken] = useState