Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove email #55

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 1 addition & 134 deletions src/renderer/components/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ function Wallet() {
const { disconnect: wagmiDisconnect } = useDisconnect();
const { nativeTokenBalance, flockTokenBalance } = useContext(WalletContext);
const [privateKey, setPrivateKey] = useState('');
const [userEmail, setUserEmail] = useState('');
const [showEmailImport, setShowEmailImport] = useState(false);

const handleConnect = async () => {
setIsWalletOpen(false);
Expand All @@ -53,66 +51,9 @@ function Wallet() {
await connectAsync({
connector: connectors[1],
});
} catch (error) {
toast.error('Invalid private key');
}
};

const loadEmail = async () => {
try {
const res = await fetch(
`https://us-central1-flock-demo-design.cloudfunctions.net/getEmailFromDB?wallet=${address}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}
);

const { email } = await res.json();
if (email) {
setUserEmail(email);
setShowWalletImport(false);
} else {
setShowWalletImport(false);
setShowEmailImport(true);
}
} catch (error) {
setShowWalletImport(false);
}
};

const importEmail = async () => {
try {
const response = await fetch(
'https://us-central1-flock-demo-design.cloudfunctions.net/postEmailToDB',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: userEmail,
wallet: address,
}),
}
);
if (response.ok) {
setShowEmailImport(false);
} else {
const data = await response.json();
console.log(data);
if (
data.error.includes(
'Unique constraint failed on the fields: (`email`)'
)
) {
toast.error('Email already exists');
}
}
} catch (error) {
console.error('Error importing email:', error);
toast.error('Invalid private key');
}
};

Expand All @@ -135,31 +76,6 @@ function Wallet() {
oAuthAccessToken?: string;
}

const loadUserInfo = async () => {
try {
if (pendingConnector?.id === 'web3auth') {
const user = await web3AuthInstance.getUserInfo();

await fetch(
'https://us-central1-flock-demo-design.cloudfunctions.net/postEmailToDB',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${user.idToken}`,
},
body: JSON.stringify({
email: user.email,
wallet: address,
}),
}
);
}
} catch (error) {
console.error('Error loading user info:', error);
}
};

const { data: dataTransfer, writeAsync: writeAsyncApprove } =
useContractWrite({
address: FLOCK_ADDRESS as `0x${string}`,
Expand Down Expand Up @@ -193,13 +109,6 @@ function Wallet() {
}
}, [isSuccessTransfer]);

useEffect(() => {
if (address) {
loadEmail();
loadUserInfo();
}
}, [address, isSuccess]);

if (showWalletSettings) {
return (
<Layer onEsc={() => setShowWalletSettings(false)} full>
Expand Down Expand Up @@ -335,48 +244,6 @@ function Wallet() {
);
}

if (showEmailImport) {
return (
<Layer onEsc={() => setShowEmailImport(false)} full>
<Box
align="center"
justify="center"
height="100vh"
pad="large"
gap="medium"
>
<Heading level="3">Enter your email</Heading>
<Text>This email will be used for claiming OAT</Text>
<TextInput
value={userEmail}
onChange={(event) => setUserEmail(event.target.value)}
/>
<Box direction="row" alignSelf="center" gap="small">
<Button
primary
label="Enter"
pad="xsmall"
disabled={!userEmail}
onClick={importEmail}
/>
</Box>
</Box>
<ToastContainer
position="bottom-left"
autoClose={5000}
hideProgressBar={false}
newestOnTop
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="light"
/>
</Layer>
);
}

return (
<DropButton
primary
Expand Down