Skip to content

Commit

Permalink
[refactor] cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Jan 14, 2025
1 parent 840694c commit 2e5f5c3
Show file tree
Hide file tree
Showing 64 changed files with 130 additions and 424 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
},
"dependencies": {
"@apollo/client": "^3.12.3",
"@apollo/client": "^3.12.5",
"@aptos-labs/ts-sdk": "^1.33.1",
"@aptos-labs/wallet-adapter-mui-design": "3.0.23",
"@aptos-labs/wallet-adapter-react": "3.7.9",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/api/hooks/useGetANS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function useGetNameFromAddress(
return queryResult.data ?? undefined;
}

// this function will return null if ans name not found to prevent useQuery complaining about undefined return
// this function will return null if ANS name not found to prevent useQuery complaining about undefined return
// source for full context: https://tanstack.com/query/v4/docs/react/guides/migrating-to-react-query-4#undefined-is-an-illegal-cache-value-for-successful-queries
async function genANSName(
address: string,
Expand Down
4 changes: 1 addition & 3 deletions src/api/hooks/useGetAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ export function useGetAccount(
) {
const [state] = useGlobalState();

const result = useQuery<Types.AccountData, ResponseError>({
return useQuery<Types.AccountData, ResponseError>({
queryKey: ["account", {address}, state.network_value],
queryFn: () => getAccount({address}, state.aptos_client),
retry: options?.retry ?? false,
});

return result;
}
4 changes: 1 addition & 3 deletions src/api/hooks/useGetAccountAllTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ export function useGetAccountAllTransactionVersions(
return [];
}

const versions: number[] = data.account_transactions.map(
return data.account_transactions.map(
(resource: {transaction_version: number}) => {
return resource.transaction_version;
},
);

return versions;
}
4 changes: 2 additions & 2 deletions src/api/hooks/useGetAccountResources.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Types} from "aptos";
import {useQuery, UseQueryResult} from "@tanstack/react-query";
import {getAccountResources} from "../../api";
import {ResponseError} from "../../api/client";
import {getAccountResources} from "../index";
import {ResponseError} from "../client";
import {useGlobalState} from "../../global-config/GlobalConfig";

export function useGetAccountResources(
Expand Down
7 changes: 1 addition & 6 deletions src/api/hooks/useGetAccountTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export function useGetAccountTransactions(
): UseQueryResult<Array<Types.Transaction>, ResponseError> {
const [state] = useGlobalState();

const accountTransactionsResult = useQuery<
Array<Types.Transaction>,
ResponseError
>({
return useQuery<Array<Types.Transaction>, ResponseError>({
queryKey: [
"accountTransactions",
{address, start, limit},
Expand All @@ -23,6 +20,4 @@ export function useGetAccountTransactions(
queryFn: () =>
getAccountTransactions({address, start, limit}, state.aptos_client),
});

return accountTransactionsResult;
}
12 changes: 4 additions & 8 deletions src/api/hooks/useGetBlock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Types} from "aptos";
import {useQuery} from "@tanstack/react-query";
import {getBlockByHeight, getBlockByVersion} from "../../api";
import {ResponseError} from "../../api/client";
import {getBlockByHeight, getBlockByVersion} from "../index";
import {ResponseError} from "../client";
import {useGlobalState} from "../../global-config/GlobalConfig";

export function useGetBlockByHeight({
Expand All @@ -13,13 +13,11 @@ export function useGetBlockByHeight({
}) {
const [state] = useGlobalState();

const result = useQuery<Types.Block, ResponseError>({
return useQuery<Types.Block, ResponseError>({
queryKey: ["block", height, state.network_value],
queryFn: () =>
getBlockByHeight({height, withTransactions}, state.aptos_client),
});

return result;
}

export function useGetBlockByVersion({
Expand All @@ -31,11 +29,9 @@ export function useGetBlockByVersion({
}) {
const [state] = useGlobalState();

const result = useQuery<Types.Block, ResponseError>({
return useQuery<Types.Block, ResponseError>({
queryKey: ["block", version, state.network_value],
queryFn: () =>
getBlockByVersion({version, withTransactions}, state.aptos_client),
});

return result;
}
3 changes: 2 additions & 1 deletion src/api/hooks/useGetPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export async function getPrice(
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
console.error(`HTTP error! Status: ${response.status}`);
return null;
}

const data = await response.json();
Expand Down
8 changes: 3 additions & 5 deletions src/api/hooks/useGetTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {Types} from "aptos";
import {useQuery} from "@tanstack/react-query";
import {getTransaction} from "../../api";
import {ResponseError} from "../../api/client";
import {getTransaction} from "../index";
import {ResponseError} from "../client";
import {useGlobalState} from "../../global-config/GlobalConfig";

export function useGetTransaction(txnHashOrVersion: string) {
const [state] = useGlobalState();

const result = useQuery<Types.Transaction, ResponseError>({
return useQuery<Types.Transaction, ResponseError>({
queryKey: ["transaction", {txnHashOrVersion}, state.network_value],
queryFn: () => getTransaction({txnHashOrVersion}, state.aptos_client),
});

return result;
}
10 changes: 3 additions & 7 deletions src/api/hooks/useGetUserTransactionVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ export default function useGetUserTransactionVersions(
return [];
}

const versions: number[] = data.user_transactions.map(
(txn: {version: number}) => {
return txn.version;
},
);

return versions;
return data.user_transactions.map((txn: {version: number}) => {
return txn.version;
});
}
15 changes: 5 additions & 10 deletions src/api/hooks/useGraphqlClient.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React from "react";
import React, {useEffect, useState} from "react";
import {
ApolloClient,
InMemoryCache,
ApolloLink,
ApolloProvider,
HttpLink,
InMemoryCache,
NormalizedCacheObject,
ApolloLink,
} from "@apollo/client";
import {useEffect, useState} from "react";
import {NetworkName, getApiKey} from "../../constants";
import {getApiKey, NetworkName} from "../../constants";
import {useGlobalState} from "../../global-config/GlobalConfig";

function getIsGraphqlClientSupportedFor(networkName: NetworkName): boolean {
Expand Down Expand Up @@ -81,9 +80,5 @@ export function GraphqlClientProvider({children}: GraphqlClientProviderProps) {

export function useGetIsGraphqlClientSupported(): boolean {
const [state] = useGlobalState();
const isGraphqlClientSupported = getIsGraphqlClientSupportedFor(
state.network_name,
);

return isGraphqlClientSupported;
return getIsGraphqlClientSupportedFor(state.network_name);
}
22 changes: 1 addition & 21 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,6 @@ export function view(
return client.view(request, parsedVersion);
}

export function getTableItem(
requestParameters: {tableHandle: string; data: Types.TableItemRequest},
client: AptosClient,
): Promise<any> {
const {tableHandle, data} = requestParameters;
return withResponseError(client.getTableItem(tableHandle, data));
}

export function getBlockByHeight(
requestParameters: {height: number; withTransactions: boolean},
client: AptosClient,
Expand Down Expand Up @@ -286,18 +278,6 @@ export async function getValidatorCommissionChange(
return withResponseError(client.view(payload));
}

export async function getDelegationPoolExist(
client: AptosClient,
validatorAddress: Types.Address,
): Promise<Types.MoveValue[]> {
const payload: Types.ViewRequest = {
function: "0x1::delegation_pool::delegation_pool_exists",
type_arguments: [],
arguments: [validatorAddress],
};
return withResponseError(client.view(payload));
}

// Return whether `pending_inactive` stake can be directly withdrawn from the delegation pool,
// for the edge case when the validator had gone inactive before its lockup expired.
export async function getCanWithdrawPendingInactive(
Expand Down Expand Up @@ -337,7 +317,7 @@ export async function getValidatorState(
return withResponseError(client.view(payload));
}

export async function getValidatorCommisionAndState(
export async function getValidatorCommissionAndState(
client: AptosClient,
validatorAddresses: Types.Address[],
): Promise<Types.MoveValue[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/api/query-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CombinedQueryResultState = {
* @returns
* @example
* const {
* combinedQueryState: {error, isLoading}},
* combinedQueryState: {error, isLoading},
* queries: [query1, query2, query3],
* } = combineQueries([
* useQuery(...),
Expand Down
2 changes: 1 addition & 1 deletion src/components/AmountTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function AmountTextField({
warnMessage,
onAmountChange,
balance,
}: AmountTextFieldProps): JSX.Element {
}: AmountTextFieldProps) {
return (
<FormControl fullWidth>
<Stack direction="row" justifyContent="space-between">
Expand Down
2 changes: 1 addition & 1 deletion src/components/GoBack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function BackButton(handleClick: () => void) {
);
}

export default function GoBack(): JSX.Element | null {
export default function GoBack() {
const navigate = useNavigate();

if (window.history.state && window.history.state.idx > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/HashButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getHashLinkStr(input: string, type: HashType): string {
}
}

function HashLink(hash: string, type: HashType): JSX.Element {
function HashLink(hash: string, type: HashType) {
switch (type) {
case HashType.ACCOUNT:
case HashType.TRANSACTION:
Expand Down Expand Up @@ -236,7 +236,7 @@ function HashButtonInner({
} else if (img) {
icon = (
<Box component="span" sx={{mr: 1, display: "flex", alignItems: "center"}}>
<img src={img} height={20} width={20} />
<img src={img} alt={img} height={20} width={20} />
</Box>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/IndividualPageContent/CollapsibleCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {grey} from "../../themes/colors/aptosColorPalette";

// return true if there is at least 1 card is not expanded
function getNotAllExpanded(expandedList: boolean[]): boolean {
return expandedList.find((expanded) => expanded === false) !== undefined;
return expandedList.find((expanded) => !expanded) !== undefined;
}

// return true if there is at least 1 card is expanded
function getNotAllCollapse(expandedList: boolean[]): boolean {
return expandedList.find((expanded) => expanded === true) !== undefined;
return expandedList.find((expanded) => expanded) !== undefined;
}

type ExpandAllCollapseAllButtonsProps = {
Expand Down
5 changes: 1 addition & 4 deletions src/components/IndividualPageContent/ContentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ interface ContentBoxProps extends BoxProps {
children: React.ReactNode;
}

export default function ContentBox({
children,
...props
}: ContentBoxProps): JSX.Element {
export default function ContentBox({children, ...props}: ContentBoxProps) {
const theme = useTheme();
// TODO: unify colors for the new transaction page
const backgroundColor = theme.palette.mode === "dark" ? grey[800] : grey[50];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ContentBoxSpaceBetweenProps extends BoxProps {
export default function ContentBoxSpaceBetween({
children,
...props
}: ContentBoxSpaceBetweenProps): JSX.Element {
}: ContentBoxSpaceBetweenProps) {
const theme = useTheme();
const backgroundColor = theme.palette.mode === "dark" ? grey[800] : grey[50];

Expand Down
Loading

0 comments on commit 2e5f5c3

Please sign in to comment.