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

(contract details) use instantiated height from indexer as fallback #364

Merged
merged 1 commit into from
May 31, 2023
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 @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#364](https://github.com/alleslabs/celatone-frontend/pull/364) (Contract Details) use instantiated height and time from indexer as fallback
- [#323](https://github.com/alleslabs/celatone-frontend/pull/323) Revise back button and breadcrumb components
- [#339](https://github.com/alleslabs/celatone-frontend/pull/339) Update all routes to plural form, and patch all codes
- [#334](https://github.com/alleslabs/celatone-frontend/pull/334) Change `osmo-test-4` to `osmo-test-5`, fix tx service when accountId is undefined
Expand Down
6 changes: 3 additions & 3 deletions src/lib/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const documents = {
types.GetInstantiatedListByUserQueryDocumentDocument,
"\n query getInstantiatedCountByUserQueryDocument($walletAddr: String!) {\n contracts_aggregate(\n where: { accountByInitBy: { address: { _eq: $walletAddr } } }\n ) {\n aggregate {\n count\n }\n }\n }\n":
types.GetInstantiatedCountByUserQueryDocumentDocument,
'\n query getInstantiateDetailByContractQueryDocument($contractAddress: String!) {\n contracts_by_pk(address: $contractAddress) {\n init_msg\n transaction {\n hash\n }\n contract_proposals(\n where: {\n proposal: {\n type: {\n _in: [\n "InstantiateContract"\n "InstantiateContract2"\n "SoftwareUpgrade"\n ]\n }\n }\n }\n order_by: { proposal: { id: asc } }\n limit: 1\n ) {\n proposal {\n id\n title\n }\n }\n }\n }\n':
'\n query getInstantiateDetailByContractQueryDocument($contractAddress: String!) {\n contracts_by_pk(address: $contractAddress) {\n init_msg\n transaction {\n hash\n block_height\n block {\n timestamp\n }\n }\n contract_proposals(\n where: {\n proposal: {\n type: {\n _in: [\n "InstantiateContract"\n "InstantiateContract2"\n "SoftwareUpgrade"\n ]\n }\n }\n }\n order_by: { proposal: { id: asc } }\n limit: 1\n ) {\n proposal {\n id\n title\n }\n }\n }\n }\n':
types.GetInstantiateDetailByContractQueryDocumentDocument,
"\n query getAdminByContractAddressesQueryDocument(\n $contractAddresses: [String!]!\n ) {\n contracts(where: { address: { _in: $contractAddresses } }) {\n address\n admin: account {\n address\n }\n }\n }\n":
types.GetAdminByContractAddressesQueryDocumentDocument,
Expand Down Expand Up @@ -117,8 +117,8 @@ export function graphql(
source: "\n query getInstantiatedCountByUserQueryDocument($walletAddr: String!) {\n contracts_aggregate(\n where: { accountByInitBy: { address: { _eq: $walletAddr } } }\n ) {\n aggregate {\n count\n }\n }\n }\n"
): typeof documents["\n query getInstantiatedCountByUserQueryDocument($walletAddr: String!) {\n contracts_aggregate(\n where: { accountByInitBy: { address: { _eq: $walletAddr } } }\n ) {\n aggregate {\n count\n }\n }\n }\n"];
export function graphql(
source: '\n query getInstantiateDetailByContractQueryDocument($contractAddress: String!) {\n contracts_by_pk(address: $contractAddress) {\n init_msg\n transaction {\n hash\n }\n contract_proposals(\n where: {\n proposal: {\n type: {\n _in: [\n "InstantiateContract"\n "InstantiateContract2"\n "SoftwareUpgrade"\n ]\n }\n }\n }\n order_by: { proposal: { id: asc } }\n limit: 1\n ) {\n proposal {\n id\n title\n }\n }\n }\n }\n'
): typeof documents['\n query getInstantiateDetailByContractQueryDocument($contractAddress: String!) {\n contracts_by_pk(address: $contractAddress) {\n init_msg\n transaction {\n hash\n }\n contract_proposals(\n where: {\n proposal: {\n type: {\n _in: [\n "InstantiateContract"\n "InstantiateContract2"\n "SoftwareUpgrade"\n ]\n }\n }\n }\n order_by: { proposal: { id: asc } }\n limit: 1\n ) {\n proposal {\n id\n title\n }\n }\n }\n }\n'];
source: '\n query getInstantiateDetailByContractQueryDocument($contractAddress: String!) {\n contracts_by_pk(address: $contractAddress) {\n init_msg\n transaction {\n hash\n block_height\n block {\n timestamp\n }\n }\n contract_proposals(\n where: {\n proposal: {\n type: {\n _in: [\n "InstantiateContract"\n "InstantiateContract2"\n "SoftwareUpgrade"\n ]\n }\n }\n }\n order_by: { proposal: { id: asc } }\n limit: 1\n ) {\n proposal {\n id\n title\n }\n }\n }\n }\n'
): typeof documents['\n query getInstantiateDetailByContractQueryDocument($contractAddress: String!) {\n contracts_by_pk(address: $contractAddress) {\n init_msg\n transaction {\n hash\n block_height\n block {\n timestamp\n }\n }\n contract_proposals(\n where: {\n proposal: {\n type: {\n _in: [\n "InstantiateContract"\n "InstantiateContract2"\n "SoftwareUpgrade"\n ]\n }\n }\n }\n order_by: { proposal: { id: asc } }\n limit: 1\n ) {\n proposal {\n id\n title\n }\n }\n }\n }\n'];
export function graphql(
source: "\n query getAdminByContractAddressesQueryDocument(\n $contractAddresses: [String!]!\n ) {\n contracts(where: { address: { _in: $contractAddresses } }) {\n address\n admin: account {\n address\n }\n }\n }\n"
): typeof documents["\n query getAdminByContractAddressesQueryDocument(\n $contractAddresses: [String!]!\n ) {\n contracts(where: { address: { _in: $contractAddresses } }) {\n address\n admin: account {\n address\n }\n }\n }\n"];
Expand Down
24 changes: 23 additions & 1 deletion src/lib/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12351,7 +12351,12 @@ export type GetInstantiateDetailByContractQueryDocumentQuery = {
contracts_by_pk?: {
__typename?: "contracts";
init_msg?: string | null;
transaction?: { __typename?: "transactions"; hash: any } | null;
transaction?: {
__typename?: "transactions";
hash: any;
block_height: number;
block: { __typename?: "blocks"; timestamp: any };
} | null;
contract_proposals: Array<{
__typename?: "contract_proposals";
proposal: { __typename?: "proposals"; id: number; title: string };
Expand Down Expand Up @@ -14236,6 +14241,23 @@ export const GetInstantiateDetailByContractQueryDocumentDocument = {
kind: "SelectionSet",
selections: [
{ kind: "Field", name: { kind: "Name", value: "hash" } },
{
kind: "Field",
name: { kind: "Name", value: "block_height" },
},
{
kind: "Field",
name: { kind: "Name", value: "block" },
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "timestamp" },
},
],
},
},
],
},
},
Expand Down
4 changes: 4 additions & 0 deletions src/lib/model/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export const useContractData = (
initTxHash: instantiateDetail?.initTxHash,
initProposalId: instantiateDetail?.initProposalId,
initProposalTitle: instantiateDetail?.initProposalTitle,
createdHeight:
instantiateInfo?.createdHeight ?? instantiateDetail?.createdHeight,
createdTime:
instantiateInfo?.createdTime ?? instantiateDetail?.createdTime,
},
isLoading:
isInstantiateInfoLoading ||
Expand Down
41 changes: 17 additions & 24 deletions src/lib/pages/contract-details/components/InstantiateInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export const InstantiateInfo = ({
initTxHash,
initProposalId,
initProposalTitle,
createdHeight,
createdTime,
},
}: InstantiateInfoProps) => {
const getAddressType = useGetAddressType();
Expand Down Expand Up @@ -163,30 +165,21 @@ export const InstantiateInfo = ({

<Divider border="1px solid" borderColor="gray.700" />

{instantiateInfo &&
(instantiateInfo.createdHeight ? (
<LabelText
label="Instantiated Block Height"
helperText1={
instantiateInfo.createdTime
? formatUTC(instantiateInfo.createdTime)
: undefined
}
helperText2={
instantiateInfo.createdTime
? dateFromNow(instantiateInfo.createdTime)
: undefined
}
>
<ExplorerLink
type="block_height"
value={instantiateInfo.createdHeight.toString()}
showCopyOnHover
/>
</LabelText>
) : (
<LabelText label="Instantiated Block Height">N/A</LabelText>
))}
{createdHeight ? (
<LabelText
label="Instantiated Block Height"
helperText1={createdTime ? formatUTC(createdTime) : undefined}
helperText2={createdTime ? dateFromNow(createdTime) : undefined}
>
<ExplorerLink
type="block_height"
value={createdHeight.toString()}
showCopyOnHover
/>
</LabelText>
) : (
<LabelText label="Instantiated Block Height">N/A</LabelText>
)}

<LabelText
label="Instantiated by"
Expand Down
4 changes: 4 additions & 0 deletions src/lib/query/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export const getInstantiateDetailByContractQueryDocument = graphql(`
init_msg
transaction {
hash
block_height
block {
timestamp
}
}
contract_proposals(
where: {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/services/contractService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import type {
import { parseDate, parseTxHashOpt, parseDateOpt } from "lib/utils";

interface InstantiateDetail {
createdHeight: Option<number>;
createdTime: Option<Date>;
initMsg: Option<string>;
initTxHash: Option<string>;
initProposalId: Option<number>;
Expand Down Expand Up @@ -136,6 +138,10 @@ export const useInstantiateDetailByContractQuery = (
return indexerGraphClient
.request(getInstantiateDetailByContractQueryDocument, { contractAddress })
.then(({ contracts_by_pk }) => ({
createdHeight: contracts_by_pk?.transaction?.block_height,
createdTime: parseDateOpt(
contracts_by_pk?.transaction?.block.timestamp
),
initMsg: contracts_by_pk?.init_msg,
initTxHash: parseTxHashOpt(contracts_by_pk?.transaction?.hash),
initProposalId: contracts_by_pk?.contract_proposals.at(0)?.proposal.id,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ export interface ContractData {
initTxHash: Option<string>;
initProposalId: Option<number>;
initProposalTitle: Option<string>;
createdHeight: Option<number>;
createdTime: Option<Date>;
}