forked from astroport-fi/astroport-classic-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwapNotification.tsx
53 lines (48 loc) · 1.37 KB
/
SwapNotification.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
46
47
48
49
50
51
52
53
import React, { FC, useEffect } from "react";
import { TxInfo } from "@terra-money/terra.js";
import { Text } from "@chakra-ui/react";
import num from "libs/num";
import { useQueryClient } from "react-query";
import {
useTokenInfo,
handleTinyAmount,
getEventsByType,
} from "modules/common";
type Props = {
txInfo: TxInfo;
data: any;
};
const SwapNotification: FC<Props> = ({ txInfo, data }) => {
const queryClient = useQueryClient();
const { getSymbol, getDecimals } = useTokenInfo();
const eventsByType = getEventsByType(txInfo);
const { token1, token2 } = data;
const amount1 = eventsByType?.wasm.offer_amount[0];
const amount2 =
eventsByType?.wasm.return_amount[
eventsByType?.wasm.return_amount.length - 1
];
const token1Decimals = getDecimals(token1);
const token2Decimals = getDecimals(token2);
const displayAmount1 = handleTinyAmount(
num(amount1)
.div(10 ** token1Decimals)
.toNumber()
);
const displayAmount2 = handleTinyAmount(
num(amount2)
.div(10 ** token2Decimals)
.toNumber()
);
useEffect(() => {
queryClient.invalidateQueries("pool");
queryClient.invalidateQueries("balance");
}, []);
return (
<Text textStyle={["small", "medium"]}>
Swap {displayAmount1} {getSymbol(token1)} for {displayAmount2}{" "}
{getSymbol(token2)}
</Text>
);
};
export default SwapNotification;