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

feat: load all contract detail #37

Merged
merged 6 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions src/lib/app-fns/tx/execute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import type { Observable } from "rxjs";

import { ExplorerLink } from "lib/components/ExplorerLink";
import type { Activity } from "lib/stores/contract";
import type { TxResultRendering } from "lib/types";
import type { ContractAddr, TxResultRendering } from "lib/types";
import { TxStreamPhase } from "lib/types";
import { encode, formatUFee } from "lib/utils";

import { catchTxError, postTx, sendingTx } from "./common";

interface ExecuteTxParams {
address: string;
contractAddress: string;
contractAddr: ContractAddr;
fee: StdFee;
msg: object;
client: SigningCosmWasmClient;
Expand All @@ -29,7 +29,7 @@ interface ExecuteTxParams {

export const executeContractTx = ({
address,
contractAddress,
contractAddr,
fee,
msg,
client,
Expand All @@ -40,14 +40,14 @@ export const executeContractTx = ({
return pipe(
sendingTx(fee),
postTx<ExecuteResult>({
postFn: () => client.execute(address, contractAddress, msg, fee),
postFn: () => client.execute(address, contractAddr, msg, fee),
}),
({ value: txInfo }) => {
onTxSucceed?.(userKey, {
type: "execute",
action: Object.keys(msg)[0],
sender: address,
contractAddress,
contractAddr,
msg: encode(JSON.stringify(msg)), // base64
timestamp: new Date(),
});
Expand Down
23 changes: 11 additions & 12 deletions src/lib/app-provider/contexts/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,21 @@ export const AppProvider = <ContractAddress, Constants extends AppConstants>({
};
}, [currentChainName]);

const states = useMemo<
AppContextInterface<ContractAddress, Constants>
>(() => {
return {
const states = useMemo<AppContextInterface<ContractAddress, Constants>>(
() => ({
chainGasPrice,
contractAddress: contractAddress(currentChainName),
constants,
...chainBoundStates,
};
}, [
chainGasPrice,
contractAddress,
currentChainName,
constants,
chainBoundStates,
]);
}),
[
chainGasPrice,
contractAddress,
currentChainName,
constants,
chainBoundStates,
]
);

useEffect(() => {
if (currentChainName) {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/app-provider/tx/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { useCallback } from "react";
import { executeContractTx } from "lib/app-fns/tx/execute";
import { useUserKey } from "lib/hooks/useUserKey";
import type { Activity } from "lib/stores/contract";
import type { ContractAddr } from "lib/types";

export interface ExecuteStreamParams {
onTxSucceed?: (userKey: string, activity: Activity) => void;
onTxFailed?: () => void;
estimatedFee: StdFee | undefined;
contractAddress: string;
contractAddr: ContractAddr;
msg: object;
}

Expand All @@ -23,7 +24,7 @@ export const useExecuteContractTx = () => {
onTxSucceed,
onTxFailed,
estimatedFee,
contractAddress,
contractAddr,
msg,
}: ExecuteStreamParams) => {
const client = await getCosmWasmClient();
Expand All @@ -33,7 +34,7 @@ export const useExecuteContractTx = () => {

return executeContractTx({
address,
contractAddress,
contractAddr,
fee: estimatedFee,
msg,
client,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/modal/code/SaveNewCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
MAX_CODE_DESCRIPTION_LENGTH,
} from "lib/data";
import { useCodeStore, useEndpoint, useUserKey } from "lib/hooks";
import { getCodeIdInfo } from "lib/services/contract";
import { getCodeIdInfo } from "lib/services/code";

interface ModalProps {
buttonProps: ButtonProps;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/modal/contract/SaveNewContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
} from "lib/data";
import { useContractStore, useEndpoint } from "lib/hooks";
import { useHandleContractSave } from "lib/hooks/useHandleSave";
import { queryContractWithTime } from "lib/services/contract";
import type { Option, RpcContractError } from "lib/types";
import { queryInstantiateInfo } from "lib/services/contract";
import type { ContractAddr, Option, RpcContractError } from "lib/types";
import { formatSlugName } from "lib/utils";

interface SaveNewContractProps {
Expand Down Expand Up @@ -62,8 +62,8 @@ export function SaveNewContract({ list, buttonProps }: SaveNewContractProps) {

// TODO: Abstract query
const { refetch } = useQuery(
["query", "contractWithTime", contractAddress],
async () => queryContractWithTime(endpoint, contractAddress),
["query", "instantiateInfo", contractAddress],
async () => queryInstantiateInfo(endpoint, contractAddress as ContractAddr),
{
enabled: false,
retry: false,
Expand All @@ -72,7 +72,7 @@ export function SaveNewContract({ list, buttonProps }: SaveNewContractProps) {
onSuccess(data) {
setInstantiator(data.instantiator);
setLabel(data.label);
setCreated(data.created);
setCreated(data.createdTime);
setName(data.label);
setStatus({
state: "success",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/modal/select-contract/SelectContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { DEFAULT_RPC_ERROR } from "lib/data";
import { useContractStore, useEndpoint } from "lib/hooks";
import { useInstantiatedByMe } from "lib/model/contract";
import { queryContract } from "lib/services/contract";
import type { RpcContractError } from "lib/types";
import type { ContractAddr, RpcContractError } from "lib/types";

import { AllContractLists } from "./AllContractLists";
import { ListDetail } from "./ListDetail";
Expand Down Expand Up @@ -71,7 +71,7 @@ export const SelectContract = ({
// TODO: Abstract query
const { refetch, isFetching, isRefetching } = useQuery(
["query", "contract", searchManual],
async () => queryContract(endpoint, searchManual),
async () => queryContract(endpoint, searchManual as ContractAddr),
{
enabled: false,
retry: false,
Expand Down
11 changes: 11 additions & 0 deletions src/lib/data/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ export const getInstantiatedListByUserQueryDocument = graphql(`
}
}
`);

export const getInstantiateDetailByContractQueryDocument = graphql(`
query getInstantiateDetailByContractQueryDocument($contractAddr: String!) {
contracts(where: { address: { _eq: $contractAddr } }) {
init_msg
transaction {
hash
}
}
}
`);
5 changes: 5 additions & 0 deletions src/lib/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const documents = {
types.GetInstantiatedCountByUserQueryDocumentDocument,
"\n query getInstantiatedListByUserQueryDocument($walletAddr: String!) {\n contracts(\n where: { transaction: { account: { address: { _eq: $walletAddr } } } }\n limit: 500\n offset: 0\n order_by: { transaction: { block: { timestamp: desc } } }\n ) {\n label\n address\n transaction {\n block {\n timestamp\n }\n }\n }\n }\n":
types.GetInstantiatedListByUserQueryDocumentDocument,
"\n query getInstantiateDetailByContractQueryDocument($contractAddr: String!) {\n contracts(where: { address: { _eq: $contractAddr } }) {\n init_msg\n transaction {\n hash\n }\n }\n }\n":
types.GetInstantiateDetailByContractQueryDocumentDocument,
};

export function graphql(
Expand All @@ -25,6 +27,9 @@ export function graphql(
export function graphql(
source: "\n query getInstantiatedListByUserQueryDocument($walletAddr: String!) {\n contracts(\n where: { transaction: { account: { address: { _eq: $walletAddr } } } }\n limit: 500\n offset: 0\n order_by: { transaction: { block: { timestamp: desc } } }\n ) {\n label\n address\n transaction {\n block {\n timestamp\n }\n }\n }\n }\n"
): typeof documents["\n query getInstantiatedListByUserQueryDocument($walletAddr: String!) {\n contracts(\n where: { transaction: { account: { address: { _eq: $walletAddr } } } }\n limit: 500\n offset: 0\n order_by: { transaction: { block: { timestamp: desc } } }\n ) {\n label\n address\n transaction {\n block {\n timestamp\n }\n }\n }\n }\n"];
export function graphql(
source: "\n query getInstantiateDetailByContractQueryDocument($contractAddr: String!) {\n contracts(where: { address: { _eq: $contractAddr } }) {\n init_msg\n transaction {\n hash\n }\n }\n }\n"
): typeof documents["\n query getInstantiateDetailByContractQueryDocument($contractAddr: String!) {\n contracts(where: { address: { _eq: $contractAddr } }) {\n init_msg\n transaction {\n hash\n }\n }\n }\n"];

export function graphql(source: string): unknown;
export function graphql(source: string) {
Expand Down
98 changes: 98 additions & 0 deletions src/lib/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4722,6 +4722,19 @@ export type GetInstantiatedListByUserQueryDocumentQuery = {
}>;
};

export type GetInstantiateDetailByContractQueryDocumentQueryVariables = Exact<{
contractAddr: Scalars["String"];
}>;

export type GetInstantiateDetailByContractQueryDocumentQuery = {
__typename?: "query_root";
contracts: Array<{
__typename?: "contracts";
init_msg?: string | null;
transaction?: { __typename?: "transactions"; hash: any } | null;
}>;
};

export const GetCodeListByUserQueryDocument = {
kind: "Document",
definitions: [
Expand Down Expand Up @@ -5200,3 +5213,88 @@ export const GetInstantiatedListByUserQueryDocumentDocument = {
GetInstantiatedListByUserQueryDocumentQuery,
GetInstantiatedListByUserQueryDocumentQueryVariables
>;
export const GetInstantiateDetailByContractQueryDocumentDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "query",
name: {
kind: "Name",
value: "getInstantiateDetailByContractQueryDocument",
},
variableDefinitions: [
{
kind: "VariableDefinition",
variable: {
kind: "Variable",
name: { kind: "Name", value: "contractAddr" },
},
type: {
kind: "NonNullType",
type: {
kind: "NamedType",
name: { kind: "Name", value: "String" },
},
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "contracts" },
arguments: [
{
kind: "Argument",
name: { kind: "Name", value: "where" },
value: {
kind: "ObjectValue",
fields: [
{
kind: "ObjectField",
name: { kind: "Name", value: "address" },
value: {
kind: "ObjectValue",
fields: [
{
kind: "ObjectField",
name: { kind: "Name", value: "_eq" },
value: {
kind: "Variable",
name: { kind: "Name", value: "contractAddr" },
},
},
],
},
},
],
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "init_msg" } },
{
kind: "Field",
name: { kind: "Name", value: "transaction" },
selectionSet: {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "hash" } },
],
},
},
],
},
},
],
},
},
],
} as unknown as DocumentNode<
GetInstantiateDetailByContractQueryDocumentQuery,
GetInstantiateDetailByContractQueryDocumentQueryVariables
>;
Loading