2021-04-18 18:58:16 -07:00
|
|
|
import styled from '@emotion/styled'
|
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
|
|
|
import { WALLET_PROVIDERS, DEFAULT_PROVIDER } from '../hooks/useWallet'
|
|
|
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
|
|
|
import WalletSelect from './WalletSelect'
|
|
|
|
import { WalletIcon } from './icons'
|
|
|
|
|
|
|
|
const StyledWalletTypeLabel = styled.div`
|
|
|
|
font-size: 0.6rem;
|
|
|
|
`
|
|
|
|
|
|
|
|
const ConnectWalletButton = () => {
|
|
|
|
const wallet = useMangoStore((s) => s.wallet.current)
|
2021-05-04 16:19:48 -07:00
|
|
|
const set = useMangoStore((s) => s.set)
|
2021-04-18 18:58:16 -07:00
|
|
|
const [savedProviderUrl] = useLocalStorageState(
|
|
|
|
'walletProvider',
|
|
|
|
DEFAULT_PROVIDER.url
|
|
|
|
)
|
|
|
|
|
2021-05-04 16:19:48 -07:00
|
|
|
const handleWalletConect = () => {
|
|
|
|
wallet.connect()
|
|
|
|
set((state) => {
|
|
|
|
state.selectedMarginAccount.initialLoad = true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-18 18:58:16 -07:00
|
|
|
return (
|
|
|
|
<div className="flex justify-between border border-th-primary rounded-md h-11 w-48">
|
|
|
|
<button
|
2021-05-04 16:19:48 -07:00
|
|
|
onClick={handleWalletConect}
|
2021-04-20 11:45:23 -07:00
|
|
|
disabled={!wallet}
|
2021-04-25 14:22:14 -07:00
|
|
|
className="text-th-primary hover:text-th-fgd-1 hover:bg-th-primary focus:outline-none disabled:text-th-fgd-4 disabled:cursor-wait rounded-r-none"
|
2021-04-18 18:58:16 -07:00
|
|
|
>
|
2021-04-25 14:22:14 -07:00
|
|
|
<div className="flex flex-row items-center px-2 justify-center h-full rounded-l default-transition hover:text-th-fgd-1">
|
2021-04-18 18:58:16 -07:00
|
|
|
<WalletIcon className="w-5 h-5 mr-3 fill-current" />
|
|
|
|
<div>
|
|
|
|
<span className="whitespace-nowrap">Connect Wallet</span>
|
|
|
|
<StyledWalletTypeLabel className="font-normal text-th-fgd-1 text-left leading-3">
|
2021-04-25 10:08:11 -07:00
|
|
|
{WALLET_PROVIDERS.find((p) => p.url === savedProviderUrl)?.name}
|
2021-04-18 18:58:16 -07:00
|
|
|
</StyledWalletTypeLabel>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
<div className="relative h-full">
|
|
|
|
<WalletSelect isPrimary />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ConnectWalletButton
|