Skip to content

Commit

Permalink
Merge pull request #177 from alleslabs/fix/render-init
Browse files Browse the repository at this point in the history
fix: properly handle instantiate hash/proposal/genesis/data n/a case
  • Loading branch information
evilpeach authored Feb 9, 2023
2 parents 9f43440 + 65624d5 commit 27de915
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#177](https://github.com/alleslabs/celatone-frontend/pull/177) Handle instantiate render: tx hash, proposal, genesis, and data not available case
- [#176](https://github.com/alleslabs/celatone-frontend/pull/176) Adjust contract table fraction, limit tag render, full ellipsis contract desc/name length
- [#168](https://github.com/alleslabs/celatone-frontend/pull/168) Past tx: Long messages should wrap to new line, clear text input when click on action in filter by actions, fail transaction should not show resend button, header table from "tx hash" to "transaction hash", send message should count unique address, contract details page transaction header (from "actions" to "messages"), hover row should display copy button
- [#174](https://github.com/alleslabs/celatone-frontend/pull/174) Change "code description" to "code name" and wireup public code name in code detail page
Expand Down
79 changes: 57 additions & 22 deletions src/lib/pages/contract-details/components/InstantiateInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Container = chakra(Flex, {
},
});

const RenderPortId = ({ portId }: { portId: string }) => {
const PortIdRender = ({ portId }: { portId: string }) => {
const charArray = portId.match(/.{1,28}/g);

return (
Expand All @@ -47,6 +47,55 @@ const RenderPortId = ({ portId }: { portId: string }) => {
);
};

const InitRender = ({
initTxHash,
initProposalTitle,
initProposalId,
createdHeight,
}: {
initTxHash: ContractData["initTxHash"];
initProposalTitle: ContractData["initProposalTitle"];
initProposalId: ContractData["initProposalId"];
createdHeight: number;
}) => {
if (initTxHash) {
return (
<LabelText label="Instantiate Transaction">
<ExplorerLink
type="tx_hash"
value={initTxHash.toUpperCase()}
canCopyWithHover
/>
</LabelText>
);
}

if (initProposalTitle && initProposalId) {
return (
<LabelText
label="Instantiate Proposal ID"
helperText1={initProposalTitle}
>
<ExplorerLink
type="proposal_id"
value={initProposalId.toString()}
canCopyWithHover
/>
</LabelText>
);
}

return createdHeight === 0 ? (
<LabelText label="Created by">
<Text variant="body2">Genesis</Text>
</LabelText>
) : (
<LabelText label="Instantiate Transaction">
<Text variant="body2">N/A</Text>
</LabelText>
);
};

export const InstantiateInfo = ({
contractData: {
contractCw2Info,
Expand Down Expand Up @@ -155,30 +204,16 @@ export const InstantiateInfo = ({
/>
</LabelText>

{initTxHash ? (
<LabelText label="Instantiate Transaction">
<ExplorerLink
type="tx_hash"
value={initTxHash.toUpperCase()}
canCopyWithHover
/>
</LabelText>
) : (
<LabelText
label="Instantiate Proposal ID"
helperText1={initProposalTitle}
>
<ExplorerLink
value={initProposalId ? `#${initProposalId}` : "Genesis"}
canCopyWithHover
isReadOnly={!initProposalId}
/>
</LabelText>
)}
<InitRender
initTxHash={initTxHash}
initProposalId={initProposalId}
initProposalTitle={initProposalTitle}
createdHeight={instantiateInfo.createdHeight}
/>

{instantiateInfo.ibcPortId && (
<LabelText label="IBC Port ID">
<RenderPortId portId={instantiateInfo.ibcPortId} />
<PortIdRender portId={instantiateInfo.ibcPortId} />
</LabelText>
)}
</Container>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const queryInstantiateInfo = async (
): Promise<InstantiateInfo> => {
const res = await queryContract(endpoint, contractAddress);

// TODO: check `created` field for contracts created with proposals
// TODO: query height from gql instead when supporting Terra
let createdHeight = -1;
let createdTime;
if (res.contract_info.created) {
Expand Down

2 comments on commit 27de915

@vercel
Copy link

@vercel vercel bot commented on 27de915 Feb 9, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 27de915 Feb 9, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.