-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathWalletConnectOfferPreview.tsx
45 lines (39 loc) · 1.4 KB
/
WalletConnectOfferPreview.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Button, Flex, useOpenDialog, chiaToMojo } from '@chia-network/core';
import { Trans } from '@lingui/macro';
import { Typography } from '@mui/material';
import React from 'react';
import parseFee from '../../util/parseFee';
import OfferBuilderViewerDialog from '../offers2/OfferBuilderViewerDialog';
export type WalletConnectOfferPreviewProps = {
value: string;
values: Record<string, any>;
onChange: (values: Record<string, any>) => void;
};
export default function WalletConnectOfferPreview(props: WalletConnectOfferPreviewProps) {
const { value: offer, values, onChange } = props;
const openDialog = useOpenDialog();
const fee = parseFee(values.fee);
async function handleShowPreview() {
const offerBuilderData = await openDialog(<OfferBuilderViewerDialog offer={offer} fee={fee} />);
if (offerBuilderData) {
// use new fee value
const feeChia = offerBuilderData.offered.fee?.[0]?.amount;
const feeMojos = feeChia ? chiaToMojo(feeChia).toFixed() : undefined;
onChange({
...values,
fee: feeMojos,
});
}
}
// show offer value and button with offer details modal
return (
<Flex direction="column" gap={2}>
<Typography noWrap>{offer}</Typography>
<Flex>
<Button variant="outlined" color="secondary" onClick={handleShowPreview}>
<Trans>Show Offer Details</Trans>
</Button>
</Flex>
</Flex>
);
}