Skip to content

Commit

Permalink
enable lock screen for all
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey committed May 3, 2024
1 parent aca5278 commit d146cc4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/mobile/src/core/Security/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Security: FC = () => {

const biometry = useBiometrySettings();

const { lockEnabled, toggleLock } = useLockSettings();
const { lockScreenEnabled, toggleLock } = useLockSettings();

const handleCopyLockupConfig = useCallback(() => {
try {
Expand Down Expand Up @@ -103,7 +103,7 @@ export const Security: FC = () => {
<CellSection>
<CellSectionItem
onPress={toggleLock}
indicator={<Switch value={lockEnabled} onChange={toggleLock} />}
indicator={<Switch value={lockScreenEnabled} onChange={toggleLock} />}
>
{t('security_lock_screen_switch')}
</CellSectionItem>
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/navigation/MainStack/MainStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export const MainStack: FC = () => {

const hasWallet = !!wallet;

const { lockEnabled } = useLockSettings();
const { lockScreenEnabled } = useLockSettings();

const shouldObtainTonProof =
hasWallet && !wallet.isWatchOnly && !wallet.tonProof.tonProofToken;

const showLockScreen =
(lockEnabled || shouldObtainTonProof) &&
(lockScreenEnabled || shouldObtainTonProof) &&
!isUnlocked &&
hasWallet &&
!attachedScreen.pathname;
Expand Down
12 changes: 6 additions & 6 deletions packages/mobile/src/wallet/Tonkeeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface WalletsStoreState {
wallets: WalletConfig[];
selectedIdentifier: string;
biometryEnabled: boolean;
lockEnabled: boolean;
lockScreenEnabled: boolean;
}

export interface MigrationState {
Expand Down Expand Up @@ -79,7 +79,7 @@ export class Tonkeeper {
wallets: [],
selectedIdentifier: '',
biometryEnabled: false,
lockEnabled: false,
lockScreenEnabled: false,
});

public migrationStore = new State<MigrationState>({
Expand Down Expand Up @@ -134,8 +134,8 @@ export class Tonkeeper {
return this.walletsStore.data.biometryEnabled;
}

public get lockEnabled() {
return this.walletsStore.data.lockEnabled;
public get lockScreenEnabled() {
return this.walletsStore.data.lockScreenEnabled;
}

public async init() {
Expand Down Expand Up @@ -563,10 +563,10 @@ export class Tonkeeper {
}

public async enableLock() {
await this.walletsStore.setAsync({ lockEnabled: true });
await this.walletsStore.setAsync({ lockScreenEnabled: true });
}

public async disableLock() {
await this.walletsStore.setAsync({ lockEnabled: false });
await this.walletsStore.setAsync({ lockScreenEnabled: false });
}
}
9 changes: 6 additions & 3 deletions packages/shared/hooks/useLockSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { tk } from '@tonkeeper/mobile/src/wallet';
import { useExternalState } from './useExternalState';

export const useLockSettings = () => {
const lockEnabled = useExternalState(tk.walletsStore, (state) => state.lockEnabled);
const lockScreenEnabled = useExternalState(
tk.walletsStore,
(state) => state.lockScreenEnabled,
);

return {
lockEnabled,
toggleLock: () => (tk.lockEnabled ? tk.disableLock() : tk.enableLock()),
lockScreenEnabled,
toggleLock: () => (tk.lockScreenEnabled ? tk.disableLock() : tk.enableLock()),
};
};

0 comments on commit d146cc4

Please sign in to comment.