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

Conversation

gomesalexandre
Copy link
Contributor

@gomesalexandre gomesalexandre commented Feb 8, 2024

Description

See lukemorales/query-key-factory#83 for more context WRT the whys of this.

This PR:

  • ensures options (enabled, staleTime etc) of react-queries are properly passed at consumer level
  • revisits various staleTime and gcTime to match the freshness we expect
  • does some refactoring WRT queries being closer to the network, avoiding overfetching starting with
    • inboundAddress: (assetId: AssetId): Promise<InboundAddressResponse> now being inboundAddresses: () => Promise<Result<InboundAddressResponse[], SwapErrorRight>>; and the derivation of asset-specific inbound address being done by a selector
    • removal of isTradingActive in favor of deriving trading active from inboundAddresses and mimir queries
- [x] Go through all of `common`, `mutations`, `midgard`, `thornode`, and `thorchainLp` queries and mutations and ensure they do not contain any property other than `queryFn` and `queryKey`
- [x] If they do, reflect those options at consumer time instead of abstacted query time
- [x] Test all affected code paths and ensure the now correct behavior doesn't rug anything

To be tested:

  • THORChain LP Add Liquidity allowance checks is happy and refetches every 30s
  • Halted checks in savers, LP, and swapper
  • Midgard swaps data i.e THORChain LP position page, pool page, and available pools are happy
  • Midgard and THORNode pool data i.e parsed position current value is happy
  • Pools Data i.e available pools is happy
  • THORNode pools data i.e lending available assets, savers available opportunities, and LP positions are happy
  • mimir is happy i.e lending repayment lock is happy and refetches mimir data every block when mounted (every ~6 seconds)
  • block height is happy i.e lending repayment lock is happy and refetches repayment lock data every block when mounted (every ~6 seconds)
  • inboundAddress query is happy i.e signing is still happy for THORChain LP
  • THORChain LP asset earnings is happy
  • THORChain LP RUNE earnings is happy
  • THORCHain LP TVL 24h change is happy
  • THORCHain LP all time volume is happy

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

Issue (if applicable)

Risk

High Risk PRs Require 2 approvals

Theoretically low as the guts of this PR is bringing react-query options at consumer time, though effectively high since the now correct (and some revisited) options being used may result in regressions, as well as the refactor of isTradingActive and inboundAddress now being inboundAddresses + selectors.
Go through all the above while testing.

What protocols, transaction types or contract interactions might be affected by this PR?

Testing

Engineering

Operations

Screenshots (if applicable)

  • LP approval checks are still done on mount, and refetch every 30s
Screen.Recording.2024-02-09.at.11.50.02.mov
  • LP halted checks - note, DOGE isn't halted anymore
image
  • Savers halted checks
image
  • Swapper halted checks
image
  • LP pool page
image
  • LP "Your Positions" page
image
  • LP position page
image
  • Lending available assets
image
  • Savers available pools
image
  • Lending repayment lock
image
  • THORChain LP signing
image image

@gomesalexandre gomesalexandre force-pushed the feat_query_key_factory_shenanigans branch from da7216f to 3e11555 Compare February 9, 2024 11:08
@gomesalexandre gomesalexandre force-pushed the feat_query_key_factory_shenanigans branch from 3e11555 to ad8137d Compare February 9, 2024 12:46
Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small regression in this guy:

❌ "Deposits are temporarily halted" tooltip always shows:

Screenshot 2024-02-13 at 9 57 40 am

@gomesalexandre gomesalexandre force-pushed the feat_query_key_factory_shenanigans branch from 081e94a to 1ce9785 Compare February 13, 2024 00:08
@gomesalexandre gomesalexandre force-pushed the feat_remove_swapperApi_getIsTradingActive branch from 54d55b0 to 529ec09 Compare February 13, 2024 13:21
Base automatically changed from feat_remove_swapperApi_getIsTradingActive to develop February 13, 2024 13:27
@woodenfurniture
Copy link
Member

Testing notes

Twsted with this patch

diff --git a/src/react-queries/selectors/index.ts b/src/react-queries/selectors/index.ts
index 463d0d7f13..8b02f92f51 100644
--- a/src/react-queries/selectors/index.ts
+++ b/src/react-queries/selectors/index.ts
@@ -1,6 +1,5 @@
 import type { AssetId } from '@shapeshiftoss/caip'
-import type { SwapErrorRight } from '@shapeshiftoss/swapper'
-import { SwapperName } from '@shapeshiftoss/swapper'
+import type { SwapErrorRight, SwapperName } from '@shapeshiftoss/swapper'
 import { Err, Ok, type Result } from '@sniptt/monads'
 import type { InboundAddressResponse } from 'lib/swapper/swappers/ThorchainSwapper/types'
 import { isRune } from 'lib/swapper/swappers/ThorchainSwapper/utils/isRune/isRune'
@@ -20,38 +19,13 @@ export const selectInboundAddressData = (
     })
     .unwrap()
 
-export const selectIsTradingActive = ({
-  assetId,
-  swapperName,
-  inboundAddressResponse,
-  mimir,
-}: {
+export const selectIsTradingActive = (_: {
   assetId: AssetId | undefined
   swapperName: SwapperName
   mimir: Record<string, unknown>
   inboundAddressResponse: InboundAddressResponse | undefined
 }): boolean => {
-  switch (swapperName) {
-    case SwapperName.Thorchain: {
-      if (!assetId) throw new Error('AssetId is required')
-      const sellAssetIsRune = isRune(assetId)
-
-      if (sellAssetIsRune) {
-        // The sell asset is RUNE, there is no inbound address data to check against
-        // Check the HALTTHORCHAIN flag on the mimir endpoint instead
-        return Object.entries(mimir).some(([k, v]) => k === 'HALTTHORCHAIN' && v === 0)
-      }
-
-      // We have inboundAddressData for the sell asset, check if it is halted
-      if (inboundAddressResponse) {
-        return !inboundAddressResponse.halted
-      }
-
-      // We have no inboundAddressData for the sell asset, fail-closed
-      return false
-    }
-    // The swapper does not require any additional checks, we assume trading is active
-    default:
-      return true
-  }
+  const isTradingActive = Date.now() % 2 === 0 ? true : false
+  console.log({ isTradingActive })
+  return isTradingActive
 }

Add Liquidity reacting to changes in halted state
image
image


❌ No halted polling on confirm dialog
image


Waiting for confirmation reacting to changes in halted state
image
image


❓ Non blocking, but

  • Polling halted state continues after tx has been submitted
  • Gas rate polling continues after tx has been submitted
gomes-1.mov

✅ Tx succeeds
image


Separate issues / non-blockers

Dead click when clicking Trade
image
image


Back button takes you to Your Positions insted of Available Pools
image
image


Back button on Add Liquidity form takes you to Available Pools instead of back to the pair
image
image
image


Rejecting tx has not effect on the application, subsequent attempts to confirm the tx are ignored (dead clicks)

gomes-2.mov

  • Seemingly lack of waiting / loadingish state between confirming tx and metamask popup, resulting in user click spam
  • Missing state waiting for user confirmation on wallet -- Button says "sign transaction" which is correct text, but is still enabled while metamask is asking for a signature which is confusing, visually appears like app broke and fell out of sync with metamask
gomes-3.mov

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few thoughts, though nothing blocking (except maybe that hardcoded thorchain swapper as commented).

Performed an app-wide smoke test and everything behaved as expected 👌

src/lib/utils/thorchain/constants.ts Outdated Show resolved Hide resolved
src/react-queries/hooks/useIsTradingActive.ts Outdated Show resolved Hide resolved
src/state/apis/swapper/swapperApi.ts Show resolved Hide resolved
@gomesalexandre
Copy link
Contributor Author

@woodenfurniture ty for the review!

Circling back on each of the points:

  • No halted polling on confirm dialog

We will absolutely want to implement that as a follow-up to align with savers, nice catch!

  • Polling continues

Also a nice catch - there may be exactly what we need to achieve this in v3.25.0 👀 https://github.com/TanStack/query/releases/tag/v3.25.0 to be added as a follow-up as well!

  • Dead click when clicking Trade

Indeed, also still needs to be implemented!

  • Back button takes you to Your Positions insted of Available Pools

Also a nice catch 👀

  • Rejecting tx has not effect on the application, subsequent attempts to confirm the tx are ignored (dead clicks) / loading states

We could definitely do one better to handle loading/errorred states, I'll dedicate a PR for these only!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure all THORChain domains do JIT halted detection
3 participants