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

60 lines
2.3 KiB
TypeScript
Raw Normal View History

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'
2023-03-26 20:11:10 -07:00
import { Popover, 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 (
2023-03-26 20:11:10 -07:00
<Popover>
2022-07-26 19:45:27 -07:00
{({ open }) => (
<>
2023-03-26 20:11:10 -07:00
<Popover.Button
2023-04-24 19:09:18 -07:00
className={`flex h-16 w-10 cursor-pointer items-center justify-center rounded-none border-l border-th-bkg-4 bg-th-bkg-3 text-th-fgd-3 hover:brightness-[1.1] focus:outline-none focus-visible:bg-th-bkg-4 disabled:opacity-25`}
2022-08-25 20:46:23 -07:00
disabled={!group}
2022-07-26 19:45:27 -07:00
>
<ChevronDownIcon
2023-04-19 18:12:45 -07:00
className={`h-6 w-6 ${open ? 'rotate-180' : 'rotate-360'}`}
2022-07-21 22:09:04 -07:00
/>
2023-03-26 20:11:10 -07:00
</Popover.Button>
2022-07-26 19:45:27 -07:00
<Transition
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"
>
2023-03-26 20:11:10 -07:00
<Popover.Panel 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) => (
2023-03-26 20:11:10 -07:00
<button
className="flex w-full flex-row items-center justify-between rounded-none py-1.5 font-normal focus:outline-none focus-visible:text-th-active md:hover:cursor-pointer md:hover:text-th-active"
2023-03-26 20:11:10 -07:00
onClick={() => {
handleSelect(wallet.adapter.name)
}}
key={wallet.adapter.name + index}
>
<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>
2022-07-26 19:45:27 -07:00
))}
2023-03-26 20:11:10 -07:00
</Popover.Panel>
2022-07-26 19:45:27 -07:00
</Transition>
</>
)}
2023-03-26 20:11:10 -07:00
</Popover>
2022-07-21 22:09:04 -07:00
)
}
export default WalletSelect