|
| 1 | +import styled from '@emotion/styled'; |
| 2 | +import { ConnectButton as RainbowKitConnectButton } from '@rainbow-me/rainbowkit'; |
| 3 | +import { WalletIcon } from 'lucide-react'; |
| 4 | + |
| 5 | +import { OpticianSans } from '@/fonts'; |
| 6 | +import { shortenAddress } from '@/utils/address'; |
| 7 | + |
| 8 | +export const ConnectButton: React.FC = () => { |
| 9 | + return ( |
| 10 | + <RainbowKitConnectButton.Custom> |
| 11 | + {({ |
| 12 | + account, |
| 13 | + chain, |
| 14 | + openAccountModal, |
| 15 | + openChainModal, |
| 16 | + openConnectModal, |
| 17 | + mounted, |
| 18 | + }) => { |
| 19 | + const ready = mounted; |
| 20 | + const connected = mounted && account && chain; |
| 21 | + |
| 22 | + return ( |
| 23 | + <div |
| 24 | + {...(!ready && { |
| 25 | + 'aria-hidden': true, |
| 26 | + style: { |
| 27 | + opacity: 0, |
| 28 | + pointerEvents: 'none', |
| 29 | + userSelect: 'none', |
| 30 | + }, |
| 31 | + })} |
| 32 | + > |
| 33 | + {(() => { |
| 34 | + if (!connected) { |
| 35 | + return ( |
| 36 | + <ConnectWalletButton onClick={openConnectModal} type="button"> |
| 37 | + Connect Wallet |
| 38 | + </ConnectWalletButton> |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + // FIXME: Check styles here |
| 43 | + if (chain.unsupported) { |
| 44 | + return ( |
| 45 | + <Button onClick={openChainModal} type="button"> |
| 46 | + Wrong network |
| 47 | + </Button> |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + return ( |
| 52 | + <div style={{ display: 'flex', gap: 12 }}> |
| 53 | + <UserButton onClick={openAccountModal} type="button"> |
| 54 | + <WalletIcon size={14} /> |
| 55 | + |
| 56 | + <span className="address"> |
| 57 | + {shortenAddress(account.address)}{' '} |
| 58 | + <span className="balance"> |
| 59 | + {account.displayBalance |
| 60 | + ? ` (${account.displayBalance})` |
| 61 | + : ''} |
| 62 | + </span> |
| 63 | + </span> |
| 64 | + </UserButton> |
| 65 | + </div> |
| 66 | + ); |
| 67 | + })()} |
| 68 | + </div> |
| 69 | + ); |
| 70 | + }} |
| 71 | + </RainbowKitConnectButton.Custom> |
| 72 | + ); |
| 73 | +}; |
| 74 | + |
| 75 | +const Button = styled.button` |
| 76 | + width: fit-content; |
| 77 | + display: flex; |
| 78 | + padding: 4px 14px; |
| 79 | + justify-content: center; |
| 80 | + align-items: center; |
| 81 | + gap: 10px; |
| 82 | +
|
| 83 | + border-radius: 8px; |
| 84 | + background: #18edeb; |
| 85 | +
|
| 86 | + color: #000; |
| 87 | + text-align: center; |
| 88 | + font-family: ${OpticianSans.style.fontFamily}; |
| 89 | + font-size: 20px; |
| 90 | + font-style: normal; |
| 91 | + font-weight: 400; |
| 92 | + line-height: 100%; |
| 93 | +`; |
| 94 | +const ConnectWalletButton = styled(Button)` |
| 95 | + padding: 4px 16px; |
| 96 | +`; |
| 97 | + |
| 98 | +const UserButton = styled(Button)` |
| 99 | + background: #253738; |
| 100 | + color: #fff; |
| 101 | +
|
| 102 | + & > svg { |
| 103 | + color: rgba(255, 255, 255, 0.6); |
| 104 | + } |
| 105 | +
|
| 106 | + & > span { |
| 107 | + font-weight: 500; |
| 108 | + font-size: 20px; |
| 109 | + line-height: 1; |
| 110 | + text-align: center; |
| 111 | + letter-spacing: -0.04em; |
| 112 | + } |
| 113 | +
|
| 114 | + span.balance { |
| 115 | + opacity: 0.7; |
| 116 | +
|
| 117 | + @media (max-width: 820px) { |
| 118 | + display: none; |
| 119 | + } |
| 120 | + } |
| 121 | +`; |
0 commit comments