Skip to content

Commit

Permalink
fix: fee and remove gas refund
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Oct 27, 2023
1 parent 22bb77d commit 809ce24
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/components/SwapForm/SwapModal/SwapDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TooltipTextOfSwapFee } from 'components/SwapForm/TradeSummary'
import useCheckStablePairSwap from 'components/SwapForm/hooks/useCheckStablePairSwap'
import { MouseoverTooltip, TextDashed } from 'components/Tooltip'
import { StyledBalanceMaxMini } from 'components/swapv2/styleds'
import { APP_PATHS } from 'constants/index'
import { useActiveWeb3React } from 'hooks'
import { isSupportKyberDao, useGasRefundTier } from 'hooks/kyberdao'
import useTheme from 'hooks/useTheme'
Expand Down Expand Up @@ -106,6 +107,8 @@ export default function SwapDetails({
const feeAmountWithSymbol =
feeAmountFromBuild && currencyFromBuild?.symbol ? `${feeAmountFromBuild} ${currencyFromBuild.symbol}` : ''

const isPartnerSwap = window.location.pathname.includes(APP_PATHS.PARTNER_SWAP)

return (
<>
<AutoColumn
Expand Down Expand Up @@ -325,7 +328,7 @@ export default function SwapDetails({
</TYPE.black>
</RowBetween>

{isSupportKyberDao(chainId) && account && Number(routeSummary?.amountInUsd || 0) > 200 && (
{!isPartnerSwap && isSupportKyberDao(chainId) && account && Number(routeSummary?.amountInUsd || 0) > 200 && (
<RowBetween height="20px" style={{ gap: '16px' }}>
<RowFixed>
<TextDashed fontSize={12} fontWeight={400} color={theme.subText}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/SwapForm/TradeSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const TradeSummary: React.FC<Props> = ({ routeSummary, slippage }) => {
}
}, [hasTrade])

const isPartnerSwap = window.location.pathname.includes(APP_PATHS.PARTNER_SWAP)
return (
<Wrapper $visible={alreadyVisible} $disabled={!hasTrade}>
<AutoColumn>
Expand Down Expand Up @@ -266,7 +267,7 @@ const TradeSummary: React.FC<Props> = ({ routeSummary, slippage }) => {
</TYPE.black>
</RowBetween>

{isSupportKyberDao(chainId) && (
{!isPartnerSwap && isSupportKyberDao(chainId) && (
<RowBetween>
<RowFixed>
<TextDashed fontSize={12} fontWeight={400} color={theme.subText}>
Expand Down
6 changes: 5 additions & 1 deletion src/components/SwapForm/hooks/useBuildRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { t } from '@lingui/macro'
import { useCallback, useRef } from 'react'
import { useSearchParams } from 'react-router-dom'
import routeApi from 'services/route'
import { BuildRouteData, BuildRoutePayload } from 'services/route/types/buildRoute'
import { RouteSummary } from 'services/route/types/getRoute'
Expand Down Expand Up @@ -31,6 +32,8 @@ type Args = {

const useBuildRoute = (args: Args) => {
const { recipient, routeSummary, slippage, transactionTimeout, permit } = args
const [searchParams] = useSearchParams()
const clientId = searchParams.get('clientId')
const { chainId, account } = useActiveWeb3React()
const abortControllerRef = useRef(new AbortController())
const { isEnableAuthenAggregator } = useKyberswapGlobalConfig()
Expand Down Expand Up @@ -58,7 +61,7 @@ const useBuildRoute = (args: Args) => {
slippageTolerance: slippage,
sender: account,
recipient: to || account,
source: 'kyberswap',
source: clientId || 'kyberswap',
skipSimulateTx: false,
permit,
}
Expand Down Expand Up @@ -90,6 +93,7 @@ const useBuildRoute = (args: Args) => {
}
}
}, [
clientId,
account,
aggregatorDomain,
chainId,
Expand Down
7 changes: 4 additions & 3 deletions src/services/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ const routeApi = createApi({
url: string
params: GetRouteParams
authentication: boolean
clientId?: string
}
>({
query: ({ params, url, authentication }) => ({
query: ({ params, url, authentication, clientId }) => ({
url,
params,
authentication,
headers: {
'x-client-id': 'kyberswap',
'x-client-id': clientId || 'kyberswap',
},
}),
}),
Expand All @@ -38,7 +39,7 @@ const routeApi = createApi({
signal,
authentication,
headers: {
'x-client-id': 'kyberswap',
'x-client-id': payload.source || 'kyberswap',
},
}),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/services/route/types/buildRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type BuildRoutePayload = {
slippageTolerance: number
sender: string
recipient: string
source: 'kyberswap'
source: string
skipSimulateTx: boolean
permit?: string
}
Expand Down
4 changes: 3 additions & 1 deletion src/services/route/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const calculateFee = (
parseUnits(routeSummary.extraFee.feeAmount, RESERVE_USD_DECIMALS).toString(),
JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(RESERVE_USD_DECIMALS)),
).divide(BIPS_BASE)
const feeCurrencyAmount = currencyAmountToTakeFee.multiply(feeAmountFraction)
const feeCurrencyAmount = routeSummary.extraFee.isInBps
? currencyAmountToTakeFee.multiply(feeAmountFraction)
: CurrencyAmount.fromRawAmount(currencyAmountToTakeFee.currency, routeSummary.extraFee.feeAmount)

const feeAmountUsd = routeSummary.extraFee.feeAmountUsd
return {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export const calculateFeeFromBuildData = (
JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(RESERVE_USD_DECIMALS)),
).divide(BIPS_BASE)

const fee = currencyAmountToTakeFee.multiply(feeAmountFraction).toSignificant(RESERVE_USD_DECIMALS)
const fee = routeSummary.extraFee.isInBps
? currencyAmountToTakeFee.multiply(feeAmountFraction).toSignificant(RESERVE_USD_DECIMALS)
: CurrencyAmount.fromRawAmount(currencyAmountToTakeFee.currency, routeSummary.extraFee.feeAmount)

const feeUsd = buildData.feeUsd

return {
Expand Down

0 comments on commit 809ce24

Please sign in to comment.