2021-04-14 18:54:23 -07:00
|
|
|
import { Menu } from '@headlessui/react'
|
2021-04-14 16:47:13 -07:00
|
|
|
import {
|
|
|
|
ChevronDownIcon,
|
|
|
|
ChevronUpIcon,
|
|
|
|
CheckCircleIcon,
|
2021-05-17 22:33:04 -07:00
|
|
|
} from '@heroicons/react/solid'
|
2021-04-13 22:23:50 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-04-14 15:46:36 -07:00
|
|
|
import { WALLET_PROVIDERS, DEFAULT_PROVIDER } from '../hooks/useWallet'
|
|
|
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
2021-04-13 22:23:50 -07:00
|
|
|
|
2021-04-19 09:15:49 -07:00
|
|
|
export default function WalletSelect({ isPrimary = false }) {
|
2021-04-13 22:23:50 -07:00
|
|
|
const setMangoStore = useMangoStore((s) => s.set)
|
2021-04-14 15:46:36 -07:00
|
|
|
const [savedProviderUrl] = useLocalStorageState(
|
|
|
|
'walletProvider',
|
|
|
|
DEFAULT_PROVIDER.url
|
|
|
|
)
|
2021-04-13 22:23:50 -07:00
|
|
|
|
|
|
|
const handleSelectProvider = (url) => {
|
|
|
|
setMangoStore((state) => {
|
|
|
|
state.wallet.providerUrl = url
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
2021-04-18 18:58:16 -07:00
|
|
|
<Menu.Button
|
2021-05-18 03:57:10 -07:00
|
|
|
className={`flex justify-center items-center h-full rounded-none focus:outline-none text-th-primary hover:text-th-fgd-1 ${
|
2021-04-18 18:58:16 -07:00
|
|
|
isPrimary
|
2021-05-18 03:57:10 -07:00
|
|
|
? 'px-3 hover:bg-th-bkg-3'
|
2021-04-18 18:58:16 -07:00
|
|
|
: 'px-2 hover:bg-th-bkg-3 border-l border-th-fgd-4'
|
|
|
|
} cursor-pointer`}
|
|
|
|
>
|
2021-04-14 16:47:13 -07:00
|
|
|
{open ? (
|
2021-05-17 22:33:04 -07:00
|
|
|
<ChevronUpIcon className="h-4 w-4" />
|
2021-04-14 16:47:13 -07:00
|
|
|
) : (
|
2021-05-17 22:33:04 -07:00
|
|
|
<ChevronDownIcon className="h-4 w-4" />
|
2021-04-14 16:47:13 -07:00
|
|
|
)}
|
2021-04-13 22:23:50 -07:00
|
|
|
</Menu.Button>
|
2021-05-18 03:57:10 -07:00
|
|
|
<Menu.Items className="absolute bg-th-bkg-1 divide-y divide-th-bkg-3 p-1 rounded-md right-0.5 mt-1 shadow-lg outline-none w-48 z-20">
|
2021-04-14 18:54:23 -07:00
|
|
|
{WALLET_PROVIDERS.map(({ name, url, icon }) => (
|
|
|
|
<Menu.Item key={name}>
|
|
|
|
<button
|
2021-05-17 22:33:04 -07:00
|
|
|
className="flex flex-row items-center justify-between rounded-none w-full p-2 hover:bg-th-bkg-2 hover:cursor-pointer font-normal focus:outline-none"
|
2021-04-14 18:54:23 -07:00
|
|
|
onClick={() => handleSelectProvider(url)}
|
|
|
|
>
|
|
|
|
<div className="flex">
|
|
|
|
<img src={icon} className="w-5 h-5 mr-2" />
|
2021-04-13 22:23:50 -07:00
|
|
|
{name}
|
2021-04-14 18:54:23 -07:00
|
|
|
</div>
|
|
|
|
{savedProviderUrl === url ? (
|
|
|
|
<CheckCircleIcon className="h-4 w-4 text-th-green" />
|
|
|
|
) : null}{' '}
|
|
|
|
</button>
|
|
|
|
</Menu.Item>
|
|
|
|
))}
|
|
|
|
</Menu.Items>
|
2021-04-13 22:23:50 -07:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|