diff --git a/src/entries/popup/components/CommandK/useCommands.tsx b/src/entries/popup/components/CommandK/useCommands.tsx index 100a7f0a77..d69bd54772 100644 --- a/src/entries/popup/components/CommandK/useCommands.tsx +++ b/src/entries/popup/components/CommandK/useCommands.tsx @@ -44,6 +44,7 @@ import { ROUTES } from '~/entries/popup/urls'; import { useBrowser } from '../../hooks/useBrowser'; import { useCurrentWalletTypeAndVendor } from '../../hooks/useCurrentWalletType'; +import { useDeviceUUID } from '../../hooks/useDeviceUUID'; import { useIsFullScreen } from '../../hooks/useIsFullScreen'; import { triggerToast } from '../Toast/Toast'; @@ -173,6 +174,13 @@ export const getStaticCommandInfo = (): CommandInfo => { symbolSize: 15, type: SearchItemType.Shortcut, }, + copyAppUUID: { + name: getCommandName('diagnostics'), + page: PAGES.HOME, + symbol: 'square.on.square', + symbolSize: 15, + type: SearchItemType.Shortcut, + }, viewProfile: { actionLabel: actionLabels.openInNewTab, name: getCommandName('view_profile'), @@ -727,6 +735,7 @@ export const useCommands = ( const isFullScreen = useIsFullScreen(); const navigate = useRainbowNavigate(); const navigateToSwaps = useNavigateToSwaps(); + const { getAppUUID, handleUUIDCopy } = useDeviceUUID(); // Wrapped to add analytics const wrappedNavigateToSwaps = React.useCallback(() => { @@ -1410,6 +1419,12 @@ export const useCommands = ( !previousPageState.selectedCommand?.asset?.address || isETHAddress(previousPageState.selectedCommand?.asset?.address), }, + copyAppUUID: { + action: async () => handleUUIDCopy(await getAppUUID()), + hidden: + searchQuery.toLowerCase() !== + getCommandName('diagnostics').toLowerCase(), + }, }), [ wrappedNavigateToSwaps, @@ -1432,6 +1447,7 @@ export const useCommands = ( currentAddress, isTokenHidden, isNftHidden, + searchQuery, navigate, handleCopy, sortedAccounts, @@ -1448,6 +1464,8 @@ export const useCommands = ( toggleHideToken, toggleHideNFT, selectSearchTokenAndNavigate, + handleUUIDCopy, + getAppUUID, ], ); diff --git a/src/entries/popup/hooks/useDeviceUUID.ts b/src/entries/popup/hooks/useDeviceUUID.ts new file mode 100644 index 0000000000..2d85f03616 --- /dev/null +++ b/src/entries/popup/hooks/useDeviceUUID.ts @@ -0,0 +1,31 @@ +import React from 'react'; + +import { i18n } from '~/core/languages'; + +import { triggerToast } from '../components/Toast/Toast'; + +export const useDeviceUUID = () => { + const getAppUUID = React.useCallback(async () => { + const storage = await chrome.storage.local.get('rainbow.zustand.deviceId'); + const entries = Object.entries(storage) as [string, string][]; + const jsonString = entries[0][1]; + const parsed = JSON.parse(jsonString) as { + state: { deviceId: string }; + version: number; + }; + return parsed.state.deviceId as string; + }, []); + + const handleUUIDCopy = React.useCallback(async (uuid: string) => { + navigator.clipboard.writeText(uuid); + triggerToast({ + title: i18n.t('command_k.action_labels.uuid_copied'), + description: `${uuid.slice(0, 5)}…${uuid.slice(-5)}`, + }); + }, []); + + return { + getAppUUID, + handleUUIDCopy, + }; +}; diff --git a/src/entries/popup/pages/settings/settings.tsx b/src/entries/popup/pages/settings/settings.tsx index 5d717a404f..9575940f01 100644 --- a/src/entries/popup/pages/settings/settings.tsx +++ b/src/entries/popup/pages/settings/settings.tsx @@ -37,6 +37,7 @@ import { logger } from '~/logger'; import packageJson from '../../../../../package.json'; import { testSandbox } from '../../handlers/wallet'; +import { useDeviceUUID } from '../../hooks/useDeviceUUID'; import { useRainbowNavigate } from '../../hooks/useRainbowNavigate'; import { useWallets } from '../../hooks/useWallets'; import { ROUTES } from '../../urls'; @@ -51,6 +52,7 @@ export function Settings() { const { soundsEnabled, toggleSoundsEnabled } = useSoundStore(); const { featureFlags, setFeatureFlag } = useFeatureFlagsStore(); const { isWatchingWallet } = useWallets(); + const { getAppUUID, handleUUIDCopy } = useDeviceUUID(); const { currentUserSelectedTheme, currentTheme, setCurrentTheme } = useCurrentThemeStore(); @@ -529,7 +531,12 @@ export function Settings() { /> )} - + handleUUIDCopy(await getAppUUID())} + >