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
index ce012003b..30b2dbfe6 100644
--- a/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap
+++ b/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap
@@ -1,781 +1,777 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP @generated
exports[`Configure with a wallet 1`] = `
Backup your wallet
-
Your seed phrase is the only way to restore your wallet. Write it down. Keep it safe.
Click to reveal seed phrase
Manage Wallets
Fiat Currency
General Settings
[
Documentation
]
`;
exports[`Configure without a wallet 1`] = `
Backup your wallet
-
Your seed phrase is the only way to restore your wallet. Write it down. Keep it safe.
Manage Wallets
Fiat Currency
General Settings
[
Documentation
]
`;
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
index bd0caefa1..6d4f5e22c 100644
--- a/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap
+++ b/web/cashtab/src/components/Send/__tests__/__snapshots__/Send.test.js.snap
@@ -1,2289 +1,2319 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP @generated
exports[`Wallet with BCH balances 1`] = `
Array [
You currently have 0
XEC
Deposit some funds to use this feature
,
,
Signatures
,
,
]
`;
exports[`Wallet with BCH balances and tokens 1`] = `
Array [
You currently have 0
XEC
Deposit some funds to use this feature
,
,
Signatures
,
,
]
`;
exports[`Wallet with BCH balances and tokens and state field 1`] = `
Array [
0.06
XEC
,
$
NaN
USD
,
,
Signatures
,
,
]
`;
exports[`Wallet without BCH balance 1`] = `
Array [
You currently have 0
XEC
Deposit some funds to use this feature
,
,
Signatures
,
,
]
`;
exports[`Without wallet defined 1`] = `
Array [
You currently have 0
XEC
Deposit some funds to use this feature
,
,
Signatures
,
,
]
`;
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
index f2af0e978..693a07b52 100644
--- a/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap
+++ b/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap
@@ -1,289 +1,288 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP @generated
exports[`Wallet with BCH balances and tokens 1`] = `null`;
exports[`Wallet with BCH balances and tokens and state field 1`] = `
Array [
6.001
TBS
,
-
If you would like to request an icon for an eToken that has already been created, please email icons@e.cash.
,
,
]
`;
exports[`Without wallet defined 1`] = `null`;
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
index 521573ded..a847b3fc4 100644
--- a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/CreateTokenForm.test.js.snap
+++ b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/CreateTokenForm.test.js.snap
@@ -1,47 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP @generated
exports[`Wallet with BCH balances and tokens and state field 1`] = `
`;
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
index 09d545863..b23a68084 100644
--- a/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap
+++ b/web/cashtab/src/components/Tokens/__tests__/__snapshots__/Tokens.test.js.snap
@@ -1,642 +1,637 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP @generated
exports[`Wallet with BCH balances 1`] = `
Array [
You need some
XEC
in your wallet to create tokens.
,
0
XEC
,
-
If you would like to request an icon for an eToken that has already been created, please email icons@e.cash.
,
,
You need at least
5.5
XEC
(
$
NaN
USD
) to create a token
,
"No ",
"eToken",
" tokens in this wallet",
]
`;
exports[`Wallet with BCH balances and tokens 1`] = `
Array [
You need some
XEC
in your wallet to create tokens.
,
0
XEC
,
-
If you would like to request an icon for an eToken that has already been created, please email icons@e.cash.
,
,
You need at least
5.5
XEC
(
$
NaN
USD
) to create a token
,
"No ",
"eToken",
" tokens in this wallet",
]
`;
exports[`Wallet with BCH balances and tokens and state field 1`] = `
Array [
0.06
XEC
,
$
NaN
USD
,
-
If you would like to request an icon for an eToken that has already been created, please email icons@e.cash.
,
,
,
]
`;
exports[`Wallet without BCH balance 1`] = `
Array [
You need some
XEC
in your wallet to create tokens.
,
0
XEC
,
-
If you would like to request an icon for an eToken that has already been created, please email icons@e.cash.
,
,
You need at least
5.5
XEC
(
$
NaN
USD
) to create a token
,
"No ",
"eToken",
" tokens in this wallet",
]
`;
exports[`Without wallet defined 1`] = `
Array [
You need some
XEC
in your wallet to create tokens.
,
0
XEC
,
-
If you would like to request an icon for an eToken that has already been created, please email icons@e.cash.
,
,
You need at least
5.5
XEC
(
$
NaN
USD
) to create a token
,
"No ",
"eToken",
" tokens in this wallet",
]
`;
diff --git a/web/cashtab/src/serviceWorker.js b/web/cashtab/src/serviceWorker.js
index c72e6e01d..524bdd32e 100644
--- a/web/cashtab/src/serviceWorker.js
+++ b/web/cashtab/src/serviceWorker.js
@@ -1,62 +1,105 @@
import { clientsClaim } from 'workbox-core';
import { setCacheNameDetails } from 'workbox-core';
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();
self.skipWaiting();
// 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
setCacheNameDetails({
prefix: prefix,
suffix: suffix,
precache: staticAssetsCache,
});
// 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),
},
];
txDetailsCaches.forEach(cache => {
registerRoute(
({ url }) => url.pathname.includes(cache.path),
new CacheFirst({
cacheName: cache.name,
plugins: [
- new CacheableResponsePlugin({
- statuses: [200],
- }),
+ cache.customPlugin,
new ExpirationPlugin({
maxEntries: 1000,
maxAgeSeconds: 365 * 24 * 60 * 60,
}),
],
}),
);
});