Skip to content

Commit

Permalink
Merge pull request #89 from cyclese96/ethereum-network-release
Browse files Browse the repository at this point in the history
Ethereum network release
  • Loading branch information
AamirAlam committed Feb 19, 2022
2 parents 53e0779 + 52225af commit b701d62
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 66 deletions.
83 changes: 70 additions & 13 deletions frontend/src/actions/dexActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import BigNumber from "bignumber.js";
import {
currentConnection,
ETH,
etheriumNetwork,
moonriverNetwork,
PBR,
routerAddresses,
Expand Down Expand Up @@ -69,7 +68,7 @@ export const swapTokens =
const toAddress = account;
const _deadlineUnix = getUnixTime(deadline);
dispatch({
type: SHOW_LOADING,
type: SHOW_DEX_LOADING,
});
dispatch({ type: START_TRANSACTION });

Expand Down Expand Up @@ -214,7 +213,6 @@ export const swapTokens =

await swapPromise
.on("receipt", async function (receipt) {
console.log("UPDATE_TRANSACTION_STATUS", receipt);
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: {
Expand All @@ -238,7 +236,7 @@ export const swapTokens =
});
}
dispatch({
type: HIDE_LOADING,
type: HIDE_DEX_LOADING,
});
};

Expand Down Expand Up @@ -282,7 +280,7 @@ export const addLiquidity =
const _routerContract = routerContract(network);

dispatch({
type: SHOW_LOADING,
type: SHOW_DEX_LOADING,
});
//input params
const token0AmountDesired = token0.amount;
Expand Down Expand Up @@ -343,7 +341,7 @@ export const addLiquidity =
}

dispatch({
type: HIDE_LOADING,
type: HIDE_DEX_LOADING,
});
};

Expand All @@ -354,7 +352,7 @@ export const addLiquidityEth =
try {
const _routerContract = routerContract(network);
dispatch({
type: SHOW_LOADING,
type: SHOW_DEX_LOADING,
});
//input params
const etherAmount = ethToken.amount;
Expand Down Expand Up @@ -417,7 +415,7 @@ export const addLiquidityEth =
}

dispatch({
type: HIDE_LOADING,
type: HIDE_DEX_LOADING,
});
};

Expand Down Expand Up @@ -510,7 +508,6 @@ export const removeLiquidityEth =
const tokenAmountMin = "0";
const lpTokenAmount = lpAmount;

console.log({ ethToken, erc20Token, lpAmount });
// deadline should be passed in minites in calculation
const _deadlineUnix = getUnixTime(deadline);

Expand Down Expand Up @@ -617,11 +614,39 @@ export const confirmAllowance =
const _routerContract = routerContract(network);

dispatch({
type: SHOW_LOADING,
type: SHOW_DEX_LOADING,
});
await _tokenContract.methods
.approve(_routerContract._address, balance)
.send({ from: account });
.send({ from: account }, function (error, transactionHash) {
if (error) {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: { type: "token_approve", hash: null, status: "failed" },
});
} else {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: { type: "token_approve", hash: transactionHash },
});
}
})
.on("receipt", async function (receipt) {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: {
type: "token_approve",
status: "success",
result: {}, // add result data for reciept
},
});
})
.on("error", async function (error) {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: { type: "token_approve", status: "failed" },
});
});

dispatch({
type: APPROVE_TOKEN,
Expand All @@ -635,7 +660,7 @@ export const confirmAllowance =
});
}
dispatch({
type: HIDE_LOADING,
type: HIDE_DEX_LOADING,
});
};

Expand Down Expand Up @@ -693,7 +718,39 @@ export const confirmLPAllowance =

await _pairContract.methods
.approve(_routerContractAddress, balance)
.send({ from: account });
.send({ from: account }, function (error, transactionHash) {
if (error) {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: {
type: "lp_token_approve",
hash: null,
status: "failed",
},
});
} else {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: { type: "lp_token_approve", hash: transactionHash },
});
}
})
.on("receipt", async function (receipt) {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: {
type: "lp_token_approve",
status: "success",
result: {}, // add result data
},
});
})
.on("error", async function (error) {
dispatch({
type: UPDATE_TRANSACTION_STATUS,
payload: { type: "lp_token_approve", status: "failed" },
});
});

dispatch({
type: APPROVE_LP_TOKENS,
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/actions/farmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export const getFarmInfo =
poolWeight: new BigNumber(poolInfo?.allocPoint)
.div(totalAllocPoint)
.toString(),
lockedLp: fromWei(poolInfo?.lpAmount),
};

dispatch({
Expand Down Expand Up @@ -363,10 +364,11 @@ export const getLpBalanceFarm =
const balObject = {};
balObject[pairAddress] = {
lpBalance,
poolLpTokens: new BigNumber(fromWei(totalSupply))
poolLpTokens: new BigNumber(fromWei(totalSupply)) // multiply this value with eth price to get correct pool total Liquidity usd value
.times(lpTokenPrice)
.toFixed(0)
.toString(),
lpTokenPrice, // multiply this value with eth price to get correct lp price in usd
};

dispatch({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/common/SelectTokenDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const useStyles = makeStyles((theme) => ({
},

closeIcon: {
color: "#f6f6f6",
color: theme.palette.textColors.heading,
fontSize: 24,
[theme.breakpoints.down("sm")]: {
fontSize: 20,
Expand Down
59 changes: 34 additions & 25 deletions frontend/src/components/pages/AddLiquidity/AddCard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Button,
Card,
CircularProgress,
IconButton,
makeStyles,
} from "@material-ui/core";
import { Button, Card, IconButton, makeStyles } from "@material-ui/core";
import { connect } from "react-redux";
import KeyboardBackspaceIcon from "@material-ui/icons/KeyboardBackspace";
import { useCallback, useEffect, useMemo, useState } from "react";
Expand Down Expand Up @@ -235,6 +229,7 @@ const AddCard = (props) => {
pairContractData,
transaction,
tokenList,
dexLoading,
},
addLiquidityEth,
checkAllowance,
Expand Down Expand Up @@ -400,7 +395,6 @@ const AddCard = (props) => {
};

const loadPairReserves = async () => {
// console.log('loading pair reserves after add liquidity')
let _pairAddress = currentPairAddress();

if (!_pairAddress) {
Expand Down Expand Up @@ -746,6 +740,11 @@ const AddCard = (props) => {
};

const handleAction = () => {
if (dexLoading) {
setSwapDialog(true);
return;
}

if (currentTokenApprovalStatus()) {
handleAddLiquidity();
} else {
Expand All @@ -762,6 +761,11 @@ const AddCard = (props) => {
return "Please wait...";
} else if (addStatus.disabled) {
return addStatus.message;
} else if (
["add", "token_approve"].includes(transaction.type) &&
transaction.status === "pending"
) {
return "Pending Transaction...";
} else {
return !currentTokenApprovalStatus()
? currApproveBtnText()
Expand All @@ -775,13 +779,24 @@ const AddCard = (props) => {
return;
}

if (transaction.type === "add" && transaction.status === "success") {
if (
["add", "token_approve"].includes(transaction.type) &&
transaction.status === "success"
) {
getAccountBalance(selectedToken0, currentNetwork);
getAccountBalance(selectedToken1, currentNetwork);
}

if (
(transaction.type === "add" && transaction.status === "success") ||
["add", "token_approve"].includes(transaction.type) &&
transaction.status === "pending"
) {
setSwapDialog(true);
}

if (
(["add", "token_approve"].includes(transaction.type) &&
transaction.status === "success") ||
transaction.status === "failed"
) {
setSwapDialog(true);
Expand All @@ -790,10 +805,16 @@ const AddCard = (props) => {

const handleConfirmSwapClose = (value) => {
setSwapDialog(value);
if (transaction.type === "add" && transaction.status === "success") {
if (
["add", "token_approve"].includes(transaction.type) &&
transaction.status === "success"
) {
store.dispatch({ type: START_TRANSACTION });
clearInputState();
} else if (transaction.type === "add" && transaction.status === "failed") {
} else if (
["add", "token_approve"].includes(transaction.type) &&
transaction.status === "failed"
) {
store.dispatch({ type: START_TRANSACTION });
}
};
Expand Down Expand Up @@ -908,19 +929,7 @@ const AddCard = (props) => {
onClick={handleAction}
className={classes.addLiquidityButton}
>
{!addStatus.disabled && loading ? (
<span>
{transaction.status === "pending" && "Transaction Pending"}

<CircularProgress
style={{ color: "grey" }}
color="secondary"
size={30}
/>
</span>
) : (
currentButton()
)}
{currentButton()}
</Button>
</div>
</Card>
Expand Down
Loading

0 comments on commit b701d62

Please sign in to comment.