From 8184c7672ebf239864ea46e92b1f11c8b82f1bdb Mon Sep 17 00:00:00 2001 From: gconnect Date: Sat, 8 Jun 2024 18:59:01 +0100 Subject: [PATCH] modified the rest api call code --- .../next-app/app/cartesi/RestExample.tsx | 16 +++++++++++++++- .../next-app/app/cartesi/services/Portal.ts | 12 ++++++------ .../app/cartesi/services/RestApiCalls.ts | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/apps/cartesify/frontend/next-app/app/cartesi/RestExample.tsx b/apps/cartesify/frontend/next-app/app/cartesi/RestExample.tsx index 792355f..aeb1e75 100644 --- a/apps/cartesify/frontend/next-app/app/cartesi/RestExample.tsx +++ b/apps/cartesify/frontend/next-app/app/cartesi/RestExample.tsx @@ -2,11 +2,14 @@ import { useEffect, useState } from "react" import { Button } from "@chakra-ui/react" import { useEthersSigner } from "../utils/useEtherSigner" -import { createOrUpdateRequest, getRequest } from "./services/RestApiCalls" +import { createOrUpdateRequest, fetchWallet, getRequest } from "./services/RestApiCalls" +import { callDAppAddressRelay } from "./services/Portal" +import { useAccount } from "wagmi" export function RestExample() { const [backendResponse, setResponse] = useState('') const signer = useEthersSigner() + const { chain } = useAccount() return (
@@ -23,6 +26,17 @@ export function RestExample() { + +
+ + + +
+
Backend response:
{backendResponse}
diff --git a/apps/cartesify/frontend/next-app/app/cartesi/services/Portal.ts b/apps/cartesify/frontend/next-app/app/cartesi/services/Portal.ts index 1503907..3f15953 100644 --- a/apps/cartesify/frontend/next-app/app/cartesi/services/Portal.ts +++ b/apps/cartesify/frontend/next-app/app/cartesi/services/Portal.ts @@ -102,7 +102,7 @@ export const depositERC20 = async (dappAddress: string, erc20address: string, const portal = ERC20Portal__factory.connect(portalAddress, signer) const tx = await portal.depositERC20Tokens(erc20address, dappAddress, parseUnits(erc20value, 6), '0x') const receipt = await (tx as any).wait() - successAlert(`Transaction Hash: `) + successAlert(`${explorer/+"tx"/receipt.hash}`) } catch (error) { console.log(error) errorAlert(error) @@ -119,7 +119,7 @@ export const depositERC721 = async (dappAddress: string, erc721address: string, const portal = ERC721Portal__factory.connect(portalAddress, signer) const tx = await portal.depositERC721Token(erc721address, dappAddress, erc721id, '0x', '0x') const receipt = await (tx as any).wait() - successAlert(`Transaction Hash: `) + successAlert(`${explorer/+"tx"/receipt.hash}`) } catch (error) { errorAlert(error) } @@ -138,7 +138,7 @@ export const depositSingleERC1155 = async (dappAddress: string, erc1155address: const portal = ERC1155SinglePortal__factory.connect(portalAddress, signer) const tx = await portal.depositSingleERC1155Token(erc1155address, dappAddress, erc1155id, amount, '0x', data) const receipt = await (tx as any).wait() - successAlert(`Transaction Hash: `) + successAlert(`${explorer/+"tx"/receipt.hash}`) } catch (error) { errorAlert(error) } @@ -156,7 +156,7 @@ export const depositBatchERC1155 = async (dappAddress: string, erc1155address: s const portal = ERC1155BatchPortal__factory.connect(portalAddress, signer) const tx = await portal.depositBatchERC1155Token(erc1155address, dappAddress, erc1155ids, amounts, '0x', data) const receipt = await (tx as any).wait() - successAlert(`Transaction Hash: `) + successAlert(`${explorer/+"tx"/receipt.hash}`) } catch (error) { errorAlert(error) } @@ -176,7 +176,7 @@ try { console.log(tx) const receipt = await (tx as any).wait() console.log('Executed!', receipt) - successAlert(`Transaction Hash: `) + successAlert(`${explorer/+"tx"/receipt.hash}`) } } catch (error) { @@ -192,7 +192,7 @@ export const callDAppAddressRelay = async (signer: JsonRpcSigner | undefined, ch const tx = await relay.relayDAppAddress(DAPP_ADDRESS) const receipt = await (tx as any).wait() console.log('Executed!', receipt) - successAlert(`Transaction Hash: `) + successAlert(`${explorer/+"tx"/receipt.hash}`) } catch (error) { errorAlert(error) } diff --git a/apps/cartesify/frontend/next-app/app/cartesi/services/RestApiCalls.ts b/apps/cartesify/frontend/next-app/app/cartesi/services/RestApiCalls.ts index cc315cf..8154362 100644 --- a/apps/cartesify/frontend/next-app/app/cartesi/services/RestApiCalls.ts +++ b/apps/cartesify/frontend/next-app/app/cartesi/services/RestApiCalls.ts @@ -330,8 +330,9 @@ export const fetchWallet = async (signer: JsonRpcSigner | undefined, const res = await fetch(`${BASE_URL}/${signer?.address}`) const json = await res.json() setResponse(JSON.stringify(json, null, 4)) + successAlert("Successful!") } catch (error) { - console.log(error) + errorAlert(error) } }