Skip to content

Commit 4387b3a

Browse files
committed
fix: review comments
1 parent 2daa8db commit 4387b3a

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ import { SovrynLogo } from '../../2_molecules/SovrynLogo/SovrynLogo';
1818
import { useWalletConnect, useWrongNetworkCheck } from '../../../hooks';
1919
import { useCurrentChain } from '../../../hooks/useChainStore';
2020
import { translations } from '../../../locales/i18n';
21+
import {
22+
IS_IMPERSONATING,
23+
stopImpersonatingAccount,
24+
} from '../../../utils/account-debug';
2125
import { isBobChain } from '../../../utils/chain';
2226
import { getOriginsUrl } from '../../../utils/helpers';
2327
import { menuItemsMapping } from './Header.constants';
2428
import { BridgeMenuItem } from './components/BridgeMenuItem/BridgeMenuItem';
2529
import { NavItem } from './components/NavItem/NavItem';
2630
import { ProductLinks } from './components/ProductLinks/ProductLinks';
27-
import { IS_IMPERSONATING } from '../../../utils/account-debug';
2831

2932
export const Header: FC = () => {
3033
const chainId = useCurrentChain();
@@ -115,7 +118,7 @@ export const Header: FC = () => {
115118
className={
116119
'fixed bottom-3 right-3 bg-sovryn-black text-trade-short-25 text-xs px-2 py-1 rounded'
117120
}
118-
onClick={() => (window as any).stopImpersonatingAccount()}
121+
onClick={() => stopImpersonatingAccount()}
119122
>
120123
<Tooltip content="You are in DEBUG MODE. All RPC requests will be called from the impersonated account. Click to disable.">
121124
<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)