-
Notifications
You must be signed in to change notification settings - Fork 5.5k
chore: bump @metamask/core-backend and set up ApiPlatformClient #40262
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { createApiPlatformClient } from '@metamask/core-backend'; | ||
| import { submitRequestToBackground } from '../store/background-connection'; | ||
|
|
||
| export const apiClient = createApiPlatformClient({ | ||
| clientProduct: 'metamask-extension', | ||
| getBearerToken: () => | ||
| submitRequestToBackground<string | undefined>('getBearerToken'), | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import type { UseInfiniteQueryOptions } from '@tanstack/react-query'; | ||
| import type { V4MultiAccountTransactionsResponse } from '@metamask/core-backend'; | ||
| import type { NormalizedV4MultiAccountTransactionsResponse } from '../../shared/lib/multichain/types'; | ||
| import { selectTransactions } from '../../shared/lib/multichain/transformations'; | ||
| import { apiClient } from './api-client'; | ||
|
|
||
| type QueryOptions = Partial< | ||
| UseInfiniteQueryOptions< | ||
| V4MultiAccountTransactionsResponse, | ||
| unknown, | ||
| NormalizedV4MultiAccountTransactionsResponse | ||
| > | ||
| >; | ||
|
|
||
| type Params = { | ||
| accountAddresses: string[]; | ||
| evmAddress: string; | ||
| networks: string[]; | ||
| }; | ||
|
|
||
| export const queries = { | ||
| transactions: ( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should have a dedicated directory for TQ primitives outside of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next PR! Have follow ups to this file too |
||
| params: Params, | ||
| options?: QueryOptions, | ||
| ): UseInfiniteQueryOptions< | ||
| V4MultiAccountTransactionsResponse, | ||
| unknown, | ||
| NormalizedV4MultiAccountTransactionsResponse | ||
| > => { | ||
| const { accountAddresses, evmAddress, networks } = params; | ||
| const queryParams = { networks, includeTxMetadata: true as const }; | ||
n3ps marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const { queryKey } = | ||
| apiClient.accounts.getV4MultiAccountTransactionsQueryOptions( | ||
| accountAddresses, | ||
| queryParams, | ||
| ); | ||
|
|
||
| return { | ||
| queryKey, | ||
| queryFn: ({ pageParam, signal }) => { | ||
| const { queryFn: fetchPage } = | ||
| apiClient.accounts.getV4MultiAccountTransactionsQueryOptions( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| accountAddresses, | ||
| { ...queryParams, cursor: pageParam }, | ||
| ); | ||
| return ( | ||
| fetchPage as (ctx: { | ||
| signal?: AbortSignal; | ||
| }) => Promise<V4MultiAccountTransactionsResponse> | ||
| )({ signal }); | ||
| }, | ||
| select: selectTransactions(evmAddress), | ||
| getNextPageParam: ({ pageInfo }) => | ||
| pageInfo.hasNextPage ? pageInfo.endCursor : undefined, | ||
| refetchOnWindowFocus: false, | ||
| refetchInterval: 15 * 1000, | ||
| staleTime: 15 * 1000, | ||
| ...options, | ||
| enabled: Boolean(accountAddresses[0]) && (options?.enabled ?? true), | ||
| }; | ||
| }, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main point of interest