@@ -3,16 +3,11 @@ import { SellOrderInfo } from '@regen-network/api/lib/generated/regen/ecocredit/
33import { QueryClient } from '@tanstack/react-query' ;
44import { getDefaultStore } from 'jotai' ;
55
6+ import { Maybe } from 'generated/graphql' ;
67import { selectedLanguageAtom } from 'lib/atoms/languageSwitcher.atoms' ;
78import { ApolloClientFactory } from 'lib/clients/apolloClientFactory' ;
89import { getMarketplaceQueryClient } from 'lib/clients/regen/ecocredit/marketplace/marketplaceQueryClient' ;
910import { getSellOrdersExtendedQuery } from 'lib/queries/react-query/ecocredit/marketplace/getSellOrdersExtendedQuery/getSellOrdersExtendedQuery' ;
10- import { GET_ACCOUNTS_QUERY_KEY } from 'lib/queries/react-query/registry-server/getAccounts/getAccountsQuery.constants' ;
11- import {
12- Accounts ,
13- PrivateAccount ,
14- } from 'lib/queries/react-query/registry-server/getAccounts/getAccountsQuery.types' ;
15- import { getAccountByIdQuery } from 'lib/queries/react-query/registry-server/graphql/getAccountByIdQuery/getAccountByIdQuery' ;
1611import { getProjectBySlugQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectBySlugQuery/getProjectBySlugQuery' ;
1712import { getFromCacheOrFetch } from 'lib/queries/react-query/utils/getFromCacheOrFetch' ;
1813
@@ -21,7 +16,7 @@ import { getIsOnChainId } from 'components/templates/ProjectDetails/ProjectDetai
2116type LoaderType = {
2217 queryClient : QueryClient ;
2318 apolloClientFactory : ApolloClientFactory ;
24- address : string | undefined ;
19+ address ?: Maybe < string > ;
2520} ;
2621/**
2722 * Loader function for the Buy Credits page that checks if there are available
@@ -40,33 +35,6 @@ export const buyCreditsLoader =
4035 const marketplaceClient = await getMarketplaceQueryClient ( ) ;
4136 const atomStore = getDefaultStore ( ) ;
4237 const selectedLanguage = atomStore . get ( selectedLanguageAtom ) ;
43- let currentActiveAddress = address ;
44-
45- if ( ! currentActiveAddress ) {
46- const data = ( await getFromCacheOrFetch ( {
47- query : { queryKey : [ GET_ACCOUNTS_QUERY_KEY ] } ,
48- reactQueryClient : queryClient ,
49- } ) ) as Accounts | null | undefined ;
50-
51- const activeAccountId = data ?. activeAccountId ;
52- const privAuthenticatedAccounts = data ?. authenticatedAccounts ;
53-
54- const authenticatedAccountsResult = await getAuthenticatedAccounts ( {
55- privAuthenticatedAccounts,
56- client : apolloClient ,
57- languageCode : selectedLanguage ,
58- queryClient,
59- } ) ;
60-
61- const authenticatedAccounts = authenticatedAccountsResult . map (
62- result => result ?. accountById ,
63- ) ;
64-
65- const activeAccount = authenticatedAccounts . find (
66- account => account ?. id === activeAccountId ,
67- ) ;
68- currentActiveAddress = activeAccount ?. addr ?? undefined ;
69- }
7038
7139 const sellOrdersQuery = getSellOrdersExtendedQuery ( {
7240 client : marketplaceClient ,
@@ -95,41 +63,10 @@ export const buyCreditsLoader =
9563
9664 const availableSellOrders = allSellOrders ?. filter (
9765 ( sellOrder : SellOrderInfo ) =>
98- sellOrder . seller !== currentActiveAddress &&
66+ sellOrder . seller !== address &&
9967 projectId &&
10068 sellOrder . batchDenom ?. startsWith ( projectId ) ,
10169 ) ;
10270
10371 return ! ! availableSellOrders ?. length ;
10472 } ;
105-
106- async function getAuthenticatedAccounts ( {
107- privAuthenticatedAccounts,
108- client,
109- languageCode,
110- queryClient,
111- } : {
112- privAuthenticatedAccounts : PrivateAccount [ ] | undefined ;
113- client : ApolloClient < NormalizedCacheObject > ;
114- languageCode : string ;
115- queryClient : QueryClient ;
116- } ) {
117- if ( ! privAuthenticatedAccounts ?. length ) return [ ] ;
118-
119- const accounts = await Promise . all (
120- privAuthenticatedAccounts . map ( ( { id } ) => {
121- const query = getAccountByIdQuery ( {
122- client,
123- id,
124- languageCode,
125- } ) ;
126-
127- return queryClient . fetchQuery ( {
128- queryKey : query . queryKey ,
129- queryFn : query . queryFn ,
130- } ) ;
131- } ) ,
132- ) ;
133-
134- return accounts ;
135- }
0 commit comments