2022-07-26 19:45:27 -07:00
|
|
|
import React, { Fragment } from '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-11-15 20:12:51 -08:00
|
|
|
import { useEnhancedWallet } from './EnhancedWalletProvider'
|
2022-11-20 12:32:38 -08:00
|
|
|
import useMangoGroup from 'hooks/useMangoGroup'
|
2022-07-21 22:09:04 -07:00
|
|
|
|
|
|
|
const WalletSelect = () => {
|
2022-11-15 20:12:51 -08:00
|
|
|
const { displayedWallets, handleSelect } = useEnhancedWallet()
|
2022-11-20 12:32:38 -08:00
|
|
|
const { group } = useMangoGroup()
|
2022-07-21 22:09:04 -07:00
|
|
|
|
|
|
|
return (
|
2022-07-26 19:45:27 -07:00
|
|
|
<Menu>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<Menu.Button
|
2022-11-30 19:32:32 -08:00
|
|
|
className={`flex h-full w-12 cursor-pointer items-center justify-center rounded-none bg-transparent text-th-fgd-3 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 ${
|
2022-08-16 15:58:03 -07:00
|
|
|
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}
|
2022-08-16 15:58:03 -07:00
|
|
|
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-10-05 17:04:16 -07:00
|
|
|
<Menu.Items className="absolute top-16 right-0 z-20 w-44 rounded-md rounded-t-none bg-th-bkg-2 px-4 py-2.5 outline-none">
|
2022-11-15 20:12:51 -08:00
|
|
|
{displayedWallets?.map((wallet, index) => (
|
2022-07-26 19:45:27 -07:00
|
|
|
<Menu.Item key={index}>
|
|
|
|
<button
|
2022-11-30 19:32:32 -08:00
|
|
|
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-active"
|
2022-07-26 19:45:27 -07:00
|
|
|
onClick={() => {
|
2022-11-15 20:12:51 -08:00
|
|
|
handleSelect(wallet.adapter.name)
|
2022-07-26 19:45:27 -07:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<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
|