Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: query-key-factory doesn't pass options through #6168

Merged
merged 44 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
271aae0
wip: wip
gomesalexandre Feb 7, 2024
66beabb
feat: throw on pool just halted at sign step so we don't infinitely spin
gomesalexandre Feb 7, 2024
93d09b4
Merge branch 'develop' into feat_thor_lp_improve_halted_checks_more
gomesalexandre Feb 8, 2024
67b2af8
feat: improve thorchain savers JIT halted checks
gomesalexandre Feb 8, 2024
0e0e9e5
feat: handle @lukemorales/query-key-factory shenanigans
gomesalexandre Feb 8, 2024
10997b2
feat: remove swapperApi's getIsTradingActive
gomesalexandre Feb 8, 2024
2fad5f8
feat: safety
gomesalexandre Feb 8, 2024
b1380a8
[skip ci] wip: query-key-factory shenanigans
gomesalexandre Feb 8, 2024
a1019fd
[skip ci] feat: swapData query
gomesalexandre Feb 9, 2024
7fd1613
[skip ci] feat: midgard.poolData query
gomesalexandre Feb 9, 2024
2a0d339
feat: midgard.poolsData and use 5mn staleTime
gomesalexandre Feb 9, 2024
041aca3
feat: thornode.poolData
gomesalexandre Feb 9, 2024
93334a1
feat: thornode.poolsData
gomesalexandre Feb 9, 2024
9b4f215
feat: thornode.mimir
gomesalexandre Feb 9, 2024
0325f7c
feat: thornode.block
gomesalexandre Feb 9, 2024
60a2ee0
feat: thornode.inboundAddress
gomesalexandre Feb 9, 2024
2439281
feat: thorchainLp.earnings
gomesalexandre Feb 9, 2024
cbbfbbb
feat: thorchainLp.tvl24hChange
gomesalexandre Feb 9, 2024
dbf0818
feat: thorchainLp.allTimeVolume
gomesalexandre Feb 9, 2024
92b73b1
feat: thorchainLp.liquidityProviderPosition
gomesalexandre Feb 9, 2024
6c2be01
feat: commentary
gomesalexandre Feb 9, 2024
ad8137d
wip: closer to network queries
gomesalexandre Feb 9, 2024
7fa3b3a
feat: refetch
gomesalexandre Feb 9, 2024
66f8d6a
feat: almost there
gomesalexandre Feb 9, 2024
53381b0
fix: tests
gomesalexandre Feb 9, 2024
4416d88
fix: types
gomesalexandre Feb 9, 2024
b300cdf
feat: disable sign and broadcast button on trading halted
gomesalexandre Feb 12, 2024
5c9c913
Merge remote-tracking branch 'origin/develop' into feat_thor_lp_impro…
gomesalexandre Feb 12, 2024
29d5975
Merge branch 'feat_thor_lp_improve_halted_checks_more' into feat_save…
gomesalexandre Feb 12, 2024
68eecd4
Merge branch 'feat_savers_improve_halted_checks_jit' into feat_remove…
gomesalexandre Feb 12, 2024
8dd0100
Merge branch 'feat_remove_swapperApi_getIsTradingActive' into feat_qu…
gomesalexandre Feb 12, 2024
e5e3c82
feat: gm
gomesalexandre Feb 12, 2024
6ce85fd
feat: improve thorchain savers JIT halted checks
gomesalexandre Feb 8, 2024
94f38a2
feat: handle @lukemorales/query-key-factory shenanigans
gomesalexandre Feb 8, 2024
fece98a
feat: disable sign and broadcast button on trading halted
gomesalexandre Feb 12, 2024
ce48c00
Merge branch 'feat_savers_improve_halted_checks_jit' into feat_remove…
gomesalexandre Feb 12, 2024
54d55b0
feat: remove swapperApiBase
gomesalexandre Feb 12, 2024
56046d1
Merge branch 'feat_remove_swapperApi_getIsTradingActive' into feat_qu…
gomesalexandre Feb 13, 2024
1ce9785
feat: what is even safety
gomesalexandre Feb 13, 2024
9e777f9
Merge remote-tracking branch 'origin/develop' into feat_query_key_fac…
gomesalexandre Feb 13, 2024
a4b0000
Merge remote-tracking branch 'origin/develop' into feat_query_key_fac…
gomesalexandre Feb 14, 2024
7114fbf
Merge branch 'develop' into feat_query_key_factory_shenanigans
gomesalexandre Feb 15, 2024
3e7844f
Merge branch 'develop' into feat_query_key_factory_shenanigans
gomesalexandre Feb 16, 2024
c54ca54
feat: cleanup following-up on review comments
gomesalexandre Feb 16, 2024
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
2 changes: 2 additions & 0 deletions src/assets/translations/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
"yourBalance": "Your balance",
"signTransaction": "Sign transaction",
"halted": "Halted",
"poolHalted": "Pool Halted",
"available": "Available",
"carousel": {
"next": "Next",
"prev": "Previous",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { TradeQuoteError as SwapperTradeQuoteError } from '@shapeshiftoss/swappe
import type { FC } from 'react'
import { useCallback, useMemo } from 'react'
import { useTranslate } from 'react-polyglot'
import { useIsTradingActive } from 'react-queries/hooks/useIsTradingActive'
import { Amount } from 'components/Amount/Amount'
import { SlippageIcon } from 'components/Icons/Slippage'
import { getQuoteErrorTranslation } from 'components/MultiHopTrade/components/TradeInput/getQuoteErrorTranslation'
import { useIsTradingActive } from 'components/MultiHopTrade/hooks/useIsTradingActive'
import { RawText } from 'components/Text'
import { useLocaleFormatter } from 'hooks/useLocaleFormatter/useLocaleFormatter'
import { bn, bnOrZero } from 'lib/bignumber/bignumber'
Expand Down Expand Up @@ -62,10 +62,17 @@ export const TradeQuoteLoaded: FC<TradeQuoteProps> = ({
number: { toPercent },
} = useLocaleFormatter()

const { isTradingActive } = useIsTradingActive()

const buyAsset = useAppSelector(selectInputBuyAsset)
const sellAsset = useAppSelector(selectInputSellAsset)
const { isTradingActive: isTradingActiveOnBuyPool } = useIsTradingActive({
assetId: buyAsset.assetId,
})
const { isTradingActive: isTradingActiveOnSellPool } = useIsTradingActive({
assetId: sellAsset.assetId,
})

const isTradingActive = Boolean(isTradingActiveOnBuyPool && isTradingActiveOnSellPool)

const userSlippagePercentageDecimal = useAppSelector(selectUserSlippagePercentageDecimal)

const buyAssetMarketData = useAppSelector(state =>
Expand Down
71 changes: 0 additions & 71 deletions src/components/MultiHopTrade/hooks/useIsTradingActive.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { fromAccountId, fromAssetId, toAssetId } from '@shapeshiftoss/caip'
import { CONTRACT_INTERACTION, FeeDataKey } from '@shapeshiftoss/chain-adapters'
import type { BuildCustomTxInput } from '@shapeshiftoss/chain-adapters/src/evm/types'
import { supportsETH } from '@shapeshiftoss/hdwallet-core'
import { SwapperName } from '@shapeshiftoss/swapper'
import type { Asset, KnownChainIds } from '@shapeshiftoss/types'
import { getConfig } from 'config'
import { getOrCreateContractByType } from 'contracts/contractManager'
Expand All @@ -28,6 +27,7 @@ import type {
import { DefiStep } from 'features/defi/contexts/DefiManagerProvider/DefiCommon'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { useTranslate } from 'react-polyglot'
import { useIsTradingActive } from 'react-queries/hooks/useIsTradingActive'
import { encodeFunctionData, getAddress } from 'viem'
import { Amount } from 'components/Amount/Amount'
import { AssetIcon } from 'components/AssetIcon'
Expand Down Expand Up @@ -58,7 +58,6 @@ import {
import { fromThorBaseUnit, getThorchainFromAddress, toThorBaseUnit } from 'lib/utils/thorchain'
import { BASE_BPS_POINTS } from 'lib/utils/thorchain/constants'
import { getInboundAddressDataForChain } from 'lib/utils/thorchain/getInboundAddressDataForChain'
import { swapperApi } from 'state/apis/swapper/swapperApi'
import {
getMaybeThorchainSaversDepositQuote,
getThorchainSaversPosition,
Expand All @@ -75,7 +74,7 @@ import {
selectPortfolioCryptoBalanceBaseUnitByFilter,
selectSelectedCurrency,
} from 'state/slices/selectors'
import { store, useAppDispatch, useAppSelector } from 'state/store'
import { store, useAppSelector } from 'state/store'

import { ThorchainSaversDepositActionType } from '../DepositCommon'
import { DepositContext } from '../DepositContext'
Expand All @@ -96,7 +95,6 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
null,
)
const [daysToBreakEven, setDaysToBreakEven] = useState<string | null>(null)
const appDispatch = useAppDispatch()
const translate = useTranslate()
const mixpanel = getMixPanel()
// TODO: Allow user to set fee priority
Expand Down Expand Up @@ -540,6 +538,10 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
})()
}, [accountId, accountMetadata, accountType, assetId, bip44Params, chainAdapter, wallet])

const { isTradingActive, refetch: refetchIsTradingActive } = useIsTradingActive({
assetId,
})
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved

const handleDeposit = useCallback(async () => {
if (!contextDispatch || !bip44Params || !accountId || !assetId) return
try {
Expand All @@ -561,15 +563,14 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {

contextDispatch({ type: ThorchainSaversDepositActionType.SET_LOADING, payload: true })

const { getIsTradingActive } = swapperApi.endpoints
const { data: isTradingActive } = await appDispatch(
getIsTradingActive.initiate({
assetId,
swapperName: SwapperName.Thorchain,
}),
)
// Was the pool active when it was fetched at the time of the component mount
// If it wasn't, it's definitely not going to become active again in the few seconds it takes to go from mount to sign click
if (isTradingActive === false) {
throw new Error(`THORChain pool halted for assetId: ${assetId}`)
}

if (!isTradingActive) {
const _isTradingActive = await refetchIsTradingActive()
if (_isTradingActive === false) {
throw new Error(`THORChain pool halted for assetId: ${assetId}`)
}

Expand Down Expand Up @@ -633,7 +634,8 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
chainAdapter,
state?.deposit.cryptoAmount,
state?.deposit.fiatAmount,
appDispatch,
isTradingActive,
refetchIsTradingActive,
protocolFeeCryptoBaseUnit,
maybeFromUTXOAccountAddress,
onNext,
Expand Down Expand Up @@ -704,7 +706,12 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
onCancel={handleCancel}
onConfirm={handleDeposit}
preFooter={preFooter}
isDisabled={!hasEnoughBalanceForGas || !userAddress || disableSmartContractDeposit}
isDisabled={
!hasEnoughBalanceForGas ||
!userAddress ||
disableSmartContractDeposit ||
isTradingActive === false
}
loading={state.loading || !userAddress || isAddressByteCodeLoading}
loadingText={translate('common.confirm')}
headerText='modals.confirm.deposit.header'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import { QueryStatus } from '@reduxjs/toolkit/dist/query'
import type { AccountId } from '@shapeshiftoss/caip'
import { toAssetId } from '@shapeshiftoss/caip'
import { SwapperName } from '@shapeshiftoss/swapper'
import type { Asset } from '@shapeshiftoss/types'
import { TxStatus } from '@shapeshiftoss/unchained-client'
import BigNumber from 'bignumber.js'
Expand All @@ -28,6 +27,7 @@ import { DefiAction } from 'features/defi/contexts/DefiManagerProvider/DefiCommo
import { useCallback, useEffect, useMemo, useState } from 'react'
import { FaTwitter } from 'react-icons/fa'
import { useTranslate } from 'react-polyglot'
import { useIsTradingActive } from 'react-queries/hooks/useIsTradingActive'
import type { AccountDropdownProps } from 'components/AccountDropdown/AccountDropdown'
import { Amount } from 'components/Amount/Amount'
import { CircularProgress } from 'components/CircularProgress/CircularProgress'
Expand All @@ -36,7 +36,6 @@ import { Text } from 'components/Text'
import { useBrowserRouter } from 'hooks/useBrowserRouter/useBrowserRouter'
import { bnOrZero } from 'lib/bignumber/bignumber'
import { fromBaseUnit, toBaseUnit } from 'lib/math'
import { useGetIsTradingActiveQuery } from 'state/apis/swapper/swapperApi'
import type { ThorchainSaversStakingSpecificMetadata } from 'state/slices/opportunitiesSlice/resolvers/thorchainsavers/types'
import {
getMaybeThorchainSaversDepositQuote,
Expand Down Expand Up @@ -129,11 +128,9 @@ export const ThorchainSaversOverview: React.FC<OverviewProps> = ({
[accountId, defaultAccountId, highestBalanceAccountId],
)

const { data: isTradingActive, isFetching: isTradingActiveQueryPending } =
useGetIsTradingActiveQuery({
assetId,
swapperName: SwapperName.Thorchain,
})
const { isTradingActive, isLoading: isTradingActiveLoading } = useIsTradingActive({
assetId,
})

useEffect(() => {
if (!maybeAccountId) return
Expand Down Expand Up @@ -272,7 +269,7 @@ export const ThorchainSaversOverview: React.FC<OverviewProps> = ({
isFull: opportunityMetadata?.isFull || isHardCapReached,
hasPendingTxs,
hasPendingQueries,
isHalted: !isTradingActive,
isHalted: isTradingActive === false,
})
}, [
earnOpportunityData,
Expand Down Expand Up @@ -355,7 +352,7 @@ export const ThorchainSaversOverview: React.FC<OverviewProps> = ({

const handleThorchainSaversEmptyClick = useCallback(() => setHideEmptyState(true), [])

if (!earnOpportunityData || isTradingActiveQueryPending) {
if (!earnOpportunityData || isTradingActiveLoading) {
return (
<Center minW='500px' minH='350px'>
<CircularProgress />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { bchChainId, fromAccountId, fromAssetId, toAssetId } from '@shapeshiftos
import { FeeDataKey } from '@shapeshiftoss/chain-adapters'
import type { BuildCustomTxInput } from '@shapeshiftoss/chain-adapters/src/evm/types'
import { supportsETH } from '@shapeshiftoss/hdwallet-core'
import { SwapperName } from '@shapeshiftoss/swapper'
import { getConfig } from 'config'
import { getOrCreateContractByType } from 'contracts/contractManager'
import { ContractType } from 'contracts/types'
Expand All @@ -29,6 +28,7 @@ import type {
import { DefiStep } from 'features/defi/contexts/DefiManagerProvider/DefiCommon'
import { useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { useTranslate } from 'react-polyglot'
import { useIsTradingActive } from 'react-queries/hooks/useIsTradingActive'
import { encodeFunctionData, getAddress } from 'viem'
import { Amount } from 'components/Amount/Amount'
import { AssetIcon } from 'components/AssetIcon'
Expand Down Expand Up @@ -58,7 +58,6 @@ import {
import { fromThorBaseUnit, toThorBaseUnit } from 'lib/utils/thorchain'
import { BASE_BPS_POINTS } from 'lib/utils/thorchain/constants'
import { getInboundAddressDataForChain } from 'lib/utils/thorchain/getInboundAddressDataForChain'
import { swapperApi } from 'state/apis/swapper/swapperApi'
import {
getThorchainSaversPosition,
getThorchainSaversWithdrawQuote,
Expand All @@ -79,7 +78,7 @@ import {
selectPortfolioCryptoBalanceBaseUnitByFilter,
selectSelectedCurrency,
} from 'state/slices/selectors'
import { useAppDispatch, useAppSelector } from 'state/store'
import { useAppSelector } from 'state/store'

import { ThorchainSaversWithdrawActionType } from '../WithdrawCommon'
import { WithdrawContext } from '../WithdrawContext'
Expand All @@ -98,7 +97,6 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
null,
)
const { state, dispatch: contextDispatch } = useContext(WithdrawContext)
const appDispatch = useAppDispatch()
const translate = useTranslate()
const mixpanel = getMixPanel()
const { query } = useBrowserRouter<DefiQueryParams, DefiParams>()
Expand Down Expand Up @@ -594,6 +592,10 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
return txId
}, [getWithdrawInput, wallet])

const { isTradingActive, refetch: refetchIsTradingActive } = useIsTradingActive({
assetId,
})

const handleConfirm = useCallback(async () => {
if (!contextDispatch || !bip44Params || !accountId || !assetId || !opportunityData) return
try {
Expand Down Expand Up @@ -625,15 +627,14 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
return
}

const { getIsTradingActive } = swapperApi.endpoints
const { data: isTradingActive } = await appDispatch(
getIsTradingActive.initiate({
assetId,
swapperName: SwapperName.Thorchain,
}),
)
// Was the pool active when it was fetched at the time of the component mount
// If it wasn't, it's definitely not going to become active again in the few seconds it takes to go from mount to sign click
if (isTradingActive === false) {
throw new Error(`THORChain pool halted for assetId: ${assetId}`)
}

if (!isTradingActive) {
const _isTradingActive = await refetchIsTradingActive()
if (_isTradingActive === false) {
throw new Error(`THORChain pool halted for assetId: ${assetId}`)
}

Expand Down Expand Up @@ -701,15 +702,16 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
state?.withdraw.cryptoAmount,
state?.withdraw.fiatAmount,
expiry,
appDispatch,
getWithdrawInput,
isTradingActive,
refetchIsTradingActive,
dustAmountCryptoBaseUnit,
protocolFeeCryptoBaseUnit,
onNext,
assets,
toast,
translate,
isTokenWithdraw,
getWithdrawInput,
handleMultiTxSend,
handleCustomTx,
])
Expand Down Expand Up @@ -809,7 +811,11 @@ export const Confirm: React.FC<ConfirmProps> = ({ accountId, onNext }) => {
preFooter={preFooter}
headerText='modals.confirm.withdraw.header'
isDisabled={
!hasEnoughBalanceForGas || !userAddress || disableSmartContractWithdraw || !canWithdraw
!hasEnoughBalanceForGas ||
!userAddress ||
disableSmartContractWithdraw ||
!canWithdraw ||
isTradingActive === false
}
loading={quoteLoading || state.loading || !userAddress || isAddressByteCodeLoading}
loadingText={translate('common.confirm')}
Expand Down
1 change: 1 addition & 0 deletions src/lib/swapper/swappers/ThorchainSwapper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export type InboundAddressResponse = {
gas_rate: string
gas_rate_units: string
router?: string
dust_threshold?: string
global_trading_paused: boolean
chain_trading_paused: boolean
chain_lp_actions_paused: boolean
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/thorchain/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { bn } from 'lib/bignumber/bignumber'

export const THOR_PRECISION = 8
export const BASE_BPS_POINTS = '10000'
export const THORCHAIN_AFFILIATE_NAME = 'ss'
export const THORCHAIN_POOL_MODULE_ADDRESS = 'thor1g98cy3n9mmjrpn0sxmn63lztelera37n8n67c0'

// Current blocktime as per https://thorchain.network/stats
export const thorchainBlockTimeSeconds = '6.1'
export const thorchainBlockTimeMs = bn(thorchainBlockTimeSeconds).times(1000).toNumber()
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
Loading