From 1d88db8eb695a94f1f16ca99968637c4011cadc1 Mon Sep 17 00:00:00 2001 From: Gareth Fuller Date: Thu, 6 Jul 2023 08:57:24 +0100 Subject: [PATCH] refactor: Optimise pool page queries (#3634) * refactor: Use single layout for any page with pool id in route * chore: Use pool provider for pool page * chore: Prevent refetch on focus & don't wait for token injection * refactor: Wait for vebal injection before enabling queries --- src/App.vue | 6 +-- .../pages/pool/MyPoolBalancesCard.vue | 2 +- src/components/layouts/DefaultLayout.vue | 28 +++++++++++ src/composables/queries/usePoolQuery.ts | 4 +- src/pages/_layouts/DefaultLayout.vue | 35 ++++---------- .../{JoinExitLayout.vue => PoolLayout.vue} | 16 ++++++- src/pages/pool/_id.vue | 48 ++++--------------- src/plugins/router/index.ts | 5 +- src/providers/local/pool.provider.ts | 21 ++++++++ src/providers/tokens.provider.ts | 9 +++- 10 files changed, 96 insertions(+), 78 deletions(-) create mode 100644 src/components/layouts/DefaultLayout.vue rename src/pages/_layouts/{JoinExitLayout.vue => PoolLayout.vue} (66%) diff --git a/src/App.vue b/src/App.vue index abf4656bd9..c655bdefb4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -41,8 +41,8 @@ const FocussedLayout = defineAsyncComponent( const ContentLayout = defineAsyncComponent( () => import('@/pages/_layouts/ContentLayout.vue') ); -const JoinExitLayout = defineAsyncComponent( - () => import('@/pages/_layouts/JoinExitLayout.vue') +const PoolLayout = defineAsyncComponent( + () => import('@/pages/_layouts/PoolLayout.vue') ); BigNumber.config({ DECIMAL_PLACES: DEFAULT_TOKEN_DECIMALS }); @@ -57,7 +57,7 @@ const Layouts = { ContentLayout: ContentLayout, DefaultLayout: DefaultLayout, FocussedLayout: FocussedLayout, - JoinExitLayout: JoinExitLayout, + PoolLayout: PoolLayout, }; /** * COMPOSABLES diff --git a/src/components/contextual/pages/pool/MyPoolBalancesCard.vue b/src/components/contextual/pages/pool/MyPoolBalancesCard.vue index 92690c5a27..1b113c6941 100644 --- a/src/components/contextual/pages/pool/MyPoolBalancesCard.vue +++ b/src/components/contextual/pages/pool/MyPoolBalancesCard.vue @@ -45,7 +45,7 @@ const { isMigratablePool } = usePoolHelpers(toRef(props, 'pool')); const { stakedShares } = usePoolStaking(); const { networkSlug } = useNetwork(); const router = useRouter(); -const { totalLockedValue } = useLock(); +const { totalLockedValue } = useLock({ enabled: isVeBalPool(props.pool.id) }); /** * COMPUTED diff --git a/src/components/layouts/DefaultLayout.vue b/src/components/layouts/DefaultLayout.vue new file mode 100644 index 0000000000..a442494b86 --- /dev/null +++ b/src/components/layouts/DefaultLayout.vue @@ -0,0 +1,28 @@ + + + + + diff --git a/src/composables/queries/usePoolQuery.ts b/src/composables/queries/usePoolQuery.ts index 2b3094c446..51f39b6dfd 100644 --- a/src/composables/queries/usePoolQuery.ts +++ b/src/composables/queries/usePoolQuery.ts @@ -79,7 +79,7 @@ export default function usePoolQuery( } // Inject pool tokens into token registry - await injectTokens([ + injectTokens([ ...tokensListExclBpt(pool), ...tokenTreeLeafs(pool.tokens), pool.address, // We need to inject pool addresses so we can fetch a user's balance for that pool. @@ -90,6 +90,8 @@ export default function usePoolQuery( const queryOptions = reactive({ enabled, + keepPreviousData: true, + refetchOnWindowFocus: false, ...options, }); diff --git a/src/pages/_layouts/DefaultLayout.vue b/src/pages/_layouts/DefaultLayout.vue index cce554af42..a6d70ee57b 100644 --- a/src/pages/_layouts/DefaultLayout.vue +++ b/src/pages/_layouts/DefaultLayout.vue @@ -1,32 +1,13 @@ - - diff --git a/src/pages/_layouts/JoinExitLayout.vue b/src/pages/_layouts/PoolLayout.vue similarity index 66% rename from src/pages/_layouts/JoinExitLayout.vue rename to src/pages/_layouts/PoolLayout.vue index 7847cc0976..f5791c1ce3 100644 --- a/src/pages/_layouts/JoinExitLayout.vue +++ b/src/pages/_layouts/PoolLayout.vue @@ -1,5 +1,6 @@ diff --git a/src/pages/pool/_id.vue b/src/pages/pool/_id.vue index 41cfeff555..eb9b094c53 100644 --- a/src/pages/pool/_id.vue +++ b/src/pages/pool/_id.vue @@ -1,7 +1,5 @@