Skip to content

Commit

Permalink
chore: fix BurnerWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Apr 28, 2024
1 parent c634a11 commit 5bc5679
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_API_KEY = <API_KEY>
NEXT_PROVIDER = <PROVIDER_NAME_EG_INFURA>
NEXT_PUBLIC_API_KEY = <API_KEY>
NEXT_PUBLIC_PROVIDER = <PROVIDER_NAME_EG_INFURA>
48 changes: 27 additions & 21 deletions frontend/src/app/components/AssetTransferModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ 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 strk_abi from "./../../../public/abi/strk_abi.json";
import abi from "./../../../public/abi/strk_abi.json";

type Props = {
isOpen: boolean;
onClose: () => void;
strkBalance: number | undefined;
ethBalance: number | undefined;
wallet: {
address: string;
privateKey: string;
publicKey: string;
};
account: any;
};

Expand All @@ -27,19 +22,8 @@ function AssetTransferModal({
onClose,
strkBalance,
ethBalance,
wallet,
account,
}: Props) {
const provider = new RpcProvider({
nodeUrl:
"https://starknet-sepolia.infura.io/v3/b935e660d34f48469cb740bfa2cfb1c0",
});
const starknet_contract = new Contract(
strk_abi,
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
provider
);

// Form Data
const [walletAddress, setWalletAddress] = useState("");
const [amount, setAmount] = useState("");
Expand Down Expand Up @@ -70,18 +54,40 @@ function AssetTransferModal({
setAssetDropDownIsOpen(false);
}

const provider = new RpcProvider({
nodeUrl:
"https://starknet-sepolia.public.blastapi.io",
});

let starknet_contract: any;
if(activeToken == "strk") {
starknet_contract = new Contract(
abi,
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
provider
);
}
else{
starknet_contract = new Contract(
abi,
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
provider
);
}

async function handleTransfer() {
try {
if (!walletAddress.length && !amount) {
return;
}
const toTransferTk: Uint256 = cairo.uint256(amount);
const transferCallData: Call = starknet_contract.populate("transfer", {
const toTransferTk: Uint256 = cairo.uint256(Number(amount) * 1e18);
const transferCall: Call = starknet_contract.populate("transfer", {
recipient: walletAddress,
amount: toTransferTk,
});
starknet_contract.connect(account);
await starknet_contract.transfer(transferCallData.calldata);
const { transaction_hash: transferTxHash } = await account.execute(transferCall);
await provider.waitForTransaction(transferTxHash);
window.alert("Your transfer was successful!");
} catch (err: any) {
console.log(err.message);
} finally {
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/app/components/BurnerWallet/BurnerWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { useEffect, useState } from "react";
import { useState } from "react";
import { createPortal } from "react-dom";
import AssetTransferModal from "../AssetTransferModal";
import ConnectionModal from "../ConnectionModal";
Expand All @@ -24,7 +24,6 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) {
const {
data: eth,
isLoading: ethLoading,
error: ethError,
} = useContractRead({
address: ETH_SEPOLIA,
abi: Erc20Abi,
Expand All @@ -36,15 +35,14 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) {
const {
data: strk,
isLoading: strkLoading,
error: strkError,
} = useContractRead({
address: STRK_SEPOLIA,
abi: Erc20Abi,
functionName: "balanceOf",
args: [wallet.address!],
watch: true,
});
console.log('ethereum:',{eth})

// @ts-ignore
const ethBalance = eth?.balance.low.toString() / 1e18;
// @ts-ignore
Expand All @@ -53,7 +51,7 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) {
function handleConnect() {
const provider = new RpcProvider({
nodeUrl:
"https://starknet-sepolia.infura.io/v3/b935e660d34f48469cb740bfa2cfb1c0",
"https://starknet-sepolia.public.blastapi.io",
});
const account: any = new Account(
provider,
Expand All @@ -74,7 +72,6 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) {
ethBalance={ethBalance}
isOpen={isSending}
onClose={() => setIsSending(false)}
wallet={wallet}
account={account}
/>,
document.body
Expand Down Expand Up @@ -125,14 +122,14 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) {
<>
<button
className=" px-6 py-4 bg-blue-500 text-white rounded-[5px] disabled:cursor-not-allowed w-[200px] font-semibold"
disabled={!strkBalance || !ethBalance}
disabled={!eth || !strk}
onClick={() => setIsSending(true)}
>
SEND
</button>
<button
className=" px-6 py-4 bg-blue-500 text-white rounded-[5px] w-[200px] font-semibold disabled:cursor-not-allowed"
disabled={!strkBalance || !ethBalance}
disabled={!eth || !strk}
>
EXECUTE
</button>
Expand All @@ -141,7 +138,7 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) {
<button
className=" px-6 py-4 bg-blue-500 disabled:cursor-not-allowed text-white rounded-[5px] w-[200px] font-semibold"
onClick={() => setIsConnecting(true)}
disabled={!strkBalance || !ethBalance}
disabled={!eth || !strk}
>
CONNECT
</button>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/components/StarknetProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function StarknetProvider({ children }: StarknetProviderProps) {
new ArgentMobileConnector(),
];

const apiKey = process.env.NEXT_API_KEY!;
const nodeProvider = process.env.NEXT_PROVIDER!;
const apiKey = process.env.NEXT_PUBLIC_API_KEY!;
const nodeProvider = process.env.NEXT_PUBLIC_PROVIDER!;

let provider;
if (nodeProvider == "infura") {
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default function Home() {
A simple tool for seamlessly deploying smart contracts to Starknet
testnet and mainnet <br />
<br />
<b>coming soon...</b>
</p>
</a>

Expand Down

0 comments on commit 5bc5679

Please sign in to comment.