Skip to content

Commit

Permalink
Merge branch 'develop' into feat/v1-contract-query-msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpeach committed Dec 27, 2023
2 parents b3fbdba + 7882521 commit 523125e
Show file tree
Hide file tree
Showing 41 changed files with 422 additions and 287 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#698](https://github.com/alleslabs/celatone-frontend/pull/698) Add ledger

### Improvements

- [#703](https://github.com/alleslabs/celatone-frontend/pull/703) api v1 - contract's query msgs
- [#697](https://github.com/alleslabs/celatone-frontend/pull/697) api v1 - contract tables (migrations and related proposals)
- [#696](https://github.com/alleslabs/celatone-frontend/pull/696) api v1 - block details
- [#695](https://github.com/alleslabs/celatone-frontend/pull/695) api v1 - contract states
- [#678](https://github.com/alleslabs/celatone-frontend/pull/678) api v1 - contract table counts
Expand Down
4 changes: 2 additions & 2 deletions src/lib/app-provider/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export enum CELATONE_QUERY_KEYS {
INSTANTIATED_COUNT_BY_WALLET_ADDRESS = "CELATONE_QUERY_INSTANTIATED_COUNT_BY_WALLET_ADDRESS",
INSTANTIATED_LIST_BY_WALLET_ADDRESS = "CELATONE_QUERY_INSTANTIATED_LIST_BY_WALLET_ADDRESS",
ADMINS_BY_CONTRACTS = "CELATONE_QUERY_ADMINS_BY_CONTRACTS",
CONTRACT_MIGRATION_HISTORIES_PAGINATION = "CELATONE_QUERY_CONTRACT_MIGRATION_HISTORIES_PAGINATION",
CONTRACT_MIGRATION_HISTORIES_BY_CONTRACT_ADDRESS = "CELATONE_QUERY_CONTRACT_MIGRATION_HISTORIES_BY_CONTRACT_ADDRESS",
CONTRACTS_BY_CODE_ID_PAGINATION = "CELATONE_QUERY_CONTRACTS_BY_CODE_ID_PAGINATION",
CONTRACTS_BY_CODE_ID_COUNT = "CELATONE_QUERY_CONTRACTS_BY_CODE_ID_COUNT",
// X/STAKING
Expand All @@ -52,7 +52,7 @@ export enum CELATONE_QUERY_KEYS {
// FAUCET
FAUCET_INFO = "CELATONE_QUERY_FAUCET_INFO",
// X/GOV
RELATED_PROPOSALS_BY_CONTRACT_ADDRESS_PAGINATION = "CELATONE_QUERY_RELATED_PROPOSALS_BY_CONTRACT_ADDRESS_PAGINATION",
RELATED_PROPOSALS_BY_CONTRACT_ADDRESS = "CELATONE_QUERY_RELATED_PROPOSALS_BY_CONTRACT_ADDRESS",
PROPOSALS_BY_MODULE_ID = "CELATONE_QUERY_PROPOSALS_BY_MODULE_ID",
PROPOSALS_COUNT_BY_MODULE_ID = "CELATONE_QUERY_PROPOSALS_COUNT_BY_MODULE_ID",
PROPOSALS_BY_ADDRESS = "CELATONE_QUERY_PROPOSALS_BY_ADDRESS",
Expand Down
1 change: 1 addition & 0 deletions src/lib/app-provider/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./useMediaQuery";
export * from "./useNetworkChange";
export * from "./useRestrictedInput";
export * from "./useSelectChain";
export * from "./useGetSigningClient";
export * from "./useBaseApiRoute";
export * from "./useRPCEndpoint";
export * from "./useConfig";
Expand Down
63 changes: 63 additions & 0 deletions src/lib/app-provider/hooks/useGetSigningClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable */
import type { WalletClient } from "@cosmos-kit/core";

import { useCurrentChain } from "./useCurrentChain";
import { useCallback } from "react";
import { useWalletClient } from "@cosmos-kit/react";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { useRPCEndpoint } from "./useRPCEndpoint";
import { getCustomedSigningCosmwasm } from "lib/providers/cosmos-kit/options";

type MergedWalletClient =
| WalletClient
// | import("@cosmos-kit/cosmostation-extension/cjs/extension/client").CosmostationClient
| import("@cosmos-kit/keplr-extension/cjs/extension/client").KeplrClient
| import("@cosmos-kit/station-extension/cjs/extension/client").StationClient;

export const isLedger = async <T extends MergedWalletClient>(
walletClient: T,
chainID: string
) => {
// mostly everything else
if ("client" in walletClient && "getKey" in walletClient.client) {
const key = await walletClient.client.getKey(chainID);
return key.isNanoLedger;
}

// cosmostation
// if ("client" in walletClient && "cosmos" in walletClient.client) {
// const account = await walletClient.client.cosmos.request({
// method: "cos_account",
// params: { chainName: chainID },
// });
// return Boolean(account.isLedger);
// }

return false;
};

export const useGetSigningClient = () => {
const { client: walletClient } = useWalletClient();
const {
chain: { chain_id: chainId },
getSigningCosmWasmClient,
} = useCurrentChain();
const rpcEndpoint = useRPCEndpoint();

return useCallback(async () => {
if (walletClient && (await isLedger(walletClient, chainId))) {
const signer =
walletClient.getOfflineSignerAmino?.(chainId) ??
(await walletClient.getOfflineSigner?.(chainId, "amino"));

if (!signer || !("signAmino" in signer)) return undefined;

return SigningCosmWasmClient.connectWithSigner(
rpcEndpoint,
signer,
getCustomedSigningCosmwasm()
);
}
return await getSigningCosmWasmClient();
}, [chainId, rpcEndpoint, JSON.stringify(walletClient)]);
};
12 changes: 9 additions & 3 deletions src/lib/app-provider/queries/simulateFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import type { UseQueryOptions } from "@tanstack/react-query";
import { gzip } from "node-gzip";

import { CELATONE_QUERY_KEYS } from "../env";
import { useCurrentChain, useDummyWallet, useRPCEndpoint } from "../hooks";
import {
useCurrentChain,
useDummyWallet,
useGetSigningClient,
useRPCEndpoint,
} from "../hooks";
import type {
AccessType,
Addr,
Expand Down Expand Up @@ -33,7 +38,8 @@ export const useSimulateFeeQuery = ({
onSuccess,
onError,
}: SimulateQueryParams) => {
const { address, getSigningCosmWasmClient, chain } = useCurrentChain();
const { address, chain } = useCurrentChain();
const getSigningClient = useGetSigningClient();
const { dummyWallet, dummyAddress } = useDummyWallet();
const rpcEndpoint = useRPCEndpoint();
const userAddress = isDummyUser ? dummyAddress : address || dummyAddress;
Expand All @@ -50,7 +56,7 @@ export const useSimulateFeeQuery = ({
rpcEndpoint,
dummyWallet
)
: await getSigningCosmWasmClient();
: await getSigningClient();

if (!client) {
throw new Error("Fail to get SigningCosmWasmClient");
Expand Down
18 changes: 12 additions & 6 deletions src/lib/app-provider/tx/clearAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { useQueryClient } from "@tanstack/react-query";
import { useCallback } from "react";

import { CELATONE_QUERY_KEYS } from "../env";
import { useCurrentChain, useFabricateFee, useWasmConfig } from "../hooks";
import {
useCurrentChain,
useFabricateFee,
useGetSigningClient,
useWasmConfig,
} from "../hooks";
import { trackTxSucceed } from "lib/amplitude";
import { clearAdminTx } from "lib/app-fns/tx/clearAdmin";
import type { ContractAddr, HumanAddr } from "lib/types";
Expand All @@ -12,14 +17,15 @@ export interface ClearAdminStreamParams {
}

export const useClearAdminTx = (contractAddress: ContractAddr) => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { address } = useCurrentChain();
const getSigningClient = useGetSigningClient();
const queryClient = useQueryClient();
const fabricateFee = useFabricateFee();
const wasm = useWasmConfig({ shouldRedirect: false });

return useCallback(
async ({ onTxSucceed }: ClearAdminStreamParams) => {
const client = await getSigningCosmWasmClient();
const client = await getSigningClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");

Expand Down Expand Up @@ -50,12 +56,12 @@ export const useClearAdminTx = (contractAddress: ContractAddr) => {
});
},
[
getSigningCosmWasmClient,
address,
wasm,
fabricateFee,
contractAddress,
fabricateFee,
getSigningClient,
queryClient,
wasm,
]
);
};
9 changes: 5 additions & 4 deletions src/lib/app-provider/tx/execute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Coin, StdFee } from "@cosmjs/stargate";
import { useCallback } from "react";

import { useCurrentChain } from "../hooks";
import { useCurrentChain, useGetSigningClient } from "../hooks";
import { trackTxSucceed } from "lib/amplitude";
import { executeContractTx } from "lib/app-fns/tx/execute";
import type { Activity } from "lib/stores/contract";
Expand All @@ -17,7 +17,8 @@ export interface ExecuteStreamParams {
}

export const useExecuteContractTx = () => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { address } = useCurrentChain();
const getSigningClient = useGetSigningClient();

return useCallback(
async ({
Expand All @@ -28,7 +29,7 @@ export const useExecuteContractTx = () => {
msg,
funds,
}: ExecuteStreamParams) => {
const client = await getSigningCosmWasmClient();
const client = await getSigningClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
if (!estimatedFee) return null;
Expand All @@ -47,6 +48,6 @@ export const useExecuteContractTx = () => {
onTxFailed,
});
},
[address, getSigningCosmWasmClient]
[address, getSigningClient]
);
};
9 changes: 5 additions & 4 deletions src/lib/app-provider/tx/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { InstantiateResult } from "@cosmjs/cosmwasm-stargate";
import type { Coin, StdFee } from "@cosmjs/stargate";
import { useCallback } from "react";

import { useCurrentChain } from "../hooks";
import { useCurrentChain, useGetSigningClient } from "../hooks";
import { trackTxSucceed } from "lib/amplitude";
import { instantiateContractTx } from "lib/app-fns/tx/instantiate";

Expand All @@ -18,7 +18,8 @@ export interface InstantiateStreamParams {
}

export const useInstantiateTx = () => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { address } = useCurrentChain();
const getSigningClient = useGetSigningClient();

return useCallback(
async ({
Expand All @@ -31,7 +32,7 @@ export const useInstantiateTx = () => {
onTxSucceed,
onTxFailed,
}: InstantiateStreamParams) => {
const client = await getSigningCosmWasmClient();
const client = await getSigningClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
if (!estimatedFee) return null;
Expand All @@ -52,6 +53,6 @@ export const useInstantiateTx = () => {
onTxFailed,
});
},
[address, getSigningCosmWasmClient]
[address, getSigningClient]
);
};
9 changes: 5 additions & 4 deletions src/lib/app-provider/tx/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StdFee } from "@cosmjs/stargate";
import { useCallback } from "react";

import { useCurrentChain } from "../hooks";
import { useCurrentChain, useGetSigningClient } from "../hooks";
import { trackTxSucceed } from "lib/amplitude";
import { migrateContractTx } from "lib/app-fns/tx/migrate";
import type { ContractAddr, HumanAddr, Option } from "lib/types";
Expand All @@ -16,7 +16,8 @@ export interface MigrateStreamParams {
}

export const useMigrateTx = () => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { address } = useCurrentChain();
const getSigningClient = useGetSigningClient();

return useCallback(
async ({
Expand All @@ -27,7 +28,7 @@ export const useMigrateTx = () => {
onTxSucceed,
onTxFailed,
}: MigrateStreamParams) => {
const client = await getSigningCosmWasmClient();
const client = await getSigningClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
if (!estimatedFee) return null;
Expand All @@ -46,6 +47,6 @@ export const useMigrateTx = () => {
onTxFailed,
});
},
[address, getSigningCosmWasmClient]
[address, getSigningClient]
);
};
9 changes: 5 additions & 4 deletions src/lib/app-provider/tx/move/executeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCallback } from "react";

import { trackTxSucceed } from "lib/amplitude";
import { executeModuleTx } from "lib/app-fns/tx/move/executeModule";
import { useCurrentChain } from "lib/app-provider/hooks";
import { useCurrentChain, useGetSigningClient } from "lib/app-provider/hooks";
import type { HexAddr, HumanAddr } from "lib/types";
import { toEncodeObject } from "lib/utils";

Expand All @@ -20,7 +20,8 @@ export interface ExecuteModuleStreamParams {
}

export const useExecuteModuleTx = () => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { address } = useCurrentChain();
const getSigningClient = useGetSigningClient();

return useCallback(
async ({
Expand All @@ -33,7 +34,7 @@ export const useExecuteModuleTx = () => {
onTxSucceed,
onTxFailed,
}: ExecuteModuleStreamParams) => {
const client = await getSigningCosmWasmClient();
const client = await getSigningClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");

Expand Down Expand Up @@ -61,6 +62,6 @@ export const useExecuteModuleTx = () => {
onTxFailed,
});
},
[address, getSigningCosmWasmClient]
[address, getSigningClient]
);
};
9 changes: 5 additions & 4 deletions src/lib/app-provider/tx/publish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { EncodeObject } from "@cosmjs/proto-signing";
import type { StdFee } from "@cosmjs/stargate";
import { useCallback } from "react";

import { useCurrentChain } from "../hooks";
import { useCurrentChain, useGetSigningClient } from "../hooks";
import { trackTxSucceed } from "lib/amplitude";
import { publishModuleTx } from "lib/app-fns/tx/publish";
import type { HumanAddr } from "lib/types";
Expand All @@ -24,7 +24,8 @@ export interface PublishModuleStreamParams {
}

export const usePublishModuleTx = () => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { address } = useCurrentChain();
const getSigningClient = useGetSigningClient();

return useCallback(
async ({
Expand All @@ -33,7 +34,7 @@ export const usePublishModuleTx = () => {
estimatedFee,
messages,
}: PublishModuleStreamParams) => {
const client = await getSigningCosmWasmClient();
const client = await getSigningClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
if (!estimatedFee) return null;
Expand All @@ -49,6 +50,6 @@ export const usePublishModuleTx = () => {
messages,
});
},
[address, getSigningCosmWasmClient]
[address, getSigningClient]
);
};
9 changes: 5 additions & 4 deletions src/lib/app-provider/tx/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { EncodeObject } from "@cosmjs/proto-signing";
import type { StdFee } from "@cosmjs/stargate";
import { useCallback } from "react";

import { useCurrentChain } from "../hooks";
import { useCurrentChain, useGetSigningClient } from "../hooks";
import { trackTxSucceed } from "lib/amplitude";
import { resendTx } from "lib/app-fns/tx/resend";
import type { HumanAddr } from "lib/types";
Expand All @@ -15,7 +15,8 @@ export interface ResendStreamParams {
}

export const useResendTx = () => {
const { address, getSigningCosmWasmClient } = useCurrentChain();
const { address } = useCurrentChain();
const getSigningClient = useGetSigningClient();

return useCallback(
async ({
Expand All @@ -24,7 +25,7 @@ export const useResendTx = () => {
estimatedFee,
messages,
}: ResendStreamParams) => {
const client = await getSigningCosmWasmClient();
const client = await getSigningClient();
if (!address || !client)
throw new Error("Please check your wallet connection.");
if (!estimatedFee) return null;
Expand All @@ -40,6 +41,6 @@ export const useResendTx = () => {
onTxFailed,
});
},
[address, getSigningCosmWasmClient]
[address, getSigningClient]
);
};
Loading

0 comments on commit 523125e

Please sign in to comment.