Skip to content

Commit

Permalink
feat: close all tabs on wallet lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed Jun 30, 2023
1 parent dad90f7 commit 407eddb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/components/guards/singleTab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react';

type GuardType = 'onboarding' | 'importLedger' | 'resetWallet';
type GuardType = 'onboarding' | 'importLedger' | 'closeWallet';

const getChannelAndPingNames = (guardName: GuardType) => {
const channelName = `${guardName}Channel`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useSingleTabGuard } from '@components/guards/singleTab';

type WalletResetGuardProps = {
type WalletCloseGuardProps = {
children?: React.ReactElement | React.ReactElement[];
};

/**
* This guard is used to close any open tabs when the wallet is reset.
* This guard is used to close any open tabs when the wallet is locked or reset.
* It should only be rendered at the root of the options page.
*/
function WalletResetGuard({ children }: WalletResetGuardProps): React.ReactNode {
useSingleTabGuard('resetWallet', false);
function WalletCloseGuard({ children }: WalletCloseGuardProps): React.ReactNode {
useSingleTabGuard('closeWallet', false);

return children;
}

export default WalletResetGuard;
export default WalletCloseGuard;
6 changes: 4 additions & 2 deletions src/app/stores/wallet/actions/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export function unlockWalletAction(seed: string) {
}

export function lockWalletAction() {
// We post the closeWallet action to the guard so that any open tabs will close
PostGuardPing('closeWallet');
return {
type: actions.LockWalletKey,
};
Expand All @@ -48,8 +50,8 @@ export function setWalletSeedPhraseAction(seedPhrase: string): actions.SetWallet
}

export function resetWalletAction(): actions.ResetWallet {
// We post the resetWallet action to the guard so that any open tabs will close
PostGuardPing('resetWallet');
// We post the closeWallet action to the guard so that any open tabs will close
PostGuardPing('closeWallet');
return {
type: actions.ResetWalletKey,
};
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Options/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WalletResetGuard from '@components/guards/walletResetGuard';
import WalletCloseGuard from '@components/guards/walletCloseGuard';
import { decryptMnemonic } from '@stacks/encryption';
import rootStore from '@stores/index';
import { setWalletSeedPhraseAction } from '@stores/wallet/actions/actionCreators';
Expand Down Expand Up @@ -29,9 +29,9 @@ const renderApp = async () => {
const container = document.getElementById('app');
const root = createRoot(container!);
return root.render(
<WalletResetGuard>
<WalletCloseGuard>
<App />
</WalletResetGuard>,
</WalletCloseGuard>,
);
};

Expand Down

0 comments on commit 407eddb

Please sign in to comment.