Compare commits
4 Commits
bc5f88d572
...
175d964b9f
Author | SHA1 | Date | |
---|---|---|---|
175d964b9f | |||
9b1c8c0f09 | |||
3348a99155 | |||
4b1c91b144 |
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
@ -220,7 +220,11 @@ const Bridge = ({ chainId, address, config, connect }) => {
|
||||
|
||||
const preparedAmount = useMemo(() => {
|
||||
try {
|
||||
return BigInt(parseFloat(amount) * Math.pow(10, 18));
|
||||
const result = BigInt(parseFloat(amount) * Math.pow(10, 18));
|
||||
if (result > ghstBalance._value) {
|
||||
return ghstBalance._value;
|
||||
}
|
||||
return result;
|
||||
} catch {
|
||||
return 0n;
|
||||
}
|
||||
@ -248,8 +252,8 @@ const Bridge = ({ chainId, address, config, connect }) => {
|
||||
setIsPending(true);
|
||||
|
||||
const txHash = await ghost(chainId, address, convertedReceiver, preparedAmount);
|
||||
|
||||
await ghstBalanceRefetch();
|
||||
|
||||
setReceiver("");
|
||||
setAmount("");
|
||||
setIsPending(false);
|
||||
|
@ -12,53 +12,41 @@ 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 === "FTSO" && bottomToken === "STNK"):
|
||||
case (upperToken === ftsoSymbol && bottomToken === stnkSymbol):
|
||||
setAction("STAKE")
|
||||
break;
|
||||
case (upperToken === "eCSPR" && bottomToken === "sCSPR"):
|
||||
case (upperToken === ftsoSymbol && bottomToken === ghstSymbol):
|
||||
setAction("STAKE")
|
||||
break;
|
||||
case (upperToken === "FTSO" && bottomToken === "GHST"):
|
||||
setAction("STAKE")
|
||||
break;
|
||||
case (upperToken === "eCSPR" && bottomToken === "CSPR"):
|
||||
setAction("STAKE")
|
||||
break;
|
||||
case (upperToken === "STNK" && bottomToken === "FTSO"):
|
||||
case (upperToken === stnkSymbol && bottomToken === ftsoSymbol):
|
||||
setAction("UNSTAKE")
|
||||
break;
|
||||
case (upperToken === "sCSPR" && bottomToken === "eCSPR"):
|
||||
case (upperToken === ghstSymbol && bottomToken === ftsoSymbol):
|
||||
setAction("UNSTAKE")
|
||||
break;
|
||||
case (upperToken === "GHST" && bottomToken === "FTSO"):
|
||||
setAction("UNSTAKE")
|
||||
break;
|
||||
case (upperToken === "CSPR" && bottomToken === "eCSPR"):
|
||||
setAction("UNSTAKE")
|
||||
break;
|
||||
case (upperToken === "STNK" && bottomToken === "GHST"):
|
||||
case (upperToken === stnkSymbol && bottomToken === ghstSymbol):
|
||||
setAction("WRAP")
|
||||
break;
|
||||
case (upperToken === "sCSPR" && bottomToken === "CSPR"):
|
||||
setAction("WRAP")
|
||||
break;
|
||||
case (upperToken === "GHST" && bottomToken === "STNK"):
|
||||
setAction("UNWRAP")
|
||||
break;
|
||||
case (upperToken === "CSPR" && bottomToken === "sCSPR"):
|
||||
case (upperToken === ghstSymbol && bottomToken === stnkSymbol):
|
||||
setAction("UNWRAP")
|
||||
break;
|
||||
default:
|
||||
|
@ -19,10 +19,16 @@ const ClaimConfirmationModal = (props) => {
|
||||
|
||||
switch (props.action.toUpperCase()) {
|
||||
case "FORFEIT":
|
||||
await forfeit(props.chainId, props.receiver);
|
||||
await forfeit(props.chainId, props.receiver, props.ftsoSymbol);
|
||||
break;
|
||||
case "CLAIM":
|
||||
await claim(props.chainId, props.receiver, props.outputToken === "STNK" || props.outputToken === "sCSPR");
|
||||
await claim(
|
||||
props.chainId,
|
||||
props.receiver,
|
||||
props.outputToken === props.stnkSymbol,
|
||||
props.stnkSymbol,
|
||||
props.ghstSymbol
|
||||
);
|
||||
break;
|
||||
default:
|
||||
console.log("Unknown action")
|
||||
@ -55,7 +61,7 @@ const ClaimConfirmationModal = (props) => {
|
||||
/>
|
||||
<Box display="flex" flexDirection="row" justifyContent="center">
|
||||
<Typography>
|
||||
{props.outputTokenName}
|
||||
{props.outputToken}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
@ -88,8 +88,10 @@ 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 ? "FTSO" : isPayoutGhst ? "GHST" : "STNK"}
|
||||
outputTokenName={claim.expiry > epoch.number ? ftsoSymbol : isPayoutGhst ? ghstSymbol : stnkSymbol}
|
||||
outputToken={claim.expiry > epoch.number ? ftsoSymbol : isPayoutGhst ? ghstSymbol : stnkSymbol}
|
||||
stnkSymbol={stnkSymbol}
|
||||
ghstSymbol={ghstSymbol}
|
||||
ftsoSymbol={ftsoSymbol}
|
||||
action={claim.expiry > epoch.number ? "forfeit" : "claim"}
|
||||
chainId={chainId}
|
||||
/>
|
||||
|
@ -71,18 +71,46 @@ const StakeConfirmationModal = (props) => {
|
||||
|
||||
switch (props.action) {
|
||||
case "STAKE":
|
||||
isRebase = props.bottomToken.toUpperCase() === "STNK";
|
||||
await stake(props.chainId, props.address, actionAmount._value.toBigInt(), isRebase, props.isClaim);
|
||||
isRebase = props.bottomToken === props.stnkSymbol;
|
||||
await stake(
|
||||
props.chainId,
|
||||
props.address,
|
||||
actionAmount._value.toBigInt(),
|
||||
isRebase,
|
||||
props.isClaim,
|
||||
props.ftsoSymbol,
|
||||
props.stnkSymbol,
|
||||
props.ghstSymbol
|
||||
);
|
||||
break;
|
||||
case "UNSTAKE":
|
||||
isRebase = props.upperToken.toUpperCase() === "STNK";
|
||||
await unstake(props.chainId, props.address, actionAmount._value.toBigInt(), props.isTrigger, isRebase);
|
||||
isRebase = props.upperToken === stnkSymbol;
|
||||
await unstake(
|
||||
props.chainId,
|
||||
props.address,
|
||||
actionAmount._value.toBigInt(),
|
||||
props.isTrigger,
|
||||
isRebase,
|
||||
props.ftsoSymbol,
|
||||
props.stnkSymbol,
|
||||
props.ghstSymbol
|
||||
);
|
||||
break;
|
||||
case "WRAP":
|
||||
await wrap(props.chainId, props.address, actionAmount._value.toBigInt());
|
||||
await wrap(
|
||||
props.chainId,
|
||||
props.address,
|
||||
actionAmount._value.toBigInt(),
|
||||
props.ghstSymbol
|
||||
);
|
||||
break;
|
||||
case "UNWRAP":
|
||||
await unwrap(props.chainId, props.address, actionAmount._value.toBigInt());
|
||||
await unwrap(
|
||||
props.chainId,
|
||||
props.address,
|
||||
actionAmount._value.toBigInt(),
|
||||
props.stnkSymbol
|
||||
);
|
||||
break;
|
||||
default:
|
||||
console.log("Wrong action to be executed!");
|
||||
@ -115,7 +143,7 @@ const StakeConfirmationModal = (props) => {
|
||||
/>
|
||||
<Box display="flex" flexDirection="row" justifyContent="center">
|
||||
<Typography>
|
||||
{props.upperToken === "FTSO" ? props.ftsoSymbol : props.upperToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
|
||||
{props.upperToken}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@ -127,7 +155,7 @@ const StakeConfirmationModal = (props) => {
|
||||
/>
|
||||
<Box display="flex" flexDirection="row" justifyContent="center">
|
||||
<Typography>
|
||||
{props.bottomToken === "FTSO" ? props.ftsoSymbol : props.bottomToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
|
||||
{props.bottomToken}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@ -141,7 +169,7 @@ const StakeConfirmationModal = (props) => {
|
||||
owner={props.address}
|
||||
spender={STAKING_ADDRESSES[props.chainId]}
|
||||
decimals={props.spendDecimals}
|
||||
approvalText={"Approve " + props.upperToken === "FTSO" ? props.ftsoSymbol : props.upperToken === "STNK" ? props.stnkSymbol : props.ghstSymbol}
|
||||
approvalText={`Approve ${props.upperToken}`}
|
||||
approvalPendingText={"Approving..."}
|
||||
connect={props.connect}
|
||||
isVertical
|
||||
|
@ -129,33 +129,33 @@ export const StakeInputArea = ({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const innerBalance = upperToken === "GHST" ?
|
||||
const innerBalance = upperToken === ghstSymbol ?
|
||||
ghstBalance
|
||||
:
|
||||
upperToken === "STNK" ?
|
||||
upperToken === stnkSymbol ?
|
||||
stnkBalance
|
||||
:
|
||||
ftsoBalance;
|
||||
|
||||
if (
|
||||
(upperToken === "FTSO" && bottomToken === "STNK") ||
|
||||
(upperToken === "STNK" && bottomToken === "FTSO")
|
||||
(upperToken === ftsoSymbol && bottomToken === stnkSymbol) ||
|
||||
(upperToken === stnkSymbol && bottomToken === ftsoSymbol)
|
||||
) {
|
||||
setReceiveAmount(amount);
|
||||
setExceedsAmount(new DecimalBigNumber(amount, 9).gt(innerBalance))
|
||||
} else {
|
||||
const decimals = upperToken === "GHST" ? 18 : 9;
|
||||
const decimals = upperToken === ghstSymbol ? 18 : 9;
|
||||
const raw = new DecimalBigNumber(amount, decimals);
|
||||
const amountIn = new DecimalBigNumber(raw._value.toBigInt(), decimals);
|
||||
const result = upperToken === "GHST" ?
|
||||
const result = upperToken === ghstSymbol ?
|
||||
currentIndex.mul(amountIn).toString()
|
||||
:
|
||||
currentIndex._value > 0n ? amountIn.div(currentIndex).toString() : "0";
|
||||
|
||||
const innerBalance = upperToken === "GHST" ?
|
||||
const innerBalance = upperToken === ghstSymbol ?
|
||||
ghstBalance
|
||||
:
|
||||
upperToken === "STNK" ?
|
||||
upperToken === stnkSymbol ?
|
||||
stnkBalance
|
||||
:
|
||||
ftsoBalance;
|
||||
@ -168,7 +168,7 @@ export const StakeInputArea = ({
|
||||
const handleTokenModalInput = (value, isUpper) => {
|
||||
if (isUpper) {
|
||||
if (value === bottomToken) {
|
||||
const newValue = value === "GHST" ? "STNK" : "GHST";
|
||||
const newValue = value === ghstSymbol ? stnkSymbol : ghstSymbol;
|
||||
setBottomToken(newValue)
|
||||
}
|
||||
setUpperToken(value);
|
||||
@ -185,28 +185,19 @@ export const StakeInputArea = ({
|
||||
}
|
||||
|
||||
const SwapCardTemplate = (tokenName, tokenAmount, isUpper, handleModal) => {
|
||||
const balance = tokenName === "STNK" || tokenName === "sCSPR" ?
|
||||
stnkBalance : tokenName === "FTSO" || tokenName === "eCSPR" ?
|
||||
ftsoBalance : ghstBalance;
|
||||
const balance = tokenName === stnkSymbol
|
||||
? stnkBalance
|
||||
: tokenName === ftsoSymbol ? ftsoBalance : ghstBalance;
|
||||
|
||||
let realTokenName = "";
|
||||
switch (tokenName.toUpperCase()) {
|
||||
case "FTSO":
|
||||
case ftsoSymbol:
|
||||
realTokenName = ftsoSymbol;
|
||||
break;
|
||||
case "ECSPR":
|
||||
realTokenName = ftsoSymbol;
|
||||
break;
|
||||
case "STNK":
|
||||
case stnkSymbol:
|
||||
realTokenName = stnkSymbol;
|
||||
break;
|
||||
case "SCSPR":
|
||||
realTokenName = stnkSymbol;
|
||||
break;
|
||||
case "GHST":
|
||||
realTokenName = ghstSymbol;
|
||||
break;
|
||||
case "CSPR":
|
||||
case ghstSymbol:
|
||||
realTokenName = ghstSymbol;
|
||||
break;
|
||||
}
|
||||
@ -320,8 +311,8 @@ export const StakeInputArea = ({
|
||||
receiveAmount={receiveAmount}
|
||||
amountExceedsBalance={exceedsAmount}
|
||||
connect={connect}
|
||||
spendDecimals={upperToken === "GHST" ? 18 : 9}
|
||||
receiveDecimals={bottomToken === "GHST" ? 18 : 9}
|
||||
spendDecimals={upperToken === ghstSymbol ? 18 : 9}
|
||||
receiveDecimals={bottomToken === ghstSymbol ? 18 : 9}
|
||||
isClaim={isClaim}
|
||||
isTrigger={isTrigger}
|
||||
ftsoSymbol={ftsoSymbol}
|
||||
|
@ -69,9 +69,9 @@ const TokenModal = ({
|
||||
</Link>
|
||||
</Box>
|
||||
<List>
|
||||
{<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} />}
|
||||
{<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} />}
|
||||
</List>
|
||||
</Box>
|
||||
</Dialog>
|
||||
|
@ -113,7 +113,7 @@ export const useGhostedSupply = (chainId) => {
|
||||
return ghostedSupply;
|
||||
}
|
||||
|
||||
export const stake = async (chainId, account, amount, isRebase, isClaim) => {
|
||||
export const stake = async (chainId, account, amount, isRebase, isClaim, ftsoSymbol, stnkSymbol, ghstSymbol) => {
|
||||
const args = [
|
||||
amount,
|
||||
account,
|
||||
@ -122,7 +122,7 @@ export const stake = async (chainId, account, amount, isRebase, isClaim) => {
|
||||
];
|
||||
const messages = {
|
||||
replacedMsg: "Staking transaction was replaced. Wait for inclusion please.",
|
||||
successMsg: `FTSO tokens staked successfully! Wait for the warmup period to claim your ${isRebase ? "STNK" : "GHST"}.`,
|
||||
successMsg: `${ftsoSymbol} tokens staked successfully! Wait for the warmup period to claim your ${isRebase ? stnkSymbol : ghstSymbol}.`,
|
||||
errorMsg: "Staking transaction failed. Check logs for error detalization.",
|
||||
};
|
||||
await executeOnChainTransaction(
|
||||
@ -134,7 +134,7 @@ export const stake = async (chainId, account, amount, isRebase, isClaim) => {
|
||||
);
|
||||
}
|
||||
|
||||
export const unstake = async (chainId, account, amount, isTrigger, isRebase) => {
|
||||
export const unstake = async (chainId, account, amount, isTrigger, isRebase, ftsoSymbol, stnkSymbol, ghstSymbol) => {
|
||||
const args = [
|
||||
amount,
|
||||
account,
|
||||
@ -143,7 +143,7 @@ export const unstake = async (chainId, account, amount, isTrigger, isRebase) =>
|
||||
];
|
||||
const messages = {
|
||||
replacedMsg: "Unstake transaction was replaced. Wait for inclusion please.",
|
||||
successMsg: `${isRebase ? "STNK" : "GHST"} tokens unstaked successfully! Check your FTSO balance on ${shorten(account)}.`,
|
||||
successMsg: `${isRebase ? stnkSymbol : ghstSymbol} tokens unstaked successfully! Check your ${ftsoSymbol} 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) =>
|
||||
);
|
||||
}
|
||||
|
||||
export const forfeit = async (chainId, account) => {
|
||||
export const forfeit = async (chainId, account, ftsoSymbol) => {
|
||||
const messages = {
|
||||
replacedMsg: "Forfeit transaction was replaced. Wait for inclusion please.",
|
||||
successMsg: `Tokens forfeited successfully! Check your FTSO balance on ${shorten(account)}.`,
|
||||
successMsg: `Tokens forfeited successfully! Check your ${ftsoSymbol} 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) => {
|
||||
);
|
||||
}
|
||||
|
||||
export const claim = async (chainId, account, isStnk) => {
|
||||
export const claim = async (chainId, account, isStnk, stnkSymbol, ghstSymbol) => {
|
||||
const args = [account, isStnk];
|
||||
const messages = {
|
||||
replacedMsg: "Claim transaction was replaced. Wait for inclusion please.",
|
||||
successMsg: `${isStnk ? "STNK" : "GHST"} tokens claimed successfully to ${shorten(account)}.`,
|
||||
successMsg: `${isStnk ? stnkSymbol : ghstSymbol} 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) => {
|
||||
);
|
||||
}
|
||||
|
||||
export const unwrap = async (chainId, account, amount) => {
|
||||
export const unwrap = async (chainId, account, amount, stnkSymbol) => {
|
||||
const messages = {
|
||||
replacedMsg: "Unwrap transaction was replaced. Wait for inclusion please.",
|
||||
successMsg: `Tokens unwrapped successfully! Check your STNK balance on ${shorten(account)}.`,
|
||||
successMsg: `Tokens unwrapped successfully! Check your ${stnkSymbol} 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) => {
|
||||
);
|
||||
}
|
||||
|
||||
export const wrap = async (chainId, account, amount) => {
|
||||
export const wrap = async (chainId, account, amount, ghstSymbol) => {
|
||||
const messages = {
|
||||
replacedMsg: "Wrap transaction was replaced. Wait for inclusion please.",
|
||||
successMsg: `Tokens wrapped successfully! Check your GHST balance on ${shorten(account)}.`,
|
||||
successMsg: `Tokens wrapped successfully! Check your ${ghstSymbol} balance on ${shorten(account)}.`,
|
||||
errorMsg: "Wrap transaction failed. Check logs for error detalization.",
|
||||
};
|
||||
await executeOnChainTransaction(
|
||||
|
Loading…
Reference in New Issue
Block a user