Skip to content

Commit

Permalink
feat: add email, sms, and metamask extension (#148)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Felix C. Morency <[email protected]>
  • Loading branch information
chalabi2 and fmorency authored Dec 20, 2024
1 parent b49a3f8 commit d3888c5
Show file tree
Hide file tree
Showing 30 changed files with 510 additions and 66 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 1 addition & 3 deletions components/3js/animatedAsterisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ export default function AnimatedAsterisk({ onLoad }: { onLoad?: () => void }) {
style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%' }}
camera={{ position: [0, 0, 10] }}
>
<ambientLight intensity={0.2} />

<Suspense fallback={null}>
{meshes}
<Environment files="/rosendal_park_sunset_puresky_4k.hdr" background={false} />
<Environment files="/rosendal_park_sunset_puresky_1k.hdr" background={false} />
</Suspense>
</Canvas>
);
Expand Down
4 changes: 1 addition & 3 deletions components/3js/animatedMesh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ export default function AnimatedShape({
style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%' }}
camera={{ position: [0, 0, 10] }}
>
<ambientLight intensity={0.2} />

<Suspense fallback={null}>
{meshes}
<Environment files="/rosendal_park_sunset_puresky_4k.hdr" background={false} />
<Environment files="/rosendal_park_sunset_puresky_1k.hdr" background={false} />
<OrbitControls enablePan={false} enableZoom={false} />
</Suspense>
</Canvas>
Expand Down
3 changes: 1 addition & 2 deletions components/3js/pennRoseTriangleScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ function PenroseTriangleScene({ onLoad }: { onLoad: () => void }) {
<CameraSetup />

{/* Lighting */}
<ambientLight intensity={0.5} />

{/* Suspense for async loading */}
<Suspense fallback={null}>
{/* Animated Penrose Triangle */}
<AnimatedPenroseTriangle />

{/* Environment */}
<Environment files="/rosendal_park_sunset_puresky_4k.hdr" background={false} />
<Environment files="/rosendal_park_sunset_puresky_1k.hdr" background={false} />
</Suspense>

{/* Adjust the plane to be closer to the Penrose Triangle */}
Expand Down
2 changes: 0 additions & 2 deletions components/bank/forms/sendForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export default function SendForm({
amount: [{ denom: values.selectedToken.coreDenom, amount: amountInBaseUnits }],
});

console.log('Estimating fee for address:', address);
const fee = await estimateFee(address, [msg]);

await tx([msg], {
Expand All @@ -150,7 +149,6 @@ export default function SendForm({
});
} catch (error) {
console.error('Error during sending:', error);
// You might want to show this error to the user through a toast or alert
} finally {
setIsSending(false);
}
Expand Down
2 changes: 0 additions & 2 deletions components/groups/modals/memberManagementModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ export function MemberManagementModal({
weight: member.markedForDeletion ? '0' : member.weight || '1',
}));

console.log('Member updates:', memberUpdates);

const msg = updateGroupMembers({
admin: groupAdmin,
groupId: BigInt(groupId),
Expand Down
85 changes: 76 additions & 9 deletions components/react/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ import type { ChainWalletBase, WalletModalProps } from 'cosmos-kit';
import { WalletStatus } from 'cosmos-kit';
import React, { useCallback, Fragment, useState, useMemo, useEffect } from 'react';
import { Dialog, Transition, Portal } from '@headlessui/react';
import { Connected, Connecting, Error, NotExist, QRCode, WalletList, Contacts } from './views';
import {
Connected,
Connecting,
Error,
NotExist,
QRCode,
WalletList,
Contacts,
EmailInput,
SMSInput,
} from './views';
import { useRouter } from 'next/router';
import { ToastProvider } from '@/contexts/toastContext';
import { Web3AuthClient, Web3AuthWallet } from '@cosmos-kit/web3auth';
import { useDeviceDetect } from '@/hooks';
export enum ModalView {
WalletList,
Expand All @@ -15,6 +26,8 @@ export enum ModalView {
Error,
NotExist,
Contacts,
EmailInput,
SMSInput,
}

export const TailwindModal: React.FC<
Expand Down Expand Up @@ -79,17 +92,29 @@ export const TailwindModal: React.FC<

const onWalletClicked = useCallback(
(name: string) => {
const wallet = walletRepo?.getWallet(name);
if (wallet?.walletInfo.prettyName === 'Email') {
setCurrentView(ModalView.EmailInput);
return;
}
if (wallet?.walletInfo.prettyName === 'SMS') {
setCurrentView(ModalView.SMSInput);
return;
}

walletRepo?.connect(name);

// 1ms timeout prevents _render from determining the view to show first
setTimeout(() => {
const wallet = walletRepo?.getWallet(name);

if (wallet?.isWalletNotExist) {
if (
wallet?.walletInfo.name === 'cosmos-extension-metamask' &&
wallet.message?.includes("Cannot read properties of undefined (reading 'request')")
) {
setCurrentView(ModalView.NotExist);
setSelectedWallet(wallet);
}
if (wallet?.walletInfo.mode === 'wallet-connect') {
} else if (wallet?.isWalletNotExist) {
setCurrentView(ModalView.NotExist);
setSelectedWallet(wallet);
} else if (wallet?.walletInfo.mode === 'wallet-connect') {
setCurrentView(isMobile ? ModalView.Connecting : ModalView.QRCode);
setQRWallet(wallet);
}
Expand All @@ -112,6 +137,48 @@ export const TailwindModal: React.FC<
wallets={walletRepo?.wallets || []}
/>
);
case ModalView.EmailInput:
return (
<EmailInput
onClose={onCloseModal}
onReturn={() => setCurrentView(ModalView.WalletList)}
onSubmit={async email => {
try {
const emailWallet = walletRepo?.wallets.find(
w => w.walletInfo.prettyName === 'Email'
) as Web3AuthWallet | undefined;

if (emailWallet?.client instanceof Web3AuthClient) {
emailWallet.client.setLoginHint(email);
await walletRepo?.connect(emailWallet.walletInfo.name);
} else {
console.error('Email wallet or client not found');
}
} catch (error) {
console.error('Email login error:', error);
// Handle the error appropriately in your UI
}
}}
/>
);

case ModalView.SMSInput:
return (
<SMSInput
onClose={onCloseModal}
onReturn={() => setCurrentView(ModalView.WalletList)}
onSubmit={phone => {
const smsWallet = walletRepo?.wallets.find(w => w.walletInfo.prettyName === 'SMS') as
| Web3AuthWallet
| undefined;

if (smsWallet?.client instanceof Web3AuthClient) {
smsWallet.client.setLoginHint(phone);
walletRepo?.connect(smsWallet.walletInfo.name);
}
}}
/>
);
case ModalView.Connected:
return (
<Connected
Expand All @@ -126,11 +193,11 @@ export const TailwindModal: React.FC<
);
case ModalView.Connecting:
let subtitle: string;
if (currentWalletData!.mode === 'wallet-connect') {
if (currentWalletData!?.mode === 'wallet-connect') {
subtitle = `Approve ${currentWalletData!.prettyName} connection request on your mobile.`;
} else {
subtitle = `Open the ${
currentWalletData!.prettyName
currentWalletData!?.prettyName
} browser extension to connect your wallet.`;
}

Expand Down
11 changes: 6 additions & 5 deletions components/react/views/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getRealLogo, shiftDigits, truncateString } from '@/utils';
import Image from 'next/image';
import { MdContacts } from 'react-icons/md';
import { Contacts } from './Contacts';
import { useTheme } from '@/contexts';

export const Connected = ({
onClose,
Expand All @@ -31,7 +30,7 @@ export const Connected = ({
const { balance } = useBalance(address ?? '');
const [copied, setCopied] = useState(false);
const [showContacts, setShowContacts] = useState(false);
const { theme } = useTheme();
const isDarkMode = document.documentElement.classList.contains('dark');

const copyAddress = () => {
if (address) {
Expand All @@ -50,7 +49,7 @@ export const Connected = ({
<div className="flex justify-between items-center -mt-4 mb-6">
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onReturn}
>
<ChevronLeftIcon className="w-5 h-5" aria-hidden="true" />
Expand All @@ -59,7 +58,9 @@ export const Connected = ({
<Image
height={0}
width={0}
src={getRealLogo(logo, theme === 'dark')}
src={
name === 'Cosmos MetaMask Extension' ? '/metamask.svg' : getRealLogo(logo, isDarkMode)
}
alt={name}
className="w-8 h-8 rounded-full mr-2"
/>
Expand All @@ -69,7 +70,7 @@ export const Connected = ({
</div>
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onClose}
>
<XMarkIcon className="w-5 h-5" aria-hidden="true" />
Expand Down
10 changes: 7 additions & 3 deletions components/react/views/Connecting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Connecting = ({
<div className="flex justify-between items-center mb-2">
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onReturn}
>
<ChevronLeftIcon className="w-5 h-5" aria-hidden="true" />
Expand All @@ -37,15 +37,19 @@ export const Connecting = ({
</Dialog.Title>
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onClose}
>
<XMarkIcon className="w-5 h-5" aria-hidden="true" />
</button>
</div>
<div className="flex flex-col w-full h-full mt-4 sm:px-8 sm:py-6">
<img
src={getRealLogo(logo, theme === 'dark')}
src={
name === 'Cosmos MetaMask Extension'
? '/metamask.svg'
: getRealLogo(logo, theme === 'dark')
}
alt={name}
className="flex-shrink-0 w-20 h-20 mx-auto aspect-1"
/>
Expand Down
12 changes: 6 additions & 6 deletions components/react/views/Contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const Contacts = ({
{onReturn ? (
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onReturn}
>
<ChevronLeftIcon className="w-5 h-5" aria-hidden="true" />
Expand All @@ -139,7 +139,7 @@ export const Contacts = ({
</Dialog.Title>
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onClose}
>
<XMarkIcon className="w-5 h-5" aria-hidden="true" />
Expand Down Expand Up @@ -192,7 +192,7 @@ export const Contacts = ({
{onReturn ? (
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onReturn}
>
<ChevronLeftIcon className="w-5 h-5" aria-hidden="true" />
Expand All @@ -208,7 +208,7 @@ export const Contacts = ({
</div>
<button
type="button"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-gray-700"
className="p-2 text-primary bg-neutral rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033]"
onClick={onClose}
>
<XMarkIcon className="w-5 h-5" aria-hidden="true" />
Expand Down Expand Up @@ -347,13 +347,13 @@ export const Contacts = ({
<div className="flex items-center">
<button
onClick={() => setEditingIndex(index)}
className="ml-2 p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors duration-200 text-blue-500"
className="ml-2 p-2 rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033] transition-colors duration-200 text-blue-500"
>
<PencilIcon className="w-5 h-5" aria-hidden="true" />
</button>
<button
onClick={() => handleRemoveContact(index)}
className="ml-2 p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors duration-200 text-red-500"
className="ml-2 p-2 rounded-full hover:bg-gray-200 dark:hover:bg-[#00000033] transition-colors duration-200 text-red-500"
>
<XMarkIcon className="w-5 h-5" aria-hidden="true" />
</button>
Expand Down
Loading

0 comments on commit d3888c5

Please sign in to comment.