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

Refactor default Mobile Wallet Adapter button UI #1005

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 41 additions & 11 deletions packages/ui/react-ui/src/WalletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Collapse } from './Collapse.js';
import { WalletListItem } from './WalletListItem.js';
import { WalletSVG } from './WalletSVG.js';
import { useWalletModal } from './useWalletModal.js';
import { SolanaMobileWalletAdapterWalletName } from '@solana-mobile/wallet-adapter-mobile';
import { Button } from './Button.js';

export interface WalletModalProps {
className?: string;
Expand All @@ -23,19 +25,23 @@ export const WalletModal: FC<WalletModalProps> = ({ className = '', container =
const [fadeIn, setFadeIn] = useState(false);
const [portal, setPortal] = useState<Element | null>(null);

const [listedWallets, collapsedWallets] = useMemo(() => {
const [listedWallets, collapsedWallets, mobileWalletAdapter] = useMemo(() => {
const installed: Wallet[] = [];
const notInstalled: Wallet[] = [];

let mobileWalletAdapter;
for (const wallet of wallets) {
if (wallet.readyState === WalletReadyState.Installed) {
if (wallet.adapter.name === SolanaMobileWalletAdapterWalletName) {
mobileWalletAdapter = wallet;
} else if (wallet.readyState === WalletReadyState.Installed) {
installed.push(wallet);
} else {
notInstalled.push(wallet);
}
}

return installed.length ? [installed, notInstalled] : [notInstalled, []];
return installed.length
? [installed, notInstalled, mobileWalletAdapter]
: [notInstalled, [], mobileWalletAdapter];
}, [wallets]);

const hideModal = useCallback(() => {
Expand Down Expand Up @@ -137,16 +143,40 @@ export const WalletModal: FC<WalletModalProps> = ({ className = '', container =
{listedWallets.length ? (
<>
<h1 className="wallet-adapter-modal-title">Connect a wallet on Solana to continue</h1>
{mobileWalletAdapter && (
<>
<h2 className="wallet-adapter-modal-header">On your phone: </h2>
<Button
className="mobile-wallet-adapter-button"
onClick={(event) =>
handleWalletClick(event, mobileWalletAdapter.adapter.name)
}
>
<span>Use an installed wallet</span>
</Button>
</>
)}
<ul className="wallet-adapter-modal-list">
{listedWallets.map((wallet) => (
<WalletListItem
key={wallet.adapter.name}
handleClick={(event) => handleWalletClick(event, wallet.adapter.name)}
wallet={wallet}
/>
))}
{mobileWalletAdapter && !collapsedWallets.length && (
<h2 className="wallet-adapter-modal-header">Other wallets: </h2>
)}
{listedWallets.map((wallet) => {
if (wallet.adapter.name === SolanaMobileWalletAdapterWalletName) {
return;
}
return (
<WalletListItem
key={wallet.adapter.name}
handleClick={(event) => handleWalletClick(event, wallet.adapter.name)}
wallet={wallet}
/>
);
})}
{collapsedWallets.length ? (
<Collapse expanded={expanded} id="wallet-adapter-modal-collapse">
{mobileWalletAdapter && listedWallets.length === 1 && (
<h2 className="wallet-adapter-modal-header">Other wallets: </h2>
)}
{collapsedWallets.map((wallet) => (
<WalletListItem
key={wallet.adapter.name}
Expand Down
22 changes: 22 additions & 0 deletions packages/ui/react-ui/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,28 @@
color: #fff;
}

.wallet-adapter-modal-header {
font-weight: 400;
font-size: 16px;
line-height: 16px;
margin: 0;
padding: 0px 24px 8px 24px;
text-align: left;
align-self: flex-start;
color: #fff;
}

.mobile-wallet-adapter-button {
background-color: #512da8;
font-weight: 400;
max-width: 85%;
border-radius: 16px;
margin: 12px 12px 36px 12px;
font-size: 18px;
justify-content: center;
}


@media (max-width: 374px) {
.wallet-adapter-modal-title {
font-size: 18px;
Expand Down