From 778f84a87f64c6ee82eb0b89981a4697e3a78a01 Mon Sep 17 00:00:00 2001 From: yumiuehara Date: Fri, 26 Apr 2024 20:24:49 -0300 Subject: [PATCH] CU-86dtb0np9 - NEON3 - Links to Etherscan --- src/renderer/src/components/NftGallery.tsx | 4 +- src/renderer/src/components/NftList.tsx | 4 +- .../src/components/TransactionsTable.tsx | 4 +- src/renderer/src/helpers/DoraHelper.ts | 93 ------------ src/renderer/src/helpers/ExplorerHelper.ts | 142 ++++++++++++++++++ .../Invocation.tsx | 4 +- .../DappPermissionContractDetails/index.tsx | 8 +- 7 files changed, 154 insertions(+), 105 deletions(-) delete mode 100644 src/renderer/src/helpers/DoraHelper.ts create mode 100644 src/renderer/src/helpers/ExplorerHelper.ts diff --git a/src/renderer/src/components/NftGallery.tsx b/src/renderer/src/components/NftGallery.tsx index dfb5fec88..c9b48e0b0 100644 --- a/src/renderer/src/components/NftGallery.tsx +++ b/src/renderer/src/components/NftGallery.tsx @@ -2,7 +2,7 @@ import { useMemo } from 'react' import PhotoAlbum from 'react-photo-album' import { NftResponse } from '@cityofzion/blockchain-service' import { IAccountState } from '@renderer/@types/store' -import { DoraHelper } from '@renderer/helpers/DoraHelper' +import { ExplorerHelper } from '@renderer/helpers/ExplorerHelper' import { StyleHelper } from '@renderer/helpers/StyleHelper' import { useNetworkTypeSelector } from '@renderer/hooks/useSettingsSelector' @@ -29,7 +29,7 @@ export const NftGallery = ({ account, nfts }: TProps) => { ) const handleClick = (nft: NftResponse) => { - window.open(DoraHelper.buildNftUrl(nft.contractHash, nft.id, networkType), '_blank') + window.open(ExplorerHelper.buildNftUrl(nft.contractHash, nft.id, networkType, account.blockchain), '_blank') } return ( diff --git a/src/renderer/src/components/NftList.tsx b/src/renderer/src/components/NftList.tsx index 31da18134..ad63dcbd8 100644 --- a/src/renderer/src/components/NftList.tsx +++ b/src/renderer/src/components/NftList.tsx @@ -3,7 +3,7 @@ import { TbChevronRight } from 'react-icons/tb' import { NftResponse } from '@cityofzion/blockchain-service' import { IAccountState } from '@renderer/@types/store' import { BlockchainIcon } from '@renderer/components/BlockchainIcon' -import { DoraHelper } from '@renderer/helpers/DoraHelper' +import { ExplorerHelper } from '@renderer/helpers/ExplorerHelper' import { useNetworkTypeSelector } from '@renderer/hooks/useSettingsSelector' type TProps = { @@ -16,7 +16,7 @@ export const NftList = ({ account, nfts }: TProps) => { const { networkType } = useNetworkTypeSelector() const handleClick = (nft: NftResponse) => { - window.open(DoraHelper.buildNftUrl(nft.contractHash, nft.id, networkType), '_blank') + window.open(ExplorerHelper.buildNftUrl(nft.contractHash, nft.id, networkType, account.blockchain), '_blank') } return ( diff --git a/src/renderer/src/components/TransactionsTable.tsx b/src/renderer/src/components/TransactionsTable.tsx index c65468e92..e5eb11f32 100644 --- a/src/renderer/src/components/TransactionsTable.tsx +++ b/src/renderer/src/components/TransactionsTable.tsx @@ -3,7 +3,7 @@ import { MdContentCopy } from 'react-icons/md' import { TbChevronRight } from 'react-icons/tb' import { TUseTransactionsTransfer } from '@renderer/@types/hooks' import { IAccountState } from '@renderer/@types/store' -import { DoraHelper } from '@renderer/helpers/DoraHelper' +import { ExplorerHelper } from '@renderer/helpers/ExplorerHelper' import { StringHelper } from '@renderer/helpers/StringHelper' import { StyleHelper } from '@renderer/helpers/StyleHelper' import { ToastHelper } from '@renderer/helpers/ToastHelper' @@ -130,7 +130,7 @@ export const TransactionsTable = forwardRef = { - mainnet: 'mainnet', - testnet: 'testnet', - } - - static colorsByType: Record = { - Signature: { - color: '#E9265C', - textColor: 'dark', - }, - Boolean: { - color: '#D355E7', - textColor: 'dark', - }, - Integer: { - color: '#B167F2', - textColor: 'dark', - }, - Hash160: { - color: '#008529', - textColor: 'light', - }, - Null: { - color: 'rgba(255, 255, 255, 0.08)', - textColor: 'dark', - }, - Hash256: { - color: '#1DB5FF', - textColor: 'dark', - }, - ByteArray: { - color: '#0DCDFF', - textColor: 'dark', - }, - PublicKey: { - color: '#00D69D', - textColor: 'dark', - }, - String: { - color: '#67DD8B', - textColor: 'dark', - }, - ByteString: { - color: '#67DD8B', - textColor: 'dark', - }, - Array: { - color: '#F28F00', - textColor: 'dark', - }, - Buffer: { - color: '#F28F00', - textColor: 'dark', - }, - InteropInterface: { - color: '#A50000', - textColor: 'light', - }, - Void: { - color: '#528D93', - textColor: 'dark', - }, - Any: { - color: '#00D69D', - textColor: 'dark', - }, - } - - static buildTransactionUrl = ( - hash: string, - network: TNetworkType, - blockchain: TBlockchainServiceKey = 'neo3' - ): string => { - if (blockchain !== 'neo3') { - throw new Error('Blockchain is not supported') - } - - return `https://dora.coz.io/transaction/neo3/${this.networkToDoraNetwork[network]}/${hash}` - } - - static buildNftUrl = (hash: string, id: string, network: TNetworkType): string => { - return `https://dora.coz.io/nft/neo3/${this.networkToDoraNetwork[network]}/${hash}/${id}` - } - - static buildContractUrl = (hash: string, network: TNetworkType): string => { - return `https://dora.coz.io/contract/neo3/${this.networkToDoraNetwork[network]}/${hash}` - } -} diff --git a/src/renderer/src/helpers/ExplorerHelper.ts b/src/renderer/src/helpers/ExplorerHelper.ts new file mode 100644 index 000000000..b665ee334 --- /dev/null +++ b/src/renderer/src/helpers/ExplorerHelper.ts @@ -0,0 +1,142 @@ +import { TBlockchainServiceKey, TNetworkType } from '@renderer/@types/blockchain' + +type ColorsByType = { color: string; textColor: 'dark' | 'light' } + +type TSupportedBlockchain = Exclude + +class DoraHelper { + static networkToDoraNetwork: Record = { + mainnet: 'mainnet', + testnet: 'testnet', + } + + static buildTransactionUrl = (hash: string, network: TNetworkType): string => { + return `https://dora.coz.io/transaction/neo3/${this.networkToDoraNetwork[network]}/${hash}` + } + + static buildNftUrl = (hash: string, id: string, network: TNetworkType): string => { + return `https://dora.coz.io/nft/neo3/${this.networkToDoraNetwork[network]}/${hash}/${id}` + } + + static buildContractUrl = (hash: string, network: TNetworkType): string => { + return `https://dora.coz.io/contract/neo3/${this.networkToDoraNetwork[network]}/${hash}` + } +} + +class EtherscanHelper { + static networkToEthereumNetwork: Record = { + mainnet: 'https://etherscan.io', + testnet: 'https://sepolia.etherscan.io', + } + + static buildTransactionUrl = (hash: string, network: TNetworkType): string => { + return `${this.networkToEthereumNetwork[network]}/tx/${hash}` + } + + static buildContractUrl = (hash: string, network: TNetworkType): string => { + return `${this.networkToEthereumNetwork[network]}/contract/${hash}` + } +} + +export class ExplorerHelper { + static colorsByType: Record = { + Signature: { + color: '#E9265C', + textColor: 'dark', + }, + Boolean: { + color: '#D355E7', + textColor: 'dark', + }, + Integer: { + color: '#B167F2', + textColor: 'dark', + }, + Hash160: { + color: '#008529', + textColor: 'light', + }, + Null: { + color: 'rgba(255, 255, 255, 0.08)', + textColor: 'dark', + }, + Hash256: { + color: '#1DB5FF', + textColor: 'dark', + }, + ByteArray: { + color: '#0DCDFF', + textColor: 'dark', + }, + PublicKey: { + color: '#00D69D', + textColor: 'dark', + }, + String: { + color: '#67DD8B', + textColor: 'dark', + }, + ByteString: { + color: '#67DD8B', + textColor: 'dark', + }, + Array: { + color: '#F28F00', + textColor: 'dark', + }, + Buffer: { + color: '#F28F00', + textColor: 'dark', + }, + InteropInterface: { + color: '#A50000', + textColor: 'light', + }, + Void: { + color: '#528D93', + textColor: 'dark', + }, + Any: { + color: '#00D69D', + textColor: 'dark', + }, + } + + static helpersByBlockchain: Record = { + neo3: DoraHelper, + ethereum: EtherscanHelper, + } + + static buildTransactionUrl = (hash: string, networkType: TNetworkType, blockchain: TBlockchainServiceKey): string => { + if (!ExplorerHelper.helpersByBlockchain[blockchain]) { + throw new Error(`Blockchain is not supported`) + } + + return ExplorerHelper.helpersByBlockchain[blockchain].buildTransactionUrl(hash, networkType) + } + + static buildContractUrl = (hash: string, networkType: TNetworkType, blockchain: TBlockchainServiceKey): string => { + if (!ExplorerHelper.helpersByBlockchain[blockchain]) { + throw new Error(`Blockchain is not supported`) + } + + return ExplorerHelper.helpersByBlockchain[blockchain].buildContractUrl(hash, networkType) + } + + static buildNftUrl = ( + hash: string, + id: string, + networkType: TNetworkType, + blockchain: TBlockchainServiceKey + ): string => { + if (!ExplorerHelper.helpersByBlockchain[blockchain]) { + throw new Error(`Blockchain is not supported`) + } + + if (!ExplorerHelper.helpersByBlockchain[blockchain].buildNftUrl) { + throw new Error(`NFT is not supported`) + } + + return ExplorerHelper.helpersByBlockchain[blockchain].buildNftUrl(hash, id, networkType) + } +} diff --git a/src/renderer/src/routes/modals/DappPermission/Neo3/ContractInvocationDappPermission/Invocation.tsx b/src/renderer/src/routes/modals/DappPermission/Neo3/ContractInvocationDappPermission/Invocation.tsx index 79d38d701..dbf2b0f28 100644 --- a/src/renderer/src/routes/modals/DappPermission/Neo3/ContractInvocationDappPermission/Invocation.tsx +++ b/src/renderer/src/routes/modals/DappPermission/Neo3/ContractInvocationDappPermission/Invocation.tsx @@ -6,7 +6,7 @@ import { Separator } from '@radix-ui/react-select' import { TBlockchainServiceKey } from '@renderer/@types/blockchain' import { IconButton } from '@renderer/components/IconButton' import { Loader } from '@renderer/components/Loader' -import { DoraHelper } from '@renderer/helpers/DoraHelper' +import { ExplorerHelper } from '@renderer/helpers/ExplorerHelper' import { useContract } from '@renderer/hooks/useContract' import { useModalNavigate } from '@renderer/hooks/useModalRouter' import { useNetworkTypeSelector } from '@renderer/hooks/useSettingsSelector' @@ -24,7 +24,7 @@ export const Invocation = ({ invocation, session, blockchain }: TProps) => { const { t } = useTranslation('modals', { keyPrefix: 'dappPermission.requests.neo3.contractInvocation' }) const handleHashClick = () => { - window.open(DoraHelper.buildContractUrl(invocation.scriptHash, networkType), '_blank') + window.open(ExplorerHelper.buildContractUrl(invocation.scriptHash, networkType, blockchain), '_blank') } return ( diff --git a/src/renderer/src/routes/modals/DappPermissionContractDetails/index.tsx b/src/renderer/src/routes/modals/DappPermissionContractDetails/index.tsx index 8d33c2489..8140acb34 100644 --- a/src/renderer/src/routes/modals/DappPermissionContractDetails/index.tsx +++ b/src/renderer/src/routes/modals/DappPermissionContractDetails/index.tsx @@ -8,7 +8,7 @@ import { DappPermissionHeader } from '@renderer/components/DappPermissionHeader' import { IconButton } from '@renderer/components/IconButton' import { Loader } from '@renderer/components/Loader' import { Separator } from '@renderer/components/Separator' -import { DoraHelper } from '@renderer/helpers/DoraHelper' +import { ExplorerHelper } from '@renderer/helpers/ExplorerHelper' import { ToastHelper } from '@renderer/helpers/ToastHelper' import { UtilsHelper } from '@renderer/helpers/UtilsHelper' import { useContract } from '@renderer/hooks/useContract' @@ -48,7 +48,7 @@ export const DappPermissionContractDetailsModal = () => { }) const handleHashClick = () => { - window.open(DoraHelper.buildContractUrl(hash, networkType), '_blank') + window.open(ExplorerHelper.buildContractUrl(hash, networkType, blockchain), '_blank') } return ( @@ -99,8 +99,8 @@ export const DappPermissionContractDetailsModal = () => {
{param.type}