Skip to content

Commit

Permalink
Merge pull request #1341 from ethereum-push-notification-service/chor…
Browse files Browse the repository at this point in the history
…e/read-only-feat-yf

chore: protect yield farming fns in read only mode
  • Loading branch information
kalashshah authored Dec 18, 2023
2 parents 3d00aee + 9c6b5f6 commit fa2bbdd
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
32 changes: 30 additions & 2 deletions src/components/yield/StakingModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import { useClickAway } from 'react-use';
import { Input, Span } from 'primaries/SharedStyling';

// React + Web3 Essentials
import React, { useState } from 'react';
import React, { useContext, useState } from 'react';
import { ethers } from 'ethers';

// External Packages
import styled, { useTheme } from 'styled-components';
import { MdCheckCircle, MdError } from 'react-icons/md';

import { useSelector } from 'react-redux';

// Internal Compoonents
import { ReactComponent as Close } from 'assets/chat/group-chat/close.svg';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import { bn, bnToInt, formatTokens } from 'helpers/StakingHelper';
import { P } from 'components/SharedStyling';
import { ButtonV2, H2V2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';
import { AppContext } from 'contexts/AppContext';

// Internal Configs
import { abis, addresses } from 'config';
Expand All @@ -42,6 +43,11 @@ const StakingModalComponent = ({ onClose, InnerComponentProps, toastObject }) =>

const [txnMessage, setTxnMessage] = useState(null);

const { userPushSDKInstance } = useSelector((state: any) => {
return state.user;
});
const { handleConnectWallet } = useContext(AppContext);

const [depositAmount, setDepositAmount] = useState(0);

const handleClose = () => {
Expand Down Expand Up @@ -88,6 +94,17 @@ const StakingModalComponent = ({ onClose, InnerComponentProps, toastObject }) =>
}, [])

const approveDeposit = async () => {
if(!userPushSDKInstance.signer) {
toastObject.showMessageToast({
toastTitle: 'Error',
toastMessage: `Please connect your wallet`,
toastType: 'ERROR',
getToastIcon: (size) => <MdError size={size} color="red" />,
});
handleConnectWallet();
return;
}

if (depositApproved || txInProgressApprDep) {
return
}
Expand Down Expand Up @@ -158,6 +175,17 @@ const StakingModalComponent = ({ onClose, InnerComponentProps, toastObject }) =>
}

const depositAmountTokenFarmSingleTx = async () => {
if(!userPushSDKInstance.signer) {
toastObject.showMessageToast({
toastTitle: 'Error',
toastMessage: `Please connect your wallet`,
toastType: 'ERROR',
getToastIcon: (size) => <MdError size={size} color="red" />,
});
handleConnectWallet();
return;
}

if (txInProgressDep || !depositApproved) {
return
}
Expand Down
63 changes: 62 additions & 1 deletion src/components/yield/YieldPoolCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// React + Web3 Essentials
import React, { useEffect, useState } from 'react';
import React, { useContext, useState } from 'react';
import { ethers } from 'ethers';

// External Packages
import styled, { useTheme } from 'styled-components';
import { MdCheckCircle, MdError, MdWarning } from 'react-icons/md';
import { useSelector } from 'react-redux';

// Internal Compoonents
import useToast from 'hooks/useToast';
Expand All @@ -16,6 +17,7 @@ import { Button, Span } from 'primaries/SharedStyling';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import { formatTokens, numberWithCommas } from 'helpers/StakingHelper';
import { ButtonV2, H2V2, ImageV2, ItemHV2, ItemVV2, SectionV2, Skeleton, SkeletonLine, SpanV2 } from 'components/reusables/SharedStylingV2';
import { AppContext } from 'contexts/AppContext';

// Internal Configs
import { abis, addresses } from 'config';
Expand All @@ -41,13 +43,29 @@ const YieldPoolCard = ({
const [unstakeErrorMessage, setUnstakeErrorMessage] = useState(null);
const [withdrawErrorMessage, setWithdrawErrorMessage] = useState(null);

const { userPushSDKInstance } = useSelector((state: any) => {
return state.user;
});
const { handleConnectWallet } = useContext(AppContext);

const [filled, setFilled] = useState(0);

const yieldFarmToast = useToast();

const theme = useTheme();

const massClaimRewardsTokensAll = async () => {
if(!userPushSDKInstance.signer) {
yieldFarmToast.showMessageToast({
toastTitle: 'Error',
toastMessage: `Please connect your wallet`,
toastType: 'ERROR',
getToastIcon: (size) => <MdError size={size} color="red" />,
});
handleConnectWallet();
return;
}

if (txInProgressClaimRewards) {
return;
}
Expand Down Expand Up @@ -126,6 +144,17 @@ const YieldPoolCard = ({
};

const withdrawTokens = async () => {
if(!userPushSDKInstance.signer) {
yieldFarmToast.showMessageToast({
toastTitle: 'Error',
toastMessage: `Please connect your wallet`,
toastType: 'ERROR',
getToastIcon: (size) => <MdError size={size} color="red" />,
});
handleConnectWallet();
return;
}

if (txInProgressWithdraw) {
return;
}
Expand Down Expand Up @@ -197,6 +226,17 @@ const YieldPoolCard = ({
};

const migrateToNewPool = async () => {
if(!userPushSDKInstance.signer) {
yieldFarmToast.showMessageToast({
toastTitle: 'Error',
toastMessage: `Please connect your wallet`,
toastType: 'ERROR',
getToastIcon: (size) => <MdError size={size} color="red" />,
});
handleConnectWallet();
return;
}

if (txInProgressMigrate) {
return;
}
Expand Down Expand Up @@ -421,6 +461,17 @@ const YieldPoolCard = ({


const depositLpToken = async (tx, withdrawAmount, totalTxnSteps) => {
if(!userPushSDKInstance.signer) {
yieldFarmToast.showMessageToast({
toastTitle: 'Error',
toastMessage: `Please connect your wallet`,
toastType: 'ERROR',
getToastIcon: (size) => <MdError size={size} color="red" />,
});
handleConnectWallet();
return;
}

var signer = provider.getSigner(account);
var stakingV2 = new ethers.Contract(addresses.stakingV2, abis.stakingV2, signer);

Expand Down Expand Up @@ -471,6 +522,16 @@ const YieldPoolCard = ({
}

const depositPushToken = async (tx, withdrawAmount, totalTxnSteps) => {
if(!userPushSDKInstance.signer) {
yieldFarmToast.showMessageToast({
toastTitle: 'Error',
toastMessage: `Please connect your wallet`,
toastType: 'ERROR',
getToastIcon: (size) => <MdError size={size} color="red" />,
});
handleConnectWallet();
return;
}

var signer = provider.getSigner(account);
let pushCoreV2 = new ethers.Contract(addresses.pushCoreV2, abis.pushCoreV2, signer);
Expand Down

0 comments on commit fa2bbdd

Please sign in to comment.