From e6a9a930ddcdf3a64cf0cb8a12e1a1a331f9e773 Mon Sep 17 00:00:00 2001 From: onmax Date: Tue, 21 Jan 2025 10:46:28 +0100 Subject: [PATCH] wip --- src/hub.ts | 1 + src/main.ts | 8 ++++++-- src/storage.ts | 3 +++ src/stores/Playground.ts | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/stores/Playground.ts diff --git a/src/hub.ts b/src/hub.ts index ad6f3937a..dcbc00e58 100644 --- a/src/hub.ts +++ b/src/hub.ts @@ -38,6 +38,7 @@ import { WELCOME_MODAL_LOCALSTORAGE_KEY, WELCOME_STAKING_MODAL_LOCALSTORAGE_KEY import { usePwaInstallPrompt } from './composables/usePwaInstallPrompt'; import type { SetupSwapWithKycResult, SWAP_KYC_HANDLER_STORAGE_KEY } from './swap-kyc-handler'; // avoid bundling import type { RelayServerInfo } from './lib/usdc/OpenGSN'; +import { usePlaygroundStore } from './stores/Playground'; export function shouldUseRedirects(ignoreSettings = false): boolean { if (!ignoreSettings) { diff --git a/src/main.ts b/src/main.ts index 79f93398f..cec359879 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,6 +17,7 @@ import { launchElectrum } from './electrum'; import { launchPolygon } from './ethers'; import { useAccountStore } from './stores/Account'; import { useFiatStore } from './stores/Fiat'; +import { usePlaygroundStore } from './stores/Playground'; import { useSettingsStore } from './stores/Settings'; import router from './router'; import { i18n, loadLanguage } from './i18n/i18n-setup'; @@ -52,8 +53,11 @@ async function start() { initTrials(); // Must be called after storage was initialized, can affect Config // Must run after VueCompositionApi has been enabled and after storage was initialized. Could potentially run in // background and in parallel to syncFromHub, but RedirectRpcClient.init does not actually run async code anyways. - await initHubApi(); - syncFromHub(); // Can run parallel to Vue initialization; must be called after storage was initialized. + console.log(usePlaygroundStore().isEnabled.value, ' it should be same as the state in Playground, but is it always true'); // This does not work + if (!usePlaygroundStore().isEnabled.value) { + await initHubApi(); + syncFromHub(); // Can run parallel to Vue initialization; must be called after storage was initialized. + } serviceWorkerHasUpdate.then((hasUpdate) => useSettingsStore().state.updateAvailable = hasUpdate); diff --git a/src/storage.ts b/src/storage.ts index 5a3abb2af..0cf6711c9 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -25,6 +25,7 @@ import { useKycStore } from './stores/Kyc'; import { useStakingStore } from './stores/Staking'; import { useGeoIp } from './composables/useGeoIp'; import { reportToSentry } from './lib/Sentry'; +import { usePlaygroundStore } from './stores/Playground'; const StorageKeys = { TRANSACTIONS: 'wallet_transactions_v01', @@ -44,6 +45,7 @@ const StorageKeys = { BANK: 'wallet_bank_v01', KYC: 'wallet_kyc_v00', STAKING: 'wallet_staking_v00', + PLAYGROUND: 'wallet_playground_v00', }; const PersistentStorageKeys = { @@ -263,6 +265,7 @@ export async function initStorage() { validators: {}, }), ), + initStoreStore(usePlaygroundStore(), StorageKeys.PLAYGROUND), ]); // Fetch missing exchange rates. diff --git a/src/stores/Playground.ts b/src/stores/Playground.ts new file mode 100644 index 000000000..dd26fc33f --- /dev/null +++ b/src/stores/Playground.ts @@ -0,0 +1,19 @@ +import { createStore } from 'pinia'; + +export type PlaygroundState = { + enabled: boolean, +}; + +export const usePlaygroundStore = createStore({ + id: 'playground', + state: (): PlaygroundState => { + const enabled = window.location.pathname === '/playground'; + console.log('playground enabled', enabled); // This works + return { + enabled, + }; + }, + getters: { + isEnabled: (state) => state.enabled, + }, +});