Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdef1cafe committed Feb 23, 2023
2 parents 91c6799 + 0be19ca commit 4ae2a06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/components/Trade/TradeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const TradeInput = () => {
const isTradeRatesEnabled = useFeatureFlag('TradeRates')

const { setTradeAmountsUsingExistingData, setTradeAmountsRefetchData } = useTradeAmounts()
const { isTradingActiveOnSellPool } = useIsTradingActive()
const { isTradingActiveOnSellPool, isTradingActiveOnBuyPool } = useIsTradingActive()
const {
checkApprovalNeeded,
getTrade,
Expand Down Expand Up @@ -349,6 +349,15 @@ export const TradeInput = () => {
},
]
}
if (!isTradingActiveOnBuyPool && bestTradeSwapper.name === SwapperName.Thorchain) {
return [
'trade.errors.tradingNotActive',
{
assetSymbol: buyTradeAsset?.asset?.symbol ?? '',
},
]
}

if (!hasValidTradeBalance) return 'common.insufficientFunds'
if (hasValidTradeBalance && !hasEnoughBalanceForGas && hasValidSellAmount)
return [
Expand Down Expand Up @@ -379,6 +388,7 @@ export const TradeInput = () => {
isBelowMinSellAmount,
isSwapperApiPending,
isTradeQuotePending,
isTradingActiveOnBuyPool,
isTradingActiveOnSellPool,
quote?.feeData.networkFeeCryptoBaseUnit,
quote?.minimum,
Expand Down
24 changes: 20 additions & 4 deletions src/components/Trade/hooks/useIsTradingActive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import { useAppDispatch } from 'state/store'

export const useIsTradingActive = () => {
const [isTradingActiveOnSellPool, setIsTradingActiveOnSellPool] = useState(false)
const [isTradingActiveOnBuyPool, setIsTradingActiveOnBuyPool] = useState(false)

const { bestTradeSwapper } = useSwapper()
const dispatch = useAppDispatch()

const { control } = useFormContext<TS>()
const sellTradeAsset = useWatch({ control, name: 'sellTradeAsset' })
const buyTradeAsset = useWatch({ control, name: 'buyTradeAsset' })
const sellTradeAssetId = sellTradeAsset?.asset?.assetId
const buyTradeAssetId = buyTradeAsset?.asset?.assetId

const { getIsTradingActive } = getIsTradingActiveApi.endpoints

useEffect(() => {
;(async () => {
const isTradingActiveResult =
const isTradingActiveOnSellPoolResult =
sellTradeAssetId &&
bestTradeSwapper &&
(
Expand All @@ -31,9 +34,22 @@ export const useIsTradingActive = () => {
)
).data

setIsTradingActiveOnSellPool(!!isTradingActiveResult)
const isTradingActiveOnBuyPoolResult =
buyTradeAssetId &&
bestTradeSwapper &&
(
await dispatch(
getIsTradingActive.initiate({
assetId: buyTradeAssetId,
swapperName: bestTradeSwapper.name,
}),
)
).data

setIsTradingActiveOnSellPool(!!isTradingActiveOnSellPoolResult)
setIsTradingActiveOnBuyPool(!!isTradingActiveOnBuyPoolResult)
})()
}, [bestTradeSwapper, dispatch, getIsTradingActive, sellTradeAssetId])
}, [bestTradeSwapper, buyTradeAssetId, dispatch, getIsTradingActive, sellTradeAssetId])

return { isTradingActiveOnSellPool }
return { isTradingActiveOnSellPool, isTradingActiveOnBuyPool }
}

0 comments on commit 4ae2a06

Please sign in to comment.