Skip to content

Commit

Permalink
fix: add better IPFS support (#879)
Browse files Browse the repository at this point in the history
## High Level Overview of Change

This PR uses `DomainLink` in the account header and adds better IPFS
support.

### Context of Change

I tried clicking on an IPFS link and I had to rewrite the URL in order
to actually see the data.

### Type of Change

- [x] Bug fix (non-breaking change which fixes an issue)
- [x] Refactor (non-breaking change that only restructures code)

### TypeScript/Hooks Update

N/A

## Before / After

<!--
If just refactoring / back-end changes, this can be just an in-English
description of the change at a technical level.
If a UI change, screenshots should be included.
-->

## Test Plan

CI passes.
  • Loading branch information
mvadari authored Nov 27, 2023
1 parent c32715b commit aa2df01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/containers/Accounts/AccountHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SocketContext from '../../shared/SocketContext'
import InfoIcon from '../../shared/images/info.svg'
import { useLanguage } from '../../shared/hooks'
import Currency from '../../shared/components/Currency'
import DomainLink from '../../shared/components/DomainLink'

const CURRENCY_OPTIONS = {
style: 'currency',
Expand Down Expand Up @@ -267,7 +268,7 @@ const AccountHeader = (props: AccountHeaderProps) => {
{info.domain && (
<li>
<span className="label"> {t('domain')}: </span>
<a href={`http://${info.domain}`}>{info.domain}</a>
<DomainLink domain={info.domain} />
</li>
)}
{info.emailHash && (
Expand Down
6 changes: 5 additions & 1 deletion src/containers/shared/components/DomainLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const DomainLink = (props: Props) => {
const domainHasProtocol = PROTOCOL_REGEX.test(decodedDomain)

// If decoded domain does not have a protocol, add one ; otherwise, don't
const href = domainHasProtocol ? decodedDomain : `https://${decodedDomain}`
let href = domainHasProtocol ? decodedDomain : `https://${decodedDomain}`

if (href.startsWith('ipfs://')) {
href = href.replace('ipfs://', 'https://ipfs.io/ipfs/')
}

return (
<a
Expand Down
14 changes: 14 additions & 0 deletions src/containers/shared/components/test/DomainLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('DomainLink', () => {
expect(wrapper.find('a').props().href).toEqual('https://bithomp.com')
wrapper.unmount()
})

it('handles domain link with decoded domain parameter', () => {
const wrapper = mount(
<DomainLink decode domain="736F6C6F67656E69632E636F6D" />,
Expand All @@ -18,13 +19,15 @@ describe('DomainLink', () => {
expect(wrapper.find('a').props().href).toEqual('https://sologenic.com')
wrapper.unmount()
})

it('handles domain link with domain parameter and classname', () => {
const wrapper = mount(<DomainLink className="test" domain="bithomp.com" />)
expect(wrapper.find('a').props().className).toEqual('domain test')
expect(wrapper.find('a').text()).toEqual('bithomp.com')
expect(wrapper.find('a').props().href).toEqual('https://bithomp.com')
wrapper.unmount()
})

it('handles domain link with decoded domain parameter and classname', () => {
const wrapper = mount(
<DomainLink
Expand All @@ -38,6 +41,7 @@ describe('DomainLink', () => {
expect(wrapper.find('a').props().href).toEqual('https://sologenic.com')
wrapper.unmount()
})

it('handles domain link with domain provided in HEX-encoded format', () => {
const url = 'https://example.com'
const urlInHex = '68747470733A2F2F6578616D706C652E636F6D'
Expand All @@ -47,4 +51,14 @@ describe('DomainLink', () => {
expect(wrapper.find('a').props().href).toEqual(url)
wrapper.unmount()
})

it('handles IPFS domain link', () => {
const wrapper = mount(<DomainLink domain="ipfs://random/metadata.json" />)
expect(wrapper.find('a').props().className).toEqual('domain')
expect(wrapper.find('a').text()).toEqual('ipfs://random/metadata.json')
expect(wrapper.find('a').props().href).toEqual(
'https://ipfs.io/ipfs/random/metadata.json',
)
wrapper.unmount()
})
})

0 comments on commit aa2df01

Please sign in to comment.