Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit bce2869

Browse files
aorumbayevMillionAlgosFather
and
MillionAlgosFather
authored
chore: refining flow (#45)
Co-authored-by: MillionAlgosFather <info@algoworld.io>
1 parent 417e5d0 commit bce2869

File tree

5 files changed

+123
-75
lines changed

5 files changed

+123
-75
lines changed

src/components/Dialogs/ManageSwapDialog.tsx

+34-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import {
2020
ASA_TO_ASA_FUNDING_FEE,
21+
TXN_SIGNING_CANCELLED_MESSAGE,
2122
TXN_SUBMISSION_FAILED_MESSAGE,
2223
} from '@/common/constants';
2324
import { connector } from '@/redux/store/connector';
@@ -123,7 +124,17 @@ const ManageSwapDialog = ({ open, onClose, onShare }: Props) => {
123124
const signedSwapDepositTxns = await signTransactions(
124125
swapDepositTxns,
125126
connector,
126-
);
127+
).catch(() => {
128+
setDepositLoading(false);
129+
enqueueSnackbar(TXN_SIGNING_CANCELLED_MESSAGE, {
130+
variant: `error`,
131+
});
132+
return;
133+
});
134+
135+
if (!signedSwapDepositTxns) {
136+
return;
137+
}
127138

128139
const signedSwapDepositResponse = await submitTransactions(
129140
chain,
@@ -170,7 +181,17 @@ const ManageSwapDialog = ({ open, onClose, onShare }: Props) => {
170181
const signedSwapDeactivateTxns = await signTransactions(
171182
swapDeactivateTxns,
172183
connector,
173-
);
184+
).catch(() => {
185+
setDeleteLoading(false);
186+
enqueueSnackbar(TXN_SIGNING_CANCELLED_MESSAGE, {
187+
variant: `error`,
188+
});
189+
return;
190+
});
191+
192+
if (!signedSwapDeactivateTxns) {
193+
return;
194+
}
174195

175196
const signedSwapDeactivateResponse = await submitTransactions(
176197
chain,
@@ -202,7 +223,17 @@ const ManageSwapDialog = ({ open, onClose, onShare }: Props) => {
202223
const signedSaveSwapConfigTxns = await signTransactions(
203224
saveSwapConfigTxns,
204225
connector,
205-
);
226+
).catch(() => {
227+
setDeleteLoading(false);
228+
enqueueSnackbar(TXN_SIGNING_CANCELLED_MESSAGE, {
229+
variant: `error`,
230+
});
231+
return;
232+
});
233+
234+
if (!signedSaveSwapConfigTxns) {
235+
return;
236+
}
206237

207238
const saveSwapConfigResponse = await submitTransactions(
208239
chain,

src/components/Headers/NavBar.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ const NavBar = () => {
281281
>
282282
{pages.map((page) => (
283283
<Link key={page.title} href={page.url}>
284-
<MenuItem>
284+
<MenuItem
285+
onClick={() => {
286+
handleCloseNavMenu();
287+
}}
288+
>
285289
<Typography textAlign="center">{page.title}</Typography>
286290
</MenuItem>
287291
</Link>
@@ -290,6 +294,7 @@ const NavBar = () => {
290294
key={`about`}
291295
onClick={() => {
292296
setIsAboutPopupOpen(!isAboutPopupOpen);
297+
handleCloseNavMenu();
293298
}}
294299
>
295300
<Typography textAlign="center">{`About`}</Typography>

src/pages/swap/[proxy]/[escrow].tsx

+79-71
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import { SwapConfiguration } from '@/models/Swap';
2626
import { ellipseAddress } from '@/redux/helpers/utilities';
2727
import useLoadingIndicator from '@/redux/hooks/useLoadingIndicator';
2828
import { setIsWalletPopupOpen } from '@/redux/slices/applicationSlice';
29-
import { optInAssets } from '@/redux/slices/walletConnectSlice';
29+
import {
30+
getAccountAssets,
31+
optInAssets,
32+
} from '@/redux/slices/walletConnectSlice';
3033
import { connector } from '@/redux/store/connector';
3134
import { useAppDispatch, useAppSelector } from '@/redux/store/hooks';
3235
import accountExists from '@/utils/api/accounts/accountExists';
@@ -232,17 +235,42 @@ const PerformSwap = () => {
232235
later...
233236
</Typography>
234237
);
238+
} else if (!address) {
239+
return (
240+
<Button
241+
onClick={() => {
242+
dispatch(setIsWalletPopupOpen(true));
243+
}}
244+
fullWidth
245+
variant="contained"
246+
color="primary"
247+
>
248+
Connect Wallet
249+
</Button>
250+
);
251+
} else {
252+
return (
253+
<Button
254+
onClick={() => {
255+
swapConfigsState.retry();
256+
}}
257+
fullWidth
258+
variant="contained"
259+
color="primary"
260+
>
261+
Click to retry loading
262+
</Button>
263+
);
235264
}
236265
}, [
266+
swapConfiguration,
237267
address,
238-
assetsToOptIn,
239-
dispatch,
268+
swapConfigsState,
240269
hasZeroBalanceAssets,
241-
swapConfigsState.error,
242-
swapConfigsState.loading,
243-
swapConfiguration,
244270
swapIsActive,
271+
assetsToOptIn,
245272
hasNoBalanceForAssets,
273+
dispatch,
246274
]);
247275

248276
const signAndSendSwapPerformTxns = async (
@@ -328,73 +356,47 @@ const PerformSwap = () => {
328356
sx={{ textAlign: `center`, pb: 5 }}
329357
component="main"
330358
>
331-
{swapConfiguration ? (
332-
<>
333-
<Grid container spacing={2}>
334-
<Grid item xs={12}>
335-
<Card>
336-
<CardHeader
337-
title={`You provide`}
338-
titleTypographyProps={{ align: `center` }}
339-
sx={{}}
359+
<Grid container spacing={2}>
360+
<Grid item xs={12}>
361+
<Card>
362+
<CardHeader
363+
title={`You provide`}
364+
titleTypographyProps={{ align: `center` }}
365+
sx={{}}
366+
/>
367+
<CardContent>
368+
{swapConfiguration && (
369+
<AssetListView
370+
assets={swapConfiguration.requesting}
371+
isOffering={false}
340372
/>
341-
<CardContent>
342-
<AssetListView
343-
assets={swapConfiguration.requesting}
344-
isOffering={false}
345-
/>
346-
</CardContent>
347-
</Card>
348-
</Grid>
349-
<Grid item xs={12}>
350-
<Card>
351-
<CardHeader
352-
title={`You receive`}
353-
titleTypographyProps={{ align: `center` }}
354-
sx={{}}
373+
)}
374+
</CardContent>
375+
</Card>
376+
</Grid>
377+
<Grid item xs={12}>
378+
<Card>
379+
<CardHeader
380+
title={`You receive`}
381+
titleTypographyProps={{ align: `center` }}
382+
sx={{}}
383+
/>
384+
<CardContent>
385+
{swapConfiguration && (
386+
<AssetListView
387+
assets={swapConfiguration.offering}
388+
isOffering={true}
355389
/>
356-
<CardContent>
357-
<AssetListView
358-
assets={swapConfiguration.offering}
359-
isOffering={true}
360-
/>
361-
</CardContent>
362-
</Card>
363-
</Grid>
364-
<Grid item xs={12}>
365-
<Stack justifyContent={`center`} direction={`column`}>
366-
{address ? (
367-
<>{errorLabelsContent}</>
368-
) : (
369-
<Button
370-
onClick={() => {
371-
dispatch(setIsWalletPopupOpen(true));
372-
}}
373-
fullWidth
374-
variant="contained"
375-
color="primary"
376-
>
377-
Connect Wallet
378-
</Button>
379-
)}
380-
</Stack>
381-
</Grid>
382-
</Grid>
383-
</>
384-
) : (
385-
<>
386-
<Button
387-
onClick={() => {
388-
swapConfigsState.retry();
389-
}}
390-
fullWidth
391-
variant="contained"
392-
color="primary"
393-
>
394-
Click to retry loading
395-
</Button>
396-
</>
397-
)}
390+
)}
391+
</CardContent>
392+
</Card>
393+
</Grid>
394+
<Grid item xs={12}>
395+
<Stack justifyContent={`center`} direction={`column`}>
396+
<>{errorLabelsContent}</>
397+
</Stack>
398+
</Grid>
399+
</Grid>
398400
</Container>
399401

400402
<ConfirmDialog
@@ -415,6 +417,12 @@ const PerformSwap = () => {
415417
open={shareSwapDialogOpen}
416418
setOpen={setShareSwapDialogOpen}
417419
onClose={() => {
420+
dispatch(
421+
getAccountAssets({
422+
chain: selectedChain,
423+
address: address,
424+
}) as any,
425+
);
418426
router.replace(`/`);
419427
}}
420428
>

src/pages/swappers/asa-to-asa.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import saveSwapConfigurations from '@/utils/api/swaps/saveSwapConfigurations';
4949
import createSwapDepositTxns from '@/utils/api/swaps/createSwapDepositTxns';
5050
import { useSnackbar } from 'notistack';
5151
import {
52+
getAccountAssets,
5253
getAccountSwaps,
5354
optInAssets,
5455
setOfferingAssets,
@@ -362,6 +363,7 @@ export default function AsaToAsa() {
362363
};
363364

364365
const resetStates = () => {
366+
dispatch(getAccountAssets({ chain, address: address }) as any);
365367
dispatch(getAccountSwaps({ chain, address }));
366368
setConfirmSwapDialogOpen(false);
367369
setShareSwapDialogOpen(false);

src/pages/swappers/asas-to-algo.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import saveSwapConfigurations from '@/utils/api/swaps/saveSwapConfigurations';
5050
import createSwapDepositTxns from '@/utils/api/swaps/createSwapDepositTxns';
5151
import { useSnackbar } from 'notistack';
5252
import {
53+
getAccountAssets,
5354
getAccountSwaps,
5455
optInAssets,
5556
selectOfferingAssetAmounts,
@@ -362,6 +363,7 @@ export default function MultiAsaToAlgo() {
362363
};
363364

364365
const resetStates = () => {
366+
dispatch(getAccountAssets({ chain, address: address }) as any);
365367
dispatch(getAccountSwaps({ chain, address }));
366368
setConfirmSwapDialogOpen(false);
367369
setShareSwapDialogOpen(false);

0 commit comments

Comments
 (0)