Skip to content

Commit

Permalink
Merge pull request #199 from the-standard/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
ZakMooney authored Apr 8, 2024
2 parents 826b8ea + d55810c commit 203df80
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 74 deletions.
19 changes: 19 additions & 0 deletions src/assets/rdntlogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 19 additions & 20 deletions src/components/collateral/Debt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Debt: React.FC<DebtProps> = ({
const [activeElement, setActiveElement] = useState(1);
// const { windowWidth, windowHeight } = useWindowSize();
const { address } = useAccount();
const [amount, setAmount] = useState<any>(0);
const [ amount, setAmount ] = useState<any>(BigInt(0));
const { vaultAddress } = useVaultAddressStore();
// const { vaultStore }: any = useVaultStore();
const { arbitrumsEuroAddress, arbitrumSepoliasEuroAddress } =
Expand Down Expand Up @@ -85,8 +85,6 @@ const Debt: React.FC<DebtProps> = ({
getCounter(1);
};

const amountInWei = parseEther(amount.toString());

const debtValue: any = ethers.BigNumber.from(currentVault?.status?.minted);

const eurosAddress = chainId === arbitrumSepolia.id ?
Expand Down Expand Up @@ -128,8 +126,8 @@ const Debt: React.FC<DebtProps> = ({

const handleAmount = (e: any) => {
if (Number(e.target.value) < 10n ** 21n) {
setAmount(Number(e.target.value));
getGreyBarUserInput(e.target.value);
setAmount(parseEther(e.target.value.toString()))
getGreyBarUserInput(formatEther(parseEther(e.target.value.toString())));
}
};

Expand All @@ -145,7 +143,7 @@ const Debt: React.FC<DebtProps> = ({
}

useEffect(() => {
setAmount(0);
setAmount(BigInt(0));
setActiveElement(4);
handleInputFocus();
getOperationType(4);
Expand All @@ -155,7 +153,7 @@ const Debt: React.FC<DebtProps> = ({
useEffect(() => {
return () => {
// Perform any cleanup tasks or actions you want before the component unmounts
setAmount(0);
setAmount(BigInt(0));
getGreyBarUserInput(0);
};
}, []);
Expand All @@ -169,7 +167,7 @@ const Debt: React.FC<DebtProps> = ({
abi: smartVaultAbi,
address: vaultAddress as any,
functionName: "mint",
args: [address as any, amountInWei],
args: [address as any, amount],
});

// getSnackBar('SUCCESS', 'Success!');
Expand All @@ -193,7 +191,7 @@ const Debt: React.FC<DebtProps> = ({
const handleCloseYield = () => setYieldModalOpen(false);

const burnFeeRate: bigint = currentVault?.burnFeeRate;
const repayFee = amountInWei * burnFeeRate / HUNDRED_PC;
const repayFee = amount * burnFeeRate / HUNDRED_PC;

const handleApprove = async () => {
setStage('APPROVE');
Expand Down Expand Up @@ -236,7 +234,7 @@ const Debt: React.FC<DebtProps> = ({
abi: smartVaultAbi,
address: vaultAddress as any,
functionName: "burn",
args: [amountInWei],
args: [amount],
});

// getSnackBar('SUCCESS', 'Success!');
Expand Down Expand Up @@ -332,15 +330,15 @@ const Debt: React.FC<DebtProps> = ({
};

const calculateRepaymentWithFee = () => {
return amountInWei + calculateRateAmount(amountInWei, currentVault?.burnFeeRate);
return amount + calculateRateAmount(amount, currentVault?.burnFeeRate);
}

const handleDebtAction = () => {
if (activeElement === 4) {
getCircularProgress(true);
handleMint();
} else {
if (amountInWei > currentVault?.status.minted) {
if (amount > currentVault?.status.minted) {
alert('Repayment amount exceeds debt in vault');
} else if (eurosWalletBalance < calculateRepaymentWithFee()) {
alert('Repayment amount exceeds your EUROs balance');
Expand Down Expand Up @@ -383,15 +381,15 @@ const Debt: React.FC<DebtProps> = ({
},
{
key: `Minting Fee (${toPercentage(currentVault?.mintFeeRate)}%)`,
value: formatEther(calculateRateAmount(amountInWei, currentVault?.mintFeeRate)),
value: formatEther(calculateRateAmount(amount, currentVault?.mintFeeRate)),
},
{
key: "Borrowing",
value: formatEther(amountInWei + calculateRateAmount(amountInWei, currentVault?.mintFeeRate)),
value: formatEther(amount + calculateRateAmount(amount, currentVault?.mintFeeRate)),
},
{
key: "Receiving",
value: amount,
value: formatEther(amount),
},
];
const repayValues = [
Expand All @@ -401,15 +399,15 @@ const Debt: React.FC<DebtProps> = ({
},
{
key: `Burn Fee (${toPercentage(currentVault?.burnFeeRate)}%)`,
value: formatEther(calculateRateAmount(amountInWei, currentVault?.burnFeeRate)),
value: formatEther(calculateRateAmount(amount, currentVault?.burnFeeRate)),
},
{
key: "Actual Repayment",
value: amount,
key: "Repaying",
value: formatEther(amount),
},
{
key: "Send",
value: formatEther(amountInWei + calculateRateAmount(amountInWei, currentVault?.burnFeeRate)),
key: "Sending",
value: formatEther(amount + calculateRateAmount(amount, currentVault?.burnFeeRate)),
},
];

Expand Down Expand Up @@ -654,6 +652,7 @@ const Debt: React.FC<DebtProps> = ({
marginLeft: "10px",
}}
clickFunction={handleDebtAction}
isDisabled={isPending}
>
{activeElement === 4 ? "Withdraw" : "Repay"}
</Button>
Expand Down
9 changes: 9 additions & 0 deletions src/components/collateral/VaultToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import linklogo from "../../assets/linklogo.svg";
import paxglogo from "../../assets/paxglogo.svg";
import arblogo from "../../assets/arblogo.svg";
import gmxlogo from "../../assets/gmxlogo.svg";
import rdntlogo from "../../assets/rdntlogo.svg";
import Button from "../../components/Button";

const tokenIcon = (symbol: any) => {
Expand Down Expand Up @@ -75,6 +76,14 @@ const tokenIcon = (symbol: any) => {
alt="gmx logo"
/>
);
case 'RDNT':
return (
<img
style={{ height: "2rem", width: "2rem" }}
src={rdntlogo}
alt="rdnt logo"
/>
);
default:
return (
<Typography variant="body2"> {symbol}</Typography>
Expand Down
21 changes: 9 additions & 12 deletions src/components/collateral/actions/Deposit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Modal, Typography } from "@mui/material";
import { useEffect, useRef, useState } from "react";
import QRCode from "react-qr-code";
import { parseEther, parseUnits } from "viem";
import { parseUnits, formatUnits } from "viem";
import { sendTransaction } from "@wagmi/core";
import {
useWriteContract,
Expand All @@ -11,7 +11,7 @@ import {
useWatchBlockNumber
} from "wagmi";
import { constants } from "ethers";
import { formatUnits } from "ethers/lib/utils";
// import { formatUnits } from "ethers/lib/utils";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";

import {
Expand Down Expand Up @@ -42,7 +42,7 @@ const Deposit: React.FC<DepositProps> = ({
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
const [amount, setAmount] = useState(0);
const [amount, setAmount] = useState<any>(0);
const [maxBal, setMaxBal] = useState(0);
///store
const { vaultAddress } = useVaultAddressStore();
Expand Down Expand Up @@ -71,7 +71,7 @@ const Deposit: React.FC<DepositProps> = ({
},
})

const walletBalance = balanceData?.value;
const walletBalance: any = balanceData?.value;

const inputRef: any = useRef<HTMLInputElement>(null);

Expand All @@ -81,9 +81,9 @@ const Deposit: React.FC<DepositProps> = ({

const handleAmount = (e: any) => {
if (Number(e.target.value) < 10n ** 21n) {
setAmount(Number(e.target.value));
setAmount(parseUnits(e.target.value.toString(), decimals))
getSymbolForGreyBar(symbol);
getGreyBarUserInput(Number(e.target.value));
getGreyBarUserInput(formatUnits(parseUnits(e.target.value.toString(), decimals), decimals));
}
};

Expand Down Expand Up @@ -119,10 +119,9 @@ const Deposit: React.FC<DepositProps> = ({
abi: erc20Abi,
address: tokenAddress as any,
functionName: "transfer",
args: [vaultAddress, parseUnits(amount.toString(), decimals)],
args: [vaultAddress, amount],
});

getSnackBar('SUCCESS', 'Success!');
} catch (error: any) {
let errorMessage: any = '';
if (error && error.shortMessage) {
Expand Down Expand Up @@ -156,13 +155,12 @@ const Deposit: React.FC<DepositProps> = ({
const hash = await sendTransaction(wagmiConfig, {
account: address,
to: toAddress,
value: parseEther(txAmount.toString()),
value: txAmount,
})

setTxdata(hash);

getCircularProgress(false); // Set getCircularProgress to false after the transaction is mined
getSnackBar('SUCCESS', 'Success!');
inputRef.current.value = "";
inputRef.current.focus();
getGreyBarUserInput(0);
Expand Down Expand Up @@ -215,6 +213,7 @@ const Deposit: React.FC<DepositProps> = ({
getProgressType(2);
getCircularProgress(true);
} else if (isSuccess) {
getSnackBar('SUCCESS', 'Success!');
getCircularProgress(false); // Set getCircularProgress to false after the transaction is mined
inputRef.current.value = "";
inputRef.current.focus();
Expand Down Expand Up @@ -305,7 +304,6 @@ const Deposit: React.FC<DepositProps> = ({
}}
clickFunction={handleOpen}
>
{" "}
<img
style={{
height: "23px",
Expand Down Expand Up @@ -514,7 +512,6 @@ const Deposit: React.FC<DepositProps> = ({
}}
onClick={handleCopyText}
>
{" "}
<ContentCopyIcon />
</Box>
</Box>
Expand Down
39 changes: 19 additions & 20 deletions src/components/collateral/actions/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const Swap: React.FC<SwapProps> = ({
const [swapLoading, setSwapLoading] = useState<any>(false);
const [swapAssets, setSwapAssets] = useState<any>();
const [amount, setAmount] = useState<any>(0);
// const [receiveAmount, setReceiveAmount] = useState<any>(0);
const [receiveAmountFormatted, setReceiveAmountFormatted] = useState<any>(0);
const [receiveAmount, setReceiveAmount] = useState<any>(0);
const [receiveAsset, setReceiveAsset] = useState<any>('');
const [receiveDecimals, setReceiveDecimals] = useState<any>();
const { vaultStore } = useVaultStore();
Expand All @@ -57,24 +56,25 @@ const Swap: React.FC<SwapProps> = ({
};

const handleAmount = (e: any) => {
setAmount(Number(e.target.value));
setAmount(parseUnits(e.target.value.toString(), decimals))
};

const handleMinReturn = (e: any) => {
setReceiveAmountFormatted(e.target.value);
setReceiveAmount(parseUnits(e.target.value.toString(), receiveDecimals));
};

const getSwapConversion = async () => {
try {
setSwapLoading(true);
const swapIn = symbol;
const swapOut = receiveAsset;
const swapAmount = parseUnits(amount.toString(), decimals);
const swapAmount = amount.toString();
const response = await axios.get(
`https://smart-vault-api.thestandard.io/estimate_swap?in=${swapIn}&out=${swapOut}&amount=${swapAmount}`
);
const data = response.data;
setReceiveAmountFormatted(formatUnits(data.toString(), receiveDecimals));
setReceiveAmount(BigInt(data));
inputReceiveRef.current.value = formatUnits(data.toString(), receiveDecimals);
setSwapLoading(false);
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -119,12 +119,10 @@ const Swap: React.FC<SwapProps> = ({
args: [
ethers.utils.formatBytes32String(symbol),
ethers.utils.formatBytes32String(receiveAsset),
parseUnits(amount.toString(), decimals),
parseUnits(receiveAmountFormatted.toString(), receiveDecimals),
amount,
receiveAmount,
],
});

// getSnackBar('SUCCESS', 'Success!');
} catch (error: any) {
let errorMessage: any = '';
if (error && error.shortMessage) {
Expand All @@ -145,15 +143,15 @@ const Swap: React.FC<SwapProps> = ({
setSwapLoading(false);
inputRef.current.value = "";
setAmount(0);
setReceiveAmountFormatted(0);
setReceiveAmount(0);
setReceiveAsset('');
} else if (isError) {
getSnackBar('ERROR', 'There was an error');
getCircularProgress(false);
setSwapLoading(false);
inputRef.current.value = "";
setAmount(0);
setReceiveAmountFormatted(0);
setReceiveAmount(0);
setReceiveAsset('');
}
}, [
Expand All @@ -164,8 +162,9 @@ const Swap: React.FC<SwapProps> = ({
]);

const handleMaxBalance = async () => {
inputRef.current.value = collateralValue.toString();
handleAmount({ target: { value: collateralValue } });
const formatted = formatUnits(parseUnits(collateralValue.toString(), decimals), decimals);
inputRef.current.value = formatted;
handleAmount({ target: { value: formatted } });
};

if (vaultStore.status.version !== 1 && vaultStore.status.version !== 2) {
Expand Down Expand Up @@ -331,11 +330,11 @@ const Swap: React.FC<SwapProps> = ({
MozBoxSizing: "border-box",
WebkitBoxSizing: "border-box",
}}
value={swapLoading ? (
''
) : (
receiveAmountFormatted
)}
// value={swapLoading ? (
// ''
// ) : (
// receiveAmount
// )}
ref={inputReceiveRef}
type="number"
onChange={handleMinReturn}
Expand Down Expand Up @@ -399,7 +398,7 @@ const Swap: React.FC<SwapProps> = ({
isDisabled={
!amount||
!receiveAsset ||
!(receiveAmountFormatted > 0) ||
!(receiveAmount > 0) ||
swapLoading
}
isSuccess={!swapLoading}
Expand Down
Loading

0 comments on commit 203df80

Please sign in to comment.