Skip to content

Commit

Permalink
Extract useExplorerAddressLink.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
b-tarczynski committed Apr 18, 2024
1 parent 4fbaa8a commit cbb16b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 13 additions & 0 deletions packages/frontend/src/blockchain/hooks/useExplorerAddressLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Hex } from 'viem'
import { useChainId, useChains } from 'wagmi'

export const useExplorerAddressLink = (address: Hex): string | undefined => {
const chains = useChains()
const chainId = useChainId()
const currentChain = chains.find((chain) => chain.id === chainId)

if (!currentChain || !currentChain.blockExplorers?.default) {
return undefined
}
return `${currentChain.blockExplorers.default.url}/address/${address}`
}
13 changes: 1 addition & 12 deletions packages/frontend/src/components/bids/BidsListEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AddressColumn, BidColumn, PlaceColumn } from '@/components/bids/BidsColumns'
import styled, { css } from 'styled-components'
import { useChainId, useChains } from 'wagmi'
import { BidWithPlace } from '@/types/bid'
import { Colors } from '@/styles/colors'
import { formatEther, Hex } from 'viem'
import { useExplorerAddressLink } from '@/blockchain/hooks/useExplorerAddressLink'

interface Props {
bid: BidWithPlace
Expand All @@ -29,17 +29,6 @@ export const BidsListEntry = ({ bid, isUser, view = 'full' }: Props) => {
)
}

const useExplorerAddressLink = (address: Hex): string | undefined => {
const chains = useChains()
const chainId = useChainId()
const currentChain = chains.find((chain) => chain.id === chainId)

if (!currentChain || !currentChain.blockExplorers?.default) {
return undefined
}
return `${currentChain.blockExplorers.default.url}/address/${address}`
}

const shortenEthAddress = (address: Hex) => `${address.substring(0, 6)}......${address.substring(address.length - 4)}`

const BidsEntryRow = styled.div<{ isUser?: boolean }>`
Expand Down

0 comments on commit cbb16b5

Please sign in to comment.