Skip to content

Commit 1959ff6

Browse files
committed
Refactor
Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
1 parent b832022 commit 1959ff6

File tree

6 files changed

+111
-126
lines changed

6 files changed

+111
-126
lines changed

wormhole-connect/src/hooks/useSendTransaction.ts wormhole-connect/src/hooks/useConfirmTransaction.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ type Props = {
3636

3737
type ReturnProps = {
3838
error: string | undefined;
39-
errorInternal: unknown | undefined;
40-
send: () => void;
39+
// errorInternal can be a result of custom validation, hence of any type.
40+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
41+
errorInternal: any | undefined;
42+
onConfirm: () => void;
4143
};
4244

4345
const useSendTransaction = (props: Props): ReturnProps => {
4446
const dispatch = useDispatch();
4547

4648
const [error, setError] = useState<string | undefined>(undefined);
47-
const [errorInternal, setErrorInternal] = useState<unknown | undefined>(
49+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
50+
const [errorInternal, setErrorInternal] = useState<any | undefined>(
4851
undefined,
4952
);
5053

@@ -74,8 +77,11 @@ const useSendTransaction = (props: Props): ReturnProps => {
7477

7578
const getUSDAmount = useUSDamountGetter();
7679

77-
const send = async () => {
78-
setError(undefined);
80+
const onConfirm = async () => {
81+
// Clear previous errors
82+
if (error) {
83+
setError(undefined);
84+
}
7985

8086
if (config.ui.previewMode) {
8187
setError('Connect is in preview mode');
@@ -95,11 +101,11 @@ const useSendTransaction = (props: Props): ReturnProps => {
95101
return;
96102
}
97103

104+
// Validate all inputs
105+
// The results of this check will be written back to Redux store (see transferInput.validations).
98106
await validate({ transferInput, relay, wallet }, dispatch, () => false);
99107

100-
const valid = isTransferValid(validations);
101-
102-
if (!valid || !route) {
108+
if (!isTransferValid(validations)) {
103109
return;
104110
}
105111

@@ -279,7 +285,7 @@ const useSendTransaction = (props: Props): ReturnProps => {
279285
};
280286

281287
return {
282-
send,
288+
onConfirm,
283289
error,
284290
errorInternal,
285291
};

wormhole-connect/src/views/v2/Bridge/AssetPicker/ChainList.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ const ChainList = (props: Props) => {
115115
return (
116116
<List component={Stack} direction="row">
117117
{topChains.map((chain: ChainConfig) => (
118-
<Tooltip title={chain.displayName}>
118+
<Tooltip key={chain.key} title={chain.displayName}>
119119
<ListItemButton
120-
key={chain.key}
121120
selected={selectedChainConfig?.key === chain.key}
122121
className={classes.chainButton}
123122
onClick={() => onChainSelect(chain.key)}

wormhole-connect/src/views/v2/Bridge/ReviewTransaction/GasSlider.tsx wormhole-connect/src/views/v2/Bridge/GasSlider/index.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ const GasSlider = (props: {
100100
const destChainConfig = config.chains[destChain!];
101101
const nativeGasTokenConfig = config.tokens[destChainConfig!.gasToken];
102102

103-
const [isGasSliderOpen, setIsGasSliderOpen] = useState(!props.disabled);
103+
const [isGasSliderOpen, setIsGasSliderOpen] = useState(false);
104104
const [percentage, setPercentage] = useState(0);
105105

106106
const [debouncedPercentage] = useDebounce(percentage, 500);
107107

108108
useEffect(() => {
109109
dispatch(setToNativeToken(debouncedPercentage / 100));
110-
}, [debouncedPercentage]);
110+
}, [debouncedPercentage, dispatch]);
111111

112112
const nativeGasPrice = useMemo(() => {
113113
if (!destChain) {
@@ -151,6 +151,7 @@ const GasSlider = (props: {
151151
<Typography>{`Need more gas on ${destChain}?`}</Typography>
152152
<StyledSwitch
153153
checked={isGasSliderOpen}
154+
disabled={props.disabled}
154155
onClick={(e: any) => {
155156
const { checked } = e.target;
156157

@@ -172,6 +173,7 @@ const GasSlider = (props: {
172173
<StyledSlider
173174
aria-label="Native gas conversion amount"
174175
defaultValue={0}
176+
disabled={props.disabled}
175177
value={percentage}
176178
baseColor={theme.palette.primary.main}
177179
railColor={theme.palette.background.default}

wormhole-connect/src/views/v2/Bridge/ReviewTransaction/SendError.tsx

-72
This file was deleted.

wormhole-connect/src/views/v2/Bridge/Routes/SingleRoute.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import type { RootState } from 'store';
3131
import { TokenConfig } from 'config/types';
3232
import FastestRoute from 'icons/FastestRoute';
3333
import CheapestRoute from 'icons/CheapestRoute';
34-
import GasSlider from 'views/v2/Bridge/ReviewTransaction/GasSlider';
34+
import GasSlider from 'views/v2/Bridge/GasSlider';
3535

3636
const HIGH_FEE_THRESHOLD = 20; // dollhairs
3737

0 commit comments

Comments
 (0)