-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from alleslabs/feat/instantiate-info
Feat/instantiate info
- Loading branch information
Showing
10 changed files
with
191 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useWallet } from "@cosmos-kit/react"; | ||
import { useCallback } from "react"; | ||
|
||
export type AddressReturnType = | ||
| "user_address" | ||
| "contract_address" | ||
| "invalid_address"; | ||
|
||
const addressLengthMap: { | ||
[key: string]: { [length: number]: AddressReturnType }; | ||
} = { | ||
osmosis: { | ||
43: "user_address", | ||
63: "contract_address", | ||
}, | ||
osmosistestnet: { | ||
43: "user_address", | ||
63: "contract_address", | ||
}, | ||
}; | ||
|
||
export const useGetAddressType = () => { | ||
const { currentChainName } = useWallet(); | ||
return useCallback( | ||
(address: string): AddressReturnType => | ||
addressLengthMap[currentChainName]?.[address.length] ?? "invalid_address", | ||
[currentChainName] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 121 additions & 19 deletions
140
src/lib/pages/contract-details/components/InstantiateInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,132 @@ | ||
import { Flex, Heading } from "@chakra-ui/react"; | ||
import { Flex, Heading, Text } from "@chakra-ui/react"; | ||
|
||
import { ExplorerLink } from "lib/components/ExplorerLink"; | ||
import { LabelText } from "lib/components/LabelText"; | ||
import type { AddressReturnType } from "lib/hooks"; | ||
import { useGetAddressType } from "lib/hooks"; | ||
import type { ContractDetail } from "lib/model/contract"; | ||
import { formatUTC, dateFromNow } from "lib/utils"; | ||
|
||
const getAddressTypeText = (addressType: AddressReturnType) => { | ||
switch (addressType) { | ||
case "contract_address": | ||
return "(Contract Address)"; | ||
case "user_address": | ||
return "(Wallet Address)"; | ||
default: | ||
return "(Invalid Address)"; | ||
} | ||
}; | ||
|
||
interface InstantiateInfoProps { | ||
contractDetail: ContractDetail; | ||
} | ||
|
||
export const InstantiateInfo = ({ contractDetail }: InstantiateInfoProps) => { | ||
const getAddressType = useGetAddressType(); | ||
|
||
const renderDataFound = () => { | ||
if (contractDetail?.instantiateInfo) { | ||
const instantiatorType = getAddressType( | ||
contractDetail.instantiateInfo.instantiator | ||
); | ||
return ( | ||
<> | ||
<LabelText label="Network">{contractDetail.chainId}</LabelText> | ||
|
||
{contractDetail.instantiateInfo && | ||
(contractDetail.instantiateInfo.createdHeight !== -1 ? ( | ||
<LabelText | ||
label="Instantiated Block Height" | ||
helperText1={formatUTC( | ||
contractDetail.instantiateInfo.createdTime.toString() | ||
)} | ||
helperText2={dateFromNow( | ||
contractDetail.instantiateInfo.createdTime.toString() | ||
)} | ||
> | ||
<ExplorerLink | ||
value={contractDetail.instantiateInfo.createdHeight.toString()} | ||
canCopyWithHover | ||
/> | ||
</LabelText> | ||
) : ( | ||
<LabelText label="Instantiated Block Height">N/A</LabelText> | ||
))} | ||
|
||
<LabelText | ||
label="Instantiated by" | ||
helperText1={getAddressTypeText(instantiatorType)} | ||
> | ||
<ExplorerLink | ||
type="user_address" | ||
value={contractDetail.instantiateInfo.instantiator} | ||
canCopyWithHover | ||
/> | ||
</LabelText> | ||
|
||
<LabelText | ||
label="From Code" | ||
helperText1={contractDetail.codeInfo?.description} | ||
> | ||
<ExplorerLink | ||
value={contractDetail.instantiateInfo.codeId} | ||
canCopyWithHover | ||
/> | ||
</LabelText> | ||
|
||
{contractDetail.initProposalId ? ( | ||
<LabelText | ||
label="Instantiate Proposal ID" | ||
helperText1={contractDetail.initProposalTitle} | ||
> | ||
<ExplorerLink | ||
value={`#${contractDetail.initProposalId.toString()}`} | ||
canCopyWithHover | ||
/> | ||
</LabelText> | ||
) : ( | ||
<LabelText label="Instantiate Transaction"> | ||
<ExplorerLink | ||
type="tx_hash" | ||
value={contractDetail.initTxHash?.toUpperCase() ?? "Genesis"} | ||
canCopyWithHover | ||
isReadOnly={!contractDetail.initTxHash} | ||
/> | ||
</LabelText> | ||
)} | ||
|
||
{contractDetail.instantiateInfo.admin && ( | ||
<LabelText label="Admin Address"> | ||
<ExplorerLink | ||
type="user_address" | ||
value={contractDetail.instantiateInfo.admin} | ||
/> | ||
</LabelText> | ||
)} | ||
|
||
{contractDetail.instantiateInfo.ibcPortId && ( | ||
<LabelText label="IBC Port ID"> | ||
{contractDetail.instantiateInfo.ibcPortId} | ||
</LabelText> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<Text variant="body2" color="text.dark"> | ||
Error fetching data | ||
</Text> | ||
); | ||
}; | ||
|
||
export const InstantiateInfo = () => { | ||
/** | ||
* @todos | ||
* - Make an interface | ||
* - All these are mockups, Wireup with real data and map render LabelText | ||
*/ | ||
return ( | ||
<Flex direction="column" gap={6} w="160px"> | ||
<Flex direction="column" gap={6} w="180px"> | ||
<Heading as="h6" variant="h6"> | ||
Instantiate Info | ||
</Heading> | ||
<LabelText label="Network">phoenix-1</LabelText> | ||
<LabelText label="Instantiated by" helperText="(Wallet Address)"> | ||
<ExplorerLink | ||
type="user_address" | ||
value="osmo1wke7j8f5kgnnacs3avchcj6fvvdtvrsalzmddx" | ||
canCopyWithHover | ||
/> | ||
</LabelText> | ||
<LabelText label="IBC Port ID"> | ||
wasm.terra1te47jv6pg272n8unq490nvhh5m43v5n5kxfgrztly2tmkmqxzw8qphrjx2 | ||
</LabelText> | ||
{renderDataFound()} | ||
</Flex> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import dayjs from "dayjs"; | ||
|
||
export const formatUTC = (timestamp: string) => { | ||
const localDate = timestamp.concat("Z"); | ||
return dayjs(localDate).utc().format("MMM DD, YYYY, h:mm:ss A [(UTC)]"); | ||
}; | ||
|
||
export const dateFromNow = (timestamp: string) => { | ||
const localDate = timestamp.concat("Z"); | ||
return dayjs(localDate).fromNow(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
692a3ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
celatone-frontend-staging – ./
celatone-frontend-staging.vercel.app
celatone-frontend-staging-git-develop-alles-labs.vercel.app
celatone-frontend-staging-alles-labs.vercel.app
osmosis-staging.celat.one