From eccbe6ac579d8ede1cd979cfe7aa6e86a98a921d Mon Sep 17 00:00:00 2001
From: Catherine Jonathan <35270183+kateberryd@users.noreply.github.com>
Date: Thu, 9 May 2024 13:48:07 +0100
Subject: [PATCH 1/9] feat: add estimateInvokeFee function to transfer function
---
.../src/app/components/AssetTransferModal.tsx | 24 +++++++++++++------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/frontend/src/app/components/AssetTransferModal.tsx b/frontend/src/app/components/AssetTransferModal.tsx
index 745762f..4702946 100644
--- a/frontend/src/app/components/AssetTransferModal.tsx
+++ b/frontend/src/app/components/AssetTransferModal.tsx
@@ -6,7 +6,14 @@ import rightArr from "../../../public/assets/right-arr.svg";
import { useEffect, useState } from "react";
import downChevron from "../../../public/assets/down-chevron.svg";
import ethLogo from "../../../public/assets/ethereumLogo2.svg";
-import { Call, Contract, RpcProvider, Uint256, cairo } from "starknet";
+import {
+ Call,
+ CallData,
+ Contract,
+ RpcProvider,
+ Uint256,
+ cairo,
+} from "starknet";
import abi from "./../../../public/abi/strk_abi.json";
import spinner from "../../../public/assets/spinner.svg";
@@ -83,14 +90,17 @@ function AssetTransferModal({
setLoading(true);
starknet_contract.connect(account);
const toTransferTk: Uint256 = cairo.uint256(Number(amount) * 1e18);
- const transferCall: Call = starknet_contract.populate("transfer", {
- recipient: walletAddress,
- amount: toTransferTk,
+ const { suggestedMaxFee: maxFee } = await account.estimateInvokeFee({
+ contractAddress:
+ "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
+ entrypoint: "transfer",
+ calldata: [walletAddress, toTransferTk],
});
- const { transaction_hash: transferTxHash, } =
- await starknet_contract.transfer(transferCall.calldata);
+ const { transaction_hash: transferTxHash } =
+ await starknet_contract.invoke("transfer", [walletAddress, toTransferTk], {
+ maxFee: maxFee,
+ });
await provider.waitForTransaction(transferTxHash);
- window.alert("Your transfer was successful!");
} catch (err: any) {
console.log(err.message);
} finally {
From 334fbd34f46a988a61b6d39ee3225851084a6011 Mon Sep 17 00:00:00 2001
From: Catherine Jonathan <35270183+kateberryd@users.noreply.github.com>
Date: Thu, 9 May 2024 13:50:57 +0100
Subject: [PATCH 2/9] feat: add toast instead of window.alert
---
frontend/src/app/components/AssetTransferModal.tsx | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/frontend/src/app/components/AssetTransferModal.tsx b/frontend/src/app/components/AssetTransferModal.tsx
index 4702946..fd90901 100644
--- a/frontend/src/app/components/AssetTransferModal.tsx
+++ b/frontend/src/app/components/AssetTransferModal.tsx
@@ -16,6 +16,7 @@ import {
} from "starknet";
import abi from "./../../../public/abi/strk_abi.json";
import spinner from "../../../public/assets/spinner.svg";
+import toast from "react-hot-toast";
type Props = {
isOpen: boolean;
@@ -97,11 +98,17 @@ function AssetTransferModal({
calldata: [walletAddress, toTransferTk],
});
const { transaction_hash: transferTxHash } =
- await starknet_contract.invoke("transfer", [walletAddress, toTransferTk], {
- maxFee: maxFee,
- });
+ await starknet_contract.invoke(
+ "transfer",
+ [walletAddress, toTransferTk],
+ {
+ maxFee: maxFee,
+ }
+ );
await provider.waitForTransaction(transferTxHash);
+ toast.success("Your transfer was successful!", { duration: 2000 });
} catch (err: any) {
+ toast.error("Your transfer was unsuccessfully", { duration: 2000 });
console.log(err.message);
} finally {
setLoading(false);
From 4bab526f6b487f0552691e9b0dbc9bc696ae5f52 Mon Sep 17 00:00:00 2001
From: Catherine Jonathan <35270183+kateberryd@users.noreply.github.com>
Date: Thu, 9 May 2024 13:51:37 +0100
Subject: [PATCH 3/9] feat: add react-hot-toast
---
frontend/package.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/frontend/package.json b/frontend/package.json
index f802e13..c8b47e8 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -25,6 +25,7 @@
"react": "^18",
"react-blockies": "^1.4.1",
"react-dom": "^18",
+ "react-hot-toast": "^2.4.1",
"react-icons": "^5.0.1",
"starknet": "^6.0.0",
"starknetkit": "^1.1.4",
From 1f7103102402ce26863eab802453d768b100cc3a Mon Sep 17 00:00:00 2001
From: Catherine Jonathan <35270183+kateberryd@users.noreply.github.com>
Date: Thu, 9 May 2024 13:52:08 +0100
Subject: [PATCH 4/9] feat: add Toaster provider
---
frontend/src/app/layout.tsx | 2 ++
1 file changed, 2 insertions(+)
diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx
index f36bc87..2121c11 100644
--- a/frontend/src/app/layout.tsx
+++ b/frontend/src/app/layout.tsx
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { StarknetProvider } from "./components/StarknetProvider";
+import {Toaster} from "react-hot-toast"
const inter = Inter({ subsets: ["latin"] });
@@ -21,6 +22,7 @@ export default function RootLayout({
className={`${inter.className} dark:bg-black bg-gray-300 dark:text-white transition-all duration-500 ease-in-out`}
>
{children}
+