Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/75-multiple-instances-of-the-wallet-opening #114

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useCallback, useEffect } from "react";
import { Route, Routes, useNavigate } from "react-router-dom";

import { ScrollToTop } from "@atoms";
import { Modal, ScrollToTop } from "@atoms";
import { PATHS } from "@consts";
import { useCardano } from "@context";
import { useCardano, useModal } from "@context";
import {
DashboardCards,
DashboardGovernanceActions,
Expand All @@ -23,6 +23,7 @@ import {
DashboardGovernanceActionsCategory,
} from "@pages";
import {
callAll,
getItemFromLocalStorage,
WALLET_LS_KEY,
removeItemFromLocalStorage,
Expand All @@ -34,6 +35,7 @@ export default function App() {
const { enable, setDRep, setIsDrepLoading } = useCardano();
const navigate = useNavigate();
const { data } = useGetDRepInfo();
const { modal, openModal, modals } = useModal();

useWalletConnectionListener();

Expand Down Expand Up @@ -118,6 +120,20 @@ export default function App() {
<Route path="*" element={<ErrorPage />} />
<Route path={PATHS.error} element={<ErrorPage />} />
</Routes>
{modals[modal.type]?.component && (
<Modal
open={Boolean(modals[modal.type].component)}
handleClose={
!modals[modal.type].preventDismiss
? callAll(modals[modal.type]?.onClose, () =>
openModal({ type: "none", state: null })
)
: undefined
}
>
{modals[modal.type]?.component ?? <></>}
</Modal>
)}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export const DashboardCards = () => {
} finally {
setIsRetirementLoading(false);
}
}, [buildDRepRetirementCert, buildSignSubmitConwayCertTx]);
}, [
buildDRepRetirementCert,
buildSignSubmitConwayCertTx,
isPendingTransaction,
openModal,
]);

const delegationDescription = useMemo(() => {
const correctAdaRepresentation = (
Expand Down
10 changes: 5 additions & 5 deletions govtool/frontend/src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ interface Props {

const ContextProviders = ({ children }: Props) => {
return (
<SnackbarProvider>
<CardanoProvider>
<ModalProvider>{children}</ModalProvider>
</CardanoProvider>
</SnackbarProvider>
<ModalProvider>
<SnackbarProvider>
<CardanoProvider>{children}</CardanoProvider>
</SnackbarProvider>
</ModalProvider>
);
};

Expand Down
22 changes: 5 additions & 17 deletions govtool/frontend/src/context/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useContext, useMemo, useReducer } from "react";

import { Modal, type MuiModalChildren } from "@atoms";
import { type MuiModalChildren } from "@atoms";
import {
ChooseWalletModal,
ExternalLinkModal,
Expand Down Expand Up @@ -53,7 +53,8 @@ interface ModalState<T> {
}

interface ModalContext<T> {
modal: ContextModal;
modal: ModalState<T>;
modals: Record<ModalType, ContextModal>;
state: T | null;
openModal: (modal: Optional<ModalState<T>, "state">) => void;
closeModal: () => void;
Expand All @@ -74,7 +75,8 @@ function ModalProvider<T>(props: ProviderProps) {

const value = useMemo(
() => ({
modal: modals[modal.type],
modals,
modal,
state: modal.state,
openModal,
closeModal: callAll(modals[modal.type]?.onClose, () =>
Expand All @@ -86,20 +88,6 @@ function ModalProvider<T>(props: ProviderProps) {

return (
<ModalContext.Provider value={value} {...props}>
{modals[modal.type]?.component && (
<Modal
open={Boolean(modals[modal.type].component)}
handleClose={
!modals[modal.type].preventDismiss
? callAll(modals[modal.type]?.onClose, () =>
openModal({ type: "none", state: null })
)
: undefined
}
>
{modals[modal.type]?.component ?? <></>}
</Modal>
)}
{props.children}
</ModalContext.Provider>
);
Expand Down
6 changes: 4 additions & 2 deletions govtool/frontend/src/context/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
VOTE_TRANSACTION_KEY,
checkIsMaintenanceOn,
} from "@utils";
import { getDRepInfo, getEpochParams, getTransactionStatus } from "@services";
import { getEpochParams, getTransactionStatus } from "@services";
import {
setLimitedDelegationInterval,
setLimitedRegistrationInterval,
Expand Down Expand Up @@ -228,8 +228,10 @@ function CardanoProvider(props: Props) {
}
return false;
}, [
registerTransaction?.transactionHash,
closeModal,
delegateTransaction?.transactionHash,
openModal,
registerTransaction?.transactionHash,
voteTransaction?.transactionHash,
]);

Expand Down
Loading