Skip to content

Commit

Permalink
fix googl
Browse files Browse the repository at this point in the history
  • Loading branch information
KamyarTaher committed Aug 4, 2024
1 parent 5c20037 commit 0b3b75c
Showing 1 changed file with 31 additions and 36 deletions.
67 changes: 31 additions & 36 deletions src/app/components/NavigationBar/ModalContents/LinkWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// ModalContents/LinkWallet.tsx

import React, { useEffect, useState } from "react";
import { LoginButton } from "../LoginButton";
import { connect } from "get-starknet";
import {
getAccessToken,
getRewardAddress,
setRewardAddressBAPI,
} from "@/app/backendAPI/backendAPI";
Expand All @@ -13,38 +10,40 @@ import { useAuthStore } from "@/app/store/authStore";

export function LinkWallet() {
const [walletAddress, setWalletAddress] = useState<string | null>(null);
const [rewardAddress, setRewardAddress] = useState("");
const isLogin = useAuthStore((state) => state.isConnected);
const googleID = useAuthStore((state) => state.googleId);
const [rewardAddress, setRewardAddress] = useState("");
console.log("accesT", getAccessToken());
const connectWallet = async () => {
try {
const starknet = await connect();
if (starknet) {
const [address] = await starknet.enable();
setWalletAddress(address);
}
} catch (error) {
console.error("Error connecting wallet:", error);
}

const connectWallet = () => {
connect()
.then((starknet) => {
if (starknet) {
return starknet.enable();
}
throw new Error("Starknet not available");
})
.then(([address]) => setWalletAddress(address))
.catch((error) => console.error("Error connecting wallet:", error));
};

const rewardAync = async () => {
const rewardAddress = (await getRewardAddress()) as any;
const fRewardAddress = `0x${rewardAddress?.address}`;
setRewardAddress(fRewardAddress);
};

const confirmLinking = async () => {
try {
setRewardAddressBAPI(walletAddress as string);
alert("Failed to link wallet. Please try in some hours...");
} catch (error) {
console.error("Error linking wallet:", error);
alert("Failed to link wallet. Please try again.");
} finally {
try {
setRewardAddressBAPI(walletAddress as string);
const confirmLinking = () => {
setRewardAddressBAPI(walletAddress as string)
.then(() => {
alert("Failed to link wallet. Please try in some hours...");
} catch (error) {
})
.catch((error) => {
console.error("Error linking wallet:", error);
alert("Failed to link wallet. Please try again.");
}
}
})
.finally(() => {
rewardAync();
});
};

const buttonStyle =
Expand All @@ -53,17 +52,13 @@ export function LinkWallet() {
"bg-gray-400 text-white font-bold py-2 px-4 rounded cursor-not-allowed";

useEffect(() => {
const getRaddress = async () => {
try {
const rewardAddress = (await getRewardAddress()) as any;
getRewardAddress()
.then((rewardAddress: any) => {
console.log(rewardAddress);
const fRewardAddress = `0x${rewardAddress?.address}`;
setRewardAddress(fRewardAddress);
} catch (err) {
console.error(err);
}
};
getRaddress();
})
.catch((err) => console.error(err));
}, [googleID, isLogin]);

if (rewardAddress?.length > 5) {
Expand Down

0 comments on commit 0b3b75c

Please sign in to comment.