Skip to content

Commit

Permalink
Feature/ik/smart wallet integration (#192)
Browse files Browse the repository at this point in the history
* update deps for smartwallet

* add base sepolia config

* add smart wallet connect button raw

* update deps for smartwallet

* fix smartwallet button visibility & text color, fix curryncy symbol at user profile

* show blockExplorer links depending on chosen network

* add base sepolia faucets & update faucets show depending on chain id

* add logic to use smartwallet batch transactions on deposit and join, update web3provider to export wagmiconfig

* add logic for deposit&join as batch transactions with 0 ingame balance before start game

* update start button text about batch txs and delete commented code
  • Loading branch information
mezger75 authored Jun 30, 2024
1 parent 88089d7 commit 6526913
Showing 1 changed file with 14 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useRef, useState } from "react";
import React, { useEffect, useRef } from "react";

import { useModal, useSIWE } from "connectkit";
import {
useAccount,
useWaitForTransactionReceipt,
useWriteContract,
} from "wagmi";
import { Address, keccak256, parseEther, toBytes } from "viem";
import { Address, parseEther } from "viem";

import WsApiService, { RaceStatistic } from "@/app/api/ws-api-service";
import {
Expand All @@ -22,12 +22,6 @@ import { Button } from "@/app/components/ui/button";
import { useConfigStore } from "@/app/store/configStore";
import Spinner from "@/app/components/ui/spinner";
import { useQueryClient } from "@tanstack/react-query";
import {
writeContracts,
showCallsStatus,
getCallsStatus,
} from "@wagmi/core/experimental";
import { wagmiConfig } from "@/app/helpers/web3-provider";

interface IStartDepositButton {
txSuccessful: boolean;
Expand All @@ -48,7 +42,6 @@ function StartDepositButton({
isConfirmingJoin,
handleBatchStartGame,
}: IStartDepositButton) {
const [batchStatusConfirmed, setBatchStatusConfirmed] = useState(false);
const { contractConfig } = useConfigStore();
const { isSignedIn, signIn } = useSIWE();
const { isConnected, chainId, address, chain, connector } = useAccount();
Expand All @@ -75,33 +68,6 @@ function StartDepositButton({
}
if (connector?.id === "coinbaseWalletSDK") {
handleBatchStartGame();
// const sessionId = sessionStorage.getItem("sessionId");
// const hashSessionId = keccak256(toBytes(sessionId as string));
// const id = await writeContracts(wagmiConfig, {
// // account: address,
// contracts: [
// {
// address: contractAddress as Address,
// abi: contractConfig.abi,
// functionName: "deposit",
// args: [],
// value: parseEther("0.001"),
// },
// {
// address: contractAddress as Address,
// abi: contractConfig.abi,
// functionName: "joinGame",
// args: [hashSessionId],
// },
// ],
// });
// console.log("ID", id);
// await showCallsStatus(wagmiConfig, { id: id });
// const status = await getCallsStatus(wagmiConfig, { id: id });
// console.log("STATus", status);
// if (status.status === "CONFIRMED") {
// setBatchStatusConfirmed(true);
// }
} else {
writeContract({
address: contractAddress as Address,
Expand All @@ -123,18 +89,7 @@ function StartDepositButton({
if (isConfirmed) {
queryClient.invalidateQueries({ queryKey });
}
if (batchStatusConfirmed) {
// setTxSuccessful(true);

wsApiServiceRef.current?.register(
localStorage.getItem("userId") ?? "",
address as Address
);
queryClient.invalidateQueries({ queryKey });
// setIsButtonDisabled(true);
// setUserStats([]);
}
}, [isConfirmed, batchStatusConfirmed]);
}, [isConfirmed]);

const showDepositButton =
isSignedIn &&
Expand All @@ -149,20 +104,19 @@ function StartDepositButton({

return (
<>
{showDepositButton &&
!isConfirmed &&
userStatus !== "registered" &&
!batchStatusConfirmed ? (
{showDepositButton && !isConfirmed && userStatus !== "registered" ? (
<Button onClick={handleUserDeposit}>
{isConfirming && <Spinner />}
{`Deposit 0.001 ${
chainId === CHAIN_ID_SCROLL_SEPOLIA_DECIMAL ||
chainId === CHAIN_ID_BLAST_SEPOLIA_DECIMAL
? "ETH"
: chainId === CHAIN_ID_AMOY_DECIMAL
? "Matic"
: ""
}`}
{connector?.id === "coinbaseWalletSDK"
? `Deposit 0.001 ETH and Start Game`
: `Deposit 0.001 ${
chainId === CHAIN_ID_SCROLL_SEPOLIA_DECIMAL ||
chainId === CHAIN_ID_BLAST_SEPOLIA_DECIMAL
? "ETH"
: chainId === CHAIN_ID_AMOY_DECIMAL
? "Matic"
: ""
}`}
</Button>
) : (
<Button
Expand Down

0 comments on commit 6526913

Please sign in to comment.