mit einem Klick
add-query
// Use an @ecency/sdk query in the mobile app or create a new app-specific query
// Use an @ecency/sdk query in the mobile app or create a new app-specific query
| name | add-query |
| description | Use an @ecency/sdk query in the mobile app or create a new app-specific query |
| argument-hint | ["query-name"] |
| disable-model-invocation | true |
Wire up SDK query options in the mobile app, or create app-specific queries.
SDK queries are platform-agnostic and shared with the web app. Use them directly:
import { useQuery } from '@tanstack/react-query';
import { getPostQueryOptions, getAccountFullQueryOptions } from '@ecency/sdk';
function MyComponent({ author, permlink }) {
const { data: post, isLoading } = useQuery(getPostQueryOptions(author, permlink));
const { data: account } = useQuery(getAccountFullQueryOptions(author));
}
For non-React contexts (Redux thunks, utilities):
import { getQueryClient } from '@ecency/sdk';
import { getAccountsQueryOptions } from '@ecency/sdk';
const queryClient = getQueryClient();
const accounts = await queryClient.fetchQuery(getAccountsQueryOptions([username]));
For queries that are mobile-specific or not in the SDK, add them in src/providers/queries/.
Location: src/providers/queries/<domain>Queries.ts or src/providers/queries/<domain>Queries/
import { useQuery, useInfiniteQuery } from '@tanstack/react-query';
import { QueryKeys } from './queryKeys';
// Simple query
export function useSomeDataQuery(param: string) {
return useQuery({
queryKey: [QueryKeys.SOME_DATA, param],
queryFn: async () => {
const response = await fetch(`https://api.ecency.com/some-endpoint/${param}`);
return response.json();
},
enabled: !!param,
});
}
// Infinite query (paginated)
export function useSomeListQuery(param: string) {
return useInfiniteQuery({
queryKey: [QueryKeys.SOME_LIST, param],
queryFn: async ({ pageParam = '' }) => {
return fetchSomeList(param, pageParam);
},
initialPageParam: '',
getNextPageParam: (lastPage) => {
if (!lastPage || lastPage.length < 20) return undefined;
return lastPage[lastPage.length - 1].id;
},
enabled: !!param,
});
}
Location: src/providers/queries/queryKeys.ts
export const QueryKeys = {
// ... existing keys
SOME_DATA: 'SOME_DATA',
SOME_LIST: 'SOME_LIST',
};
Add to src/providers/queries/index.ts:
export { useSomeDataQuery } from './someQueries';
SDK queries are configured in src/providers/queries/sdk-config.ts:
ConfigManager.setQueryClient(queryClient) — shares the QueryClientConfigManager.setHiveNodes(nodes) — configures RPC nodes with failoverConfigManager.setPrivateApiHost(host) — Ecency backend APIConfigManager.setDmcaLists(lists) — DMCA content filteringThis is called once at app startup. You don't need to touch it for new queries.
Always use enabled to prevent queries from running with missing params:
useQuery({
queryKey: [QueryKeys.POST, author, permlink],
queryFn: () => fetchPost(author!, permlink!),
enabled: !!author && !!permlink,
});
For optimistic updates, use Redux cache reducer:
import { useInjectVotesCache } from '../../hooks';
// Injects cached vote data into post objects
const posts = useInjectVotesCache(rawPosts);
Wallet-specific queries live in src/providers/queries/walletQueries/ and use SDK query options for blockchain data (delegations, balances, etc.).
@ecency/sdkenabled — prevents queries from running before params are readyundefined from getNextPageParam to stop pagination, not nullAdd a new feature or screen to the Ecency mobile app following established patterns
Add a new blockchain mutation wrapper using @ecency/sdk in the mobile app
Add a new bottom sheet (action sheet) to the mobile app
Review code changes for bugs, pattern violations, and common pitfalls in ecency-mobile
Debug common issues in the Ecency mobile app with known solutions and investigation patterns