Skip to content

Commit d234d86

Browse files
authored
Merge pull request #214 from xch-dev/misc-fixes-typing
Tweaks
2 parents ce334a2 + bf1f63e commit d234d86

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

src/pages/ViewOffer.tsx

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import { commands, OfferSummary, TakeOfferResponse } from '@/bindings';
22
import ConfirmationDialog from '@/components/ConfirmationDialog';
33
import Container from '@/components/Container';
44
import Header from '@/components/Header';
5+
import { Loading } from '@/components/Loading';
56
import { OfferCard } from '@/components/OfferCard';
67
import { Button } from '@/components/ui/button';
78
import { Input } from '@/components/ui/input';
89
import { Label } from '@/components/ui/label';
910
import { useErrors } from '@/hooks/useErrors';
10-
import { toDecimal, toMojos } from '@/lib/utils';
11+
import { toMojos } from '@/lib/utils';
1112
import { useWalletState } from '@/state';
12-
import BigNumber from 'bignumber.js';
1313
import { useEffect, useState } from 'react';
1414
import { useNavigate, useParams } from 'react-router-dom';
15-
import { Loading } from '@/components/Loading';
1615

1716
export function ViewOffer() {
1817
const { offer } = useParams();
@@ -30,21 +29,17 @@ export function ViewOffer() {
3029
if (!offer) return;
3130

3231
const loadOffer = async () => {
33-
try {
34-
setIsLoading(true);
35-
setLoadingStatus('Decoding offer...');
32+
setIsLoading(true);
33+
setLoadingStatus('Fetching offer details...');
3634

37-
setLoadingStatus('Fetching offer details...');
38-
const data = await commands.viewOffer({ offer });
39-
40-
setLoadingStatus('Processing offer data...');
41-
setSummary(data.offer);
42-
} catch (error: any) {
43-
setLoadingStatus('Error loading offer');
44-
addError(error);
45-
} finally {
46-
setIsLoading(false);
47-
}
35+
commands
36+
.viewOffer({ offer })
37+
.then((data) => {
38+
setSummary(data.offer);
39+
setLoadingStatus('Processing offer data...');
40+
})
41+
.catch(addError)
42+
.finally(() => setIsLoading(false));
4843
};
4944

5045
loadOffer();
@@ -58,15 +53,13 @@ export function ViewOffer() {
5853
};
5954

6055
const take = async () => {
61-
try {
62-
const result = await commands.takeOffer({
56+
await commands
57+
.takeOffer({
6358
offer: offer!,
6459
fee: toMojos(fee || '0', walletState.sync.unit.decimals),
65-
});
66-
setResponse(result);
67-
} catch (error: any) {
68-
addError(error);
69-
}
60+
})
61+
.then((result) => setResponse(result))
62+
.catch(addError);
7063
};
7164

7265
return (

0 commit comments

Comments
 (0)