Use global snackbar provider

This commit is contained in:
IshaVenikar 2024-07-31 12:23:19 +05:30
parent 3b396e81c5
commit fcf93ac6b7
5 changed files with 24 additions and 9 deletions

View File

@ -8,7 +8,7 @@ import React, {
useCallback, useCallback,
useRef, useRef,
} from "react"; } from "react";
import { SnackbarProvider, enqueueSnackbar } from "notistack"; import { enqueueSnackbar } from "notistack";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import SignClient from "@walletconnect/sign-client"; import SignClient from "@walletconnect/sign-client";
@ -160,7 +160,6 @@ export const WalletConnectProvider = ({
> >
{children} {children}
</walletConnectContext.Provider> </walletConnectContext.Provider>
<SnackbarProvider />
</> </>
); );
}; };

View File

@ -1,6 +1,11 @@
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import { Buffer } from "buffer"; import { Buffer } from "buffer";
import { closeSnackbar, SnackbarProvider } from 'notistack';
import CloseIcon from '@mui/icons-material/Close';
import { IconButton } from '@mui/material';
import './index.css'; import './index.css';
import App from './App'; import App from './App';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
@ -8,11 +13,25 @@ import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement document.getElementById('root') as HTMLElement
); );
function SnackbarCloseButton({ key } : any) {
return (
<IconButton onClick={() => closeSnackbar(key)}>
<CloseIcon color='action'/>
</IconButton>
);
}
// Reference: https://github.com/vitejs/vite/discussions/2785#discussion-3298776 // Reference: https://github.com/vitejs/vite/discussions/2785#discussion-3298776
globalThis.Buffer = Buffer; globalThis.Buffer = Buffer;
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<SnackbarProvider
action={key => <SnackbarCloseButton key={key} />}
>
<App /> <App />
</SnackbarProvider>
</React.StrictMode> </React.StrictMode>
); );

View File

@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { SnackbarProvider, enqueueSnackbar } from "notistack"; import { enqueueSnackbar } from "notistack";
import { useLocation } from "react-router-dom"; import { useLocation } from "react-router-dom";
import { Box, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
@ -114,7 +114,6 @@ const OnboardingSuccess = () => {
onMessage={messageHandler} onMessage={messageHandler}
/> />
)} )}
<SnackbarProvider />
</Box> </Box>
); );
}; };

View File

@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useMemo, useState } from "react"; import React, { useCallback, useEffect, useMemo, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom"; import { useLocation, useNavigate } from "react-router-dom";
import { SnackbarProvider, enqueueSnackbar } from "notistack"; import { enqueueSnackbar } from "notistack";
import { Box, Card, CardContent, Grid, Typography } from "@mui/material"; import { Box, Card, CardContent, Grid, Typography } from "@mui/material";
import LoadingButton from "@mui/lab/LoadingButton/LoadingButton"; import LoadingButton from "@mui/lab/LoadingButton/LoadingButton";
@ -205,7 +205,6 @@ const SignWithCosmos = () => {
Send transaction Send transaction
</LoadingButton> </LoadingButton>
</Box> </Box>
<SnackbarProvider />
</Box> </Box>
); );
}; };

View File

@ -1,6 +1,6 @@
import React, { useState, useMemo, useEffect } from "react"; import React, { useState, useMemo, useEffect } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { SnackbarProvider, enqueueSnackbar } from "notistack"; import { enqueueSnackbar } from "notistack";
import canonicalStringify from "canonical-json"; import canonicalStringify from "canonical-json";
import { import {
@ -136,7 +136,6 @@ const SignWithNitroKey = () => {
Sign using Nitro key Sign using Nitro key
</LoadingButton> </LoadingButton>
</Box> </Box>
<SnackbarProvider />
</Box> </Box>
) : ( ) : (
<>Loading...</> <>Loading...</>