mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-04 12:18:10 +01:00
ADD: Privacy settings for iOS 14 widgets
This commit is contained in:
parent
f4cdccf948
commit
5d8f08b7a8
4 changed files with 72 additions and 10 deletions
|
@ -1,4 +1,6 @@
|
|||
function WidgetCommunication(props) {
|
||||
WidgetCommunication.isBalanceDisplayAllowed = false;
|
||||
WidgetCommunication.setBalanceDisplayAllowed = () => {};
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,34 @@ import { useContext, useEffect } from 'react';
|
|||
import { BlueStorageContext } from './storage-context';
|
||||
import DefaultPreference from 'react-native-default-preference';
|
||||
import RNWidgetCenter from 'react-native-widget-center';
|
||||
|
||||
const WidgetCommunicationAllWalletsSatoshiBalance = 'WidgetCommunicationAllWalletsSatoshiBalance';
|
||||
const WidgetCommunicationAllWalletsLatestTransactionTime = 'WidgetCommunicationAllWalletsLatestTransactionTime';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
function WidgetCommunication() {
|
||||
WidgetCommunication.WidgetCommunicationAllWalletsSatoshiBalance = 'WidgetCommunicationAllWalletsSatoshiBalance';
|
||||
WidgetCommunication.WidgetCommunicationAllWalletsLatestTransactionTime = 'WidgetCommunicationAllWalletsLatestTransactionTime';
|
||||
WidgetCommunication.WidgetCommunicationDisplayBalanceAllowed = 'WidgetCommunicationDisplayBalanceAllowed';
|
||||
const { wallets, walletsInitialized, isStorageEncrypted } = useContext(BlueStorageContext);
|
||||
|
||||
WidgetCommunication.isBalanceDisplayAllowed = async () => {
|
||||
try {
|
||||
const displayBalance = JSON.parse(await AsyncStorage.getItem(WidgetCommunication.WidgetCommunicationDisplayBalanceAllowed));
|
||||
if (displayBalance !== null) {
|
||||
return displayBalance;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
WidgetCommunication.setBalanceDisplayAllowed = async value => {
|
||||
await AsyncStorage.setItem(WidgetCommunication.WidgetCommunicationDisplayBalanceAllowed, JSON.stringify(value));
|
||||
setValues();
|
||||
};
|
||||
|
||||
const allWalletsBalanceAndTransactionTime = async () => {
|
||||
if (await isStorageEncrypted()) {
|
||||
if ((await isStorageEncrypted()) || !(await WidgetCommunication.isBalanceDisplayAllowed())) {
|
||||
return { allWalletsBalance: 0, latestTransactionTime: 0 };
|
||||
} else {
|
||||
let balance = 0;
|
||||
|
@ -30,8 +49,11 @@ function WidgetCommunication() {
|
|||
const setValues = async () => {
|
||||
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
|
||||
const { allWalletsBalance, latestTransactionTime } = await allWalletsBalanceAndTransactionTime();
|
||||
await DefaultPreference.set(WidgetCommunicationAllWalletsSatoshiBalance, JSON.stringify(allWalletsBalance));
|
||||
await DefaultPreference.set(WidgetCommunicationAllWalletsLatestTransactionTime, JSON.stringify(latestTransactionTime));
|
||||
await DefaultPreference.set(WidgetCommunication.WidgetCommunicationAllWalletsSatoshiBalance, JSON.stringify(allWalletsBalance));
|
||||
await DefaultPreference.set(
|
||||
WidgetCommunication.WidgetCommunicationAllWalletsLatestTransactionTime,
|
||||
JSON.stringify(latestTransactionTime),
|
||||
);
|
||||
RNWidgetCenter.reloadAllTimelines();
|
||||
};
|
||||
|
||||
|
|
|
@ -293,7 +293,10 @@
|
|||
"retype_password": "Re-type password",
|
||||
"save": "Save",
|
||||
"saved": "Saved",
|
||||
"success_transaction_broadcasted" : "Success! You transaction has been broadcasted!"
|
||||
"success_transaction_broadcasted" : "Success! You transaction has been broadcasted!",
|
||||
"total_balance": "Total Balance",
|
||||
"total_balance_explanation": "Display the total balance of all your wallets on your home screen widgets.",
|
||||
"widgets": "Widgets"
|
||||
},
|
||||
"notifications": {
|
||||
"would_you_like_to_receive_notifications": "Would you like to receive notifications when you get incoming payments?",
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Linking } from 'react-native';
|
||||
import { BlueText, BlueSpacing20, BlueListItem, BlueNavigationStyle, BlueCard } from '../../BlueComponents';
|
||||
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Linking, Platform } from 'react-native';
|
||||
import { BlueText, BlueSpacing20, BlueListItem, BlueNavigationStyle, BlueCard, BlueHeaderDefaultSub } from '../../BlueComponents';
|
||||
import { useTheme } from '@react-navigation/native';
|
||||
import loc from '../../loc';
|
||||
import BlueClipboard from '../../blue_modules/clipboard';
|
||||
import DeviceQuickActions from '../../class/quick-actions';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
|
||||
import WidgetCommunication from '../../blue_modules/WidgetCommunication';
|
||||
|
||||
const SettingsPrivacy = () => {
|
||||
const { colors } = useTheme();
|
||||
const { isStorageEncrypted } = useContext(BlueStorageContext);
|
||||
const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2 });
|
||||
const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 });
|
||||
const [isLoading, setIsLoading] = useState(sections.ALL);
|
||||
const [isReadClipboardAllowed, setIsReadClipboardAllowed] = useState(false);
|
||||
|
||||
const [isDisplayWidgetBalanceAllowed, setIsDisplayWidgetBalanceAllowed] = useState(false);
|
||||
const [isQuickActionsEnabled, setIsQuickActionsEnabled] = useState(false);
|
||||
const [storageIsEncrypted, setStorageIsEncrypted] = useState(true);
|
||||
|
||||
|
@ -22,6 +26,7 @@ const SettingsPrivacy = () => {
|
|||
setIsReadClipboardAllowed(await BlueClipboard.isReadClipboardAllowed());
|
||||
setStorageIsEncrypted(await isStorageEncrypted());
|
||||
setIsQuickActionsEnabled(await DeviceQuickActions.getEnabled());
|
||||
setIsDisplayWidgetBalanceAllowed(await WidgetCommunication.isBalanceDisplayAllowed());
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
@ -52,6 +57,17 @@ const SettingsPrivacy = () => {
|
|||
setIsLoading(false);
|
||||
};
|
||||
|
||||
const onWidgetsTotalBalanceValueChange = async value => {
|
||||
setIsLoading(sections.WIDGETS);
|
||||
try {
|
||||
await WidgetCommunication.setBalanceDisplayAllowed(value);
|
||||
setIsDisplayWidgetBalanceAllowed(value);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
const stylesWithThemeHook = StyleSheet.create({
|
||||
root: {
|
||||
backgroundColor: colors.background,
|
||||
|
@ -64,6 +80,7 @@ const SettingsPrivacy = () => {
|
|||
|
||||
return (
|
||||
<ScrollView style={[styles.root, stylesWithThemeHook.root]}>
|
||||
<BlueHeaderDefaultSub leftText={loc.settings.general} rightComponent={null} />
|
||||
<BlueListItem
|
||||
hideChevron
|
||||
title={loc.settings.privacy_read_clipboard}
|
||||
|
@ -87,6 +104,24 @@ const SettingsPrivacy = () => {
|
|||
</BlueCard>
|
||||
</>
|
||||
)}
|
||||
{Platform.OS === 'ios' && !storageIsEncrypted && (
|
||||
<>
|
||||
<BlueHeaderDefaultSub leftText={loc.settings.widgets} rightComponent={null} />
|
||||
<BlueListItem
|
||||
hideChevron
|
||||
title={loc.settings.total_balance}
|
||||
Component={TouchableWithoutFeedback}
|
||||
switch={{
|
||||
onValueChange: onWidgetsTotalBalanceValueChange,
|
||||
value: isDisplayWidgetBalanceAllowed,
|
||||
disabled: isLoading === sections.ALL,
|
||||
}}
|
||||
/>
|
||||
<BlueCard>
|
||||
<BlueText>{loc.settings.total_balance_explanation}</BlueText>
|
||||
</BlueCard>
|
||||
</>
|
||||
)}
|
||||
<BlueSpacing20 />
|
||||
<BlueListItem title={loc.settings.privacy_system_settings} chevron onPress={openApplicationSettings} />
|
||||
<BlueSpacing20 />
|
||||
|
|
Loading…
Add table
Reference in a new issue