Skip to content

Commit

Permalink
chore: remove service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed May 7, 2024
1 parent 5d5a6a4 commit 7d22692
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 136 deletions.
2 changes: 1 addition & 1 deletion app/app.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
packages = {
app = unstablePkgs.buildNpmPackage {
npmDepsHash = "sha256-m3x4ij54Lf1pzycCxoVztIKcXrj40vMExmi9nFeMj4o=";
npmDepsHash = "sha256-mrDHHnmmJIkboY+HJC+/28wocjmhKrbCP+jUwTcppzc=";
src = ./.;
sourceRoot = "app";
npmFlags = [ "--legacy-peer-deps" ];
Expand Down
8 changes: 4 additions & 4 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"uint8array-extras": "^1.1.0",
"valibot": "^0.30.0",
"vaul-svelte": "^0.3.0",
"viem": "^2.9.32"
"viem": "^2.10.1"
},
"devDependencies": {
"@0no-co/graphqlsp": "^1.12.2",
Expand Down
8 changes: 2 additions & 6 deletions app/src/lib/wallet/cosmos/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ function createCosmosStore(
update,
subscribe,
connect: async (walletId: string) => {
console.log({ walletId })
// alert("Please install Keplr wallet")
if (!walletId || (walletId !== "keplr" && walletId !== "leap")) return
update(v => ({ ...v, connectionStatus: "connecting", connectedWallet: walletId }))
console.log({ walletId })
if (!window[walletId]) {
alert(`Please install ${walletId} wallet`)
update(v => ({ ...v, connectionStatus: "disconnected", connectedWallet: walletId }))
return
return update(v => ({ ...v, connectionStatus: "disconnected" }))
}
await window[walletId]?.enable(["union-testnet-8"])
const account = await window[walletId]?.getKey("union-testnet-8")
console.log({ account })
update(v => ({
...v,
connectionStatus: "connected",
Expand Down
196 changes: 98 additions & 98 deletions app/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
<script lang="ts">
import "$lib/polyfill.ts"
import "$styles/index.css"
import {
hydrate,
dehydrate,
QueryClient,
MutationCache,
notifyManager,
QueryClientProvider
} from "@tanstack/svelte-query"
import { ModeWatcher } from "mode-watcher"
import { browser } from "$app/environment"
import { setContext, onMount } from "svelte"
import { Toaster } from "svelte-french-toast"
import { page, navigating } from "$app/stores"
import { setContextClient } from "@urql/svelte"
import { cosmosStore } from "$lib/wallet/cosmos"
import Footer from "$lib/components/footer.svelte"
import { graphqlClient } from "$lib/graphql/client"
import Header from "$lib/components/header/header.svelte"
import { updateTheme } from "$lib/utilities/update-theme.ts"
import OnlineStatus from "$lib/components/online-status.svelte"
import { SvelteQueryDevtools } from "@tanstack/svelte-query-devtools"
import PreloadingIndicator from "$lib/components/preloading-indicator.svelte"
if (browser) notifyManager.setScheduler(window.requestAnimationFrame)
$: updateTheme({ path: $page.url.pathname, activeTheme: "dark" })
onMount(() => {
/* fix for iOS Safari viewport zooming on input focus */
if (navigator.userAgent.indexOf("iPhone") === -1) return
const metaElement = document.querySelector("meta[name=viewport]")
if (!metaElement) return
metaElement.setAttribute("content", "width=device-width, initial-scale=1, maximum-scale=1")
})
onMount(() => {
const lastConnectedWallet = $cosmosStore["connectedWallet"] as "leap" | "keplr"
if (
lastConnectedWallet &&
["leap", "keplr"].includes(lastConnectedWallet) &&
window[lastConnectedWallet]
) {
return cosmosStore.connect(lastConnectedWallet)
}
if (window?.keplr) cosmosStore.connect("keplr")
else if (window?.leap) cosmosStore.connect("leap")
})
/**
* @see https://commerce.nearform.com/open-source/urql/docs/basics/svelte/#providing-the-client
*/
setContextClient(graphqlClient)
const queryClient: QueryClient = new QueryClient({
defaultOptions: {
queries: {
enabled: browser,
refetchOnReconnect: () => !queryClient.isMutating()
}
},
mutationCache: new MutationCache({
onSettled: () => {
if (queryClient.isMutating() === 1) {
return queryClient.invalidateQueries()
}
}
import '$lib/polyfill.ts'
import '$styles/index.css'
import {
hydrate,
dehydrate,
QueryClient,
MutationCache,
notifyManager,
QueryClientProvider,
} from '@tanstack/svelte-query'
import { ModeWatcher } from 'mode-watcher'
import { browser } from '$app/environment'
import { setContext, onMount } from 'svelte'
import { Toaster } from 'svelte-french-toast'
import { page, navigating } from '$app/stores'
import { setContextClient } from '@urql/svelte'
import { cosmosStore } from '$lib/wallet/cosmos'
import Footer from '$lib/components/footer.svelte'
import { graphqlClient } from '$lib/graphql/client'
import Header from '$lib/components/header/header.svelte'
import { updateTheme } from '$lib/utilities/update-theme.ts'
import OnlineStatus from '$lib/components/online-status.svelte'
import { SvelteQueryDevtools } from '@tanstack/svelte-query-devtools'
import PreloadingIndicator from '$lib/components/preloading-indicator.svelte'
if (browser) notifyManager.setScheduler(window.requestAnimationFrame)
$: updateTheme({ path: $page.url.pathname, activeTheme: 'dark' })
onMount(() => {
/* fix for iOS Safari viewport zooming on input focus */
if (navigator.userAgent.indexOf('iPhone') === -1) return
const metaElement = document.querySelector('meta[name=viewport]')
if (!metaElement) return
metaElement.setAttribute('content', 'width=device-width, initial-scale=1, maximum-scale=1')
})
onMount(() => {
const lastConnectedWallet = $cosmosStore['connectedWallet'] as 'leap' | 'keplr'
if (
lastConnectedWallet &&
window[lastConnectedWallet] &&
['leap', 'keplr'].includes(lastConnectedWallet)
)
return cosmosStore.connect(lastConnectedWallet)
if (window?.keplr) cosmosStore.connect('keplr')
else if (window?.leap) cosmosStore.connect('leap')
})
})
setContext("$$_queryClient", queryClient)
function hydrateClient() {
try {
const storeValue = localStorage.getItem("QUERY_CLIENT")
if (!storeValue) return
const persistedValue = JSON.parse(storeValue) as Record<string, any>
if ("timestamp" in persistedValue && persistedValue?.["timestamp"]) {
const MAX_AGE = 1000 * 60 * 60 * 24
const expired = Date.now() - persistedValue["timestamp"] > MAX_AGE
if (!expired) hydrate(queryClient, persistedValue.clientState)
} else localStorage.removeItem("QUERY_CLIENT")
} catch (error) {
localStorage.removeItem("QUERY_CLIENT")
/**
* @see https://commerce.nearform.com/open-source/urql/docs/basics/svelte/#providing-the-client
*/
setContextClient(graphqlClient)
const queryClient: QueryClient = new QueryClient({
defaultOptions: {
queries: {
enabled: browser,
refetchOnReconnect: () => !queryClient.isMutating(),
},
},
mutationCache: new MutationCache({
onSettled: () => {
if (queryClient.isMutating() === 1) {
return queryClient.invalidateQueries()
}
},
}),
})
setContext('$$_queryClient', queryClient)
function hydrateClient() {
try {
const storeValue = localStorage.getItem('QUERY_CLIENT')
if (!storeValue) return
const persistedValue = JSON.parse(storeValue) as Record<string, any>
if ('timestamp' in persistedValue && persistedValue?.['timestamp']) {
const MAX_AGE = 1000 * 60 * 60 * 24
const expired = Date.now() - persistedValue['timestamp'] > MAX_AGE
if (!expired) hydrate(queryClient, persistedValue.clientState)
} else localStorage.removeItem('QUERY_CLIENT')
} catch (error) {
localStorage.removeItem('QUERY_CLIENT')
}
}
}
const saveClient = () =>
localStorage.setItem(
"QUERY_CLIENT",
JSON.stringify({ timestamp: Date.now(), clientState: dehydrate(queryClient, {}) })
)
const unload = () => saveClient()
onMount(() => {
hydrateClient()
queryClient.mount()
return () => queryClient.unmount()
})
$: if ($navigating) console.log("Navigating to", $page.url.pathname)
const saveClient = () =>
localStorage.setItem(
'QUERY_CLIENT',
JSON.stringify({ timestamp: Date.now(), clientState: dehydrate(queryClient, {}) }),
)
const unload = () => saveClient()
onMount(() => {
hydrateClient()
queryClient.mount()
return () => queryClient.unmount()
})
$: if ($navigating) console.log('Navigating to', $page.url.pathname)
</script>

<svelte:head>
Expand Down
26 changes: 0 additions & 26 deletions app/src/service-worker/index.ts

This file was deleted.

0 comments on commit 7d22692

Please sign in to comment.