-
Notifications
You must be signed in to change notification settings - Fork 11
fix: APP-491 empty choose credits form appears for ms #2591
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
Merged
blushi
merged 8 commits into
dev
from
fix-APP-491-empty-choose-credits-form-appears-for-ms
Feb 13, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36c520d
feat: create BuyCredits route loader
r41ph 8060738
feat: redirect to project page accounts that cannot buy credits
r41ph 9fd859e
feat: add loading state for accounts that cannot buy credits
r41ph ee69e9d
feat: pass address to BuyCredits route loader
r41ph 29ff85c
feat: update BuyCredits loader to handle project slug and active address
r41ph 7ea06b0
fix: pass missing address parameter to getRegenRoutes
r41ph 05c74e7
refactor: update BuyCredits loader and RegenRoutes to use activeWalle…
r41ph bb54dde
docs: clarify BuyCredits loader documentation
r41ph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { ApolloClient, NormalizedCacheObject } from '@apollo/client'; | ||
| import { SellOrderInfo } from '@regen-network/api/lib/generated/regen/ecocredit/marketplace/v1/query'; | ||
| import { QueryClient } from '@tanstack/react-query'; | ||
| import { getDefaultStore } from 'jotai'; | ||
|
|
||
| import { Maybe } from 'generated/graphql'; | ||
| import { selectedLanguageAtom } from 'lib/atoms/languageSwitcher.atoms'; | ||
| import { ApolloClientFactory } from 'lib/clients/apolloClientFactory'; | ||
| import { getMarketplaceQueryClient } from 'lib/clients/regen/ecocredit/marketplace/marketplaceQueryClient'; | ||
| import { getSellOrdersExtendedQuery } from 'lib/queries/react-query/ecocredit/marketplace/getSellOrdersExtendedQuery/getSellOrdersExtendedQuery'; | ||
| import { getProjectBySlugQuery } from 'lib/queries/react-query/registry-server/graphql/getProjectBySlugQuery/getProjectBySlugQuery'; | ||
| import { getFromCacheOrFetch } from 'lib/queries/react-query/utils/getFromCacheOrFetch'; | ||
|
|
||
| import { getIsOnChainId } from 'components/templates/ProjectDetails/ProjectDetails.utils'; | ||
|
|
||
| type LoaderType = { | ||
| queryClient: QueryClient; | ||
| apolloClientFactory: ApolloClientFactory; | ||
| address?: Maybe<string>; | ||
| }; | ||
| /** | ||
| * Loader function for the Buy Credits page that checks if there are available | ||
| * sell orders in a given project where the current account address is not the seller. | ||
| * Returns true if at least one sell order exists from a different seller. | ||
| */ | ||
| export const buyCreditsLoader = | ||
| ({ queryClient, apolloClientFactory, address }: LoaderType) => | ||
| async ({ | ||
| params: { projectId: projectIdParam }, | ||
| }: { | ||
| params: { projectId?: string }; | ||
| }) => { | ||
| const isOnChainId = getIsOnChainId(projectIdParam); | ||
| const apolloClient = | ||
| apolloClientFactory.getClient() as ApolloClient<NormalizedCacheObject>; | ||
| const marketplaceClient = await getMarketplaceQueryClient(); | ||
| const atomStore = getDefaultStore(); | ||
| const selectedLanguage = atomStore.get(selectedLanguageAtom); | ||
|
|
||
| const sellOrdersQuery = getSellOrdersExtendedQuery({ | ||
| client: marketplaceClient, | ||
| reactQueryClient: queryClient, | ||
| request: {}, | ||
| }); | ||
|
|
||
| const allSellOrders = await getFromCacheOrFetch({ | ||
| query: sellOrdersQuery, | ||
| reactQueryClient: queryClient, | ||
| }); | ||
|
|
||
| const projectBySlugQuery = getProjectBySlugQuery({ | ||
| client: apolloClient, | ||
| enabled: !!projectIdParam && !isOnChainId, | ||
| slug: projectIdParam as string, | ||
| languageCode: selectedLanguage, | ||
| }); | ||
|
|
||
| const projectBySlug = await getFromCacheOrFetch({ | ||
| query: projectBySlugQuery, | ||
| reactQueryClient: queryClient, | ||
| }); | ||
| const projectBySlugId = projectBySlug?.data?.projectBySlug?.onChainId; | ||
| const projectId = isOnChainId ? projectIdParam : projectBySlugId; | ||
|
|
||
| const availableSellOrders = allSellOrders?.filter( | ||
| (sellOrder: SellOrderInfo) => | ||
| sellOrder.seller !== address && | ||
| projectId && | ||
| sellOrder.batchDenom?.startsWith(projectId), | ||
| ); | ||
|
|
||
| return !!availableSellOrders?.length; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.