Skip to content

Commit

Permalink
add a hook for UUID finding / copying. add it to cmd+k and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
BrodyHughes committed Jan 3, 2025
1 parent 1b81384 commit 9868c02
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/entries/popup/components/CommandK/useCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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,
Expand All @@ -1432,6 +1447,7 @@ export const useCommands = (
currentAddress,
isTokenHidden,
isNftHidden,
searchQuery,
navigate,
handleCopy,
sortedAccounts,
Expand All @@ -1448,6 +1464,8 @@ export const useCommands = (
toggleHideToken,
toggleHideNFT,
selectSearchTokenAndNavigate,
handleUUIDCopy,
getAppUUID,
],
);

Expand Down
31 changes: 31 additions & 0 deletions src/entries/popup/hooks/useDeviceUUID.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};
9 changes: 8 additions & 1 deletion src/entries/popup/pages/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down Expand Up @@ -529,7 +531,12 @@ export function Settings() {
/>
</Menu>
)}
<Box padding="10px" alignItems="center" justifyContent="center">
<Box
padding="10px"
alignItems="center"
justifyContent="center"
onDoubleClick={async () => handleUUIDCopy(await getAppUUID())}
>
<Text
size="12pt"
weight="semibold"
Expand Down
6 changes: 4 additions & 2 deletions static/json/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
"open_in_new_tab": "Open in New Tab",
"switch_to_wallet": "Switch to Wallet",
"send_to_contact": "Send to Contact",
"view": "View"
"view": "View",
"uuid_copied": "UUID copied"
},
"commands": {
"names": {
Expand Down Expand Up @@ -497,7 +498,8 @@
"send_contact": "Send to Contact",
"export_addresses_as_csv": "Export Addresses as CSV",
"enable_flashbots": "Enable Flashbots",
"disable_flashbots": "Disable Flashbots"
"disable_flashbots": "Disable Flashbots",
"diagnostics": "Diagnostics"
},
"search_tags": {
"swap": "buy, sell, trade, order, exchange, dex, routes",
Expand Down

0 comments on commit 9868c02

Please sign in to comment.