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

Update client to use injected Axios Instance #22

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 27 additions & 11 deletions .pnp.cjs

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

Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"dependencies": {
"@many-things/cosmos-query": "*",
"axios": "^1.2.2",
"next": "12.2.5",
"qs": "^6.11.0",
"react": "18.2.0",
"react-dom": "18.2.0"
},
Expand Down
13 changes: 12 additions & 1 deletion examples/application/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { NextPage } from "next";
import { useEffect } from "react";
import { getCosmosQuery } from "@many-things/cosmos-query";
import axios, { ParamsSerializerOptions } from "axios";
import { stringify } from "qs";

const lcdList = {
["cosmoshub-4"]: "https://lcd-cosmoshub.blockapsis.com",
Expand All @@ -27,9 +29,18 @@ const lcdList = {
};

const Home: NextPage = () => {
const { getAccounts } = getCosmosQuery(lcdList["osmosis-1"]);
const client = axios.create({
baseURL: lcdList["osmosis-1"],
paramsSerializer: {
serialize: (params: Record<string, any>) => {
return stringify(params, { allowDots: true });
},
},
});
const { getAccounts } = getCosmosQuery(client);
Comment on lines +32 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용법이 앞으로 위와 같은 방식으로 변경됩니다.

사용되는 서비스에서 AxiosInstance를 만들고 parameter로 전달해주세요.
Axios는 v1.x를 사용해야합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paramsSerializer를 덮어쓰는 방법이 있을지


useEffect(() => {
console.info("-----test--00------");
(async () => {
const a = await getAccounts({
pagination: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"vite-plugin-dts": "^1.4.1"
},
"dependencies": {
"axios": "^0.27.2",
"axios": "^1.2.2",
"buffer": "^6.0.3",
"qs": "^6.11.0"
}
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/apis/cosmos/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { instance } from "../../../common";
import { AxiosInstance } from "axios";
import type { PaginationParams } from "../../../types";
import type {
AccountResponse,
Expand All @@ -9,28 +9,27 @@ import type {
export type { AccountResponse, AccountsResponse, AuthParamsResponse };

export const getAccounts =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({
pagination,
}: {
pagination?: PaginationParams;
}): Promise<AccountsResponse> => {
return (
await instance(baseURL).get("/cosmos/auth/v1beta1/accounts", {
await instance.get("/cosmos/auth/v1beta1/accounts", {
params: { pagination },
})
).data;
};

export const getAccountByAddress =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({ address }: { address: string }): Promise<AccountResponse> => {
return (
await instance(baseURL).get(`/cosmos/auth/v1beta1/accounts/${address}`)
).data;
return (await instance.get(`/cosmos/auth/v1beta1/accounts/${address}`))
.data;
};

export const getAuthParams =
(baseURL: string) => async (): Promise<AuthParamsResponse> => {
return (await instance(baseURL).get("/cosmos/auth/v1beta1/params")).data;
(instance: AxiosInstance) => async (): Promise<AuthParamsResponse> => {
return (await instance.get("/cosmos/auth/v1beta1/params")).data;
};
6 changes: 3 additions & 3 deletions packages/core/src/apis/cosmos/authz/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { instance } from "../../../common";
import { AxiosInstance } from "axios";
import type { PaginationParams } from "../../../types";
import type { GrantsResponse } from "./types";

export type { GrantsResponse };

export const getGrants =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({
granter,
grantee,
Expand All @@ -18,7 +18,7 @@ export const getGrants =
pagination?: PaginationParams;
}): Promise<GrantsResponse> => {
return (
await instance(baseURL).get("/cosmos/authz/v1beta1/grants", {
await instance.get("/cosmos/authz/v1beta1/grants", {
params: {
granter,
grantee,
Expand Down
49 changes: 20 additions & 29 deletions packages/core/src/apis/cosmos/bank/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { instance } from "../../../common";
import { AxiosInstance } from "axios";
import type { PaginationParams } from "../../../types";
import type {
AllBalancesResponse,
Expand All @@ -23,7 +23,7 @@ export type {
};

export const getAllBalances =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({
address,
pagination,
Expand All @@ -32,14 +32,14 @@ export const getAllBalances =
pagination?: PaginationParams;
}): Promise<AllBalancesResponse> => {
return (
await instance(baseURL).get(`/cosmos/bank/v1beta1/balances/${address}`, {
await instance.get(`/cosmos/bank/v1beta1/balances/${address}`, {
params: { pagination },
})
).data;
};

export const getBalance =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({
address,
denom,
Expand All @@ -48,14 +48,12 @@ export const getBalance =
denom: string;
}): Promise<BalanceResponse> => {
return (
await instance(baseURL).get(
`/cosmos/bank/v1beta1/balances/${address}/${denom}`
)
await instance.get(`/cosmos/bank/v1beta1/balances/${address}/${denom}`)
).data;
};

export const getDenomOwners =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({
denom,
pagination,
Expand All @@ -64,61 +62,54 @@ export const getDenomOwners =
pagination?: PaginationParams;
}): Promise<DenomOwnersResponse> => {
return (
await instance(baseURL).get(
`/cosmos/bank/v1beta1/denom_owners/${denom}`,
{
params: { pagination },
}
)
await instance.get(`/cosmos/bank/v1beta1/denom_owners/${denom}`, {
params: { pagination },
})
).data;
};

export const getAllDenomsMetadata =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({
pagination,
}: {
pagination?: PaginationParams;
}): Promise<AllDenomsMetadataResponse> => {
return (
await instance(baseURL).get("/cosmos/bank/v1beta1/denoms_metadata", {
await instance.get("/cosmos/bank/v1beta1/denoms_metadata", {
params: { pagination },
})
).data;
};

export const getDenomMetadata =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({ denom }: { denom: string }): Promise<DenomMetadataResponse> => {
return (
await instance(baseURL).get(
`/cosmos/bank/v1beta1/denoms_metadata/${denom}`
)
).data;
return (await instance.get(`/cosmos/bank/v1beta1/denoms_metadata/${denom}`))
.data;
};

export const getBankParams =
(baseURL: string) => async (): Promise<BankParamsResponse> => {
return (await instance(baseURL).get("/cosmos/bank/v1beta1/params")).data;
(instance: AxiosInstance) => async (): Promise<BankParamsResponse> => {
return (await instance.get("/cosmos/bank/v1beta1/params")).data;
};

export const getTotalSupply =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({
pagination,
}: {
pagination?: PaginationParams;
}): Promise<TotalSupplyResponse> => {
return (
await instance(baseURL).get("/cosmos/bank/v1beta1/supply", {
await instance.get("/cosmos/bank/v1beta1/supply", {
params: { pagination },
})
).data;
};

export const getSupply =
(baseURL: string) =>
(instance: AxiosInstance) =>
async ({ denom }: { denom: string }): Promise<SupplyResponse> => {
return (await instance(baseURL).get(`/cosmos/bank/v1beta1/supply/${denom}`))
.data;
return (await instance.get(`/cosmos/bank/v1beta1/supply/${denom}`)).data;
};
Loading