add maximum gatekeeped amount guard
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
7d4085f226
commit
62cd599250
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.10",
|
||||
"version": "0.8.11",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -535,9 +535,13 @@ const BridgeIn = ({ chainId, address, config, connect }) => {
|
||||
/>
|
||||
|
||||
<DataRow
|
||||
title={`Min Bridge-In`}
|
||||
title={<Typography variant="caption">Min Bridge-In</Typography>}
|
||||
tooltip="Minimum amount that could be handled by the bridge to avoid dust balances."
|
||||
balance={<span>{formatCurrency(existentialDeposit.toString(), formatDecimals, ghstSymbol)}</span>}
|
||||
balance={
|
||||
<Typography variant="caption">
|
||||
{formatCurrency(existentialDeposit.toString(), formatDecimals, ghstSymbol)}
|
||||
</Typography>
|
||||
}
|
||||
/>
|
||||
|
||||
<PrimaryButton
|
||||
|
||||
@ -31,7 +31,7 @@ import { PrimaryButton } from "../../components/Button";
|
||||
|
||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||
import { useUnstableProvider } from "../../hooks/ghost";
|
||||
import { useGatekeeperApy, useGatekeeperAddress } from "../../hooks/staking";
|
||||
import { useGatekeeperApy, useGatekeeperAddress, useGhostedSupply } from "../../hooks/staking";
|
||||
import { useLocalStorage } from "../../hooks/localstorage";
|
||||
import { useTokenSymbol, useBalance } from "../../hooks/tokens";
|
||||
import { formatNumber, formatCurrency } from "../../helpers";
|
||||
@ -113,6 +113,8 @@ const BridgeOut = ({ chainId, address, config, connect }) => {
|
||||
const { balance: ghstBalance } = useBalance(chainId, "GHST", address);
|
||||
const { gatekeeperAddress } = useGatekeeperAddress(chainId);
|
||||
|
||||
const ghostedSupply = useGhostedSupply(chainId);
|
||||
|
||||
const { data: formatDecimals } = useStorageValue(chainId, address, DECIMALS_PREFIX, "5");
|
||||
|
||||
const nativeSymbol = useMemo(() => {
|
||||
@ -243,6 +245,29 @@ const BridgeOut = ({ chainId, address, config, connect }) => {
|
||||
}
|
||||
);
|
||||
|
||||
const { data: networkGatekeeperAmount } = useSWR(
|
||||
casperApi ? ['networkGatekeeperAmount', casperApi, chainId] : null,
|
||||
async () => {
|
||||
const key = BigInt(chainId);
|
||||
const res = await casperApi.query.GhostNetworks.GatekeeperAmounts.getValue(key);
|
||||
return res;
|
||||
},
|
||||
{
|
||||
refreshInterval: 12000,
|
||||
revalidateOnFocus: true
|
||||
}
|
||||
);
|
||||
|
||||
const gatekeepedAmount = useMemo(() => {
|
||||
const gatekeeperAmount = new DecimalBigNumber(
|
||||
networkGatekeeperAmount ? networkGatekeeperAmount : 0n,
|
||||
chainProperties ? chainProperties.properties.tokenDecimals : 18,
|
||||
);
|
||||
|
||||
if (ghostedSupply.lt(gatekeeperAmount)) return ghostedSupply;
|
||||
else return gatekeeperAmount;
|
||||
}, [ghostedSupply, networkGatekeeperAmount, chainProperties]);
|
||||
|
||||
const participants = useMemo(() => {
|
||||
if (!qualificationDkgState) return { total: 0, participated: 0 }
|
||||
|
||||
@ -335,11 +360,12 @@ const BridgeOut = ({ chainId, address, config, connect }) => {
|
||||
chainProperties ? chainProperties.properties.tokenDecimals : 18
|
||||
);
|
||||
|
||||
const notEnoughGatekeeped = gatekeepedAmount.lt(preparedAmount);
|
||||
const smallAmount = bigMinimumBridgeOut.gt(preparedAmount);
|
||||
const validReceiver = isAddress(customReceiver ? customReceiver : receiver);
|
||||
|
||||
return differentGatekeepers || smallAmount || insufficientAmount || !validReceiver;
|
||||
}, [networkData, gatekeeperAddress, minimumBridgeOut, preparedAmount, accountBalance, customReceiver, receiver]);
|
||||
return notEnoughGatekeeped || differentGatekeepers || smallAmount || insufficientAmount || !validReceiver;
|
||||
}, [gatekeepedAmount, networkData, gatekeeperAddress, minimumBridgeOut, preparedAmount, accountBalance, customReceiver, receiver]);
|
||||
|
||||
const startGhostExodus = async () => {
|
||||
alert("not ready yet");
|
||||
@ -492,20 +518,30 @@ const BridgeOut = ({ chainId, address, config, connect }) => {
|
||||
}
|
||||
/>
|
||||
|
||||
<DataRow
|
||||
title={`Min Bridge-Out`}
|
||||
tooltip="Minimum amount that could be handled by the bridge to avoid dust balances."
|
||||
balance={<span>{
|
||||
formatCurrency(
|
||||
new DecimalBigNumber(
|
||||
minimumBridgeOut ? minimumBridgeOut : 0n,
|
||||
chainProperties ? chainProperties.properties.tokenDecimals : 18,
|
||||
),
|
||||
formatDecimals,
|
||||
ghstSymbol
|
||||
)
|
||||
}</span>}
|
||||
/>
|
||||
<Box m="15px 0" display="flex" flexDirection="column" gap="1px" sx={{ "& .DataRow-root": { margin: 0 } }}>
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Min Bridge-Out</Typography>}
|
||||
tooltip="Minimum amount that could be handled by the bridge to avoid dust balances."
|
||||
balance={<Typography variant="caption">{
|
||||
formatCurrency(
|
||||
new DecimalBigNumber(
|
||||
minimumBridgeOut ? minimumBridgeOut : 0n,
|
||||
chainProperties ? chainProperties.properties.tokenDecimals : 18,
|
||||
),
|
||||
formatDecimals,
|
||||
ghstSymbol
|
||||
)
|
||||
}</Typography>}
|
||||
/>
|
||||
|
||||
<DataRow
|
||||
title={<Typography variant="caption">Gatekeeped Amount</Typography>}
|
||||
tooltip="Minimum amount that could be handled by the bridge to avoid dust balances."
|
||||
balance={<Typography variant="caption">{
|
||||
formatCurrency(gatekeepedAmount, formatDecimals, ghstSymbol)
|
||||
}</Typography>}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<PrimaryButton
|
||||
fullWidth
|
||||
|
||||
Loading…
Reference in New Issue
Block a user