-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from pnetwork-association/feat/redirect-banner
Feat/redirect banner
- Loading branch information
Showing
9 changed files
with
209 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import { Alert, Row } from 'react-bootstrap' | ||
import styled from 'styled-components' | ||
|
||
import Icon from '../../atoms/icon/Icon' | ||
import { OuterContainerSwap } from '../../pages/swap/Swap' | ||
|
||
const DISMISSED_DOMAIN = 'ptokens.io' | ||
|
||
const StyledAlert = styled(Alert)` | ||
// background: ${({ theme }) => theme.bg1}; | ||
font-size: 16px; | ||
padding-top: 0px; | ||
padding-bottom: 0px; | ||
padding-left: 0.5rem; | ||
` | ||
|
||
const WarningIcon = styled(Icon)` | ||
height: 20px; | ||
width: 20px; | ||
margin: 5px; | ||
vertical-align: top; | ||
color: #475965; | ||
` | ||
|
||
const Paragraph = styled.div` | ||
text-align: center; | ||
margin: 0rem; | ||
margin-left: 2px; | ||
` | ||
|
||
const getDomain = () => { | ||
try { | ||
const currentUrl = new URL(window.location.href) | ||
return currentUrl.hostname | ||
} catch (_err) { | ||
// Handle error in case of use with ipns/ipfs enabled browsers | ||
console.error('Error while retreiving url', _err.message) | ||
return null | ||
} | ||
} | ||
|
||
const RedirectBanner = () => { | ||
const domain = getDomain() | ||
return ( | ||
<> | ||
{domain && domain.includes(DISMISSED_DOMAIN) ? ( | ||
<Row> | ||
<OuterContainerSwap className="mx-auto"> | ||
<StyledAlert variant="info"> | ||
<Paragraph> | ||
<WarningIcon icon="info" /> | ||
<br /> | ||
You are using an old domain that will be dismissed in the future. | ||
<br /> | ||
Please use <a href="https://dapp.pnetworkprotocol.eth.limo">pnetworkprotocol.eth</a> | ||
</Paragraph> | ||
</StyledAlert> | ||
</OuterContainerSwap> | ||
</Row> | ||
) : null} | ||
</> | ||
) | ||
} | ||
|
||
export default RedirectBanner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/components/molecules/popup/__test__/RedirectBanner.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable import/first */ | ||
import { render, screen } from '@testing-library/react' | ||
import { describe, expect, it, vi } from 'vitest' | ||
|
||
import RedirectBanner from '../RedirectBanner' | ||
|
||
const expectedText = 'You are using an old domain that will be dismissed in the future.' | ||
|
||
describe('RedirectBanner', async () => { | ||
test.each([ | ||
['http://ptokens.io'], | ||
['http://dapp.ptokens.io'], | ||
['https://dapp.ptokens.io/#/swap?asset=btc&from=btc&to=eth'], | ||
])('Should show the url popup only on specific url', async (url) => { | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: url, | ||
}, | ||
}) | ||
render(<RedirectBanner />) | ||
const textElement = screen.getByText((content) => content.includes(expectedText)) | ||
expect(textElement).toBeInTheDocument() | ||
}) | ||
|
||
test.each([ | ||
['http://p.network/'], | ||
['http://pnetworkprotocol.eth'], | ||
['https://dapp.pnetworkprotocol.eth.limo/'], | ||
['ipns://dapp.pnetworkprotocol.eth']['https://dapp.pnetworkprotocol.eth/#/swap?asset=btc&from=btc&to=eth'], | ||
])('Should show the url popup only on specific url', async (url) => { | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: url, | ||
}, | ||
}) | ||
const { container } = render(<RedirectBanner />) | ||
expect(container.firstChild).toBeNull() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f76e6e6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following parameters
https://ptokens-dapp.4everland.app