Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add analytics on chainId bypass attempts #160

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 73 additions & 55 deletions src/components/simulation/SimulationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
StoredSimulationState,
updateSimulationAction,
} from '../../lib/simulation/storage';
import { RecommendedActionType } from '../../models/simulation/Transaction';
import { BypassType, RecommendedActionType } from '../../models/simulation/Transaction';
import styles from '../../styles/simulation/SimulationButton.module.css';
import localStorageHelpers from '../../lib/helpers/chrome/localStorage';
import { WgKeys } from '../../lib/helpers/chrome/localStorageKeys';
Expand Down Expand Up @@ -54,6 +54,10 @@ export const ConfirmSimulationButton: React.FC<ConfirmSimulationButtonProps> = (
setNeedsConfirm(false);
}

function joinDiscord() {
chrome.tabs.create({ url: 'https://discord.gg/mvbtaJzXDP' });
}

function handlePosthogIds() {
localStorageHelpers.get<string[] | null>(WgKeys.AddressList).then((res) => {
const addresses = res || [];
Expand All @@ -76,78 +80,92 @@ export const ConfirmSimulationButton: React.FC<ConfirmSimulationButtonProps> = (
return (
<div className={`${styles['footer-container']}`}>
<div className={styles['button-container']}>
<div className="row">
<div className="col-6" style={{ paddingRight: '7.5px' }}>
<SimulationActionButton
backgroundColor="#424242"
imgSrc="/images/popup/x.png"
imgWidth={13}
color="white"
buttonText="Reject"
onClick={() => {
posthog.capture('simulation rejected', {
storedSimulation: storedSimulation,
});
updateSimulationAction(id, StoredSimulationState.Rejected);
}}
/>
</div>
<div className="col-6" style={{ paddingLeft: '7.5px' }}>
{!storedSimulation || storedSimulation.state === StoredSimulationState.Simulating ? (
<SimulationActionButton
backgroundColor="white"
imgSrc="/images/popup/ArrowRight.png"
imgWidth={19}
buttonText="Skip"
onClick={() => {
posthog.capture('simulation skipped', {
storedSimulation: storedSimulation,
});
updateSimulationAction(id, StoredSimulationState.Confirmed);
}}
/>
) : !storedSimulation.simulation.error &&
storedSimulation.simulation.recommendedAction === RecommendedActionType.Block &&
needsConfirm ? (
<div
className="col-12 text-center"
style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center' }}
>
{storedSimulation.args.bypassType === BypassType.ChainId && (
<>
<p style={{ marginBottom: 0, fontSize: '14px' }}>Caution: Your wallet may be incompatible with Wallet Guard</p>
<a href="#" onClick={joinDiscord} style={{ marginBottom: '10px' }}>
Open Support Ticket
</a>
</>
)}

<div className="row">
<div className="col-6" style={{ paddingRight: '7.5px' }}>
<SimulationActionButton
backgroundColor="rgb(211 211 211 / 8%)"
backgroundColor="#424242"
imgSrc="/images/popup/x.png"
imgWidth={13}
color="white"
buttonText="Proceed anyway"
buttonText="Reject"
onClick={() => {
posthog.capture('simulation proceed anyway', {
posthog.capture('simulation rejected', {
storedSimulation: storedSimulation,
});
handleProceedAnyway();
updateSimulationAction(id, StoredSimulationState.Rejected);
}}
/>
) : storedSimulation.lockedAssetsState?.shouldBlockTx ?
(
</div>
<div className="col-6" style={{ paddingLeft: '7.5px' }}>
{!storedSimulation || storedSimulation.state === StoredSimulationState.Simulating ? (
<SimulationActionButton
backgroundColor={'white'}
buttonText="Visit Dashboard"
backgroundColor="white"
imgSrc="/images/popup/ArrowRight.png"
imgWidth={19}
buttonText="Skip"
onClick={() => {
posthog.capture('simulation rejected', {
posthog.capture('simulation skipped', {
storedSimulation: storedSimulation,
isSoftLockedTx: true
});
openDashboard('lockedAsset');
updateSimulationAction(id, StoredSimulationState.Rejected);
updateSimulationAction(id, StoredSimulationState.Confirmed);
}}
/>) :
(
/>
) : !storedSimulation.simulation.error &&
storedSimulation.simulation.recommendedAction === RecommendedActionType.Block &&
needsConfirm ? (
<SimulationActionButton
backgroundColor={'white'}
imgSrc="/images/popup/ArrowRight.png"
imgWidth={19}
buttonText="Continue"
backgroundColor="rgb(211 211 211 / 8%)"
color="white"
buttonText="Proceed anyway"
onClick={() => {
posthog.capture('simulation confirmed', {
posthog.capture('simulation proceed anyway', {
storedSimulation: storedSimulation,
});
updateSimulationAction(id, StoredSimulationState.Confirmed);
handleProceedAnyway();
}}
/>
)}
) : storedSimulation.lockedAssetsState?.shouldBlockTx ?
(
<SimulationActionButton
backgroundColor={'white'}
buttonText="Visit Dashboard"
onClick={() => {
posthog.capture('simulation rejected', {
storedSimulation: storedSimulation,
isSoftLockedTx: true
});
openDashboard('lockedAsset');
updateSimulationAction(id, StoredSimulationState.Rejected);
}}
/>) :
(
<SimulationActionButton
backgroundColor={'white'}
imgSrc="/images/popup/ArrowRight.png"
imgWidth={19}
buttonText="Continue"
onClick={() => {
posthog.capture('simulation confirmed', {
storedSimulation: storedSimulation,
});
updateSimulationAction(id, StoredSimulationState.Confirmed);
}}
/>
)}
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/content-scripts/contentScripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ listenToRequest(async (request: TransactionArgs) => {
}

// Set the bypassType, but do not set bypassed = true because otherwise the simulation buttons will be incorrect
request.bypassType = BypassType.ChainId
request.bypassType = BypassType.ChainId;
}

let currentTab = window.location.href;
Expand Down
81 changes: 80 additions & 1 deletion src/injected/injectWalletGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EthereumProviderError, ethErrors } from 'eth-rpc-errors';
import logger from '../lib/logger';
import { RequestManager, Response } from '../lib/simulation/requests';
import posthog from 'posthog-js';

declare global {
interface Window {
Expand Down Expand Up @@ -41,6 +42,14 @@ export function convertObjectValuesToString(inputObj: any): any {
return output;
}

posthog.init('phc_rb7Dd9nqkBMJYCCh7MQWpXtkNqIGUFdCZbUThgipNQD', {
api_host: 'https://app.posthog.com',
persistence: 'localStorage',
autocapture: false,
capture_pageleave: false,
disable_session_recording: true,
});

const log = logger.child({ component: 'Injected' });

// Handling all the request communication.
Expand Down Expand Up @@ -117,6 +126,13 @@ const addWalletGuardProxy = (provider: any) => {

// Override the result if it cannot be trusted
if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -160,6 +176,13 @@ const addWalletGuardProxy = (provider: any) => {
const requestAsString = provider?.request?.toString();

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -190,6 +213,13 @@ const addWalletGuardProxy = (provider: any) => {
const requestAsString = provider?.request?.toString();

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -221,6 +251,13 @@ const addWalletGuardProxy = (provider: any) => {
const requestAsString = provider?.request?.toString();

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -259,6 +296,13 @@ const addWalletGuardProxy = (provider: any) => {
const requestAsString = provider?.request?.toString();

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -317,6 +361,13 @@ const addWalletGuardProxy = (provider: any) => {
const requestAsString = provider?.request?.toString();

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -373,6 +424,13 @@ const addWalletGuardProxy = (provider: any) => {

// Override the result if it cannot be trusted
if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -410,6 +468,13 @@ const addWalletGuardProxy = (provider: any) => {
const requestAsString = provider?.request?.toString();

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -451,6 +516,13 @@ const addWalletGuardProxy = (provider: any) => {
const requestAsString = provider?.request?.toString();

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down Expand Up @@ -495,9 +567,16 @@ const addWalletGuardProxy = (provider: any) => {
}

let chainId = await provider.request({ method: 'eth_chainId' });
const requestAsString = provider?.request?.toString();
const requestAsString = provider?.request?.toString()

if (requestAsString !== 'function () { [native code] }') {
posthog.capture('window.ethereum.request override', {
requestAsString: requestAsString,
isMetaMask: window.ethereum.isMetaMask,
isPhantom: window?.phantom?.ethereum?.isPhantom,
isCoinbaseWallet: window?.ethereum?.isCoinbaseWallet,
isRabby: window.ethereum?.isRabby,
});
chainId = '';
}

Expand Down
Loading