Skip to content

Commit

Permalink
restrict redirection to Wallet Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kartiksaini3 committed Jan 24, 2025
1 parent 6a2d350 commit d99c199
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
31 changes: 17 additions & 14 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function App(props) {
showCongratLoader,
externalControlsState,
setExternalControlState,
setWindowAndTab
setWindowAndTab,
dontRedirect
} = useContext(AuthContext);

const navigate = useNavigate();
Expand All @@ -66,20 +67,22 @@ function App(props) {
}, []);

useEffect(() => {
//sync the current action route with main popup
if (activeSession && isLogin) {
navigate(`/${activeSession.route}`);
return;
}
if (!dontRedirect) {
//sync the current action route with main popup
if (activeSession && isLogin) {
navigate(`/${activeSession.route}`);
return;
}

if ((!isLogin && vault) || (state?.pass && !isLogin && !vault)) {
navigate(ROUTES.UNLOACK_WALLET);
} else if (detailsPage) {
navigate(ROUTES.NEW_WALLET_DETAILS);
} else if (isLogin && vault && !detailsPage) {
navigate(ROUTES.WALLET);
} else if (!isLogin && !vault) {
navigate(ROUTES.DEFAULT);
if ((!isLogin && vault) || (state?.pass && !isLogin && !vault)) {
navigate(ROUTES.UNLOACK_WALLET);
} else if (detailsPage) {
navigate(ROUTES.NEW_WALLET_DETAILS);
} else if (isLogin && vault && !detailsPage) {
navigate(ROUTES.WALLET);
} else if (!isLogin && !vault) {
navigate(ROUTES.DEFAULT);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
Expand Down
7 changes: 5 additions & 2 deletions src/Pages/MyAccount/MyAccount.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function MyAccount() {
externalControlsState,
setNewWalletName,
windowAndTab,
setSelectedToken
setSelectedToken,
setDontRedirect
} = useContext(AuthContext);
const { connectedApps } = externalControlsState;
const { currentAccount, allAccountsBalance, currentNetwork } = state;
Expand Down Expand Up @@ -151,12 +152,14 @@ function MyAccount() {

const handleOutsideClick = () => {
setRenameId("");
oldName !== renameInput.trim() &&
if (oldName !== renameInput.trim()) {
setDontRedirect(true); // restrict redirection to Wallet Screen
sendRuntimeMessage(
MESSAGE_TYPE_LABELS.EXTENSION_UI_KEYRING,
MESSAGE_EVENT_LABELS.RENAME_ACCOUNT_NAME,
{ oldName: oldName.trim(), newName: renameInput.trim() }
);
}
};

const handleEnter = (e) => {
Expand Down
6 changes: 5 additions & 1 deletion src/Store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function Context({ children }) {
const [accountName, setAccName] = useState(null);
const [allAccounts, setAllAccounts] = useState([]);
const [detailsPage, setDetailsPage] = useState(false);
const [dontRedirect, setDontRedirect] = useState(false);
const [estimatedGas, setEstimatedGas] = useState(null);
const [newWalletName, setNewWalletName] = useState("");
const [passVerified, setPassVerified] = useState(false);
Expand Down Expand Up @@ -292,6 +293,7 @@ export default function Context({ children }) {
account.accountName === oldName ? { ...account, accountName: newName } : account
);
setAllAccounts(updatedAccounts);
setDontRedirect(false);
};

const getAccounts = (data) => {
Expand Down Expand Up @@ -378,6 +380,7 @@ export default function Context({ children }) {
externalControlsState,
externalNativeTxDetails,
edValue,
dontRedirect,

//data setters
setState,
Expand Down Expand Up @@ -406,7 +409,8 @@ export default function Context({ children }) {
setExternalControlState,
importAccountByMnemonics,
setExternalNativeTxDetails,
setEDValue
setEDValue,
setDontRedirect
};

return <AuthContext.Provider value={values}>{children}</AuthContext.Provider>;
Expand Down

0 comments on commit d99c199

Please sign in to comment.