From f66a2a809f1cadd9806bb9309afa622f54d3636a Mon Sep 17 00:00:00 2001 From: ioay Date: Mon, 20 Nov 2023 12:33:31 +0100 Subject: [PATCH] UI improvements, changes naming conventions: pushNotifications -> notifications --- background/main.ts | 11 ++--------- background/redux-slices/ui.ts | 20 ++++++++++---------- background/services/preferences/index.ts | 10 ++-------- ui/_locales/en/messages.json | 2 +- ui/components/Wallet/Banner/PortalBanner.tsx | 1 - ui/components/Wallet/WalletSubscapeLink.tsx | 19 ++++++++++++++++--- ui/pages/Settings.tsx | 20 ++++++++++---------- 7 files changed, 41 insertions(+), 42 deletions(-) diff --git a/background/main.ts b/background/main.ts index 7dee3fe2c..c02b7641b 100644 --- a/background/main.ts +++ b/background/main.ts @@ -84,10 +84,9 @@ import { setShowAnalyticsNotification, setSelectedNetwork, setAutoLockInterval, - togglePushNotifications, + toggleNotifications, setShownDismissableItems, dismissableItemMarkedAsShown, - showPushNotifications, } from "./redux-slices/ui" import { estimatedFeesPerGas, @@ -601,8 +600,6 @@ export default class Main extends BaseService { }) this.initializeRedux() - - // shouldShowNotifications } protected override async internalStartService(): Promise { @@ -1862,7 +1859,7 @@ export default class Main extends BaseService { await this.preferenceService.setShouldShowNotifications( shouldShowNotifications, ) - this.store.dispatch(togglePushNotifications(isPermissionGranted)) + this.store.dispatch(toggleNotifications(isPermissionGranted)) }, ) @@ -2050,10 +2047,6 @@ export default class Main extends BaseService { const { ui } = this.store.getState() - if (ui.settings.showPushNotifications === undefined) { - this.store.dispatch(showPushNotifications(true)) - } - const openTime = Date.now() const originalNetworkName = ui.selectedAccount.network.name diff --git a/background/redux-slices/ui.ts b/background/redux-slices/ui.ts index 26c82c2a3..5fe979a4c 100644 --- a/background/redux-slices/ui.ts +++ b/background/redux-slices/ui.ts @@ -16,7 +16,7 @@ export const defaultSettings = { hideDust: false, defaultWallet: false, showTestNetworks: false, - showPushNotifications: undefined, + showNotifications: undefined, collectAnalytics: false, showAnalyticsNotification: false, showUnverifiedAssets: false, @@ -35,7 +35,7 @@ export type UIState = { hideDust: boolean defaultWallet: boolean showTestNetworks: boolean - showPushNotifications?: boolean + showNotifications?: boolean collectAnalytics: boolean showAnalyticsNotification: boolean showUnverifiedAssets: boolean @@ -119,11 +119,11 @@ const uiSlice = createSlice({ showAnalyticsNotification: false, }, }), - togglePushNotifications: ( + toggleNotifications: ( immerState, - { payload: showPushNotifications }: { payload: boolean }, + { payload: showNotifications }: { payload: boolean }, ) => { - immerState.settings.showPushNotifications = showPushNotifications + immerState.settings.showNotifications = showNotifications }, setShowAnalyticsNotification: ( state, @@ -235,7 +235,7 @@ export const { toggleUseFlashbots, setShowAnalyticsNotification, toggleHideBanners, - togglePushNotifications, + toggleNotifications, setSelectedAccount, setSnackbarMessage, setDefaultWallet, @@ -259,8 +259,8 @@ export const updateAnalyticsPreferences = createBackgroundAsyncThunk( }, ) -export const showPushNotifications = createBackgroundAsyncThunk( - "ui/showPushNotifications", +export const showNotifications = createBackgroundAsyncThunk( + "ui/showNotifications", async (shouldShowNotifications: boolean) => { await emitter.emit("shouldShowNotifications", shouldShowNotifications) }, @@ -446,9 +446,9 @@ export const selectCollectAnalytics = createSelector( (settings) => settings?.collectAnalytics, ) -export const selectPushNotifications = createSelector( +export const selectNotifications = createSelector( selectSettings, - (settings) => settings?.showPushNotifications, + (settings) => settings?.showNotifications, ) export const selectHideBanners = createSelector( diff --git a/background/services/preferences/index.ts b/background/services/preferences/index.ts index 5615b204d..300757a6f 100644 --- a/background/services/preferences/index.ts +++ b/background/services/preferences/index.ts @@ -17,7 +17,6 @@ import { EVMNetwork, sameNetwork } from "../../networks" import { HexString, UNIXTime } from "../../types" import { AccountSignerSettings } from "../../ui" import { AccountSignerWithId } from "../../signing" -import logger from "../../lib/logger" export { AnalyticsPreferences, @@ -277,17 +276,12 @@ export default class PreferenceService extends BaseService { { permissions: ["notifications"], }, - async (granted) => { + (granted) => { resolve(granted) }, ) } else { - chrome.permissions.remove( - { permissions: ["notifications"] }, - async (removed) => { - resolve(!removed) - }, - ) + resolve(false) } }) diff --git a/ui/_locales/en/messages.json b/ui/_locales/en/messages.json index e0278635f..d9fd7129e 100644 --- a/ui/_locales/en/messages.json +++ b/ui/_locales/en/messages.json @@ -559,7 +559,7 @@ }, "mainMenu": "Settings", "signing": "Signing", - "showPushNotifications": "Show notifications", + "showNotifications": "Show Subscape notifications", "hideSmallAssetBalance": "Hide asset balances under {{sign}}{{amount}}", "setAsDefault": "Use Taho as default wallet", "enableTestNetworks": "Show testnet networks", diff --git a/ui/components/Wallet/Banner/PortalBanner.tsx b/ui/components/Wallet/Banner/PortalBanner.tsx index 17cc9f427..e891a2a6d 100644 --- a/ui/components/Wallet/Banner/PortalBanner.tsx +++ b/ui/components/Wallet/Banner/PortalBanner.tsx @@ -13,7 +13,6 @@ export default function PortalBanner(): ReactElement | null { const hasIslandAssets = useBackgroundSelector(selectHasIslandAssets) const showIslandAndDismissBanner = () => { - browser.permissions.request({ permissions: ["notifications"] }) browser.tabs.create({ url: "https://app.taho.xyz" }) } diff --git a/ui/components/Wallet/WalletSubscapeLink.tsx b/ui/components/Wallet/WalletSubscapeLink.tsx index c5988d40f..e352e2d24 100644 --- a/ui/components/Wallet/WalletSubscapeLink.tsx +++ b/ui/components/Wallet/WalletSubscapeLink.tsx @@ -1,17 +1,30 @@ import React, { ReactElement, useState } from "react" import classNames from "classnames" +import { useDispatch, useSelector } from "react-redux" +import { + selectNotifications, + showNotifications, +} from "@tallyho/tally-background/redux-slices/ui" import SharedIcon from "../Shared/SharedIcon" export default function WalletSubspaceLink(): ReactElement { + const dispatch = useDispatch() + const shouldShowNotifications = useSelector(selectNotifications) const [isIconOnly, setIsIconOnly] = useState(true) + const onClick = () => { + if (!shouldShowNotifications) { + dispatch(showNotifications(true)) + } + + window.open("https://app.taho.xyz/", "_blank")?.focus() + } + return (