Compare commits

..

No commits in common. "175d964b9fed45524cecfd63654d79ee19bc3d4a" and "bc5f88d57255773178f3134dc5a74f1927bbb639" have entirely different histories.

9 changed files with 84 additions and 103 deletions

View File

@ -1,7 +1,7 @@
{
"name": "ghost-dao-interface",
"private": true,
"version": "0.2.4",
"version": "0.2.0",
"type": "module",
"scripts": {
"dev": "vite",

View File

@ -220,11 +220,7 @@ const Bridge = ({ chainId, address, config, connect }) => {
const preparedAmount = useMemo(() => {
try {
const result = BigInt(parseFloat(amount) * Math.pow(10, 18));
if (result > ghstBalance._value) {
return ghstBalance._value;
}
return result;
return BigInt(parseFloat(amount) * Math.pow(10, 18));
} catch {
return 0n;
}
@ -252,8 +248,8 @@ const Bridge = ({ chainId, address, config, connect }) => {
setIsPending(true);
const txHash = await ghost(chainId, address, convertedReceiver, preparedAmount);
await ghstBalanceRefetch();
await ghstBalanceRefetch();
setReceiver("");
setAmount("");
setIsPending(false);

View File

@ -12,41 +12,53 @@ import GhostStyledIcon from "../../components/Icon/GhostIcon";
import Modal from "../../components/Modal/Modal";
import Paper from "../../components/Paper/Paper";
import TokenStack from "../../components/TokenStack/TokenStack";
import { useTokenSymbol } from "../../hooks/tokens";
const Stake = ({ chainId, address, isOpened, closeModal, connect }) => {
const [action, setAction] = useState("STAKE");
const [upperToken, setUpperToken] = useState("FTSO");
const [bottomToken, setBottomToken] = useState("GHST");
const [settingsModalOpen, setSettingsModalOpen] = useState(false);
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
const { symbol: stnkSymbol } = useTokenSymbol(chainId, "STNK");
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
const [upperToken, setUpperToken] = useState(ftsoSymbol);
const [bottomToken, setBottomToken] = useState(ghstSymbol);
const setSettingsModalOpenInner = (value) => {
setSettingsModalOpen(value);
}
useEffect(() => {
switch (true) {
case (upperToken === ftsoSymbol && bottomToken === stnkSymbol):
case (upperToken === "FTSO" && bottomToken === "STNK"):
setAction("STAKE")
break;
case (upperToken === ftsoSymbol && bottomToken === ghstSymbol):
case (upperToken === "eCSPR" && bottomToken === "sCSPR"):
setAction("STAKE")
break;
case (upperToken === stnkSymbol && bottomToken === ftsoSymbol):
case (upperToken === "FTSO" && bottomToken === "GHST"):
setAction("STAKE")
break;
case (upperToken === "eCSPR" && bottomToken === "CSPR"):
setAction("STAKE")
break;
case (upperToken === "STNK" && bottomToken === "FTSO"):
setAction("UNSTAKE")
break;
case (upperToken === ghstSymbol && bottomToken === ftsoSymbol):
case (upperToken === "sCSPR" && bottomToken === "eCSPR"):
setAction("UNSTAKE")
break;
case (upperToken === stnkSymbol && bottomToken === ghstSymbol):
case (upperToken === "GHST" && bottomToken === "FTSO"):
setAction("UNSTAKE")
break;
case (upperToken === "CSPR" && bottomToken === "eCSPR"):
setAction("UNSTAKE")
break;
case (upperToken === "STNK" && bottomToken === "GHST"):
setAction("WRAP")
break;
case (upperToken === ghstSymbol && bottomToken === stnkSymbol):
case (upperToken === "sCSPR" && bottomToken === "CSPR"):
setAction("WRAP")
break;
case (upperToken === "GHST" && bottomToken === "STNK"):
setAction("UNWRAP")
break;
case (upperToken === "CSPR" && bottomToken === "sCSPR"):
setAction("UNWRAP")
break;
default:

View File

@ -19,16 +19,10 @@ const ClaimConfirmationModal = (props) => {
switch (props.action.toUpperCase()) {
case "FORFEIT":
await forfeit(props.chainId, props.receiver, props.ftsoSymbol);
await forfeit(props.chainId, props.receiver);
break;
case "CLAIM":
await claim(
props.chainId,
props.receiver,
props.outputToken === props.stnkSymbol,
props.stnkSymbol,
props.ghstSymbol
);
await claim(props.chainId, props.receiver, props.outputToken === "STNK" || props.outputToken === "sCSPR");
break;
default:
console.log("Unknown action")
@ -61,7 +55,7 @@ const ClaimConfirmationModal = (props) => {
/>
<Box display="flex" flexDirection="row" justifyContent="center">
<Typography>
{props.outputToken}
{props.outputTokenName}
</Typography>
</Box>
</Box>

View File

@ -88,10 +88,8 @@ export const ClaimsArea = ({ chainId, address, epoch }) => {
chainid={chainId}
receiver={address}
receiveAmount={claim.expiry > epoch.number ? claim.deposit : isPayoutGhst ? balanceForShares.div(currentIndex) : balanceForShares}
outputToken={claim.expiry > epoch.number ? ftsoSymbol : isPayoutGhst ? ghstSymbol : stnkSymbol}
stnkSymbol={stnkSymbol}
ghstSymbol={ghstSymbol}
ftsoSymbol={ftsoSymbol}
outputToken={claim.expiry > epoch.number ? "FTSO" : isPayoutGhst ? "GHST" : "STNK"}
outputTokenName={claim.expiry > epoch.number ? ftsoSymbol : isPayoutGhst ? ghstSymbol : stnkSymbol}
action={claim.expiry > epoch.number ? "forfeit" : "claim"}
chainId={chainId}
/>

View File

@ -71,46 +71,18 @@ const StakeConfirmationModal = (props) => {
switch (props.action) {
case "STAKE":
isRebase = props.bottomToken === props.stnkSymbol;
await stake(
props.chainId,
props.address,
actionAmount._value.toBigInt(),
isRebase,
props.isClaim,
props.ftsoSymbol,
props.stnkSymbol,
props.ghstSymbol
);
isRebase = props.bottomToken.toUpperCase() === "STNK";
await stake(props.chainId, props.address, actionAmount._value.toBigInt(), isRebase, props.isClaim);
break;
case "UNSTAKE":
isRebase = props.upperToken === stnkSymbol;
await unstake(
props.chainId,
props.address,
actionAmount._value.toBigInt(),
props.isTrigger,
isRebase,
props.ftsoSymbol,
props.stnkSymbol,
props.ghstSymbol
);
isRebase = props.upperToken.toUpperCase() === "STNK";
await unstake(props.chainId, props.address, actionAmount._value.toBigInt(), props.isTrigger, isRebase);
break;
case "WRAP":
await wrap(
props.chainId,
props.address,
actionAmount._value.toBigInt(),
props.ghstSymbol
);
await wrap(props.chainId, props.address, actionAmount._value.toBigInt());
break;
case "UNWRAP":
await unwrap(
props.chainId,
props.address,
actionAmount._value.toBigInt(),
props.stnkSymbol
);
await unwrap(props.chainId, props.address, actionAmount._value.toBigInt());
break;
default:
console.log("Wrong action to be executed!");
@ -143,7 +115,7 @@ const StakeConfirmationModal = (props) => {
/>
<Box display="flex" flexDirection="row" justifyContent="center">
<Typography>
{props.upperToken}
{props.upperToken === "FTSO" ? props.ftsoSymbol : props.upperToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
</Typography>
</Box>
</Box>
@ -155,7 +127,7 @@ const StakeConfirmationModal = (props) => {
/>
<Box display="flex" flexDirection="row" justifyContent="center">
<Typography>
{props.bottomToken}
{props.bottomToken === "FTSO" ? props.ftsoSymbol : props.bottomToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
</Typography>
</Box>
</Box>
@ -169,7 +141,7 @@ const StakeConfirmationModal = (props) => {
owner={props.address}
spender={STAKING_ADDRESSES[props.chainId]}
decimals={props.spendDecimals}
approvalText={`Approve ${props.upperToken}`}
approvalText={"Approve " + props.upperToken === "FTSO" ? props.ftsoSymbol : props.upperToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
approvalPendingText={"Approving..."}
connect={props.connect}
isVertical

View File

@ -129,33 +129,33 @@ export const StakeInputArea = ({
}
useEffect(() => {
const innerBalance = upperToken === ghstSymbol ?
const innerBalance = upperToken === "GHST" ?
ghstBalance
:
upperToken === stnkSymbol ?
upperToken === "STNK" ?
stnkBalance
:
ftsoBalance;
if (
(upperToken === ftsoSymbol && bottomToken === stnkSymbol) ||
(upperToken === stnkSymbol && bottomToken === ftsoSymbol)
(upperToken === "FTSO" && bottomToken === "STNK") ||
(upperToken === "STNK" && bottomToken === "FTSO")
) {
setReceiveAmount(amount);
setExceedsAmount(new DecimalBigNumber(amount, 9).gt(innerBalance))
} else {
const decimals = upperToken === ghstSymbol ? 18 : 9;
const decimals = upperToken === "GHST" ? 18 : 9;
const raw = new DecimalBigNumber(amount, decimals);
const amountIn = new DecimalBigNumber(raw._value.toBigInt(), decimals);
const result = upperToken === ghstSymbol ?
const result = upperToken === "GHST" ?
currentIndex.mul(amountIn).toString()
:
currentIndex._value > 0n ? amountIn.div(currentIndex).toString() : "0";
const innerBalance = upperToken === ghstSymbol ?
const innerBalance = upperToken === "GHST" ?
ghstBalance
:
upperToken === stnkSymbol ?
upperToken === "STNK" ?
stnkBalance
:
ftsoBalance;
@ -168,7 +168,7 @@ export const StakeInputArea = ({
const handleTokenModalInput = (value, isUpper) => {
if (isUpper) {
if (value === bottomToken) {
const newValue = value === ghstSymbol ? stnkSymbol : ghstSymbol;
const newValue = value === "GHST" ? "STNK" : "GHST";
setBottomToken(newValue)
}
setUpperToken(value);
@ -185,19 +185,28 @@ export const StakeInputArea = ({
}
const SwapCardTemplate = (tokenName, tokenAmount, isUpper, handleModal) => {
const balance = tokenName === stnkSymbol
? stnkBalance
: tokenName === ftsoSymbol ? ftsoBalance : ghstBalance;
const balance = tokenName === "STNK" || tokenName === "sCSPR" ?
stnkBalance : tokenName === "FTSO" || tokenName === "eCSPR" ?
ftsoBalance : ghstBalance;
let realTokenName = "";
switch (tokenName.toUpperCase()) {
case ftsoSymbol:
case "FTSO":
realTokenName = ftsoSymbol;
break;
case stnkSymbol:
case "ECSPR":
realTokenName = ftsoSymbol;
break;
case "STNK":
realTokenName = stnkSymbol;
break;
case ghstSymbol:
case "SCSPR":
realTokenName = stnkSymbol;
break;
case "GHST":
realTokenName = ghstSymbol;
break;
case "CSPR":
realTokenName = ghstSymbol;
break;
}
@ -311,8 +320,8 @@ export const StakeInputArea = ({
receiveAmount={receiveAmount}
amountExceedsBalance={exceedsAmount}
connect={connect}
spendDecimals={upperToken === ghstSymbol ? 18 : 9}
receiveDecimals={bottomToken === ghstSymbol ? 18 : 9}
spendDecimals={upperToken === "GHST" ? 18 : 9}
receiveDecimals={bottomToken === "GHST" ? 18 : 9}
isClaim={isClaim}
isTrigger={isTrigger}
ftsoSymbol={ftsoSymbol}

View File

@ -69,9 +69,9 @@ const TokenModal = ({
</Link>
</Box>
<List>
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token={ftsoSymbol} name={ftsoSymbol} balance={ftsoBalance} />}
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token={stnkSymbol} name={stnkSymbol} balance={stnkBalance} />}
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token={ghstSymbol} name={ghstSymbol} balance={ghstBalance} />}
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token="FTSO" name={ftsoSymbol} balance={ftsoBalance} />}
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token="STNK" name={stnkSymbol} balance={stnkBalance} />}
{<TokenItem isUpper={isUpper} exclude={tokenToExclude} token="GHST" name={ghstSymbol} balance={ghstBalance} />}
</List>
</Box>
</Dialog>

View File

@ -113,7 +113,7 @@ export const useGhostedSupply = (chainId) => {
return ghostedSupply;
}
export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSymbol, stnkSymbol, ghstSymbol) => {
export const stake = async (chainId, account, amount, isRebase, isClaim) => {
const args = [
amount,
account,
@ -122,7 +122,7 @@ export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSym
];
const messages = {
replacedMsg: "Staking transaction was replaced. Wait for inclusion please.",
successMsg: `${ftsoSymbol} tokens staked successfully! Wait for the warmup period to claim your ${isRebase ? stnkSymbol : ghstSymbol}.`,
successMsg: `FTSO tokens staked successfully! Wait for the warmup period to claim your ${isRebase ? "STNK" : "GHST"}.`,
errorMsg: "Staking transaction failed. Check logs for error detalization.",
};
await executeOnChainTransaction(
@ -134,7 +134,7 @@ export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSym
);
}
export const unstake = async (chainId, account, amount, isTrigger, isRebase, ftsoSymbol, stnkSymbol, ghstSymbol) => {
export const unstake = async (chainId, account, amount, isTrigger, isRebase) => {
const args = [
amount,
account,
@ -143,7 +143,7 @@ export const unstake = async (chainId, account, amount, isTrigger, isRebase, fts
];
const messages = {
replacedMsg: "Unstake transaction was replaced. Wait for inclusion please.",
successMsg: `${isRebase ? stnkSymbol : ghstSymbol} tokens unstaked successfully! Check your ${ftsoSymbol} balance on ${shorten(account)}.`,
successMsg: `${isRebase ? "STNK" : "GHST"} tokens unstaked successfully! Check your FTSO balance on ${shorten(account)}.`,
errorMsg: "Unstake transaction failed. Check logs for error detalization.",
};
await executeOnChainTransaction(
@ -155,10 +155,10 @@ export const unstake = async (chainId, account, amount, isTrigger, isRebase, fts
);
}
export const forfeit = async (chainId, account, ftsoSymbol) => {
export const forfeit = async (chainId, account) => {
const messages = {
replacedMsg: "Forfeit transaction was replaced. Wait for inclusion please.",
successMsg: `Tokens forfeited successfully! Check your ${ftsoSymbol} balance on ${shorten(account)}.`,
successMsg: `Tokens forfeited successfully! Check your FTSO balance on ${shorten(account)}.`,
errorMsg: "Forfeit transaction failed. Check logs for error detalization.",
};
await executeOnChainTransaction(
@ -170,11 +170,11 @@ export const forfeit = async (chainId, account, ftsoSymbol) => {
);
}
export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) => {
export const claim = async (chainId, account, isStnk) => {
const args = [account, isStnk];
const messages = {
replacedMsg: "Claim transaction was replaced. Wait for inclusion please.",
successMsg: `${isStnk ? stnkSymbol : ghstSymbol} tokens claimed successfully to ${shorten(account)}.`,
successMsg: `${isStnk ? "STNK" : "GHST"} tokens claimed successfully to ${shorten(account)}.`,
errorMsg: "Claim transaction failed. Check logs for error detalization.",
};
await executeOnChainTransaction(
@ -186,10 +186,10 @@ export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) =>
);
}
export const unwrap = async (chainId, account, amount, stnkSymbol) => {
export const unwrap = async (chainId, account, amount) => {
const messages = {
replacedMsg: "Unwrap transaction was replaced. Wait for inclusion please.",
successMsg: `Tokens unwrapped successfully! Check your ${stnkSymbol} balance on ${shorten(account)}.`,
successMsg: `Tokens unwrapped successfully! Check your STNK balance on ${shorten(account)}.`,
errorMsg: "Unwrap transaction failed. Check logs for error detalization.",
};
await executeOnChainTransaction(
@ -201,10 +201,10 @@ export const unwrap = async (chainId, account, amount, stnkSymbol) => {
);
}
export const wrap = async (chainId, account, amount, ghstSymbol) => {
export const wrap = async (chainId, account, amount) => {
const messages = {
replacedMsg: "Wrap transaction was replaced. Wait for inclusion please.",
successMsg: `Tokens wrapped successfully! Check your ${ghstSymbol} balance on ${shorten(account)}.`,
successMsg: `Tokens wrapped successfully! Check your GHST balance on ${shorten(account)}.`,
errorMsg: "Wrap transaction failed. Check logs for error detalization.",
};
await executeOnChainTransaction(