Skip to content

Commit

Permalink
Merge pull request #14 from CityOfZion/CU-86dtb0np9
Browse files Browse the repository at this point in the history
CU-86dtb0np9 - NEON3 - Links to Etherscan
  • Loading branch information
raulduartep authored Apr 29, 2024
2 parents aa663f6 + 778f84a commit acc28ae
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/renderer/src/components/NftGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/components/NftList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/components/TransactionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -130,7 +130,7 @@ export const TransactionsTable = forwardRef<HTMLDivElement, TTransactionListProp
if (row.isPending) return

try {
const url = DoraHelper.buildTransactionUrl(row.hash, networkType, row.account.blockchain)
const url = ExplorerHelper.buildTransactionUrl(row.hash, networkType, row.account.blockchain)
window.open(url)
} catch (error) {
ToastHelper.error({ message: t('components:transactionsTable.doraError') })
Expand Down
93 changes: 0 additions & 93 deletions src/renderer/src/helpers/DoraHelper.ts

This file was deleted.

142 changes: 142 additions & 0 deletions src/renderer/src/helpers/ExplorerHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { TBlockchainServiceKey, TNetworkType } from '@renderer/@types/blockchain'

type ColorsByType = { color: string; textColor: 'dark' | 'light' }

type TSupportedBlockchain = Exclude<TBlockchainServiceKey, 'neoLegacy'>

class DoraHelper {
static networkToDoraNetwork: Record<TNetworkType, string> = {
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<TNetworkType, string> = {
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<string, ColorsByType> = {
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<TSupportedBlockchain, typeof DoraHelper | typeof EtherscanHelper> = {
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -99,8 +99,8 @@ export const DappPermissionContractDetailsModal = () => {
<div
className="rounded-full px-3.5 py-1 text-asphalt text-xs"
style={{
backgroundColor: DoraHelper.colorsByType[param.type].color,
color: DoraHelper.colorsByType[param.type].textColor === 'dark' ? 'black' : 'white',
backgroundColor: ExplorerHelper.colorsByType[param.type].color,
color: ExplorerHelper.colorsByType[param.type].textColor === 'dark' ? 'black' : 'white',
}}
>
{param.type}
Expand Down

0 comments on commit acc28ae

Please sign in to comment.