diff options
| author | Adam Soltys <[email protected]> | 2024-10-18 09:08:07 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-18 09:09:14 -0700 |
| commit | 002cd9134d2e23bec34f838f6d6fefba41f2d530 (patch) | |
| tree | 92fa0e0ab54ce1a715d25f458de8b8ed8cc70bd5 /src/routes/(app)/settings | |
| parent | f6bfe889d91bc6e36b0300d7b618f10158efe176 (diff) | |
| download | coinos-ui-002cd9134d2e23bec34f838f6d6fefba41f2d530.tar.gz coinos-ui-002cd9134d2e23bec34f838f6d6fefba41f2d530.zip | |
biome format
Diffstat (limited to 'src/routes/(app)/settings')
| -rw-r--r-- | src/routes/(app)/settings/[...tab]/+page.svelte | 8 | ||||
| -rw-r--r-- | src/routes/(app)/settings/[...tab]/_pos.svelte | 44 |
2 files changed, 47 insertions, 5 deletions
diff --git a/src/routes/(app)/settings/[...tab]/+page.svelte b/src/routes/(app)/settings/[...tab]/+page.svelte index f59806d1..7ef1653d 100644 --- a/src/routes/(app)/settings/[...tab]/+page.svelte +++ b/src/routes/(app)/settings/[...tab]/+page.svelte @@ -87,7 +87,7 @@ try { data.set( "cipher", - await reEncryptEntropy(user, data.get("password")) + await reEncryptEntropy(user, data.get("password")), ); } catch (e) { console.log("Failed to encrypt keys with new password"); @@ -98,7 +98,7 @@ if ($avatar) { try { let { hash } = JSON.parse( - await upload($avatar.file, $avatar.type, $avatar.progress, token) + await upload($avatar.file, $avatar.type, $avatar.progress, token), ); data.set("profile", hash); @@ -115,7 +115,7 @@ if ($banner) { try { let { hash } = JSON.parse( - await upload($banner.file, $banner.type, $banner.progress, token) + await upload($banner.file, $banner.type, $banner.progress, token), ); data.set("banner", hash); @@ -161,7 +161,7 @@ await post( "/api/request", { id: user.id, email: user.email }, - auth(cookies) + auth(cookies), ); warning($t("user.settings.verifying"), false); diff --git a/src/routes/(app)/settings/[...tab]/_pos.svelte b/src/routes/(app)/settings/[...tab]/_pos.svelte index dcfcbe44..7ccaa69f 100644 --- a/src/routes/(app)/settings/[...tab]/_pos.svelte +++ b/src/routes/(app)/settings/[...tab]/_pos.svelte @@ -13,7 +13,7 @@ let { currency } = user; let rate = rates[currency]; - let fiats = Object.keys(rates).sort((a,b) => a.localeCompare(b)); + let fiats = Object.keys(rates).sort((a, b) => a.localeCompare(b)); $: user.language = $locale; let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click()); @@ -38,6 +38,36 @@ if (!user.threshold) user.threshold = 1000000; if (!user.reserve) user.reserve = 100000; let reserveEl, thresholdEl; + + let subscription; + $: updateNotifications(user.push); + let updateNotifications = async (push) => { + if (push && navigator.serviceWorker) { + const VAPID_PUBLIC_KEY = + "BEfgMDTeAn1F8ZQUGC6v5iKTD86zYXaa3QVr1E-ylKXC5c24JplcfSAN9PDlXAsVtUd3cU6j4-LsX_TKQzz_yDQ"; + + const swRegistration = await navigator.serviceWorker.getRegistration(); + const pushManager = swRegistration.pushManager; + if (!isPushManagerActive(pushManager)) { + console.log("not active"); + return; + } + subscription = await pushManager.subscribe({ + userVisibleOnly: true, + applicationServerKey: VAPID_PUBLIC_KEY, + }); + } + }; + + function isPushManagerActive(pushManager) { + if (pushManager) return true; + + if (!window.navigator.standalone) { + console.log("not standalone"); + } + + return false; + } </script> <div> @@ -74,6 +104,18 @@ <div> <div class="flex justify-between items-center"> + <span class="font-bold">{$t("user.settings.pushNotifications")}</span> + <Toggle id="push" bind:value={user.push} /> + </div> + <p class="text-secondary mt-1 w-9/12"> + {$t("user.settings.pushNotificationsDesc")} + </p> +</div> + +{JSON.stringify(subscription)} + +<div> + <div class="flex justify-between items-center"> <span class="font-bold">{$t("user.settings.tipPrompt")}</span> <Toggle id="prompt" bind:value={user.prompt} /> </div> |
