Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions apps/Cloverfield/components/App/AccountData/AccountOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Title = styled(Row)`
`};
`;

const AccountHealth = styled(RowEnd)<{ color?: string }>`
const AccountHealth = styled(RowEnd) <{ color?: string }>`
font-weight: 500;
font-size: 16px;
padding: 12px 12px 12px 0px;
Expand Down Expand Up @@ -282,8 +282,7 @@ export const BypassPrecisionCheckModeTitle = ({
useEffect(() => {
const toggleExpertMode = () => {
toast.success(
`Bypass Precision Check is ${
bypassPrecisionCheck ? "deactivated" : "activated"
`Bypass Precision Check is ${bypassPrecisionCheck ? "deactivated" : "activated"
}!`
);
setBypassPrecisionCheck(!bypassPrecisionCheck);
Expand All @@ -294,12 +293,11 @@ export const BypassPrecisionCheckModeTitle = ({
toggleExpertMode();
} else if (tries > 2) {
toast.error(
`Bypass Precision Check is ${
bypassPrecisionCheck ? "deactivating" : "activating"
`Bypass Precision Check is ${bypassPrecisionCheck ? "deactivating" : "activating"
} #${tries}`
);
}
}, [tries, setBypassPrecisionCheck]);
}, [tries, setBypassPrecisionCheck, bypassPrecisionCheck]);

const handleAccountOverviewClick = () => {
setTries(tries + 1);
Expand Down
65 changes: 17 additions & 48 deletions apps/Cloverfield/components/App/TradePanel/MinPositionInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from "react";
import BigNumber from "bignumber.js";
// import BigNumber from "bignumber.js";

import { DEFAULT_PRECISION } from "@symmio/frontend-sdk/constants/misc";
import { useCollateralToken } from "@symmio/frontend-sdk/constants/tokens";
Expand All @@ -14,10 +14,11 @@ import { InputField } from "@symmio/frontend-sdk/types/trade";
import useActiveWagmi from "@symmio/frontend-sdk/lib/hooks/useActiveWagmi";
import {
useActiveMarket,
useActiveMarketPrice,
// useActiveMarketPrice,
useSetTypedValue,
} from "@symmio/frontend-sdk/state/trade/hooks";
import { useLeverage } from "@symmio/frontend-sdk/state/user/hooks";

import useTradePage from "@symmio/frontend-sdk/hooks/useTradePage";

import InfoItem from "components/InfoItem";

Expand All @@ -30,65 +31,33 @@ export default function MinPositionInfo() {
chainId
);

const leverage = useLeverage();
const market = useActiveMarket();
const marketPrice = useActiveMarketPrice();
const [
outputTicker,
pricePrecision,
quantityPrecision,
minAcceptableQuoteValue,
] = useMemo(
const tradePage = useTradePage();
const [outputTicker, pricePrecision] = useMemo(
() =>
market
? [
market.symbol,
market.pricePrecision,
market.quantityPrecision,
market.minAcceptableQuoteValue,
market.maxLeverage,
]
: ["", DEFAULT_PRECISION, DEFAULT_PRECISION, 10],
market ? [market.symbol, market.pricePrecision] : ["", DEFAULT_PRECISION],
[market]
);
const [minPositionValue, minPositionQuantity] = useMemo(() => {
// find maximum quantity between min quote value & minimum value base on quantity precision
const quantity = BigNumber.max(
toBN(minAcceptableQuoteValue)
.div(marketPrice)
.times(leverage)
.toFixed(quantityPrecision, RoundMode.ROUND_UP),
toBN(10)
.pow(quantityPrecision * -1)
.toFixed(quantityPrecision, RoundMode.ROUND_UP)
);
const value = toBN(quantity).times(marketPrice).div(leverage);

if (value.isNaN()) return ["-", "-"];
return [
value.toFixed(pricePrecision, RoundMode.ROUND_UP),
quantity.toFixed(quantityPrecision, RoundMode.ROUND_UP),
];
}, [
leverage,
marketPrice,
minAcceptableQuoteValue,
pricePrecision,
quantityPrecision,
]);
const [value, quantity] = useMemo(
() =>
tradePage
? [tradePage.minPositionValue, tradePage.minPositionQuantity]
: ["-", "-"],
[tradePage]
);

return (
<InfoItem
label={"Minimum position size:"}
balanceExact={formatPrice(
minPositionValue,
value,
pricePrecision,
false,
RoundMode.ROUND_UP
)}
amount={`${minPositionValue} ${collateralCurrency?.symbol} (${
toBN(minPositionQuantity).eq(0) ? "-" : minPositionQuantity
} ${outputTicker})`}
amount={`${value} ${collateralCurrency?.symbol} (${toBN(quantity).eq(0) ? "-" : quantity
} ${outputTicker})`}
onClick={(value) => setTypedValue(value, InputField.PRICE)}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const LabelsWrapper = styled(Column)`
gap: 12px;
`;

const ErrorMsgStyle = styled.div<{ color?: string; size?: string }>`
color: ${({ theme, color }) => color ?? theme.red2};
font-size: ${({ size }) => size ?? "12px"};
`;

export default function OpenPositionData() {
const theme = useTheme();
const { chainId } = useActiveWagmi();
Expand All @@ -42,19 +47,22 @@ export default function OpenPositionData() {
chainId
);

const { price, formattedAmounts } = useTradePage();
const tradePage = useTradePage();

const [symbol, pricePrecision] = useMemo(
() =>
market ? [market.symbol, market.pricePrecision] : ["", DEFAULT_PRECISION],
[market]
);
const quantityAsset = useMemo(
() => (toBN(formattedAmounts[1]).isNaN() ? "0" : formattedAmounts[1]),
[formattedAmounts]
() =>
toBN(tradePage.formattedAmounts[1]).isNaN()
? "0"
: tradePage.formattedAmounts[1],
[tradePage.formattedAmounts]
);
const { tp, sl } = useTradeTpSl();
const notionalValue = useNotionalValue(quantityAsset, price);
const notionalValue = useNotionalValue(quantityAsset, tradePage.price);

const { total: lockedValue } = useLockedValues(notionalValue);

Expand All @@ -71,39 +79,40 @@ export default function OpenPositionData() {
const basedInfo = [
{
title: "Locked Value:",
value: `${
lockedValueBN.isNaN() ? "0" : lockedValueBN.toFixed(pricePrecision)
} ${collateralCurrency?.symbol}`,
value: `${lockedValueBN.isNaN() ? "0" : lockedValueBN.toFixed(pricePrecision)
} ${collateralCurrency?.symbol}`,
},
{ title: "Leverage:", value: `${userLeverage} X` },
{
title: "Open Price:",
value: `${
price === "" ? "-" : orderType === OrderType.MARKET ? "Market" : price
}`,
value: `${tradePage.price === ""
? "-"
: orderType === OrderType.MARKET
? "Market"
: tradePage.price
}`,
valueColor: theme.primaryBlue,
},
{
title: "Platform Fee:",
value: !toBN(tradingFee).isNaN()
? `${formatAmount(
toBN(tradingFee).div(2),
3,
true
)} (OPEN) / ${formatAmount(
toBN(tradingFee).div(2),
3,
true
)} (CLOSE) ${collateralCurrency?.symbol}`
toBN(tradingFee).div(2),
3,
true
)} (OPEN) / ${formatAmount(
toBN(tradingFee).div(2),
3,
true
)} (CLOSE) ${collateralCurrency?.symbol}`
: `0 (OPEN) / 0 (CLOSE) ${collateralCurrency?.symbol}`,
},
{
title: "Order Expire Time:",
value: `${
orderType === OrderType.MARKET
value: `${orderType === OrderType.MARKET
? `${MARKET_ORDER_DEADLINE} seconds`
: "Unlimited"
}`,
}`,
},
];
if (tp || sl) {
Expand All @@ -115,14 +124,17 @@ export default function OpenPositionData() {
pricePrecision,
collateralCurrency?.symbol,
userLeverage,
price,
tradePage.price,
orderType,
theme.primaryBlue,
tradingFee,
tp,
sl,
]);

const errorMsg =
"Caution: The trade size might be smaller than the threshold while the order is being filled.";

return (
<React.Fragment>
<LabelsWrapper>
Expand All @@ -136,7 +148,7 @@ export default function OpenPositionData() {

<DisplayLabel
label="Receive"
value={formattedAmounts[1]}
value={tradePage.formattedAmounts[1]}
symbol={symbol}
/>
</LabelsWrapper>
Expand All @@ -150,6 +162,13 @@ export default function OpenPositionData() {
/>
);
})}
<ErrorMsgStyle>
<div>
{toBN(tradePage.formattedAmounts[1]).lt(
tradePage.minPositionQuantity
) && errorMsg}
</div>
</ErrorMsgStyle>
<ActionButton />
</React.Fragment>
);
Expand Down
31 changes: 14 additions & 17 deletions packages/core/src/apollo/queries.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import gql from "graphql-tag";

export const ORDER_HISTORY_DATA = gql`
query OrderHistory($address: String!, $first: Int!, $skip: Int!) {
resultEntities(
query OrderHistory($address: Bytes!, $first: Int!, $skip: Int!) {
quotes(
first: $first
skip: $skip
orderBy: timeStamp
orderBy: timestamp
orderDirection: desc
where: { partyA: $address, quoteStatus_in: [3, 7, 8, 9] }
) {
Expand All @@ -26,9 +26,9 @@ export const ORDER_HISTORY_DATA = gql`
requestedOpenPrice
closedPrice
quantityToClose
timeStamp
timestamp
closePrice
deadline
openDeadline
partyBsWhiteList
symbolId
fillAmount
Expand All @@ -37,19 +37,16 @@ export const ORDER_HISTORY_DATA = gql`
liquidateAmount
liquidatePrice
closedAmount
initialData {
cva
lf
partyAmm
partyBmm
timeStamp
}
initialLf
initialCva
initialPartyAmm
initialPartyBmm
}
}
`;

export const BALANCE_CHANGES_DATA = gql`
query BalanceChanges($account: String!, $first: Int!, $skip: Int!) {
query BalanceChanges($account: Bytes!, $first: Int!, $skip: Int!) {
balanceChanges(
where: { account: $account, type_not: "ALLOCATE_PARTY_A" }
first: $first
Expand All @@ -67,7 +64,7 @@ export const BALANCE_CHANGES_DATA = gql`
`;

export const TOTAL_DEPOSITS_AND_WITHDRAWALS = gql`
query TotalDepositsAndWithdrawals($id: String!) {
query TotalDepositsAndWithdrawals($id: ID!) {
accounts(where: { id: $id }) {
id
timestamp
Expand All @@ -79,9 +76,9 @@ export const TOTAL_DEPOSITS_AND_WITHDRAWALS = gql`
`;

export const GET_PAID_AMOUNT = gql`
query GetPaidAmount($id: String!) {
resultEntities(where: { quoteId: $id }) {
fee
query GetPaidAmount($id: BigInt!) {
quotes(where: { quoteId: $id }) {
userPaidFunding
}
}
`;
Loading