Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor to use central clipboard clear timeout retrieval method (#881)

Leendert de Borst81538d466652
diff --git a/apps/mobile-app/components/credentials/CredentialCard.tsx b/apps/mobile-app/components/credentials/CredentialCard.tsx
index 5952d9b16..3cbd5e1cc 100644
--- a/apps/mobile-app/components/credentials/CredentialCard.tsx
+++ b/apps/mobile-app/components/credentials/CredentialCard.tsx
@@ -1,4 +1,3 @@
-import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Clipboard from 'expo-clipboard';
import { router } from 'expo-router';
import { useTranslation } from 'react-i18next';
@@ -11,6 +10,7 @@ import type { Credential } from '@/utils/dist/shared/models/vault';
import { useColors } from '@/hooks/useColorScheme';
import { CredentialIcon } from '@/components/credentials/CredentialIcon';
+import { useAuth } from '@/context/AuthContext';
import NativeVaultManager from '@/specs/NativeVaultManager';
type CredentialCardProps = {
@@ -24,6 +24,7 @@ type CredentialCardProps = {
export function CredentialCard({ credential, onCredentialDelete }: CredentialCardProps) : React.ReactNode {
const colors = useColors();
const { t } = useTranslation();
+ const { getClipboardClearTimeout } = useAuth();
/**
* Get the display text for a credential, showing username by default,
@@ -68,8 +69,7 @@ export function CredentialCard({ credential, onCredentialDelete }: CredentialCar
await Clipboard.setStringAsync(text);
// Get clipboard clear timeout from settings
- const timeoutStr = await AsyncStorage.getItem('clipboard_clear_timeout');
- const timeoutSeconds = timeoutStr ? parseInt(timeoutStr, 10) : 10;
+ const timeoutSeconds = await getClipboardClearTimeout();
// Schedule clipboard clear if timeout is set
if (timeoutSeconds > 0) {
diff --git a/apps/mobile-app/components/credentials/details/TotpSection.tsx b/apps/mobile-app/components/credentials/details/TotpSection.tsx
index be612edca..08983b201 100644
--- a/apps/mobile-app/components/credentials/details/TotpSection.tsx
+++ b/apps/mobile-app/components/credentials/details/TotpSection.tsx
@@ -1,4 +1,3 @@
-import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Clipboard from 'expo-clipboard';
import * as OTPAuth from 'otpauth';
import React, { useState, useEffect } from 'react';
@@ -12,6 +11,7 @@ import { useColors } from '@/hooks/useColorScheme';
import { ThemedText } from '@/components/themed/ThemedText';
import { ThemedView } from '@/components/themed/ThemedView';
+import { useAuth } from '@/context/AuthContext';
import { useDb } from '@/context/DbContext';
import NativeVaultManager from '@/specs/NativeVaultManager';
@@ -28,6 +28,7 @@ export const TotpSection: React.FC<TotpSectionProps> = ({ credential }) : React.
const colors = useColors();
const dbContext = useDb();
const { t } = useTranslation();
+ const { getClipboardClearTimeout } = useAuth();
/**
* Get the remaining seconds.
@@ -76,8 +77,7 @@ export const TotpSection: React.FC<TotpSectionProps> = ({ credential }) : React.
await Clipboard.setStringAsync(code);
// Get clipboard clear timeout from settings
- const timeoutStr = await AsyncStorage.getItem('clipboard_clear_timeout');
- const timeoutSeconds = timeoutStr ? parseInt(timeoutStr, 10) : 10;
+ const timeoutSeconds = await getClipboardClearTimeout();
// Schedule clipboard clear if timeout is set
if (timeoutSeconds > 0) {
diff --git a/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx b/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx
index 40b847c0b..867747a49 100644
--- a/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx
+++ b/apps/mobile-app/components/form/FormInputCopyToClipboard.tsx
@@ -1,5 +1,4 @@
import { MaterialIcons } from '@expo/vector-icons';
-import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Clipboard from 'expo-clipboard';
import React, { useState, useRef, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
@@ -8,6 +7,7 @@ import Toast from 'react-native-toast-message';
import { useColors } from '@/hooks/useColorScheme';
+import { useAuth } from '@/context/AuthContext';
import { useClipboardCountdown } from '@/context/ClipboardCountdownContext';
import NativeVaultManager from '@/specs/NativeVaultManager';
@@ -28,6 +28,7 @@ const FormInputCopyToClipboard: React.FC<FormInputCopyToClipboardProps> = ({
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const colors = useColors();
const { t } = useTranslation();
+ const { getClipboardClearTimeout } = useAuth();
const { activeFieldId, setActiveField } = useClipboardCountdown();
const animatedWidth = useRef(new Animated.Value(0)).current;
@@ -50,8 +51,7 @@ const FormInputCopyToClipboard: React.FC<FormInputCopyToClipboardProps> = ({
animatedWidth.setValue(100);
// Get timeout and start animation
- AsyncStorage.getItem('clipboard_clear_timeout').then((timeoutStr) => {
- const timeoutSeconds = timeoutStr ? parseInt(timeoutStr, 10) : 10;
+ getClipboardClearTimeout().then((timeoutSeconds) => {
if (timeoutSeconds > 0 && activeFieldId === fieldId) {
Animated.timing(animatedWidth, {
toValue: 0,
@@ -70,7 +70,7 @@ const FormInputCopyToClipboard: React.FC<FormInputCopyToClipboardProps> = ({
animatedWidth.stopAnimation();
animatedWidth.setValue(0);
}
- }, [isCountingDown, activeFieldId, fieldId, animatedWidth, setActiveField]);
+ }, [isCountingDown, activeFieldId, fieldId, animatedWidth, setActiveField, getClipboardClearTimeout]);
/**
* Copy the value to the clipboard.
@@ -82,8 +82,7 @@ const FormInputCopyToClipboard: React.FC<FormInputCopyToClipboardProps> = ({
await Clipboard.setStringAsync(value);
// Get clipboard clear timeout from settings
- const timeoutStr = await AsyncStorage.getItem('clipboard_clear_timeout');
- const timeoutSeconds = timeoutStr ? parseInt(timeoutStr, 10) : 10;
+ const timeoutSeconds = await getClipboardClearTimeout();
// Schedule clipboard clear if timeout is set
if (timeoutSeconds > 0) {
diff --git a/apps/mobile-app/context/AuthContext.tsx b/apps/mobile-app/context/AuthContext.tsx
index 36ec8c545..a06685591 100644
--- a/apps/mobile-app/context/AuthContext.tsx
+++ b/apps/mobile-app/context/AuthContext.tsx
@@ -274,7 +274,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
const getClipboardClearTimeout = useCallback(async (): Promise<number> => {
try {
const timeoutStr = await AsyncStorage.getItem(CLIPBOARD_TIMEOUT_KEY);
- return timeoutStr ? parseInt(timeoutStr, 10) : 10;
+ return timeoutStr ? parseInt(timeoutStr, 10) : 15;
} catch (error) {
console.error('Failed to get clipboard clear timeout:', error);
return 10;