Skip to content

Commit 525af70

Browse files
committed
Refactor
Signed-off-by: Emre Bogazliyanlioglu <emre@wormholelabs.xyz>
1 parent 5249e20 commit 525af70

File tree

6 files changed

+108
-128
lines changed

6 files changed

+108
-128
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const GasSlider = (props: {
107107

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

112112
const nativeGasPrice = useMemo(() => {
113113
if (!destChain) {

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)