Skip to content

Commit

Permalink
chore: update url generation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
enesozturk committed Feb 12, 2024
1 parent b5be9a2 commit 4f20a53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Text from '@/components/general/Text'
import W3iContext from '@/contexts/W3iContext/context'
import { noop } from '@/utils/general'
import { useIsMobile } from '@/utils/hooks'
import getDomainHref from '@/utils/url'

import AppNotificationDropdown from '../AppNotificationDropdown'

Expand All @@ -29,7 +30,7 @@ const AppNotificationsHeader: React.FC<IAppNotificationsHeaderProps> = ({
}) => {
const isMobile = useIsMobile()
const { dappOrigin } = useContext(W3iContext)
const url = new URL('https://' + domain)
const href = getDomainHref(domain)

return (
<div className="AppNotificationsHeader">
Expand Down Expand Up @@ -58,7 +59,7 @@ const AppNotificationsHeader: React.FC<IAppNotificationsHeaderProps> = ({
<div className="AppNotificationsHeader__app__name_container">
<h2 className="AppNotificationsHeader__app__name">{name}</h2>
<Link
to={url.href}
to={href}
className="AppNotificationsHeader__app__link"
target="_blank"
rel="noopener noreferrer"
Expand Down
16 changes: 16 additions & 0 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const PROTOCOL = 'https://'

/**
* Returns the full URL of the given domain
* @param domain
* @return Href value - string
*/
export default function getDomainHref(domain: string): string {
if (!domain) {
throw new Error('Domain is required')
}

const url = new URL(PROTOCOL + domain)

return url.href
}

0 comments on commit 4f20a53

Please sign in to comment.