From ba8758aa91c6c6093292789f5a85f82693a2613f Mon Sep 17 00:00:00 2001
From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
Date: Fri, 9 Feb 2024 10:35:09 +0100
Subject: [PATCH] perps: add tradingfee percentage tooltip (#787)
---
src/components/common/SummaryLine.tsx | 14 +++++++++++++-
src/components/common/Tooltip/index.tsx | 4 ++--
src/components/perps/Module/PerpsModule.tsx | 2 +-
src/components/perps/Module/Summary.tsx | 11 ++++++++---
.../Module/{OpeningFee.tsx => TradingFee.tsx} | 8 ++++----
.../perps/{useOpeningFee.ts => useTradingFee.ts} | 7 ++++---
6 files changed, 32 insertions(+), 14 deletions(-)
rename src/components/perps/Module/{OpeningFee.tsx => TradingFee.tsx} (63%)
rename src/hooks/perps/{useOpeningFee.ts => useTradingFee.ts} (64%)
diff --git a/src/components/common/SummaryLine.tsx b/src/components/common/SummaryLine.tsx
index c9cbb3bf..23d4fea7 100644
--- a/src/components/common/SummaryLine.tsx
+++ b/src/components/common/SummaryLine.tsx
@@ -1,6 +1,9 @@
import classNames from 'classnames'
import React from 'react'
+import Text from 'components/common/Text'
+import { Tooltip } from 'components/common/Tooltip'
+
const infoLineClasses = 'flex flex-row justify-between flex-1 mb-1 text-xs text-white'
interface SummaryLineProps {
@@ -8,11 +11,20 @@ interface SummaryLineProps {
className?: string
contentClassName?: string
label: string
+ tooltip?: string
}
export default function SummaryLine(props: SummaryLineProps) {
return (
- {props.label}
+ {props.tooltip ? (
+ {props.tooltip}} type='info' underline>
+
+ {props.label}
+
+
+ ) : (
+ {props.label}
+ )}
{props.children}
)
diff --git a/src/components/common/Tooltip/index.tsx b/src/components/common/Tooltip/index.tsx
index c5260681..85a47f22 100644
--- a/src/components/common/Tooltip/index.tsx
+++ b/src/components/common/Tooltip/index.tsx
@@ -51,8 +51,8 @@ export const Tooltip = (props: Props) => {
diff --git a/src/components/perps/Module/PerpsModule.tsx b/src/components/perps/Module/PerpsModule.tsx
index 6912c095..f62f1e8d 100644
--- a/src/components/perps/Module/PerpsModule.tsx
+++ b/src/components/perps/Module/PerpsModule.tsx
@@ -104,7 +104,7 @@ export function PerpsModule() {
/>
s.modifyPerpPosition)
const closePerpPosition = useStore((s) => s.closePerpPosition)
const currentAccount = useCurrentAccount()
+ const { data: tradingFee, isLoading } = useTradingFee(props.asset.denom, props.amount)
const newAmount = useMemo(
() => (props.previousAmount ?? BN_ZERO).plus(props.amount),
@@ -74,8 +76,11 @@ export default function PerpsSummary(props: Props) {
Summary
-
-
-
+
+
-
diff --git a/src/components/perps/Module/OpeningFee.tsx b/src/components/perps/Module/TradingFee.tsx
similarity index 63%
rename from src/components/perps/Module/OpeningFee.tsx
rename to src/components/perps/Module/TradingFee.tsx
index c56beb62..5544ea1c 100644
--- a/src/components/perps/Module/OpeningFee.tsx
+++ b/src/components/perps/Module/TradingFee.tsx
@@ -2,18 +2,18 @@ import BigNumber from 'bignumber.js'
import { CircularProgress } from 'components/common/CircularProgress'
import DisplayCurrency from 'components/common/DisplayCurrency'
-import useOpeningFee from 'hooks/perps/useOpeningFee'
+import useTradingFee from 'hooks/perps/useTradingFee'
type Props = {
denom: string
amount: BigNumber
}
-export default function OpeningFee(props: Props) {
- const { data: openingFee, isLoading } = useOpeningFee(props.denom, props.amount)
+export default function TradingFee(props: Props) {
+ const { data: openingFee, isLoading } = useTradingFee(props.denom, props.amount)
if (isLoading) return
if (props.amount.isZero() || !openingFee) return '-'
- return
+ return
}
diff --git a/src/hooks/perps/useOpeningFee.ts b/src/hooks/perps/useTradingFee.ts
similarity index 64%
rename from src/hooks/perps/useOpeningFee.ts
rename to src/hooks/perps/useTradingFee.ts
index d81cd390..ddc74453 100644
--- a/src/hooks/perps/useOpeningFee.ts
+++ b/src/hooks/perps/useTradingFee.ts
@@ -5,16 +5,17 @@ import useChainConfig from 'hooks/useChainConfig'
import useClients from 'hooks/useClients'
import useDebounce from 'hooks/useDebounce'
import { BNCoin } from 'types/classes/BNCoin'
+import { BN } from 'utils/helpers'
-export default function useOpeningFee(denom: string, amount: BigNumber) {
+export default function useTradingFee(denom: string, amount: BigNumber) {
const chainConfig = useChainConfig()
const debouncedAmount = useDebounce(amount.toString(), 500)
const clients = useClients()
const enabled = !amount.isZero() && clients
- return useSWR(enabled && `${chainConfig.id}/perps/${denom}/openingFee/${debouncedAmount}`, () =>
+ return useSWR(enabled && `${chainConfig.id}/perps/${denom}/tradingFee/${debouncedAmount}`, () =>
clients!.perps
.openingFee({ denom, size: amount as any })
- .then((resp) => BNCoin.fromCoin(resp.fee)),
+ .then((resp) => ({ rate: BN(resp.rate), fee: BNCoin.fromCoin(resp.fee) })),
)
}