-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add explorer link to the support card (#292)
- Loading branch information
Showing
6 changed files
with
77 additions
and
34 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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export const defaultMaxHeight = 686; | ||
|
||
export const lifiExplorerUrl = 'https://scan.li.fi'; |
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
70 changes: 70 additions & 0 deletions
70
packages/widget/src/pages/TransactionDetailsPage/TransferIdCard.tsx
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,70 @@ | ||
import { ContentCopyRounded, OpenInNew } from '@mui/icons-material'; | ||
import { Box, Typography } from '@mui/material'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Card } from '../../components/Card/Card.js'; | ||
import { CardIconButton } from '../../components/Card/CardIconButton.js'; | ||
import { CardTitle } from '../../components/Card/CardTitle.js'; | ||
import { lifiExplorerUrl } from '../../config/constants.js'; | ||
import { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js'; | ||
|
||
interface TransferIdCardProps { | ||
transferId: string; | ||
} | ||
|
||
const getTxHash = (transferId: string) => | ||
transferId.indexOf('_') !== -1 | ||
? transferId.substring(0, transferId.indexOf('_')) | ||
: transferId; | ||
|
||
export const TransferIdCard = ({ transferId }: TransferIdCardProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const { explorerUrl } = useWidgetConfig(); | ||
|
||
const copyTransferId = async () => { | ||
await navigator.clipboard.writeText(transferId); | ||
}; | ||
|
||
const openTransferIdInExplorer = () => { | ||
const txHash = getTxHash(transferId); | ||
const urlBase = explorerUrl ?? lifiExplorerUrl; | ||
window.open(`${urlBase}/tx/${txHash}`, '_blank'); | ||
}; | ||
|
||
return ( | ||
<Card sx={{ marginTop: 2 }}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flex: 1, | ||
}} | ||
> | ||
<CardTitle flex={1}>{t('main.transferId')}</CardTitle> | ||
<Box | ||
sx={{ | ||
gap: 1, | ||
display: 'flex', | ||
marginRight: 2, | ||
marginTop: 1, | ||
}} | ||
> | ||
<CardIconButton size="small" onClick={copyTransferId}> | ||
<ContentCopyRounded fontSize="inherit" /> | ||
</CardIconButton> | ||
<CardIconButton size="small" onClick={openTransferIdInExplorer}> | ||
<OpenInNew fontSize="inherit" /> | ||
</CardIconButton> | ||
</Box> | ||
</Box> | ||
<Typography | ||
variant="body2" | ||
pt={1} | ||
pb={2} | ||
px={2} | ||
sx={{ wordBreak: 'break-all' }} | ||
> | ||
{transferId} | ||
</Typography> | ||
</Card> | ||
); | ||
}; |
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