diff --git a/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap b/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap --- a/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap +++ b/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap @@ -61,9 +61,6 @@
-
@@ -86,25 +83,27 @@ role="button" tabIndex={0} > - - - - - + + +
Click to reveal seed phrase
@@ -470,9 +469,6 @@
-
diff --git a/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap b/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap --- a/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap +++ b/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap @@ -44,7 +44,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -154,7 +155,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -365,25 +367,27 @@ role="button" tabIndex={0} > - - - - - + + +
Advanced
@@ -430,25 +434,27 @@ role="button" tabIndex={0} > - - - - - + + +
Sign Message
@@ -500,7 +506,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -610,7 +617,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -821,25 +829,27 @@ role="button" tabIndex={0} > - - - - - + + +
Advanced
@@ -886,25 +896,27 @@ role="button" tabIndex={0} > - - - - - + + +
Sign Message
@@ -963,7 +975,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -1073,7 +1086,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -1284,25 +1298,27 @@ role="button" tabIndex={0} > - - - - - + + +
Advanced
@@ -1350,25 +1366,27 @@ role="button" tabIndex={0} > - - - - - + + +
Sign Message
@@ -1420,7 +1438,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -1530,7 +1549,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -1741,25 +1761,27 @@ role="button" tabIndex={0} > - - - - - + + +
Advanced
@@ -1806,25 +1828,27 @@ role="button" tabIndex={0} > - - - - - + + +
Sign Message
@@ -1876,7 +1900,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -1986,7 +2011,7 @@ className="sc-iwsKbI ebAbAb" >
@@ -2197,25 +2223,27 @@ role="button" tabIndex={0} > - - - - - + + +
Advanced
@@ -2262,25 +2290,27 @@ role="button" tabIndex={0} > - - - - - + + +
Sign Message
diff --git a/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap b/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap --- a/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap +++ b/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap @@ -47,9 +47,6 @@
-
@@ -81,7 +78,7 @@ className="sc-VigVT hchaxg" >
@@ -191,7 +189,7 @@ className="sc-VigVT hchaxg" >
diff --git a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/CreateTokenForm.test.js.snap b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/CreateTokenForm.test.js.snap --- a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/CreateTokenForm.test.js.snap +++ b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/CreateTokenForm.test.js.snap @@ -21,25 +21,27 @@ role="button" tabIndex={0} > - - - - - + + +
Create eToken
diff --git a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap --- a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap +++ b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap @@ -52,9 +52,6 @@
-
@@ -83,25 +80,27 @@ role="button" tabIndex={-1} > - - - - - + + +
Create eToken
@@ -179,9 +178,6 @@
-
@@ -210,25 +206,27 @@ role="button" tabIndex={-1} > - - - - - + + +
Create eToken
@@ -307,9 +305,6 @@
-
@@ -338,25 +333,27 @@ role="button" tabIndex={0} > - - - - - + + +
Create eToken
@@ -439,9 +436,6 @@
-
@@ -470,25 +464,27 @@ role="button" tabIndex={-1} > - - - - - + + +
Create eToken
@@ -566,9 +562,6 @@
-
@@ -597,25 +590,27 @@ role="button" tabIndex={-1} > - - - - - + + +
Create eToken
diff --git a/web/cashtab/src/serviceWorker.js b/web/cashtab/src/serviceWorker.js --- a/web/cashtab/src/serviceWorker.js +++ b/web/cashtab/src/serviceWorker.js @@ -3,7 +3,6 @@ import { precacheAndRoute } from 'workbox-precaching'; import { registerRoute } from 'workbox-routing'; import { CacheFirst } from 'workbox-strategies'; -import { CacheableResponsePlugin } from 'workbox-cacheable-response'; import { ExpirationPlugin } from 'workbox-expiration'; clientsClaim(); @@ -11,7 +10,7 @@ // cofingure prefix, suffix, and cacheNames const prefix = 'cashtab'; -const suffix = 'v1.0.0'; +const suffix = 'v1.0.1'; const staticAssetsCache = `static-assets`; // configure prefix and suffix for default cache names @@ -24,22 +23,68 @@ // injection point for static assets caching precacheAndRoute(self.__WB_MANIFEST); +// A response is only cacheable if +// - status code is 200 +// - it has a blockhash - meaning it has been confirmed +const isResponseCacheable = async ( + response, + checkResponseDataForCacheableConditons, +) => { + // TODO: add error checking + // response must be of type Response + // checkResponseDataForCacheableConditons() must be a function + let cachable = false; + if (response && response.status === 200) { + const clonedResponse = response.clone(); + const clonedResponseData = await clonedResponse.json(); + if (checkResponseDataForCacheableConditons(clonedResponseData)) { + cachable = true; + } + } + + return cachable; +}; + +const createCustomPlugin = checkResponseDataForCacheableConditons => { + return { + cacheWillUpdate: async ({ response }) => { + const cacheable = await isResponseCacheable( + response, + checkResponseDataForCacheableConditons, + ); + if (cacheable) { + return response; + } + return null; + }, + }; +}; + +const blockhashExistsInTxResponse = responseBodyJson => { + return responseBodyJson && responseBodyJson.blockhash; +}; + +const blockhashExistsInSlpTxResponse = responseBodyJson => { + return ( + responseBodyJson && + responseBodyJson.retData && + responseBodyJson.retData.blockhash + ); +}; + // Caching TX and Token Details using CacheFirst Strategy const txDetailsCaches = [ { // ecash tx path: '/rawtransactions/getRawTransaction/', name: `${prefix}-tx-data-${suffix}`, + customPlugin: createCustomPlugin(blockhashExistsInTxResponse), }, { // slp tx path: '/slp/txDetails/', name: `${prefix}-slp-tx-data-${suffix}`, - }, - { - // slp token - path: '/slp/tokenStats/', - name: `${prefix}-slp-token-stats-${suffix}`, + customPlugin: createCustomPlugin(blockhashExistsInSlpTxResponse), }, ]; @@ -49,9 +94,7 @@ new CacheFirst({ cacheName: cache.name, plugins: [ - new CacheableResponsePlugin({ - statuses: [200], - }), + cache.customPlugin, new ExpirationPlugin({ maxEntries: 1000, maxAgeSeconds: 365 * 24 * 60 * 60,