Skip to content

Commit

Permalink
feat: add mobile options on desktop wallet list
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Dec 10, 2024
1 parent f059f3b commit 7ff68a0
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 44 deletions.
1 change: 0 additions & 1 deletion 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 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
29 changes: 24 additions & 5 deletions components/react/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,29 @@ export const TailwindModal: React.FC<
}
}, [isOpen, walletStatus, currentWalletName, showContacts]);

useEffect(() => {
if (!isOpen && current?.walletStatus === WalletStatus.Connecting) {
current.disconnect();

Check warning on line 81 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L81

Added line #L81 was not covered by tests
}
}, [isOpen, current]);

const onWalletClicked = useCallback(
(name: string) => {
const timeoutId = setTimeout(() => {
const wallet = walletRepo?.getWallet(name);
if (wallet?.walletStatus === WalletStatus.Connecting) {
wallet.disconnect();
setCurrentView(ModalView.Error);
}
}, 30000);

Check warning on line 94 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L87-L94

Added lines #L87 - L94 were not covered by tests
walletRepo?.connect(name);

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

if (wallet?.isWalletNotExist) {
clearTimeout(timeoutId);

Check warning on line 101 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L101

Added line #L101 was not covered by tests
setCurrentView(ModalView.NotExist);
setSelectedWallet(wallet);
}
Expand All @@ -93,13 +107,18 @@ export const TailwindModal: React.FC<
setQRWallet(wallet);
}
}, 1);

Check warning on line 110 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L110

Added line #L110 was not covered by tests
return () => clearTimeout(timeoutId);
},
[walletRepo]
);

const onCloseModal = useCallback(() => {
if (current?.walletStatus === WalletStatus.Connecting) {
current.disconnect();
}

Check warning on line 119 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L117-L119

Added lines #L117 - L119 were not covered by tests
setOpen(false);
}, [setOpen]);
}, [setOpen, current]);

const _render = useMemo(() => {
switch (currentView) {
Expand All @@ -125,11 +144,11 @@ export const TailwindModal: React.FC<
);
case ModalView.Connecting:
let subtitle: string;
if (currentWalletData!.mode === 'wallet-connect') {
subtitle = `Approve ${currentWalletData!.prettyName} connection request on your mobile.`;
if (currentWalletData!?.mode === 'wallet-connect') {
subtitle = `Approve ${currentWalletData!.prettyName} connection request on your mobile device.`;

Check warning on line 148 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L147-L148

Added lines #L147 - L148 were not covered by tests
} else {
subtitle = `Open the ${
currentWalletData!.prettyName
currentWalletData!?.prettyName

Check warning on line 151 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L151

Added line #L151 was not covered by tests
} browser extension to connect your wallet.`;
}

Expand Down
64 changes: 42 additions & 22 deletions components/react/views/WalletList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ export const WalletList = ({
wallet.walletInfo.prettyName
)

Check warning on line 26 in components/react/views/WalletList.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/WalletList.tsx#L24-L26

Added lines #L24 - L26 were not covered by tests
);
console.log(wallets);

const mobile = wallets.filter(wallet =>
['Wallet Connect', 'Keplr Mobile', 'Cosmostation Mobile', 'Leap Mobile'].includes(
wallet.walletInfo.prettyName
)
['Keplr Mobile', 'Cosmostation Mobile', 'Leap Mobile'].includes(wallet.walletInfo.prettyName)

Check warning on line 30 in components/react/views/WalletList.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/WalletList.tsx#L30

Added line #L30 was not covered by tests
);

const hasMobileVersion = (prettyName: string) => {
return mobile.some(w => w.walletInfo.prettyName.startsWith(prettyName));
};

const getMobileWalletName = (browserName: string) => {
return mobile.find(w => w.walletInfo.prettyName.startsWith(browserName))?.walletInfo.name;
};

Check warning on line 40 in components/react/views/WalletList.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/WalletList.tsx#L32-L40

Added lines #L32 - L40 were not covered by tests
return (
<div className="p-1 relative max-w-sm mx-auto">
<h1 className="text-sm font-semibold text-center mb-6">Connect Wallet</h1>
Expand All @@ -46,24 +53,37 @@ export const WalletList = ({
<div className="hidden md:block">
<div className="space-y-2 mb-4">
{browser.map(({ walletInfo: { name, prettyName, logo } }) => (
<button
key={name}
onClick={() => onWalletClicked(name)}
className="flex items-center w-full p-3 rounded-lg dark:bg-[#ffffff0c] bg-[#f0f0ff5c] dark:hover:bg-[#0000004c] hover:bg-[#a8a8a84c] transition"
>
<img
src={
prettyName === 'Cosmos MetaMask Extension'
? '/metamask.svg'
: getRealLogo(logo?.toString() ?? '')
}
alt={prettyName}
className="w-10 h-10 rounded-xl mr-3"
/>
<span className="text-md">
{prettyName === 'Cosmos MetaMask Extension' ? 'MetaMask' : prettyName}
</span>
</button>
<div key={name} className="w-full">
<button
onClick={() => onWalletClicked(name)}
className="flex items-center w-full p-3 rounded-lg dark:bg-[#ffffff0c] bg-[#f0f0ff5c] dark:hover:bg-[#0000004c] hover:bg-[#a8a8a84c] transition"
>
<img
src={
prettyName === 'Cosmos MetaMask Extension'
? '/metamask.svg'
: getRealLogo(logo?.toString() ?? '')
}
alt={prettyName}
className="w-10 h-10 rounded-xl mr-3"
/>
<span className="text-md flex-1 text-left">
{prettyName === 'Cosmos MetaMask Extension' ? 'MetaMask' : prettyName}
</span>
{hasMobileVersion(prettyName) && (
<div
onClick={e => {
e.stopPropagation();
onWalletClicked(getMobileWalletName(prettyName) || '');
}}
className="p-1.5 rounded-lg dark:hover:bg-[#ffffff1a] hover:bg-[#0000000d] dark:bg-[#ffffff37] bg-[#d5d5e4] transition cursor-pointer"
title={`Connect with ${prettyName} Mobile`}
>
<img src={getRealLogo('/sms')} alt="mobile" className="w-5 h-5" />
</div>
)}
</button>
</div>

Check warning on line 86 in components/react/views/WalletList.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/WalletList.tsx#L56-L86

Added lines #L56 - L86 were not covered by tests
))}
</div>

Expand Down
40 changes: 27 additions & 13 deletions components/wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { MouseEventHandler, useEffect, useMemo, useState } from 'react';
import React, { MouseEventHandler, useEffect, useMemo, useState, useRef } from 'react';

import { ArrowDownTrayIcon, ArrowPathIcon } from '@heroicons/react/24/outline';
import { ArrowUpIcon, CopyIcon } from './icons';
Expand Down Expand Up @@ -36,20 +36,32 @@ interface WalletSectionProps {
export const WalletSection: React.FC<WalletSectionProps> = ({ chainName }) => {
const { connect, openView, status, username, address } = useChain(chainName);
const [localStatus, setLocalStatus] = useState(status);
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();

Check warning on line 39 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L39

Added line #L39 was not covered by tests

useEffect(() => {
let timeoutId: ReturnType<typeof setTimeout>;

if (status === WalletStatus.Connecting) {
timeoutId = setTimeout(() => {
// Clear any existing timeout
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}

// Set new timeout
timeoutRef.current = setTimeout(() => {

Check warning on line 49 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L43-L49

Added lines #L43 - L49 were not covered by tests
setLocalStatus(WalletStatus.Error);
}, 10000); // 10 seconds timeout
}, 30000); // 30 seconds timeout

Check warning on line 51 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L51

Added line #L51 was not covered by tests
} else {
setLocalStatus(status);
// Clear timeout when status changes
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}

Check warning on line 57 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L54-L57

Added lines #L54 - L57 were not covered by tests
}

// Cleanup on unmount

Check warning on line 60 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L60

Added line #L60 was not covered by tests
return () => {
if (timeoutId) clearTimeout(timeoutId);
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}

Check warning on line 64 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L62-L64

Added lines #L62 - L64 were not covered by tests
};
}, [status]);

Expand Down Expand Up @@ -202,7 +214,11 @@ export const IconWallet: React.FC<WalletSectionProps> = ({ chainName }) => {
}

let onClick;
if (status === WalletStatus.Disconnected || status === WalletStatus.Rejected)
if (
status === WalletStatus.Disconnected ||
status === WalletStatus.Rejected ||
status === WalletStatus.Error
)

Check warning on line 221 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L217-L221

Added lines #L217 - L221 were not covered by tests
onClick = onClickConnect;
else onClick = openView;

Expand All @@ -211,12 +227,10 @@ export const IconWallet: React.FC<WalletSectionProps> = ({ chainName }) => {
return (
<div className="relative group">
<button
onClick={
status === WalletStatus.Disconnected || status === WalletStatus.Rejected
? onClick
: () => {}
}
className={`flex justify-center items-center w-8 h-8 hover:text-primary duration-200 ease-in-out ${status === WalletStatus.Disconnected || status === WalletStatus.Rejected ? 'cursor-pointer' : 'cursor-default'}`}
onClick={onClick}
className={`flex justify-center items-center w-8 h-8 hover:text-primary duration-200 ease-in-out ${
status === WalletStatus.Connected ? 'cursor-default' : 'cursor-pointer'
}`}

Check warning on line 233 in components/wallet.tsx

View check run for this annotation

Codecov / codecov/patch

components/wallet.tsx#L230-L233

Added lines #L230 - L233 were not covered by tests
>
<buttonData.icon className="w-8 h-8" />
</button>
Expand Down
2 changes: 1 addition & 1 deletion pages/groups/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function CreateGroup() {
const [currentStep, setCurrentStep] = useState(1);
const [formData, dispatch] = useReducer(formDataReducer, initialFormData);
const { address } = useChain(chainName);
console.log(formData);

const nextStep = () => {
if (currentStep < 5) {
setCurrentStep(currentStep + 1);
Expand Down
File renamed without changes

0 comments on commit 7ff68a0

Please sign in to comment.