mango-v4-ui/components/wallet/WalletSelect.tsx

65 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-07-26 19:45:27 -07:00
import React, { Fragment } from 'react'
2022-07-21 22:09:04 -07:00
import { useWallet } from '@solana/wallet-adapter-react'
2022-09-06 21:36:35 -07:00
import { ChevronDownIcon } from '@heroicons/react/20/solid'
2022-07-26 19:45:27 -07:00
import { Menu, Transition } from '@headlessui/react'
2022-09-12 08:53:57 -07:00
import mangoStore from '@store/mangoStore'
2022-07-21 22:09:04 -07:00
const WalletSelect = () => {
2022-07-26 21:40:17 -07:00
const { wallets, select } = useWallet()
2022-08-25 20:46:23 -07:00
const group = mangoStore((s) => s.group)
2022-07-21 22:09:04 -07:00
return (
2022-07-26 19:45:27 -07:00
<Menu>
{({ open }) => (
<>
<Menu.Button
2022-09-13 23:24:26 -07:00
className={`flex h-full w-12 cursor-pointer items-center justify-center rounded-none bg-transparent text-white hover:brightness-[1.1] focus:outline-none disabled:opacity-25`}
2022-08-25 20:46:23 -07:00
disabled={!group}
2022-07-26 19:45:27 -07:00
>
<ChevronDownIcon
className={`default-transition h-6 w-6 ${
open ? 'rotate-180' : 'rotate-360'
2022-07-26 19:45:27 -07:00
}`}
2022-07-21 22:09:04 -07:00
/>
2022-07-26 19:45:27 -07:00
</Menu.Button>
<Transition
appear={true}
show={open}
as={Fragment}
enter="transition ease-in duration-200"
enterFrom="opacity-0 scale-75"
enterTo="opacity-100 scale-100"
2022-07-26 19:45:27 -07:00
leave="transition ease-out duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
2022-07-26 21:40:17 -07:00
<Menu.Items className="absolute top-16 right-0 z-20 w-44 rounded-md rounded-t-none border border-t-0 border-th-bkg-3 bg-th-bkg-1 px-4 py-2.5 outline-none">
2022-07-26 19:45:27 -07:00
{wallets?.map((wallet, index) => (
<Menu.Item key={index}>
<button
className="flex w-full flex-row items-center justify-between rounded-none py-1.5 font-normal focus:outline-none md:hover:cursor-pointer md:hover:text-th-primary"
onClick={() => {
select(wallet.adapter.name)
}}
>
<div className="flex items-center">
<img
src={wallet.adapter.icon}
className="mr-2 h-5 w-5"
alt={`${wallet.adapter.name} icon`}
/>
{wallet.adapter.name}
</div>
</button>
</Menu.Item>
))}
</Menu.Items>
</Transition>
</>
)}
</Menu>
2022-07-21 22:09:04 -07:00
)
}
export default WalletSelect