From dc697028d0462e175d039e090067f8d47497b9fa Mon Sep 17 00:00:00 2001 From: yhtiyar Date: Mon, 2 Aug 2021 15:10:41 +0300 Subject: [PATCH] Added txinfo service --- frontend/src/core/hooks/useTxInfo.js | 21 ++++++++++++++++++++ frontend/src/core/services/txinfo.service.js | 11 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 frontend/src/core/hooks/useTxInfo.js create mode 100644 frontend/src/core/services/txinfo.service.js diff --git a/frontend/src/core/hooks/useTxInfo.js b/frontend/src/core/hooks/useTxInfo.js new file mode 100644 index 00000000..77a9bef4 --- /dev/null +++ b/frontend/src/core/hooks/useTxInfo.js @@ -0,0 +1,21 @@ +import { useQuery } from "react-query"; +import { TxInfoService } from "../services"; +import { queryCacheProps } from "./hookCommon"; +import { useToast } from "."; + +const useTxInfo = (transaction) => { + const toast = useToast(); + const getTxInfo = async () => { + const data = await TxInfoService.getTxInfo(transaction); + return data; + } + const { data, isLoading, isFetchedAfterMount, refetch, isError, error } = + useQuery(["txinfo", {transaction}], getTxInfo, { + ...queryCacheProps, + onError: (error) => toast(error, "error"), + }); + + return { data, isFetchedAfterMount, isLoading, refetch, isError, error }; +} + +export default useTxInfo; \ No newline at end of file diff --git a/frontend/src/core/services/txinfo.service.js b/frontend/src/core/services/txinfo.service.js new file mode 100644 index 00000000..f4825b96 --- /dev/null +++ b/frontend/src/core/services/txinfo.service.js @@ -0,0 +1,11 @@ +import { http } from "../utils"; + +const API = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL; + +export const getTxInfo = (tx) => { + http({ + method: "POST", + url: `${API}/txinfo/ethereum_blockchain`, + tx + }) +} \ No newline at end of file