Skip to content

Commit eea0a49

Browse files
Fix popup UI bugs (#13)
* fix: clicking x on window now rejects transaction * fix: handle simulation errors from TAS * wip * add types to error response * new server response handling with errors * componentize for error handling * fix: storage error handling * add generalized error components * add component for reverts * update signature request * add todo * fix alt texts --------- Co-authored-by: Jacob Lebowitz <[email protected]>
1 parent 18d51fc commit eea0a49

File tree

14 files changed

+286
-76
lines changed

14 files changed

+286
-76
lines changed
16.3 KB
Loading

src/background.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logger from './lib/logger';
22
import { REQUEST_COMMAND } from './lib/simulation/requests';
3-
import type { StoredSimulation } from './lib/simulation/storage';
3+
import { StoredSimulation, StoredSimulationState, updateSimulationState } from './lib/simulation/storage';
44
import { clearOldSimulations, fetchSimulationAndUpdate, simulationNeedsAction } from './lib/simulation/storage';
55
import { RequestArgs } from './models/simulation/Transaction';
66
import { AlertHandler } from './lib/helpers/chrome/alertHandler';
@@ -26,6 +26,7 @@ Sentry.init({
2626

2727
// Open Dashboard on Extension click
2828
chrome.action.onClicked.addListener(function (tab) {
29+
// TODO: Make this open the current popup if one exists
2930
openDashboard();
3031
});
3132

@@ -138,6 +139,13 @@ chrome.runtime.onStartup.addListener(() => {
138139
chrome.windows.onRemoved.addListener((windowId: number) => {
139140
if (currentPopup && currentPopup === windowId) {
140141
currentPopup = undefined;
142+
localStorageHelpers.get<StoredSimulation[]>(WgKeys.Simulations).then((res) => {
143+
// Reject the simulation
144+
if (res && res.length > 0) {
145+
const id = res[0].id;
146+
updateSimulationState(id, StoredSimulationState.Rejected);
147+
}
148+
});
141149
}
142150
});
143151

src/components/simulation/ConfirmSimulationButton.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import posthog from 'posthog-js';
2-
import React, { useEffect, useState } from 'react';
2+
import React from 'react';
33
import type { StoredSimulation } from '../../lib/simulation/storage';
44
import { simulationNeedsAction, StoredSimulationState, updateSimulationState } from '../../lib/simulation/storage';
55
import { SimulationMethodType, SimulationWarningType } from '../../models/simulation/Transaction';
@@ -10,8 +10,8 @@ export const ConfirmSimulationButton = ({ storedSimulation }: { storedSimulation
1010

1111
if (simulationNeedsAction(state)) {
1212
return (
13-
<div className="container">
14-
<div className="row text-center pl-3 pr-3 pt-4">
13+
<div className={`${styles['footer-container']}`}>
14+
<div className="row px-3 pt-4">
1515
<div className="col-6 text-center">
1616
<button
1717
className={`${styles['reject-button']} btn`}
@@ -25,16 +25,18 @@ export const ConfirmSimulationButton = ({ storedSimulation }: { storedSimulation
2525
>
2626
<img
2727
src="/images/popup/x.png"
28-
alt=""
28+
alt="An X icon in a circle, indicating cancel or close."
2929
width={19}
30-
className={`${styles['font-archivo-bold']} pr-2`}
30+
className={`${styles['font-archivo-medium']} pr-2`}
3131
style={{ marginTop: '-3px' }}
3232
/>
3333
Reject
3434
</button>
3535
</div>
3636
<div className="col-6 text-center">
37-
{state === StoredSimulationState.Success || state === StoredSimulationState.Revert ? (
37+
{state === StoredSimulationState.Success ||
38+
state === StoredSimulationState.Revert ||
39+
state === StoredSimulationState.Error ? (
3840
<button
3941
className={`${styles['confirm-button']} btn`}
4042
onClick={() => {
@@ -48,9 +50,9 @@ export const ConfirmSimulationButton = ({ storedSimulation }: { storedSimulation
4850
<div>
4951
<img
5052
src="/images/popup/circleCheck.png"
51-
alt=""
53+
alt="Circle with a checkmark in the center, indicating approval or continuation of the transaction."
5254
width={23}
53-
className={`${styles['font-archivo-bold']} pr-2`}
55+
className={`${styles['font-archivo-medium']} pr-2`}
5456
style={{ marginTop: '-2px' }}
5557
/>
5658
Continue
@@ -75,9 +77,9 @@ export const ConfirmSimulationButton = ({ storedSimulation }: { storedSimulation
7577
<div>
7678
<img
7779
src="/images/popup/circleCheck.png"
78-
alt=""
80+
alt="Circle with a checkmark in the center, indicating approval or continuation of the transaction."
7981
width={23}
80-
className={`${styles['font-archivo-bold']} pr-2`}
82+
className={`${styles['font-archivo-medium']} pr-2`}
8183
style={{ marginTop: '-2px' }}
8284
/>
8385
Skip
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { posthog } from 'posthog-js';
2+
import React from 'react';
3+
import { StoredSimulation, StoredSimulationState } from '../../lib/simulation/storage';
4+
import { ErrorType, SimulationWarningType } from '../../models/simulation/Transaction';
5+
import { ConfirmSimulationButton } from './ConfirmSimulationButton';
6+
import { SimulationHeader } from './SimulationHeader';
7+
import { SimulationOverview } from './SimulationOverview';
8+
import GeneralErrorComponent from './SimulationSubComponents/errors/GeneralError';
9+
import InsufficientFundsComponent from './SimulationSubComponents/errors/InsufficientFundsError';
10+
import RevertComponent from './SimulationSubComponents/errors/RevertError';
11+
12+
interface ErrorComponentProps {
13+
filteredSimulations: StoredSimulation[];
14+
type: ErrorType;
15+
}
16+
17+
export const ErrorComponent = (props: ErrorComponentProps) => {
18+
const { filteredSimulations, type } = props;
19+
20+
posthog.capture('show simulation error', {
21+
filteredSimulations: filteredSimulations,
22+
});
23+
24+
function getErrorComponent() {
25+
switch (type) {
26+
case ErrorType.InsufficientFunds:
27+
return <InsufficientFundsComponent filteredSimulations={filteredSimulations} />;
28+
case ErrorType.Revert:
29+
return <RevertComponent filteredSimulations={filteredSimulations} />;
30+
default:
31+
return <GeneralErrorComponent filteredSimulations={filteredSimulations} />;
32+
}
33+
}
34+
35+
return (
36+
<div>
37+
<SimulationHeader />
38+
39+
<div>
40+
{((filteredSimulations[0].state === StoredSimulationState.Success &&
41+
filteredSimulations[0].simulation?.warningType === SimulationWarningType.Warn) ||
42+
filteredSimulations[0].simulation?.warningType === SimulationWarningType.Info ||
43+
filteredSimulations[0].simulation?.error) && (
44+
<div>
45+
<SimulationOverview
46+
warningType={filteredSimulations[0].simulation?.warningType}
47+
message={filteredSimulations[0].simulation?.message}
48+
method={filteredSimulations[0].simulation.method}
49+
/>
50+
</div>
51+
)}
52+
</div>
53+
54+
<div className="row text-center" style={{ marginTop: '65px' }}>
55+
<div className="col-12">
56+
<img
57+
src="/images/popup/simulation_error.png"
58+
alt="A picture of a wallet UI with a red exclamation mark displayed in the center of the screen over an empty transaction screen representing an error"
59+
width={150}
60+
/>
61+
</div>
62+
</div>
63+
64+
{getErrorComponent()}
65+
66+
<ConfirmSimulationButton storedSimulation={filteredSimulations && filteredSimulations[0]} />
67+
</div>
68+
);
69+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import styles from '../../simulation.module.css';
3+
import { ErrorComponentProps } from './GeneralError';
4+
5+
export default function ErrorTextComponent(props: ErrorComponentProps) {
6+
return (
7+
<div className="col-12 text-center">
8+
<p
9+
className={`${styles['font-archivo-medium']}`}
10+
style={{
11+
color: 'white',
12+
fontSize: '16px',
13+
marginBottom: 0,
14+
}}
15+
>
16+
Reach out to our <a href="https://discord.com/invite/cM8USCesnd">Discord</a> if you have any questions
17+
</p>
18+
<p
19+
className={`${styles['font-archivo-medium']} text-muted`}
20+
style={{
21+
fontSize: '16px',
22+
}}
23+
>
24+
ID: {props.filteredSimulations[0].id}
25+
</p>
26+
</div>
27+
);
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import { StoredSimulation } from '../../../../lib/simulation/storage';
3+
import styles from '../../simulation.module.css';
4+
import ErrorTextComponent from './ErrorText';
5+
6+
export interface ErrorComponentProps {
7+
filteredSimulations: StoredSimulation[];
8+
}
9+
10+
export default function GeneralErrorComponent(props: ErrorComponentProps) {
11+
return (
12+
<div className="row pt-5 text-center pl-4 pr-4">
13+
<div className="col-12 text-center">
14+
<h4 className={`${styles['font-archivo-medium']} pb-3`} style={{ color: 'white', marginBottom: '20px' }}>
15+
Oops... Something went wrong
16+
</h4>
17+
</div>
18+
<ErrorTextComponent filteredSimulations={props.filteredSimulations} />
19+
</div>
20+
);
21+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import styles from '../../simulation.module.css';
3+
import ErrorTextComponent from './ErrorText';
4+
import { ErrorComponentProps } from './GeneralError';
5+
6+
export default function InsufficientFundsComponent(props: ErrorComponentProps) {
7+
return (
8+
<div className="row pt-5 text-center pl-4 pr-4">
9+
<div className="col-12">
10+
<h4 className={`${styles['font-archivo-medium']} pb-3`} style={{ color: 'white', marginBottom: '20px' }}>
11+
Insufficient funds
12+
</h4>
13+
14+
{/* TODO: Circle back to this */}
15+
{/* <div className="text-center">
16+
<p className={`${styles['font-archivo-medium']} text-muted`} style={{ marginBottom: 0 }}>
17+
Balance:
18+
</p>
19+
<p className={`${styles['font-archivo-medium']}`} style={{ color: 'white' }}>
20+
0.005 ETH
21+
</p>
22+
23+
<p className={`${styles['font-archivo-medium']} text-muted`} style={{ marginBottom: 0 }}>
24+
Transaction:
25+
</p>
26+
<p className={`${styles['font-archivo-medium']}`} style={{ color: 'white' }}>
27+
0.14 ETH + gas
28+
</p>
29+
</div> */}
30+
</div>
31+
<ErrorTextComponent filteredSimulations={props.filteredSimulations} />
32+
</div>
33+
);
34+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import styles from '../../simulation.module.css';
3+
import ErrorTextComponent from './ErrorText';
4+
import { ErrorComponentProps } from './GeneralError';
5+
6+
export default function RevertComponent(props: ErrorComponentProps) {
7+
return (
8+
<div className="row pt-5 text-center pl-4 pr-4">
9+
<div className="col-12">
10+
<h4 className={`${styles['font-archivo-medium']} pb-3`} style={{ color: 'white', marginBottom: '20px' }}>
11+
The transaction will be reverted
12+
</h4>
13+
</div>
14+
<ErrorTextComponent filteredSimulations={props.filteredSimulations} />
15+
</div>
16+
);
17+
}

src/components/simulation/simulation.module.css

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@
3636
animation-delay: 0.4s;
3737
}
3838

39+
.footer-container {
40+
position: fixed;
41+
bottom: 0;
42+
background-color: #232323;
43+
width: 100%;
44+
padding-bottom: 1.5rem !important;
45+
}
46+
3947
.confirm-button {
4048
min-width: 100px;
4149
border-radius: .5em;
4250
background-color: #ffffff;
4351
border-color: #7e7e7e;
4452
color: black;
45-
font-weight: bold;
53+
font-weight: 500;
4654
width: 90%;
4755
padding-bottom: 12px;
4856
padding-top: 12px;
@@ -53,7 +61,7 @@
5361
border-radius: .5em;
5462
background-color: #0e0e0e;
5563
border-color: white;
56-
font-weight: bold;
64+
font-weight: 500;
5765
color: white;
5866
width: 90%;
5967
padding-bottom: 12px;
@@ -82,15 +90,15 @@
8290
url("../../fonts/Archivo-Medium.ttf") format("truetype");
8391
}
8492

85-
.font-archivo-medium {
86-
font-family: "ArchivoMedium";
87-
}
93+
.font-archivo-medium {
94+
font-family: "ArchivoMedium";
95+
}
8896

8997
.font-archivo-bold {
9098
font-family: "ArchivoBold";
91-
}
99+
}
92100

93-
.links:hover {
101+
.links:hover {
94102
text-decoration: underline solid #ffffff;
95103
}
96104

src/lib/helpers/chrome/localStorageKeys.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export enum WgKeys {
66
CurrentSite = 'currentSite',
77
Metamask = 'metamask', // Current version of metamask and wallets.. yes this was poorly named
88
Phantom = 'phantom',
9-
TutorialComplete = 'tutorialComplete'
9+
TutorialComplete = 'tutorialComplete',
10+
Simulations = 'simulations',
1011
}

0 commit comments

Comments
 (0)