From ed5b7d64441dfb941a1ec14c1e2c8a5ff84835c7 Mon Sep 17 00:00:00 2001 From: songwongtp <16089160+songwongtp@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:37:53 +0700 Subject: [PATCH 1/3] feat: evm proxy contract and checksum --- CHANGELOG.md | 1 + src/lib/hooks/useFormatAddresses.ts | 32 +++-- .../components/nfts/NftsSectionSequencer.tsx | 9 +- .../hooks/useAccountRedirect.ts | 9 +- .../components/ContractTop.tsx | 6 +- .../components/EvmContractDetailsTop.tsx | 55 +++++++-- .../OverviewProxyTargetInfo.tsx | 43 +++++++ .../OverviewVerifiedCmds.tsx | 115 ++++++------------ .../OverviewVerifiedProxyTargetCmds.tsx | 63 ++++++++++ .../evm-contract-details-overview/index.tsx | 8 +- .../interact-evm-contract/index.tsx | 25 ++-- src/lib/pages/evm-contract-details/index.tsx | 26 ++-- src/lib/services/evm/json-rpc/proxy/utils.ts | 3 +- src/lib/services/move/module/index.ts | 21 ++-- src/lib/services/move/resource/index.ts | 14 +-- src/lib/services/searchService.ts | 13 +- src/lib/services/types/tx.ts | 87 +++++++------ src/lib/utils/address.ts | 14 +-- src/lib/utils/evm.ts | 10 +- 19 files changed, 356 insertions(+), 198 deletions(-) create mode 100644 src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewProxyTargetInfo.tsx create mode 100644 src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedProxyTargetCmds.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f886667..bca1b5d82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements +- [#1242](https://github.com/alleslabs/celatone-frontend/pull/1242) Fix EVM proxy contract details and checksum address - [#1236](https://github.com/alleslabs/celatone-frontend/pull/1236) Remove unnecessary configs for users in custom network configs - [#1228](https://github.com/alleslabs/celatone-frontend/pull/1228) Refactor EVM verification form path and form type location - [#1215](https://github.com/alleslabs/celatone-frontend/pull/1215) Bump react wallet widget package to support http endpoints diff --git a/src/lib/hooks/useFormatAddresses.ts b/src/lib/hooks/useFormatAddresses.ts index a223019d4..b08c4a602 100644 --- a/src/lib/hooks/useFormatAddresses.ts +++ b/src/lib/hooks/useFormatAddresses.ts @@ -1,35 +1,49 @@ import { useCallback } from "react"; -import { useConvertHexAddress } from "lib/app-provider"; -import type { BechAddr, HexAddr } from "lib/types"; +import { useCelatoneApp, useConvertHexAddress } from "lib/app-provider"; +import { type HexAddr, zBechAddr, zHexAddr } from "lib/types"; import { bech32AddressToHex, isHexModuleAddress, isHexWalletAddress, + toChecksumAddress, unpadHexAddress, } from "lib/utils"; export const useFormatAddresses = () => { + const { + chainConfig: { + features: { move }, + }, + } = useCelatoneApp(); const { convertHexWalletAddress, convertHexModuleAddress } = useConvertHexAddress(); + const formatHexAddress = useCallback( + (address: HexAddr) => { + if (move.enabled) return unpadHexAddress(address); + return toChecksumAddress(address); + }, + [move.enabled] + ); + return useCallback( (address: string) => { if (isHexWalletAddress(address)) return { - address: convertHexWalletAddress(address as HexAddr), - hex: unpadHexAddress(address as HexAddr), + address: convertHexWalletAddress(zHexAddr.parse(address)), + hex: formatHexAddress(zHexAddr.parse(address)), }; if (isHexModuleAddress(address)) return { - address: convertHexModuleAddress(address as HexAddr), - hex: unpadHexAddress(address as HexAddr), + address: convertHexModuleAddress(zHexAddr.parse(address)), + hex: formatHexAddress(zHexAddr.parse(address)), }; return { - address: address as BechAddr, - hex: unpadHexAddress(bech32AddressToHex(address as BechAddr)), + address: zBechAddr.parse(address), + hex: formatHexAddress(bech32AddressToHex(zBechAddr.parse(address))), }; }, - [convertHexModuleAddress, convertHexWalletAddress] + [convertHexModuleAddress, convertHexWalletAddress, formatHexAddress] ); }; diff --git a/src/lib/pages/account-details/components/nfts/NftsSectionSequencer.tsx b/src/lib/pages/account-details/components/nfts/NftsSectionSequencer.tsx index 9b6ff5236..b746318da 100644 --- a/src/lib/pages/account-details/components/nfts/NftsSectionSequencer.tsx +++ b/src/lib/pages/account-details/components/nfts/NftsSectionSequencer.tsx @@ -6,7 +6,12 @@ import { useMobile } from "lib/app-provider"; import { Loading } from "lib/components/Loading"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { useNftsByAccountByCollectionSequencer } from "lib/services/nft"; -import type { HexAddr, HexAddr32, Option } from "lib/types"; +import { + type HexAddr, + type HexAddr32, + type Option, + zHexAddr32, +} from "lib/types"; import { FilterItem } from "./FilterItem"; import { NftsByCollectionSequencer } from "./NftsByCollectionSequencer"; @@ -72,7 +77,7 @@ export const NftsSectionSequencer = ({ collectionName={nfts[0].collectionName} onClick={() => handleOnClick({ - collectionAddress: collectionAddress as HexAddr32, + collectionAddress: zHexAddr32.parse(collectionAddress), nftsCount: nfts.length, }) } diff --git a/src/lib/pages/account-details/hooks/useAccountRedirect.ts b/src/lib/pages/account-details/hooks/useAccountRedirect.ts index 993697661..3711d1061 100644 --- a/src/lib/pages/account-details/hooks/useAccountRedirect.ts +++ b/src/lib/pages/account-details/hooks/useAccountRedirect.ts @@ -6,7 +6,12 @@ import { } from "lib/app-provider"; import { useEvmCodesByAddress } from "lib/services/evm"; import { useContractData } from "lib/services/wasm/contract"; -import type { BechAddr, BechAddr32, HexAddr, HexAddr20 } from "lib/types"; +import { + type BechAddr, + type BechAddr32, + type HexAddr, + zHexAddr20, +} from "lib/types"; import { isHexWalletAddress } from "lib/utils"; export const useAccountRedirect = (bechAddr: BechAddr, hexAddr: HexAddr) => { @@ -24,7 +29,7 @@ export const useAccountRedirect = (bechAddr: BechAddr, hexAddr: HexAddr) => { const { data: evmCodes, isFetching: isEvmCodesFetching } = useEvmCodesByAddress( - hexAddr as HexAddr20, + zHexAddr20.parse(hexAddr), evm.enabled && isHexWalletAddress(hexAddr) ); diff --git a/src/lib/pages/contract-details/components/ContractTop.tsx b/src/lib/pages/contract-details/components/ContractTop.tsx index 0e0856175..fe39e39cd 100644 --- a/src/lib/pages/contract-details/components/ContractTop.tsx +++ b/src/lib/pages/contract-details/components/ContractTop.tsx @@ -177,7 +177,7 @@ export const ContractTop = ({ fontWeight={500} whiteSpace="nowrap" > - Contract Address + Contract Address: - Label + Label: {contract.label} @@ -212,7 +212,7 @@ export const ContractTop = ({ variant="body2" fontWeight={500} > - Public Name + Public Name: {publicInfo.name} diff --git a/src/lib/pages/evm-contract-details/components/EvmContractDetailsTop.tsx b/src/lib/pages/evm-contract-details/components/EvmContractDetailsTop.tsx index 34267eda2..f43dd37dd 100644 --- a/src/lib/pages/evm-contract-details/components/EvmContractDetailsTop.tsx +++ b/src/lib/pages/evm-contract-details/components/EvmContractDetailsTop.tsx @@ -4,18 +4,22 @@ import { useConvertHexAddress, useInternalNavigate } from "lib/app-provider"; import { CopyLink } from "lib/components/CopyLink"; import { CustomIcon } from "lib/components/icon"; import { TotalValue } from "lib/components/TotalValue"; -import type { HexAddr20 } from "lib/types"; +import type { EvmVerifyInfo, HexAddr20, Option } from "lib/types"; import { TabIndex } from "../types"; import { getInteractTabsIndex } from "../utils"; interface EvmContractDetailsTopProps { contractAddress: HexAddr20; - isVerified: boolean; + evmVerifyInfo: Option; + proxyTargetAddress: Option; + proxyTargetEvmVerifyInfo: Option; } export const EvmContractDetailsTop = ({ contractAddress, - isVerified, + evmVerifyInfo, + proxyTargetAddress, + proxyTargetEvmVerifyInfo, }: EvmContractDetailsTopProps) => { const navigate = useInternalNavigate(); const { convertHexWalletAddress } = useConvertHexAddress(); @@ -26,8 +30,8 @@ export const EvmContractDetailsTop = ({ justifyContent="space-between" gap={4} > - - + + - + Contract Address: @@ -47,7 +51,7 @@ export const EvmContractDetailsTop = ({ amptrackSection="contract_top" type="contract_address" /> - {isVerified && ( + {!!evmVerifyInfo?.isVerified && ( + {!!evmVerifyInfo?.isVerified && evmVerifyInfo.contractName && ( + + + Contract Name: + + + {evmVerifyInfo.contractName} + + + )} + {proxyTargetAddress && ( + + + Implementation Address: + + + + {!!proxyTargetEvmVerifyInfo?.isVerified && ( + + )} + + + )} - {isVerified && ( + {!!evmVerifyInfo?.isVerified && (