aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/App.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-04-11 23:48:55 -0300
committerSebastian <sebasjm@gmail.com>2024-04-11 23:48:55 -0300
commit9bafc6864b9e0ef237b6975165f23ba31f0d8d88 (patch)
treeb8b12d8b78c874384368adc5a8600363c04b54c5 /packages/aml-backoffice-ui/src/App.tsx
parent516bda58bb53738fa4d2ae0b10a25e53c138180b (diff)
downloadwallet-core-9bafc6864b9e0ef237b6975165f23ba31f0d8d88.tar.xz
fix AML spa memo and fix #8615
Diffstat (limited to 'packages/aml-backoffice-ui/src/App.tsx')
-rw-r--r--packages/aml-backoffice-ui/src/App.tsx62
1 files changed, 52 insertions, 10 deletions
diff --git a/packages/aml-backoffice-ui/src/App.tsx b/packages/aml-backoffice-ui/src/App.tsx
index d461934c0..5244476d7 100644
--- a/packages/aml-backoffice-ui/src/App.tsx
+++ b/packages/aml-backoffice-ui/src/App.tsx
@@ -6,9 +6,11 @@ import { ExchangeApiProvider } from "./context/config.js";
import { getInitialBackendBaseURL } from "./hooks/useBackend.js";
import { HashPathProvider, Router } from "./route.js";
import { Pages } from "./pages.js";
+import { SWRConfig } from "swr";
-const pageList = Object.values(Pages);
+const WITH_LOCAL_STORAGE_CACHE = false;
+const pageList = Object.values(Pages);
export function App(): VNode {
const baseUrl = getInitialBackendBaseURL();
@@ -16,17 +18,57 @@ export function App(): VNode {
<TranslationProvider source={{}}>
<ExchangeApiProvider baseUrl={baseUrl} frameOnError={ExchangeAmlFrame}>
<HashPathProvider>
- <ExchangeAmlFrame>
- <Router
- pageList={pageList}
- onNotFound={() => {
- window.location.href = Pages.cases.url
- return <div>not found</div>;
- }}
- />
- </ExchangeAmlFrame>
+ <SWRConfig
+ value={{
+ provider: WITH_LOCAL_STORAGE_CACHE
+ ? localStorageProvider
+ : undefined,
+ // normally, do not revalidate
+ revalidateOnFocus: false,
+ revalidateOnReconnect: false,
+ revalidateIfStale: false,
+ revalidateOnMount: undefined,
+ focusThrottleInterval: undefined,
+
+ // normally, do not refresh
+ refreshInterval: undefined,
+ dedupingInterval: 2000,
+ refreshWhenHidden: false,
+ refreshWhenOffline: false,
+
+ // ignore errors
+ shouldRetryOnError: false,
+ errorRetryCount: 0,
+ errorRetryInterval: undefined,
+
+ // do not go to loading again if already has data
+ keepPreviousData: true,
+ }}
+ >
+
+ <ExchangeAmlFrame>
+ <Router
+ pageList={pageList}
+ onNotFound={() => {
+ window.location.href = Pages.cases.url
+ return <div>not found</div>;
+ }}
+ />
+ </ExchangeAmlFrame>
+ </SWRConfig>
</HashPathProvider>
</ExchangeApiProvider>
</TranslationProvider>
);
}
+
+
+function localStorageProvider(): Map<unknown, unknown> {
+ const map = new Map(JSON.parse(localStorage.getItem("app-cache") || "[]"));
+
+ window.addEventListener("beforeunload", () => {
+ const appCache = JSON.stringify(Array.from(map.entries()));
+ localStorage.setItem("app-cache", appCache);
+ });
+ return map;
+}