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

Migrate GraphQL to API #1155

Merged
merged 58 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
5e13566
feat(utils): add get account type by api
Poafs1 Sep 4, 2024
0709d81
docs: update changelog
Poafs1 Sep 4, 2024
d3639b7
feat(utils): update txs graphql to api
Poafs1 Sep 6, 2024
6ca8474
docs: update changelog
Poafs1 Sep 6, 2024
00d29aa
feat(utils): update code to use api instead of graphql
Poafs1 Sep 6, 2024
d7e8b0b
feat(utils): remove graphql query from fe (tx)
Poafs1 Sep 6, 2024
ad1fc68
docs: update changelog
Poafs1 Sep 6, 2024
e01c21f
docs: update changelog
Poafs1 Sep 6, 2024
67ada12
docs: update changelog
Poafs1 Sep 6, 2024
42d49d4
feat(utils): update txs pool service function
Poafs1 Sep 9, 2024
64483f5
feat(utils): nft graphql to api
Poafs1 Sep 10, 2024
3a0aea7
docs: update changelog
Poafs1 Sep 10, 2024
7bac957
feat(utils): add nft collection api
Poafs1 Sep 10, 2024
170ea44
feat(utils): add nft collections api instead of gql
Poafs1 Sep 11, 2024
bd1b2e1
docs: update changelog
Poafs1 Sep 11, 2024
91c442e
feat(types): update zod
Poafs1 Sep 11, 2024
8e08321
feat(types): update zod type
Poafs1 Sep 11, 2024
9f94029
feat(types): update zod
Poafs1 Sep 11, 2024
ab91308
fix: pr comments
Poafs1 Sep 12, 2024
6286e2f
fix: pr comments
Poafs1 Sep 13, 2024
b2a34b9
Merge pull request #1132 from alleslabs/feature/cfe-634-account-gql
evilpeach Sep 16, 2024
84974fd
fix: pr comments
Poafs1 Sep 16, 2024
470fec7
Merge branch 'refactor/graphql' into feature/cfe-636-code-graphql
evilpeach Sep 16, 2024
3265cee
Merge pull request #1148 from alleslabs/feature/cfe-638-nft-collectio…
evilpeach Sep 17, 2024
ba507a3
Merge pull request #1136 from alleslabs/feature/cfe-636-code-graphql
evilpeach Sep 17, 2024
e382c19
Merge branch 'develop' into refactor/graphql
songwongtp Sep 17, 2024
e0ba961
feat(utils): update zod
Poafs1 Sep 17, 2024
66a0deb
fix: conflict
Poafs1 Sep 18, 2024
9325348
fix: pr comments
Poafs1 Sep 18, 2024
8f64587
docs: update changelog
Poafs1 Sep 18, 2024
8410577
fix: merge conflict
Poafs1 Sep 18, 2024
7335bbd
fix: handle count
songwongtp Sep 18, 2024
8577048
fix: pool txs table
songwongtp Sep 18, 2024
f96c818
Merge pull request #1135 from alleslabs/feature/cfe-635-tx-graphql
songwongtp Sep 18, 2024
843398d
Merge branch 'develop' into refactor/graphql
songwongtp Sep 18, 2024
7c9c08e
Merge branch 'refactor/graphql' into feature/cfe-637-nft-graphql
Poafs1 Sep 18, 2024
6717810
Merge branch 'refactor/graphql' into feature/cfe-637-nft-graphql
songwongtp Sep 18, 2024
5cb435c
docs: update changelog
Poafs1 Sep 18, 2024
6cb1868
fix: pr comments
Poafs1 Sep 18, 2024
be7c174
fix: pr comments
Poafs1 Sep 18, 2024
d6a0cd5
fix: pr comments
Poafs1 Sep 18, 2024
195be75
Merge pull request #1140 from alleslabs/feature/cfe-637-nft-graphql
evilpeach Sep 18, 2024
5dee693
feat: osmosis pools to api
songwongtp Sep 18, 2024
514a810
Merge branch 'refactor/graphql' into feat/pool-graphql
songwongtp Sep 18, 2024
1240439
fix: query params
songwongtp Sep 18, 2024
7288a8c
feat: remove graphql and change faucet button
songwongtp Sep 18, 2024
e03fbc1
fix: remove unused query keys
songwongtp Sep 18, 2024
848a789
fix: comment
songwongtp Sep 19, 2024
aec6f05
fix: remove faucet entry
songwongtp Sep 19, 2024
f52897b
Merge pull request #1156 from alleslabs/feat/pool-graphql
songwongtp Sep 19, 2024
cd02ca3
Merge pull request #1157 from alleslabs/feat/remove-gql-and-faucet
evilpeach Sep 19, 2024
277ffb2
fix: remove expression
songwongtp Sep 20, 2024
f58d70d
fix: gql
songwongtp Sep 20, 2024
9b87cb4
fix: remove gql
songwongtp Sep 20, 2024
38fe3ce
fix: invalid search proposal and pool
songwongtp Sep 20, 2024
dda393f
fix: scaling factors type
songwongtp Sep 20, 2024
ee113a1
Merge pull request #1159 from alleslabs/fix/invalid-search
songwongtp Sep 20, 2024
1764573
Merge branch 'develop' into refactor/graphql
songwongtp Sep 20, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#1136](https://github.com/alleslabs/celatone-frontend/pull/1136) Update code to get data from API instead of GraphQL
- [#1132](https://github.com/alleslabs/celatone-frontend/pull/1132) Update account type to get data from API instead of GraphQL

### Bug fixes

- [#1137](https://github.com/alleslabs/celatone-frontend/pull/1137) Bump axios and remove initia js client usage
Expand Down
3 changes: 1 addition & 2 deletions src/lib/app-provider/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export enum CELATONE_QUERY_KEYS {
// ACCOUNT
ACCOUNT_DATA = "CELATONE_QUERY_ACCOUNT_DATA",
ACCOUNT_TYPE = "CELATONE_QUERY_ACCOUNT_TYPE",
ACCOUNT_TYPE_LCD = "CELATONE_QUERY_ACCOUNT_TYPE_LCD",
ACCOUNT_BECH_32_LCD = "CELATONE_QUERY_ACCOUNT_BECH_32_LCD",
// ASSET
ASSET_INFOS = "CELATONE_QUERY_ASSET_INFOS",
Expand All @@ -31,7 +30,7 @@ export enum CELATONE_QUERY_KEYS {
CODES_LCD = "CELATONE_QUERY_CODES_LCD",
CODES_BY_ADDRESS = "CELATONE_QUERY_CODES_BY_ADDRESS",
ALL_CODES_BY_ADDRESS = "CELATONE_QUERY_ALL_CODES_BY_ADDRESS",
CODES_BY_IDS = "CELATONE_QUERY_CODES_BY_IDS",
CODE_LIST = "CELATONE_QUERY_CODE_LIST",
CODE_DATA = "CELATONE_QUERY_CODE_DATA",
CODE_DATA_LCD = "CELATONE_QUERY_CODE_DATA_LCD",
// CONTRACT
Expand Down
14 changes: 2 additions & 12 deletions src/lib/components/modal/account/SaveNewAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
useCelatoneApp,
useExampleAddresses,
useMoveConfig,
useTierConfig,
useValidateAddress,
useWasmConfig,
} from "lib/app-provider";
Expand All @@ -18,7 +17,7 @@ import { ControllerInput, ControllerTextarea } from "lib/components/forms";
import { useGetMaxLengthError, useHandleAccountSave } from "lib/hooks";
import { useFormatAddresses } from "lib/hooks/useFormatAddresses";
import { useAccountStore } from "lib/providers/store";
import { useAccountType, useAccountTypeLcd } from "lib/services/account";
import { useAccountType } from "lib/services/account";
import type { BechAddr } from "lib/types";
import { AccountType } from "lib/types";

Expand Down Expand Up @@ -49,7 +48,6 @@ export function SaveNewAccountModal({
publicDescription,
}: SaveNewAccountModalProps) {
const { constants } = useCelatoneApp();
const { isFullTier } = useTierConfig();
const { user: exampleUserAddress } = useExampleAddresses();
const { isSomeValidAddress } = useValidateAddress();
const formatAddresses = useFormatAddresses();
Expand Down Expand Up @@ -109,20 +107,12 @@ export function SaveNewAccountModal({
setErrorStatus(err.message);
};

const { refetch: refetchLite } = useAccountTypeLcd(addressState, {
const { refetch } = useAccountType(addressState, {
enabled: false,
onSuccess,
onError,
});

const { refetch: refetchFull } = useAccountType(addressState, {
enabled: false,
onSuccess,
onError,
});

const refetch = isFullTier ? refetchFull : refetchLite;

useEffect(() => {
if (addressState.trim().length === 0) {
setStatus({
Expand Down
9 changes: 3 additions & 6 deletions src/lib/model/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { useCurrentChain } from "lib/app-provider";
import type { PermissionFilterValue } from "lib/hooks";
import { useCodePermissionFilter, useCodeSearchFilter } from "lib/hooks";
import { useCodeStore } from "lib/providers/store";
import {
useAllCodesByAddress,
useCodeListByCodeIds,
} from "lib/services/wasm/code";
import { useAllCodesByAddress, useCodeList } from "lib/services/wasm/code";
import type { BechAddr, CodeInfo } from "lib/types";
import { AccessConfigPermission } from "lib/types";

Expand All @@ -33,10 +30,10 @@ const useSavedCodes = () => {
const { lastSavedCodes, lastSavedCodeIds, isHydrated } = useCodeStore();

const savedCodeIds = lastSavedCodeIds();
const { data: rawSavedCodes, isLoading } = useCodeListByCodeIds(savedCodeIds);
const { data: rawSavedCodes, isLoading } = useCodeList(savedCodeIds);

const savedCodes = lastSavedCodes().map<CodeInfo>((localSavedCode) => {
const rawSavedCode = rawSavedCodes?.find(
const rawSavedCode = rawSavedCodes?.items.find(
(savedCode) => savedCode.id === localSavedCode.id
);
return {
Expand Down
9 changes: 0 additions & 9 deletions src/lib/query/account.ts

This file was deleted.

85 changes: 0 additions & 85 deletions src/lib/query/code.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export * from "./block";
export * from "./code";
export * from "./contract";
export * from "./pool";
export * from "./tx";
export * from "./account";
export * from "./collection";
export * from "./collectionOld";
export * from "./nft";
Expand Down
11 changes: 10 additions & 1 deletion src/lib/services/account/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import axios from "axios";

import { zAccountData, zAccountTableCounts } from "../types";
import {
zAccountData,
zAccountTableCounts,
zAccountTypeResponse,
} from "../types";
import type { AccountData, AccountTableCounts } from "../types";
import type { BechAddr } from "lib/types";
import { parseWithError } from "lib/utils";
Expand All @@ -27,3 +31,8 @@ export const getAccountTableCounts = async (
},
})
.then(({ data }) => parseWithError(zAccountTableCounts, data));

export const getAccountType = async (endpoint: string, address: BechAddr) =>
axios
.get(`${endpoint}/${encodeURIComponent(address)}/type`)
.then(({ data }) => parseWithError(zAccountTypeResponse, data));
42 changes: 0 additions & 42 deletions src/lib/services/account/gql.ts

This file was deleted.

14 changes: 8 additions & 6 deletions src/lib/services/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "lib/app-provider";
import type { AccountType, BechAddr, Option } from "lib/types";

import { getAccountData, getAccountTableCounts } from "./api";
import { getAccountData, getAccountTableCounts, getAccountType } from "./api";
import {
getAccountBech32Lcd,
getAccountDataLcd,
Expand Down Expand Up @@ -63,13 +63,15 @@ export const useAccountTableCounts = (
);
};

export const useAccountTypeLcd = (
export const useAccountType = (
address: Option<BechAddr>,
options: Pick<
UseQueryOptions<AccountType, Error>,
"enabled" | "onSuccess" | "onError"
> = {}
): UseQueryResult<AccountType> => {
const { isFullTier } = useTierConfig();
const apiEndpoint = useBaseApiRoute("accounts");
const lcdEndpoint = useLcdEndpoint();

const queryFn = useCallback(async () => {
Expand All @@ -78,11 +80,13 @@ export const useAccountTypeLcd = (
"Fetching account type: failed to retrieve address. (useAccountTypeLcd)"
);

if (isFullTier) return getAccountType(apiEndpoint, address);

return getAccountTypeLcd(lcdEndpoint, address);
}, [lcdEndpoint, address]);
}, [lcdEndpoint, address, apiEndpoint, isFullTier]);

return useQuery(
[CELATONE_QUERY_KEYS.ACCOUNT_TYPE_LCD, lcdEndpoint, address],
[CELATONE_QUERY_KEYS.ACCOUNT_TYPE, apiEndpoint, lcdEndpoint, address],
queryFn,
{
...options,
Expand All @@ -103,5 +107,3 @@ export const useAccountBech32 = (
refetchOnWindowFocus: false,
}
);

export * from "./gql";
13 changes: 12 additions & 1 deletion src/lib/services/types/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { z } from "zod";

import { AccountTypeLcd, zProjectInfo, zPublicAccountInfo } from "lib/types";
import {
AccountType,
AccountTypeLcd,
zProjectInfo,
zPublicAccountInfo,
} from "lib/types";
import { snakeToCamel } from "lib/utils";

const zIcns = z.object({
Expand Down Expand Up @@ -38,6 +43,12 @@ export const zAccountTypeLcd = z
})
.transform((data) => data.account["@type"]);

export const zAccountTypeResponse = z
.object({
type: z.nativeEnum(AccountType),
})
.transform((val) => val.type);

export const zAccountBech32LcdResponse = z
.object({
bech32_prefix: z.string(),
Expand Down
14 changes: 5 additions & 9 deletions src/lib/services/types/wasm/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,7 @@ const zCodesResponseItem = z
instantiate_permission: z.nativeEnum(AccessConfigPermission),
permission_addresses: z.array(zBechAddr),
})
.transform<CodeInfo>((val) => ({
id: val.id,
cw2Contract: val.cw2_contract,
cw2Version: val.cw2_version,
uploader: val.uploader,
contractCount: val.contract_count,
instantiatePermission: val.instantiate_permission,
permissionAddresses: val.permission_addresses,
}));
.transform<CodeInfo>(snakeToCamel);

export const zCodesResponse = z.object({
items: z.array(zCodesResponseItem),
Expand Down Expand Up @@ -163,3 +155,7 @@ export const zCodeInfoResponseLcd = z
uploader: creator,
})
);

export const zCodeListResponse = z.object({
items: z.array(zCodesResponseItem),
});
15 changes: 14 additions & 1 deletion src/lib/services/wasm/code/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import axios from "axios";

import { zCodeData, zCodesResponse } from "lib/services/types";
import {
zCodeData,
zCodeListResponse,
zCodesResponse,
} from "lib/services/types";
import type { CodeData, CodesResponse } from "lib/services/types";
import type { BechAddr, BechAddr20, Option } from "lib/types";
import { parseWithError } from "lib/utils";
Expand Down Expand Up @@ -58,3 +62,12 @@ export const getCodeData = async (
},
})
.then(({ data }) => parseWithError(zCodeData, data));

export const getCodeList = async (endpoint: string, codeIds: number[]) =>
axios
.get(`${endpoint}/list`, {
params: {
code_ids: codeIds.join(","),
},
})
.then(({ data }) => parseWithError(zCodeListResponse, data));
Loading
Loading