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

fix: properly handle instantiate hash/proposal/genesis/data n/a case #177

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -110,6 +110,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
- [#174](https://github.com/alleslabs/celatone-frontend/pull/174) Change "code description" to "code name" and wireup public code name in code detail page
- [#173](https://github.com/alleslabs/celatone-frontend/pull/173) Add connect wallet alert to migrate page
- [#161](https://github.com/alleslabs/celatone-frontend/pull/161) Fix editable cell, no wrap when hover and click outside to close the editable cell
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