forked from Uniswap/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only link to create issue from known prod URLs (Uniswap#2572)
- Loading branch information
1 parent
5a3c91f
commit f68fa08
Showing
3 changed files
with
122 additions
and
97 deletions.
There are no files selected for viewing
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,90 @@ | ||
import store, { AppState } from '../../state' | ||
import { userAgent } from '../../utils/userAgent' | ||
import GetHelpLink from './GetHelpLink' | ||
|
||
export default function CreateIssueLink(props: { error: Error }) { | ||
const onKnownProdURL = window.location.href.match(/uniswap\.org|ipfs\.dweb\.link|ipfs\.cf-ipfs\.com/) | ||
|
||
// Do not display link to make issue on github if not on a known prod URL | ||
// (prevents creating issues from forks of the interface) | ||
if (!onKnownProdURL) return null | ||
|
||
const error = props.error | ||
const encodedBody = encodeURIComponent(issueBody(error)) | ||
|
||
return ( | ||
<GetHelpLink | ||
id="create-github-issue-link" | ||
href={`https://github.com/Uniswap/uniswap-interface/issues/new?assignees=&labels=bug&body=${encodedBody}&title=${encodeURIComponent( | ||
`Crash report: \`${error.name}${error.message && `: ${error.message}`}\`` | ||
)}`} | ||
text="Create an issue on GitHub" | ||
/> | ||
) | ||
} | ||
|
||
function issueBody(error: Error): string { | ||
const relevantState = getRelevantState() | ||
const deviceData = userAgent | ||
return `## URL | ||
${window.location.href} | ||
${ | ||
relevantState | ||
? `## \`${relevantState}\` state | ||
\`\`\`json | ||
${JSON.stringify(store.getState()[relevantState], null, 2)} | ||
\`\`\` | ||
` | ||
: '' | ||
} | ||
${ | ||
error.name && | ||
`## Error | ||
\`\`\` | ||
${error.name}${error.message && `: ${error.message}`} | ||
\`\`\` | ||
` | ||
} | ||
${ | ||
error.stack && | ||
`## Stacktrace | ||
\`\`\` | ||
${error.stack} | ||
\`\`\` | ||
` | ||
} | ||
${ | ||
deviceData && | ||
`## Device data | ||
\`\`\`json | ||
${JSON.stringify(deviceData, null, 2)} | ||
\`\`\` | ||
` | ||
} | ||
` | ||
} | ||
|
||
function getRelevantState(): null | keyof AppState { | ||
const path = window.location.hash | ||
if (!path.startsWith('#/')) { | ||
return null | ||
} | ||
const pieces = path.substring(2).split(/[\/\\?]/) | ||
switch (pieces[0]) { | ||
case 'swap': | ||
return 'swap' | ||
case 'add': | ||
if (pieces[1] === 'v2') return 'mint' | ||
else return 'mintV3' | ||
case 'remove': | ||
if (pieces[1] === 'v2') return 'burn' | ||
else return 'burnV3' | ||
} | ||
return null | ||
} |
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,22 @@ | ||
import { Trans } from '@lingui/macro' | ||
import styled from 'styled-components/macro' | ||
|
||
import { ExternalLink, TYPE } from '../../theme' | ||
|
||
const LinkWrapper = styled.div` | ||
color: ${({ theme }) => theme.blue1}; | ||
padding: 6px 24px; | ||
` | ||
|
||
export default function GetHelpLink(props: { id: string; href: string; text: string }) { | ||
return ( | ||
<LinkWrapper> | ||
<ExternalLink id={props.id} href={props.href} target="_blank"> | ||
<TYPE.link fontSize={16}> | ||
<Trans>{props.text}</Trans> | ||
<span>↗</span> | ||
</TYPE.link> | ||
</ExternalLink> | ||
</LinkWrapper> | ||
) | ||
} |
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