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

Add logging error in Zod parsing #800

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#800](https://github.com/alleslabs/celatone-frontend/pull/800) Add logging error in Zod parsing
- [#798](https://github.com/alleslabs/celatone-frontend/pull/798) Add empty state to proposal messages
- [#797](https://github.com/alleslabs/celatone-frontend/pull/797) Fix Vote Periods subtab internal state instead of route
- [#784](https://github.com/alleslabs/celatone-frontend/pull/784) Make proposal list row clickable with command/ctrl
Expand Down
6 changes: 3 additions & 3 deletions src/lib/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from "axios";
import { z } from "zod";

import { zProjectInfo, zPublicAccountInfo, type BechAddr } from "lib/types";
import { snakeToCamel } from "lib/utils";
import { parseWithError, snakeToCamel } from "lib/utils";

const zIcns = z.object({
names: z.array(z.string()),
Expand All @@ -25,7 +25,7 @@ export const getAccountData = async (
): Promise<AccountData> =>
axios
.get(`${endpoint}/${encodeURIComponent(address)}/info`)
.then(({ data }) => zAccountData.parse(data));
.then(({ data }) => parseWithError(zAccountData, data));

const zAccountTableCounts = z
.object({
Expand All @@ -52,4 +52,4 @@ export const getAccountTableCounts = async (
is_wasm: isWasm,
},
})
.then(({ data }) => zAccountTableCounts.parse(data));
.then(({ data }) => parseWithError(zAccountTableCounts, data));
3 changes: 2 additions & 1 deletion src/lib/services/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";

import type { AssetInfo } from "lib/types";
import { zAssetInfo } from "lib/types";
import { parseWithError } from "lib/utils";

export const getAssetInfos = async (
endpoint: string,
Expand All @@ -14,4 +15,4 @@ export const getAssetInfos = async (
with_prices: withPrices,
},
})
.then(({ data }) => z.array(zAssetInfo).parse(data));
.then(({ data }) => parseWithError(z.array(zAssetInfo), data));
3 changes: 2 additions & 1 deletion src/lib/services/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from "axios";
import { z } from "zod";

import type { BechAddr } from "lib/types";
import { parseWithError } from "lib/utils";

const zBalancesResponse = z
.array(
Expand All @@ -19,4 +20,4 @@ export const getBalances = async (
): Promise<Coin[]> =>
axios
.get(`${endpoint}/${encodeURIComponent(address)}/balances`)
.then(({ data }) => zBalancesResponse.parse(data));
.then(({ data }) => parseWithError(zBalancesResponse, data));
6 changes: 3 additions & 3 deletions src/lib/services/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "zod";

import type { Block, BlockData, Validator } from "lib/types";
import { zValidatorAddr, zUtcDate } from "lib/types";
import { parseTxHash } from "lib/utils";
import { parseTxHash, parseWithError } from "lib/utils";

const zNullableValidator = z.nullable(
z
Expand Down Expand Up @@ -54,7 +54,7 @@ export const getBlocks = async (
offset,
},
})
.then(({ data }) => zBlocksResponse.parse(data));
.then(({ data }) => parseWithError(zBlocksResponse, data));

const zBlockDataResponse = z
.object({
Expand All @@ -77,4 +77,4 @@ const zBlockDataResponse = z
export const getBlockData = async (endpoint: string, height: number) =>
axios
.get(`${endpoint}/${height}/info`)
.then(({ data }) => zBlockDataResponse.parse(data));
.then(({ data }) => parseWithError(zBlockDataResponse, data));
5 changes: 3 additions & 2 deletions src/lib/services/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { z } from "zod";

import { AccessConfigPermission, zBechAddr } from "lib/types";
import type { BechAddr, BechAddr20, CodeInfo, Option } from "lib/types";
import { parseWithError } from "lib/utils";

export interface CodeIdInfoResponse {
code_info: {
Expand Down Expand Up @@ -71,7 +72,7 @@ export const getCodes = async (
permission,
},
})
.then(({ data }) => zCodesResponse.parse(data));
.then(({ data }) => parseWithError(zCodesResponse, data));

export const getCodesByAddress = async (
endpoint: string,
Expand All @@ -86,4 +87,4 @@ export const getCodesByAddress = async (
offset,
},
})
.then(({ data }) => zCodesResponse.parse(data));
.then(({ data }) => parseWithError(zCodesResponse, data));
18 changes: 9 additions & 9 deletions src/lib/services/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
zPublicContractInfo,
zUtcDate,
} from "lib/types";
import { encode, parseTxHash, snakeToCamel } from "lib/utils";
import { encode, parseTxHash, parseWithError, snakeToCamel } from "lib/utils";

export interface ContractCw2Info {
contract: string;
Expand Down Expand Up @@ -58,7 +58,7 @@ export const queryContract = async (
contractAddress: BechAddr32
) =>
axios(`${endpoint}/cosmwasm/wasm/v1/contract/${contractAddress}`).then(
({ data }) => zContractRest.parse(data)
({ data }) => parseWithError(zContractRest, data)
);

const zContractsResponseItem = z
Expand Down Expand Up @@ -101,7 +101,7 @@ export const getContracts = async (
offset,
},
})
.then(({ data }) => zContractsResponse.parse(data));
.then(({ data }) => parseWithError(zContractsResponse, data));

export const getInstantiatedContractsByAddress = async (
endpoint: string,
Expand All @@ -119,7 +119,7 @@ export const getInstantiatedContractsByAddress = async (
},
}
)
.then(({ data }) => zContractsResponse.parse(data));
.then(({ data }) => parseWithError(zContractsResponse, data));

export const getAdminContractsByAddress = async (
endpoint: string,
Expand All @@ -134,7 +134,7 @@ export const getAdminContractsByAddress = async (
offset,
},
})
.then(({ data }) => zContractsResponse.parse(data));
.then(({ data }) => parseWithError(zContractsResponse, data));

export const zContract = z
.object({
Expand Down Expand Up @@ -182,7 +182,7 @@ export const getContractDataByContractAddress = async (
is_gov: isGov,
},
})
.then(({ data }) => zContractData.parse(data));
.then(({ data }) => parseWithError(zContractData, data));

const zContractTableCounts = z
.object({
Expand All @@ -204,7 +204,7 @@ export const getContractTableCounts = async (
is_gov: isGov,
},
})
.then(({ data }) => zContractTableCounts.parse(data));
.then(({ data }) => parseWithError(zContractTableCounts, data));

const zMigrationHistoriesResponseItem = z
.object({
Expand Down Expand Up @@ -248,7 +248,7 @@ export const getMigrationHistoriesByContractAddress = async (
offset,
},
})
.then(({ data }) => zMigrationHistoriesResponse.parse(data));
.then(({ data }) => parseWithError(zMigrationHistoriesResponse, data));

const zContractQueryMsgs = z
.object({
Expand All @@ -264,4 +264,4 @@ export const getContractQueryMsgs = async (
) =>
axios
.get(`${endpoint}/${encodeURIComponent(contractAddress)}/query-msgs`)
.then(({ data }) => zContractQueryMsgs.parse(data));
.then(({ data }) => parseWithError(zContractQueryMsgs, data));
9 changes: 7 additions & 2 deletions src/lib/services/contractState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { z } from "zod";

import type { BechAddr32, ContractState } from "lib/types";
import { zPagination } from "lib/types/rest";
import { libDecode, parseJsonStr, parseStateKey } from "lib/utils";
import {
libDecode,
parseJsonStr,
parseStateKey,
parseWithError,
} from "lib/utils";

const zResponseContractState = z.object({
key: z.string(),
Expand All @@ -28,7 +33,7 @@ export const getContractStates = async (
pagination_key: paginationKey,
},
})
.then(({ data }) => zResponseContractStates.parse(data));
.then(({ data }) => parseWithError(zResponseContractStates, data));

const parsedStates = states.models.map<ContractState>((model) => ({
rawKey: model.key,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/services/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from "axios";
import { z } from "zod";

import { type BechAddr, zUtcDate, zValidator } from "lib/types";
import { snakeToCamel } from "lib/utils";
import { parseWithError, snakeToCamel } from "lib/utils";

const zDelegations = z
.object({
Expand Down Expand Up @@ -132,4 +132,4 @@ export const getDelegationsByAddress = async (
): Promise<Delegations> =>
axios
.get(`${endpoint}/${encodeURIComponent(address)}/delegations`)
.then(({ data }) => zDelegations.parse(data));
.then(({ data }) => parseWithError(zDelegations, data));
5 changes: 3 additions & 2 deletions src/lib/services/move/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { zHexAddr, UpgradePolicy, zUtcDate, zBechAddr } from "lib/types";
import {
libDecode,
parseJsonABI,
parseWithError,
serializeAbiData,
snakeToCamel,
} from "lib/utils";
Expand All @@ -44,7 +45,7 @@ export const getModulesByAddress = async (
): Promise<AccountModulesResponse> =>
axios
.get(`${endpoint}/${encodeURIComponent(address)}/move/modules`)
.then(({ data }) => zAccountModulesResponse.parse(data));
.then(({ data }) => parseWithError(zAccountModulesResponse, data));

export const getAccountModules = async (
baseEndpoint: string,
Expand Down Expand Up @@ -189,4 +190,4 @@ export const getModules = async (
offset,
},
})
.then(({ data }) => zModulesResponse.parse(data));
.then(({ data }) => parseWithError(zModulesResponse, data));
3 changes: 2 additions & 1 deletion src/lib/services/move/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from "axios";
import { z } from "zod";

import { zHexAddr } from "lib/types";
import { parseWithError } from "lib/utils";

const zPairResponseCoin = z.object({
metadata: zHexAddr,
Expand Down Expand Up @@ -43,4 +44,4 @@ const zPairResponse = z
export const getMovePoolInfos = async (endpoint: string) =>
axios
.get(`${endpoint}/pools`)
.then(({ data }) => z.array(zPairResponse).parse(data));
.then(({ data }) => parseWithError(z.array(zPairResponse), data));
4 changes: 2 additions & 2 deletions src/lib/services/move/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "zod";

import type { Addr } from "lib/types";
import { zHexAddr } from "lib/types";
import { snakeToCamel } from "lib/utils";
import { parseWithError, snakeToCamel } from "lib/utils";

const zResourcesResponseItem = z
.object({
Expand All @@ -26,4 +26,4 @@ export const getAccountResources = async (
): Promise<ResourceResponse> =>
axios
.get(`${endpoint}/${encodeURIComponent(address)}/move/resources`)
.then(({ data }) => zResourcesResponse.parse(data));
.then(({ data }) => parseWithError(zResourcesResponse, data));
38 changes: 23 additions & 15 deletions src/lib/services/nft/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "lib/query";
import type { HexAddr, HexAddr32, MutateEvent } from "lib/types";
import { zHexAddr, zHexAddr32, zRemark, zUtcDate } from "lib/types";
import { parseTxHash } from "lib/utils";
import { parseTxHash, parseWithError } from "lib/utils";

const zCollection = z
.object({
Expand Down Expand Up @@ -58,7 +58,7 @@ export const getCollections = async (
query: getCollectionsQuery,
variables: { offset, pageSize, search },
})
.then(({ data: res }) => zCollectionsResponse.parse(res.data));
.then(({ data: res }) => parseWithError(zCollectionsResponse, res.data));

const zCollectionByCollectionAddressResponse = z.object({
data: z
Expand Down Expand Up @@ -102,7 +102,7 @@ export const getCollectionByCollectionAddress = async (
variables: { vmAddress: collectionAddress },
})
.then(({ data: res }) =>
zCollectionByCollectionAddressResponse.parse({
parseWithError(zCollectionByCollectionAddressResponse, {
data: res.data.collections[0],
})
);
Expand All @@ -122,7 +122,7 @@ export const getCollectionTotalBurnedCount = async (
query: getCollectionTotalBurnedCountQuery,
variables: { vmAddress: collectionAddress },
})
.then(({ data }) => zTotalBurnedResponse.parse(data.data));
.then(({ data }) => parseWithError(zTotalBurnedResponse, data.data));

const zCollectionCreatorResponse = z
.object({
Expand Down Expand Up @@ -165,7 +165,9 @@ export const getCollectionCreator = async (
query: getCollectionCreatorQuery,
variables: { vmAddress: collectionAddress },
})
.then(({ data: res }) => zCollectionCreatorResponse.parse(res.data));
.then(({ data: res }) =>
parseWithError(zCollectionCreatorResponse, res.data)
);

const zActivity = z
.object({
Expand Down Expand Up @@ -213,7 +215,7 @@ export const getCollectionActivities = async (
},
})
.then(({ data: res }) =>
zActivity.array().parse(res.data.collection_transactions)
parseWithError(zActivity.array(), res.data.collection_transactions)
);
};

Expand All @@ -236,7 +238,7 @@ export const getCollectionActivitiesCount = async (
query: getCollectionActivitiesCountQuery,
variables: { vmAddress: collectionAddress },
})
.then(({ data }) => zActivitiesCountResponse.parse(data.data));
.then(({ data }) => parseWithError(zActivitiesCountResponse, data.data));

const zCollectionMutateEventsResponse = z
.object({
Expand Down Expand Up @@ -270,9 +272,10 @@ export const getCollectionMutateEvents = async (
},
})
.then(({ data: res }) =>
zCollectionMutateEventsResponse
.array()
.parse(res.data.collection_mutation_events)
parseWithError(
zCollectionMutateEventsResponse.array(),
res.data.collection_mutation_events
)
);

const zMutationEventsCountResponseItem = z
Expand All @@ -294,7 +297,9 @@ export const getCollectionMutateEventsCount = async (
query: getCollectionMutateEventsCountQuery,
variables: { vmAddress: collectionAddress },
})
.then(({ data }) => zMutationEventsCountResponseItem.parse(data.data));
.then(({ data }) =>
parseWithError(zMutationEventsCountResponseItem, data.data)
);

const zUniqueHoldersCountResponseItem = z
.object({
Expand All @@ -313,7 +318,9 @@ export const getCollectionUniqueHoldersCount = async (
query: getCollectionUniqueHoldersCountQuery,
variables: { vmAddress: collectionAddress },
})
.then(({ data }) => zUniqueHoldersCountResponseItem.parse(data.data));
.then(({ data }) =>
parseWithError(zUniqueHoldersCountResponseItem, data.data)
);

const zCollectionsByAccountResponse = z
.object({
Expand Down Expand Up @@ -343,7 +350,8 @@ export const getCollectionsByAccount = async (
variables: { accountAddress },
})
.then(({ data: res }) =>
zCollectionsByAccountResponse
.parse(res.data.collections)
.filter((collection) => collection.hold > 0)
parseWithError(
zCollectionsByAccountResponse,
res.data.collections
).filter((collection) => collection.hold > 0)
);
Loading
Loading