Skip to content

Commit be68ade

Browse files
committed
fix: review comments
1 parent 1ede2ca commit be68ade

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

apps/frontend/src/app/3_organisms/Header/Header.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ import { NetworkPicker } from '../../2_molecules/NetworkPicker/NetworkPicker';
1616
import { SovrynLogo } from '../../2_molecules/SovrynLogo/SovrynLogo';
1717
import { useWalletConnect, useWrongNetworkCheck } from '../../../hooks';
1818
import { translations } from '../../../locales/i18n';
19+
import {
20+
IS_IMPERSONATING,
21+
stopImpersonatingAccount,
22+
} from '../../../utils/account-debug';
1923
import { getOriginsUrl } from '../../../utils/helpers';
2024
import { menuItemsMapping } from './Header.constants';
2125
import { BridgeMenuItem } from './components/BridgeMenuItem/BridgeMenuItem';
2226
import { NavItem } from './components/NavItem/NavItem';
2327
import { ProductLinks } from './components/ProductLinks/ProductLinks';
24-
import { IS_IMPERSONATING } from '../../../utils/account-debug';
2528

2629
export const Header: FC = () => {
2730
const [isOpen, toggle] = useReducer(v => !v, false);
@@ -94,7 +97,7 @@ export const Header: FC = () => {
9497
className={
9598
'fixed bottom-3 right-3 bg-sovryn-black text-trade-short-25 text-xs px-2 py-1 rounded'
9699
}
97-
onClick={() => (window as any).stopImpersonatingAccount()}
100+
onClick={() => stopImpersonatingAccount()}
98101
>
99102
<Tooltip content="You are in DEBUG MODE. All RPC requests will be called from the impersonated account. Click to disable.">
100103
<span>DEBUG MODE</span>

apps/frontend/src/utils/account-debug.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,39 @@ export function maybeDebugAccount(address?: string): string {
1515
return address?.toLowerCase() ?? '';
1616
}
1717

18-
function impersonateAccount(address: string) {
19-
if (!ethers.utils.isAddress(address?.toLowerCase())) {
18+
export function impersonateAccount(address?: string) {
19+
if (!address || !ethers.utils.isAddress(address.toLowerCase())) {
2020
throw new Error("It's not a valid Ethereum address.");
2121
}
22-
22+
const lowercasedAddress = address.toLowerCase();
2323
if (typeof localStorage !== 'undefined') {
24-
localStorage.setItem('impersonate', address.toLowerCase());
24+
localStorage.setItem('impersonate', lowercasedAddress);
2525
window.location.reload();
2626
}
2727
}
2828

29-
function stopImpersonatingAccount() {
29+
export function stopImpersonatingAccount() {
3030
if (typeof localStorage !== 'undefined') {
3131
localStorage.removeItem('impersonate');
3232
window.location.reload();
3333
}
3434
}
3535

36+
declare global {
37+
interface Window {
38+
impersonateAccount: (address: string) => void;
39+
stopImpersonatingAccount: () => void;
40+
}
41+
}
42+
3643
(() => {
3744
if (typeof window !== 'undefined') {
38-
(window as any).impersonateAccount = impersonateAccount;
39-
(window as any).stopImpersonatingAccount = stopImpersonatingAccount;
45+
window.impersonateAccount = impersonateAccount;
46+
window.stopImpersonatingAccount = stopImpersonatingAccount;
4047
}
4148

4249
if (IS_IMPERSONATING) {
43-
console.warn(
50+
console.log(
4451
'%cYou are in DEBUG MODE. All RPC requests will be called from the impersonated account. However transactions still will be signed with your connected wallet.\nTo stop impersonation, run stopImpersonatingAccount().',
4552
'background: red; color: white; font-size: 16px; padding: 4px;',
4653
);

0 commit comments

Comments
 (0)