-
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.
Merge remote-tracking branch 'clearcontracts/main' into test
- Loading branch information
Showing
9 changed files
with
180 additions
and
52 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
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
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,54 @@ | ||
import { useTheme } from '@mui/material'; | ||
import Alert from '@mui/material/Alert'; | ||
import AlertTitle from '@mui/material/AlertTitle'; | ||
import Box from '@mui/material/Box'; | ||
import CircularProgress from '@mui/material/CircularProgress'; | ||
import Typography from '@mui/material/Typography'; | ||
|
||
interface Props { | ||
title: string; | ||
message: string; | ||
} | ||
|
||
/** | ||
* Transaction in progress popup | ||
* @param title - Title of the popup | ||
* @param message - Message of the popup | ||
* @returns Popup for when a transaction is in progress | ||
*/ | ||
export function TxPopup(props: Props): JSX.Element { | ||
const { title, message } = props; | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Box display="flex" alignContent="center"> | ||
<Alert | ||
elevation={6} | ||
variant="filled" | ||
severity="warning" | ||
iconMapping={{ | ||
warning: ( | ||
<Box | ||
alignItems="center" | ||
justifyContent="center" | ||
display="flex" | ||
minWidth="40px" | ||
> | ||
<CircularProgress /> | ||
</Box> | ||
), | ||
}} | ||
> | ||
<AlertTitle color={theme.palette.secondary.contrastText}> | ||
{title} | ||
</AlertTitle> | ||
<Typography | ||
variant="subtitle2" | ||
color={theme.palette.secondary.contrastText} | ||
> | ||
{message} | ||
</Typography> | ||
</Alert> | ||
</Box> | ||
); | ||
} |
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,48 @@ | ||
import { isTransactionConfirmed } from '@claritydao/clarity-backend'; | ||
import * as Sentry from '@sentry/nextjs'; | ||
import toast from 'react-hot-toast'; | ||
|
||
import { buildClarityBackendReq } from '@/lib/buildClarityBackendReq'; | ||
|
||
/** | ||
* Monitors a transaction until it is confirmed | ||
* @param txId - The transaction ID to monitor | ||
* @returns Boolean - True if the transaction is confirmed, false otherwise | ||
*/ | ||
export async function awaitTxConfirm(txId: string): Promise<boolean> { | ||
try { | ||
const clarityBackendReq = await buildClarityBackendReq(); | ||
if (!clarityBackendReq) { | ||
toast.error('Error monitoring transaction.'); | ||
return false; | ||
} | ||
return new Promise((resolve) => { | ||
// timeout is just hardcoded to 300 seconds (5 minutes) | ||
let elapsedTime = 0; | ||
const intervalId = setInterval(async () => { | ||
elapsedTime += 5000; // Increment elapsed time by 5 seconds (5000 ms) | ||
// If the elapsed time exceeds or equals the max time, clear the interval and exit | ||
if (elapsedTime >= 300000) { | ||
// Clear the interval once the transaction is confirmed | ||
clearInterval(intervalId); | ||
resolve(false); | ||
} | ||
|
||
const isConfirmed = await isTransactionConfirmed( | ||
clarityBackendReq.url, | ||
txId, | ||
); | ||
|
||
if (isConfirmed) { | ||
// Clear the interval once the transaction is confirmed | ||
clearInterval(intervalId); | ||
resolve(true); | ||
} | ||
}, 5000); // Run every 5 seconds | ||
}); | ||
} catch (error) { | ||
Sentry.captureException(error); | ||
toast.error('Error monitoring transaction.'); | ||
return false; | ||
} | ||
} |
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
Oops, something went wrong.