Skip to content
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

next: bugfix #859

Merged
merged 3 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/purple-bananas-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/next': minor
Y0moo marked this conversation as resolved.
Show resolved Hide resolved
---

1. No infinite rerenders when pass Moralis Datatypes to the hooks as params.
2. No unexpected challenge requests when use `requestChallengeAsync` from the challenge hooks.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from '{{ names.commonUtils }}';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const {{ names.hook }} = (request: {{ names.request }}, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<{{ names.response }}>(
['{{ url }}', {operation, request}],
['{{ url }}', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/utils/ModuleGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { operations as evmOperations } from 'moralis/common-evm-utils';
import { operations as solOperations } from 'moralis/common-sol-utils';
import { operations as authOperations } from '@moralisweb3/auth';
import { operations as authOperations } from 'moralis/common-auth-utils';

import { Module, OperationAction } from '../next/types';
import path from 'node:path';
Expand Down
20 changes: 16 additions & 4 deletions packages/next/src/hooks/auth/useAuthRequestChallengeEvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,31 @@ export type RequestChallengeEvmRequestClient = Pick<RequestChallengeEvmRequest,

export const useAuthRequestChallengeEvm = (request?: RequestChallengeEvmRequestClient, fetchParams?: FetchParams) => {
const endpoint = 'auth/requestChallengeEvm';
const { deserializeResponse } = operation;

const { data, error, isValidating, mutate } = useSWR<RequestChallengeEvmResponse>(
[endpoint, { operation, request }],
fetcher,
[
endpoint,
{
deserializeResponse,
request,
},
],
request ? fetcher : null,
{
revalidateOnMount: request ? true : false,
revalidateOnFocus: false,
revalidateIfStale: false,
...fetchParams,
},
);

const requestChallengeAsync = useCallback((params: RequestChallengeEvmRequestClient) => {
return mutate(fetcher(endpoint, { operation, request: params }));
return mutate(
fetcher(endpoint, {
deserializeResponse,
request: params,
}),
);
}, []);

return {
Expand Down
22 changes: 17 additions & 5 deletions packages/next/src/hooks/auth/useAuthRequestChallengeSolana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,35 @@ import useSWR from 'swr';
export type RequestChallengeSolanaRequestClient = Pick<RequestChallengeSolanaRequest, 'address' | 'network'>;

export const useAuthRequestChallengeSolana = (
request: RequestChallengeSolanaRequestClient,
request?: RequestChallengeSolanaRequestClient,
fetchParams?: FetchParams,
) => {
const endpoint = 'auth/requestChallengeSolana';
const { deserializeResponse } = operation;

const { data, error, isValidating, mutate } = useSWR<RequestChallengeSolanaResponse>(
[endpoint, { operation, request }],
fetcher,
[
endpoint,
{
deserializeResponse,
request,
},
],
request ? fetcher : null,
{
revalidateOnMount: request ? true : false,
revalidateOnFocus: false,
revalidateIfStale: false,
...fetchParams,
},
);

const requestChallengeAsync = useCallback((params: RequestChallengeSolanaRequestClient) => {
return mutate(fetcher(endpoint, { operation, request: params }));
return mutate(
fetcher(endpoint, {
deserializeResponse,
request: params,
}),
);
}, []);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNativeBalance = (request: GetNativeBalanceRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNativeBalanceResponse>(
['evmApi/getNativeBalance', {operation, request}],
['evmApi/getNativeBalance', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmBlock = (request: GetBlockRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetBlockResponse>(
['evmApi/getBlock', {operation, request}],
['evmApi/getBlock', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmDateToBlock = (request: GetDateToBlockRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetDateToBlockResponse>(
['evmApi/getDateToBlock', {operation, request}],
['evmApi/getDateToBlock', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmPairAddress = (request: GetPairAddressRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetPairAddressResponse>(
['evmApi/getPairAddress', {operation, request}],
['evmApi/getPairAddress', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmPairReserves = (request: GetPairReservesRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetPairReservesResponse>(
['evmApi/getPairReserves', {operation, request}],
['evmApi/getPairReserves', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmContractEvents = (request: GetContractEventsRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetContractEventsResponse>(
['evmApi/getContractEvents', {operation, request}],
['evmApi/getContractEvents', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmContractLogs = (request: GetContractLogsRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetContractLogsResponse>(
['evmApi/getContractLogs', {operation, request}],
['evmApi/getContractLogs', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmUploadFolder = (request: UploadFolderRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<UploadFolderResponse>(
['evmApi/uploadFolder', {operation, request}],
['evmApi/uploadFolder', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmContractNFTs = (request: GetContractNFTsRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetContractNFTsResponse>(
['evmApi/getContractNFTs', {operation, request}],
['evmApi/getContractNFTs', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTContractMetadata = (request: GetNFTContractMetadataRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTContractMetadataResponse>(
['evmApi/getNFTContractMetadata', {operation, request}],
['evmApi/getNFTContractMetadata', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTContractTransfers = (request: GetNFTContractTransfersRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTContractTransfersResponse>(
['evmApi/getNFTContractTransfers', {operation, request}],
['evmApi/getNFTContractTransfers', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTLowestPrice = (request: GetNFTLowestPriceRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTLowestPriceResponse>(
['evmApi/getNFTLowestPrice', {operation, request}],
['evmApi/getNFTLowestPrice', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTMetadata = (request: GetNFTMetadataRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTMetadataResponse>(
['evmApi/getNFTMetadata', {operation, request}],
['evmApi/getNFTMetadata', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTOwners = (request: GetNFTOwnersRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTOwnersResponse>(
['evmApi/getNFTOwners', {operation, request}],
['evmApi/getNFTOwners', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTTokenIdOwners = (request: GetNFTTokenIdOwnersRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTTokenIdOwnersResponse>(
['evmApi/getNFTTokenIdOwners', {operation, request}],
['evmApi/getNFTTokenIdOwners', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTTrades = (request: GetNFTTradesRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTTradesResponse>(
['evmApi/getNFTTrades', {operation, request}],
['evmApi/getNFTTrades', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTTransfers = (request: GetNFTTransfersRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTTransfersResponse>(
['evmApi/getNFTTransfers', {operation, request}],
['evmApi/getNFTTransfers', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTTransfersByBlock = (request: GetNFTTransfersByBlockRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTTransfersByBlockResponse>(
['evmApi/getNFTTransfersByBlock', {operation, request}],
['evmApi/getNFTTransfersByBlock', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmNFTTransfersFromToBlock = (request: GetNFTTransfersFromToBlockRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<GetNFTTransfersFromToBlockResponse>(
['evmApi/getNFTTransfersFromToBlock', {operation, request}],
['evmApi/getNFTTransfersFromToBlock', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmReSyncMetadata = (request: ReSyncMetadataRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<ReSyncMetadataResponse>(
['evmApi/reSyncMetadata', {operation, request}],
['evmApi/reSyncMetadata', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
} from 'moralis/common-evm-utils';
import { FetchParams } from '../../../types';
import useSWR from 'swr';
import Moralis from 'moralis';

export const useEvmSearchNFTs = (request: SearchNFTsRequest, fetchParams?: FetchParams) => {
const { deserializeResponse, serializeRequest } = operation
const { data, error, mutate, isValidating } = useSWR<SearchNFTsResponse>(
['evmApi/searchNFTs', {operation, request}],
['evmApi/searchNFTs', { deserializeResponse, request: serializeRequest(request, Moralis.Core) }],
fetcher,
{revalidateOnFocus: false, ...fetchParams}
);
Expand Down
Loading