diff --git a/web/cashtab/extension/src/components/App.js b/web/cashtab/extension/src/components/App.js --- a/web/cashtab/extension/src/components/App.js +++ b/web/cashtab/extension/src/components/App.js @@ -433,11 +433,33 @@ window.close(); }; + const checkForPersistentStorage = async () => { + // Request persistent storage for site + if (navigator.storage && navigator.storage.persist) { + // Check if storage is persistent + const isPersisted = await navigator.storage.persisted(); + console.log(`Persisted storage status: ${isPersisted}`); + // If not, request persistent storage + if (!isPersisted) { + console.log(`Requesting persistent storage`); + const persistanceRequestResult = + await navigator.storage.persist(); + console.log( + `Persistent storage granted: ${persistanceRequestResult}`, + ); + } + } + }; + useEffect(() => { copyAddressToExtensionStorage(wallet); }, [wallet]); useEffect(() => { + // On load useEffect() block + + // Check for peristent storage + checkForPersistentStorage(); // Parse for query string asking for user approval of sharing extension info with a web page // Do not set txInfo in state if query strings are not present if ( diff --git a/web/cashtab/src/components/App.js b/web/cashtab/src/components/App.js --- a/web/cashtab/src/components/App.js +++ b/web/cashtab/src/components/App.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import 'antd/dist/antd.less'; import PropTypes from 'prop-types'; import { Spin } from 'antd'; @@ -367,6 +367,24 @@ const selectedKey = location && location.pathname ? location.pathname.substr(1) : ''; + const checkForPersistentStorage = async () => { + // Request persistent storage for site + if (navigator.storage && navigator.storage.persist) { + // Check if storage is persistent + const isPersisted = await navigator.storage.persisted(); + console.log(`Persisted storage status: ${isPersisted}`); + // If not, request persistent storage + if (!isPersisted) { + console.log(`Requesting persistent storage`); + const persistanceRequestResult = + await navigator.storage.persist(); + console.log( + `Persistent storage granted: ${persistanceRequestResult}`, + ); + } + } + }; + // Easter egg boolean not used in extension/src/components/App.js const hasTab = validWallet ? checkForTokenById( @@ -375,6 +393,10 @@ ) : false; + useEffect(() => { + checkForPersistentStorage(); + }, []); + return (