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

Fix: post-QA issues #57

Merged
merged 6 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions app/allocation/components/BudgetAllocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ interface IBudgetAllocationProps extends BudgetCategory {
delegations: number
loading: boolean
username?: string
isBadgeholder: boolean
bhCategory: string
categorySlug: string
onDelegate: () => void
onScore: () => void
}
Expand All @@ -33,6 +36,9 @@ const BudgetAllocation: React.FC<IBudgetAllocationProps> = ({
loading,
progress = CollectionProgressStatusEnum.Pending,
username,
isBadgeholder,
bhCategory,
categorySlug,
onScore,
onDelegate,
}) => {
Expand All @@ -55,6 +61,9 @@ const BudgetAllocation: React.FC<IBudgetAllocationProps> = ({
progress={progress}
delegations={delegations}
isAutoConnecting={isAutoConnecting}
isBadgeholder={isBadgeholder}
bhCategory={bhCategory}
categorySlug={categorySlug}
/>
);
}
Expand Down
9 changes: 9 additions & 0 deletions app/allocation/components/CategoryAllocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ interface CategoryAllocationProps extends TCategory {
delegations: number
loading: boolean
username?: string
isBadgeholder: boolean
bhCategory: string
categorySlug: string
onDelegate: () => void
onScore: () => void
onLockClick: () => void
Expand All @@ -53,6 +56,9 @@ const CategoryAllocation: FC<CategoryAllocationProps> = ({
delegations,
loading,
username,
isBadgeholder,
bhCategory,
categorySlug,
onDelegate,
onScore,
onLockClick,
Expand Down Expand Up @@ -104,6 +110,9 @@ const CategoryAllocation: FC<CategoryAllocationProps> = ({
progress={progress}
isAutoConnecting={isAutoConnecting}
delegations={delegations}
isBadgeholder={isBadgeholder}
bhCategory={bhCategory}
categorySlug={categorySlug}
/>
);
}
Expand Down
64 changes: 46 additions & 18 deletions app/allocation/components/EOA/ConnectEOAModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import { FC, useState } from 'react';
import Image from 'next/image';
import { useActiveWallet } from 'thirdweb/react';
import { Step } from './EmailLoginModal';
Expand All @@ -7,29 +7,47 @@ import { axiosInstance } from '@/app/utils/axiosInstance';
type TConnectEOAModalProps = {
email: string
setStep: (step: number) => void
}
};

const ConnectEOAModal: FC<TConnectEOAModalProps> = ({
email,
setStep,
}) => {
const ConnectEOAModal: FC<TConnectEOAModalProps> = ({ email, setStep }) => {
const wallet = useActiveWallet();
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<string | null>(null);

const connectEOA = async () => {
if (!wallet) return;
const msg = 'Sign in with Thirdweb wallet';
const account = wallet?.getAccount();
setLoading(true);
setError(null);

if (!wallet) {
setError('Unable to connect to your wallet');
setLoading(false);
return;
}

try {
const msg = 'Sign in with Thirdweb wallet';
const account = wallet?.getAccount();

if (!account) return;
if (!account) {
setError('Unable to connect to your wallet');
setLoading(false);
return;
}

const signature = await account.signMessage({ message: msg });
const signature = await account.signMessage({ message: msg });

await axiosInstance.post('auth/thirdweb/login', {
message: msg,
signature,
address: account.address,
});
setStep(Step.SUCCESS);
await axiosInstance.post('auth/thirdweb/login', {
message: msg,
signature,
address: account.address,
});
setLoading(false);
setStep(Step.SUCCESS);
}
catch (err) {
setError('An error occurred while connecting to your wallet');
setLoading(false);
}
};

return (
Expand All @@ -54,11 +72,21 @@ const ConnectEOAModal: FC<TConnectEOAModalProps> = ({
<p className="text-gray-400">
Please link this with your connected ETH address to continue.
</p>

{error && (
<div className="mt-4 flex w-[90%] flex-col items-start gap-1 rounded-lg border border-primary bg-status-bg-error px-3 py-2">
<p className="text-sm font-semibold text-primary">
An error occurred!
</p>
<p className="text-center text-xs text-dark-500">{error}</p>
</div>
)}

<button
className="my-4 w-full rounded-lg border bg-primary px-4 py-2 font-semibold text-white transition duration-300"
onClick={connectEOA}
>
Connect
{loading ? 'Connecting...' : 'Connect'}
</button>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/allocation/components/EOA/EmailLoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const EmailLoginModal = ({ closeModal, selectedCategoryId }: TEmailLoginModalPro
handleGoBack={goBack}
setStep={setStep}
resendOTP={sendOTP}
closeModal={closeModal}
/>
)}
</div>
Expand Down
15 changes: 6 additions & 9 deletions app/allocation/components/EOA/MethodSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const MethodSelection: FC<IMethodSelectionProps> = ({
setOtpData,
sendOTP,
setStep,
closeModal,
}) => {
const { connect } = useConnect();

Expand All @@ -50,21 +51,17 @@ export const MethodSelection: FC<IMethodSelectionProps> = ({
const smartWallet = await createSmartWalletFromEOA(account);
setOAuthData({ ...oAuthData, loading: false });

connect(smartWallet);

if (!personalWalletId) {
setOAuthData({
...oAuthData,
loading: true,
error: 'There was a problem connecting to your Google account',
});
setStep(Step.CONNECT_EOA);
Copy link
Collaborator

@mmahdigh mmahdigh Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggle to understand this part. You're checking if personalWalletId exists to check if the smart wallet creation was successful or not?

If it's false, why should we setStep(Step.CONNECT_EOA)? ConnectEOAModal modal is for forming the (realOpAddress, smartWalletAddress) mapping in our backend. Ideally, we would check if the mapping exists in the db or not, if it exists we move the user to the step === Step.SUCCESS if not, to the step === Step.CONNECT_EOA. However, since we are lacking that endpoint, I would move all users regardless to the step === Step.CONNECT_EOA.

However, I can't understand why we would move them to step === Step.CONNECT_EOA if !personalWalletId

Copy link
Collaborator Author

@Meriem-BM Meriem-BM Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's regarding this 1st point #4 (comment)

If the user already has a smart wallet but only logged out (token expired) we should not show the create wallet loading, connect, and success connection models, we have to close the modal automatically after the OTP is correct. #58](#58)

so that is just to not show the connect and success modals

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personalWalletId

is just to check if the user has already a smart wallet

setPickedMethod(null);
}
else {
console.log('Connecting to smart wallet');
connect(smartWallet);
setStep(Step.CONNECT_EOA);
closeModal();
}
}
catch (error: any) {
console.error(error);
setOAuthData({
...oAuthData,
loading: true,
Expand Down
19 changes: 12 additions & 7 deletions app/allocation/components/EOA/OTPVerification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IOTPVerificationProps {
handleGoBack: () => void
setStep: (step: number) => void
resendOTP: () => void
closeModal: () => void
}

const FIVE_MINUTES = 1 * 60 * 1000;
Expand All @@ -32,6 +33,7 @@ export const OTPVerification: FC<IOTPVerificationProps> = ({
handleGoBack,
setStep,
resendOTP,
closeModal,
}) => {
const { connect } = useConnect();

Expand Down Expand Up @@ -118,16 +120,19 @@ export const OTPVerification: FC<IOTPVerificationProps> = ({

const smartWallet = await createSmartWalletFromEOA(account);

setOtpData({
...otpData,
loading: false,
otpStatus: OtpStatus.VERIFIED,
});

connect(smartWallet);

if (!personalWalletId) {
setOtpData({
...otpData,
loading: false,
otpStatus: OtpStatus.INCORRECT,
});
setStep(Step.CONNECT_EOA);
}
else {
connect(smartWallet);
setStep(Step.CONNECT_EOA);
closeModal();
}
}
catch {
Expand Down
24 changes: 16 additions & 8 deletions app/allocation/components/ProgressCards/PendingCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ type TPendingCategoryProps = {
progress: string
isAutoConnecting: boolean
delegations?: number
isBadgeholder: boolean
bhCategory: string
categorySlug: string
};

const PendingCategory = ({
Expand All @@ -14,26 +17,33 @@ const PendingCategory = ({
isAutoConnecting,
delegations,
progress,
isBadgeholder,
bhCategory,
categorySlug,
}: TPendingCategoryProps) => {
return (
<div className="flex w-full flex-col items-center justify-center gap-2">
<div className="flex w-full items-center justify-between">
<button
onClick={onScore}
className={`w-[48%] whitespace-nowrap rounded-md py-3 text-sm font-medium ${
isAutoConnecting
className={`whitespace-nowrap rounded-md py-3 text-sm font-medium ${
isAutoConnecting || (isBadgeholder && bhCategory !== categorySlug)
? 'border bg-gray-300 text-gray-600'
: 'bg-primary text-white'
} ${
isBadgeholder && bhCategory === categorySlug ? 'w-full' : 'w-[48%]'
}`}
disabled={isAutoConnecting}
disabled={
isAutoConnecting || (isBadgeholder && bhCategory !== categorySlug)
}
>
Vote
</button>
<button
onClick={onDelegate}
className={`w-[48%] rounded-md border py-3 text-sm font-medium ${
isAutoConnecting ? 'bg-gray-300 text-gray-600' : 'text-gray-700'
}`}
} ${isBadgeholder && bhCategory === categorySlug ? 'hidden' : ''}`}
disabled={isAutoConnecting}
>
Delegate
Expand All @@ -53,14 +63,12 @@ const PendingCategory = ({
</p>
</div>
)}
{progress === 'WIP' && (
{progress === 'WIP'
&& !(isBadgeholder && bhCategory !== categorySlug) && (
<div className="flex w-full justify-center gap-2 rounded-xl border border-[#FFA15A] bg-[#FFF7ED] py-1">
<p className="text-xs font-medium text-[#FFA15A]">Voting</p>
</div>
)}
{/* <div className="flex w-full justify-center gap-2 rounded-xl border border-[#17B26A] bg-[#ECFDF3] py-1">
<p className="text-xs font-medium text-[#17B26A]">Voting</p>
</div> */}
</div>
);
};
Expand Down
Loading