From ddf8a87fd3d88df1be5799aa2acb9cabc892c78c Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Mon, 18 Jan 2021 22:40:11 -0500 Subject: [PATCH 1/3] REF: Handoff Component --- ...ctivity.android.js => WatchConnectivity.js | 0 blue_modules/handoff.ios.js | 16 +++++++++++++ blue_modules/handoff.js | 5 ++++ blue_modules/storage-context.js | 20 ++++++++++++++++ class/app-storage.js | 1 + class/handoff.js | 24 ------------------- screen/receive/details.js | 9 +++---- screen/settings/GeneralSettings.js | 14 ++++------- screen/transactions/details.js | 17 +++++-------- screen/transactions/transactionStatus.js | 14 +++++------ screen/wallets/transactions.js | 9 +++---- 11 files changed, 65 insertions(+), 64 deletions(-) rename WatchConnectivity.android.js => WatchConnectivity.js (100%) create mode 100644 blue_modules/handoff.ios.js create mode 100644 blue_modules/handoff.js delete mode 100644 class/handoff.js diff --git a/WatchConnectivity.android.js b/WatchConnectivity.js similarity index 100% rename from WatchConnectivity.android.js rename to WatchConnectivity.js diff --git a/blue_modules/handoff.ios.js b/blue_modules/handoff.ios.js new file mode 100644 index 000000000..8800e6090 --- /dev/null +++ b/blue_modules/handoff.ios.js @@ -0,0 +1,16 @@ +import React, { useContext } from 'react'; +import Handoff from 'react-native-handoff'; +import { BlueStorageContext } from './storage-context'; +import PropTypes from 'prop-types'; + +const HandoffComponent = props => { + const { isHandOffUseEnabled } = useContext(BlueStorageContext); + + return isHandOffUseEnabled && props && props.url ? : null; +}; +HandoffComponent.STORAGE_KEY = 'HandOff'; +export default HandoffComponent; + +HandoffComponent.propTypes = { + url: PropTypes.string, +}; diff --git a/blue_modules/handoff.js b/blue_modules/handoff.js new file mode 100644 index 000000000..7d0b11d75 --- /dev/null +++ b/blue_modules/handoff.js @@ -0,0 +1,5 @@ +const HandoffComponent = () => { + return null; +}; + +export default HandoffComponent; diff --git a/blue_modules/storage-context.js b/blue_modules/storage-context.js index f8e4fa039..db0523500 100644 --- a/blue_modules/storage-context.js +++ b/blue_modules/storage-context.js @@ -18,6 +18,12 @@ export const BlueStorageProvider = ({ children }) => { const getPreferredCurrencyAsyncStorage = useAsyncStorage(AppStorage.PREFERRED_CURRENCY).getItem; const getLanguageAsyncStorage = useAsyncStorage(AppStorage.LANG).getItem; const [newWalletAdded, setNewWalletAdded] = useState(false); + const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState(false); + const setIsHandOffUseEnabledAsyncStorage = value => { + setIsHandOffUseEnabled(value); + return BlueApp.setItem(AppStorage.HANDOFF_STORAGE_KEY, value === true ? '1' : ''); + }; + const saveToDisk = async () => { BlueApp.tx_metadata = txMetadata; await BlueApp.saveToDisk(); @@ -29,6 +35,18 @@ export const BlueStorageProvider = ({ children }) => { setWallets(BlueApp.getWallets()); }, []); + useEffect(() => { + (async () => { + try { + const enabledHandoff = await BlueApp.getItem(AppStorage.HANDOFF_STORAGE_KEY); + setIsHandOffUseEnabled(!!enabledHandoff); + } catch (_e) { + setIsHandOffUseEnabledAsyncStorage(false); + setIsHandOffUseEnabled(false); + } + })(); + }, []); + const getPreferredCurrency = async () => { const item = await getPreferredCurrencyAsyncStorage(); _setPreferredFiatCurrency(item); @@ -187,6 +205,8 @@ export const BlueStorageProvider = ({ children }) => { preferredFiatCurrency, setLanguage, language, + isHandOffUseEnabled, + setIsHandOffUseEnabledAsyncStorage, }} > {children} diff --git a/class/app-storage.js b/class/app-storage.js index fbe2a04f3..8a2745ef2 100644 --- a/class/app-storage.js +++ b/class/app-storage.js @@ -35,6 +35,7 @@ export class AppStorage { static HODL_HODL_API_KEY = 'HODL_HODL_API_KEY'; static HODL_HODL_SIGNATURE_KEY = 'HODL_HODL_SIGNATURE_KEY'; static HODL_HODL_CONTRACTS = 'HODL_HODL_CONTRACTS'; + static HANDOFF_STORAGE_KEY = 'HandOff'; constructor() { /** {Array.} */ diff --git a/class/handoff.js b/class/handoff.js deleted file mode 100644 index 4bc73a418..000000000 --- a/class/handoff.js +++ /dev/null @@ -1,24 +0,0 @@ -import { Platform } from 'react-native'; - -const BlueApp = require('../BlueApp'); - -export default class HandoffSettings { - static STORAGEKEY = 'HandOff'; - - static async isHandoffUseEnabled() { - if (Platform.OS !== 'ios') { - return false; - } - try { - const enabledHandoff = await BlueApp.getItem(HandoffSettings.STORAGEKEY); - return !!enabledHandoff; - } catch (_e) { - await BlueApp.setItem(HandoffSettings.STORAGEKEY, ''); - return false; - } - } - - static async setHandoffUseEnabled(value) { - await BlueApp.setItem(HandoffSettings.STORAGEKEY, value === true && Platform.OS === 'ios' ? '1' : ''); - } -} diff --git a/screen/receive/details.js b/screen/receive/details.js index 4f6e9231a..b51baf739 100644 --- a/screen/receive/details.js +++ b/screen/receive/details.js @@ -13,7 +13,6 @@ import { import QRCode from 'react-native-qrcode-svg'; import { useNavigation, useRoute, useTheme, useFocusEffect } from '@react-navigation/native'; import Share from 'react-native-share'; -import Handoff from 'react-native-handoff'; import { BlueLoading, @@ -31,7 +30,7 @@ import navigationStyle from '../../components/navigationStyle'; import BottomModal from '../../components/BottomModal'; import Privacy from '../../Privacy'; import { Chain, BitcoinUnit } from '../../models/bitcoinUnits'; -import HandoffSettings from '../../class/handoff'; +import HandoffComponent from '../../blue_modules/handoff'; import DeeplinkSchemaMatch from '../../class/deeplink-schema-match'; import loc from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; @@ -42,7 +41,6 @@ const ReceiveDetails = () => { const { walletID } = useRoute().params; const { wallets, saveToDisk, sleep } = useContext(BlueStorageContext); const wallet = wallets.find(w => w.getID() === walletID); - const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState(false); const [address, setAddress] = useState(''); const [customLabel, setCustomLabel] = useState(); const [customAmount, setCustomAmount] = useState(0); @@ -172,7 +170,6 @@ const ReceiveDetails = () => { }; const obtainWalletAddress = useCallback(async () => { - HandoffSettings.isHandoffUseEnabled().then(setIsHandOffUseEnabled); Privacy.enableBlur(); console.log('receive/details - componentDidMount'); wallet.setUserHasSavedExport(true); @@ -338,8 +335,8 @@ const ReceiveDetails = () => { return ( - {isHandOffUseEnabled && address !== undefined && showAddress && ( - { - const { isAdancedModeEnabled, setIsAdancedModeEnabled, wallets } = useContext(BlueStorageContext); + const { isAdancedModeEnabled, setIsAdancedModeEnabled, wallets, isHandOffUseEnabled, setIsHandOffUseEnabledAsyncStorage } = useContext( + BlueStorageContext, + ); const [isLoading, setIsLoading] = useState(true); const [isAdancedModeSwitchEnabled, setIsAdancedModeSwitchEnabled] = useState(false); - const [isHandoffUseEnabled, setIsHandoffUseEnabled] = useState(false); const { navigate } = useNavigation(); const { colors } = useTheme(); const onAdvancedModeSwitch = async value => { @@ -26,15 +26,9 @@ const GeneralSettings = () => { setIsAdancedModeSwitchEnabled(value); }; - const onHandOffEnabledSwitch = async value => { - await HandoffSettings.setHandoffUseEnabled(value); - setIsHandoffUseEnabled(value); - }; - useEffect(() => { (async () => { setIsAdancedModeSwitchEnabled(await isAdancedModeEnabled()); - setIsHandoffUseEnabled(await HandoffSettings.isHandoffUseEnabled()); setIsLoading(false); })(); }); @@ -69,7 +63,7 @@ const GeneralSettings = () => { hideChevron title={loc.settings.general_continuity} Component={TouchableWithoutFeedback} - switch={{ onValueChange: onHandOffEnabledSwitch, value: isHandoffUseEnabled }} + switch={{ onValueChange: setIsHandOffUseEnabledAsyncStorage, value: isHandOffUseEnabled }} /> {loc.settings.general_continuity_e} diff --git a/screen/transactions/details.js b/screen/transactions/details.js index 570fd552b..85febb9e7 100644 --- a/screen/transactions/details.js +++ b/screen/transactions/details.js @@ -2,10 +2,9 @@ import React, { useContext, useEffect, useState } from 'react'; import { View, ScrollView, TouchableOpacity, Text, TextInput, Linking, StatusBar, StyleSheet, Keyboard } from 'react-native'; import { useNavigation, useRoute, useTheme } from '@react-navigation/native'; -import Handoff from 'react-native-handoff'; import { BlueCard, BlueCopyToClipboardButton, BlueLoading, BlueSpacing20, BlueText, SafeBlueArea } from '../../BlueComponents'; import navigationStyle from '../../components/navigationStyle'; -import HandoffSettings from '../../class/handoff'; +import HandoffComponent from '../../blue_modules/handoff'; import loc from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; const dayjs = require('dayjs'); @@ -28,7 +27,6 @@ const TransactionsDetails = () => { const { setOptions } = useNavigation(); const { hash } = useRoute().params; const { saveToDisk, txMetadata, wallets, getTransactions } = useContext(BlueStorageContext); - const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState(false); const [from, setFrom] = useState(); const [to, setTo] = useState(); const [isLoading, setIsLoading] = useState(true); @@ -110,11 +108,6 @@ const TransactionsDetails = () => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [hash, wallets]); - useEffect(() => { - HandoffSettings.isHandoffUseEnabled().then(setIsHandOffUseEnabled); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - const handleOnSaveButtonTapped = () => { Keyboard.dismiss(); txMetadata[tx.hash] = { memo }; @@ -136,9 +129,11 @@ const TransactionsDetails = () => { return ( - {isHandOffUseEnabled && ( - - )} + diff --git a/screen/transactions/transactionStatus.js b/screen/transactions/transactionStatus.js index 1269aba13..5b5a74352 100644 --- a/screen/transactions/transactionStatus.js +++ b/screen/transactions/transactionStatus.js @@ -1,7 +1,6 @@ import React, { useContext, useEffect, useRef, useState } from 'react'; import { View, ActivityIndicator, Text, TouchableOpacity, StyleSheet, StatusBar } from 'react-native'; import { Icon } from 'react-native-elements'; -import Handoff from 'react-native-handoff'; import { useNavigation, useRoute, useTheme } from '@react-navigation/native'; import { @@ -19,7 +18,7 @@ import { import navigationStyle from '../../components/navigationStyle'; import { HDSegwitBech32Transaction } from '../../class'; import { BitcoinUnit } from '../../models/bitcoinUnits'; -import HandoffSettings from '../../class/handoff'; +import HandoffComponent from '../../blue_modules/handoff'; import loc, { formatBalanceWithoutSuffix } from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; @@ -31,7 +30,6 @@ const buttonStatus = Object.freeze({ const TransactionsStatus = () => { const { setSelectedWallet, wallets, txMetadata, getTransactions } = useContext(BlueStorageContext); - const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState(false); const { hash } = useRoute().params; const { navigate, setOptions } = useNavigation(); const { colors } = useTheme(); @@ -127,7 +125,6 @@ const TransactionsStatus = () => { useEffect(() => { console.log('transactions/details - useEffect'); - HandoffSettings.isHandoffUseEnabled().then(setIsHandOffUseEnabled); }, []); const checkPossibilityOfCPFP = async () => { @@ -282,9 +279,12 @@ const TransactionsStatus = () => { } return ( - {isHandOffUseEnabled && ( - - )} + + diff --git a/screen/wallets/transactions.js b/screen/wallets/transactions.js index ac7b73c2b..c56c533d4 100644 --- a/screen/wallets/transactions.js +++ b/screen/wallets/transactions.js @@ -21,7 +21,6 @@ import { import { launchImageLibrary } from 'react-native-image-picker'; import Clipboard from '@react-native-community/clipboard'; import { Icon } from 'react-native-elements'; -import Handoff from 'react-native-handoff'; import { useRoute, useNavigation, useTheme, useFocusEffect } from '@react-navigation/native'; import isCatalyst from 'react-native-is-catalyst'; @@ -30,7 +29,7 @@ import { BlueTransactionListItem, BlueWalletNavigationHeader, BlueAlertWalletExp import WalletGradient from '../../class/wallet-gradient'; import navigationStyle from '../../components/navigationStyle'; import { LightningCustodianWallet, MultisigHDWallet, WatchOnlyWallet } from '../../class'; -import HandoffSettings from '../../class/handoff'; +import HandoffComponent from '../../blue_modules/handoff'; import ActionSheet from '../ActionSheet'; import loc from '../../loc'; import { FContainer, FButton } from '../../components/FloatButtons'; @@ -50,7 +49,6 @@ const buttonFontSize = const WalletTransactions = () => { const { wallets, saveToDisk, setSelectedWallet } = useContext(BlueStorageContext); - const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState(false); const [isLoading, setIsLoading] = useState(false); const [isManageFundsModalVisible, setIsManageFundsModalVisible] = useState(false); const { walletID } = useRoute().params; @@ -107,7 +105,6 @@ const WalletTransactions = () => { }; useEffect(() => { - HandoffSettings.isHandoffUseEnabled().then(setIsHandOffUseEnabled); const interval = setInterval(() => setTimeElapsed(prev => prev + 1), 60000); return () => { clearInterval(interval); @@ -590,8 +587,8 @@ const WalletTransactions = () => { return ( - {wallet.current.chain === Chain.ONCHAIN && wallet.current.type !== MultisigHDWallet.type && isHandOffUseEnabled && ( - Date: Tue, 19 Jan 2021 07:11:31 -0500 Subject: [PATCH 2/3] Update handoff.ios.js --- blue_modules/handoff.ios.js | 1 - 1 file changed, 1 deletion(-) diff --git a/blue_modules/handoff.ios.js b/blue_modules/handoff.ios.js index 8800e6090..37b516c87 100644 --- a/blue_modules/handoff.ios.js +++ b/blue_modules/handoff.ios.js @@ -8,7 +8,6 @@ const HandoffComponent = props => { return isHandOffUseEnabled && props && props.url ? : null; }; -HandoffComponent.STORAGE_KEY = 'HandOff'; export default HandoffComponent; HandoffComponent.propTypes = { From 1c4d4c100c21393a5267dbecd4c78386a42b3ea9 Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Fri, 22 Jan 2021 11:34:47 -0500 Subject: [PATCH 3/3] REF: Update component location --- {blue_modules => components}/handoff.ios.js | 2 +- {blue_modules => components}/handoff.js | 0 screen/receive/details.js | 2 +- screen/transactions/details.js | 2 +- screen/transactions/transactionStatus.js | 2 +- screen/wallets/transactions.js | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename {blue_modules => components}/handoff.ios.js (85%) rename {blue_modules => components}/handoff.js (100%) diff --git a/blue_modules/handoff.ios.js b/components/handoff.ios.js similarity index 85% rename from blue_modules/handoff.ios.js rename to components/handoff.ios.js index 37b516c87..e18099aa7 100644 --- a/blue_modules/handoff.ios.js +++ b/components/handoff.ios.js @@ -1,6 +1,6 @@ import React, { useContext } from 'react'; import Handoff from 'react-native-handoff'; -import { BlueStorageContext } from './storage-context'; +import { BlueStorageContext } from '../blue_modules/storage-context'; import PropTypes from 'prop-types'; const HandoffComponent = props => { diff --git a/blue_modules/handoff.js b/components/handoff.js similarity index 100% rename from blue_modules/handoff.js rename to components/handoff.js diff --git a/screen/receive/details.js b/screen/receive/details.js index b51baf739..2439b3c6a 100644 --- a/screen/receive/details.js +++ b/screen/receive/details.js @@ -30,7 +30,7 @@ import navigationStyle from '../../components/navigationStyle'; import BottomModal from '../../components/BottomModal'; import Privacy from '../../Privacy'; import { Chain, BitcoinUnit } from '../../models/bitcoinUnits'; -import HandoffComponent from '../../blue_modules/handoff'; +import HandoffComponent from '../../components/handoff'; import DeeplinkSchemaMatch from '../../class/deeplink-schema-match'; import loc from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; diff --git a/screen/transactions/details.js b/screen/transactions/details.js index 85febb9e7..23bb78dd4 100644 --- a/screen/transactions/details.js +++ b/screen/transactions/details.js @@ -4,7 +4,7 @@ import { View, ScrollView, TouchableOpacity, Text, TextInput, Linking, StatusBar import { useNavigation, useRoute, useTheme } from '@react-navigation/native'; import { BlueCard, BlueCopyToClipboardButton, BlueLoading, BlueSpacing20, BlueText, SafeBlueArea } from '../../BlueComponents'; import navigationStyle from '../../components/navigationStyle'; -import HandoffComponent from '../../blue_modules/handoff'; +import HandoffComponent from '../../components/handoff'; import loc from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; const dayjs = require('dayjs'); diff --git a/screen/transactions/transactionStatus.js b/screen/transactions/transactionStatus.js index 5b5a74352..4d9eec3f5 100644 --- a/screen/transactions/transactionStatus.js +++ b/screen/transactions/transactionStatus.js @@ -18,7 +18,7 @@ import { import navigationStyle from '../../components/navigationStyle'; import { HDSegwitBech32Transaction } from '../../class'; import { BitcoinUnit } from '../../models/bitcoinUnits'; -import HandoffComponent from '../../blue_modules/handoff'; +import HandoffComponent from '../../components/handoff'; import loc, { formatBalanceWithoutSuffix } from '../../loc'; import { BlueStorageContext } from '../../blue_modules/storage-context'; diff --git a/screen/wallets/transactions.js b/screen/wallets/transactions.js index c56c533d4..f08bd503f 100644 --- a/screen/wallets/transactions.js +++ b/screen/wallets/transactions.js @@ -29,7 +29,7 @@ import { BlueTransactionListItem, BlueWalletNavigationHeader, BlueAlertWalletExp import WalletGradient from '../../class/wallet-gradient'; import navigationStyle from '../../components/navigationStyle'; import { LightningCustodianWallet, MultisigHDWallet, WatchOnlyWallet } from '../../class'; -import HandoffComponent from '../../blue_modules/handoff'; +import HandoffComponent from '../../components/handoff'; import ActionSheet from '../ActionSheet'; import loc from '../../loc'; import { FContainer, FButton } from '../../components/FloatButtons';