1import { useCallback, useMemo, useState } from 'react';
2import { Icon, Row, Box } from '@tlon/indigo-react';
3import { Just } from 'folktale/maybe';
5import LayerIndicator from 'components/L2/LayerIndicator';
6import CopiableAddressWrap from 'components/copiable/CopiableAddressWrap';
7import { TooltipPosition } from 'components/WithTooltip';
9import { useWallet } from 'store/wallet';
10import { useHistory } from 'store/history';
11import { usePointCursor } from 'store/pointCursor';
12import { clearInvitesStorage } from 'store/storage/roller';
13import { useRollerStore } from 'store/rollerStore';
15import { abbreviateAddress } from 'lib/utils/address';
17import Dropdown from './Dropdown';
18import './AccountsDropdown.scss';
20interface AccountsDropdownProps {
24const AccountsDropdown = ({ showMigrate = false }: AccountsDropdownProps) => {
25 const [open, setOpen] = useState<boolean>(false);
26 const walletInfo: any = useWallet();
27 const { push, popTo, names, reset }: any = useHistory();
28 const { setPointCursor }: any = usePointCursor();
29 const { point, pointList } = useRollerStore();
31 const canBitcoin = Just.hasInstance(walletInfo.urbitWallet);
33 const currentAddress = walletInfo?.wallet?.value?.address || '';
34 const displayAddress = abbreviateAddress(currentAddress);
36 const selectPoint = useCallback(
37 (point: number) => () => {
39 setPointCursor(Just(point));
43 [push, popTo, names, setOpen, setPointCursor]
46 const goHome = useCallback(() => popTo(names.POINTS), [names, popTo]);
48 const goMigrate = useCallback(() => push(names.MIGRATE_L2), [
53 const goBitcoin = useCallback(() => push(names.BITCOIN), [
58 const goSpawn = useCallback(() => {
59 if (point.isL2Spawn && point.isStar) {
60 push(names.INVITE_COHORT);
62 push(names.ISSUE_CHILD);
64 }, [names, push, point]);
66 const onLogout = () => {
67 clearInvitesStorage();
71 const hasL1Points = Boolean(pointList.find(({ layer }) => layer === 1));
72 const showMigrateOption = useMemo(() => {
73 return showMigrate || hasL1Points;
74 }, [hasL1Points, showMigrate]);
77 point.value >= 0 ? point.patp : currentAddress.slice(0, 6);
79 const displayedPoints = useMemo(
80 () => pointList.filter(({ ownManageSpawn }) => ownManageSpawn),
86 className="accounts-dropdown"
89 toggleOpen={() => setOpen(!open)}>
91 className="current-address"
92 position={TooltipPosition.Left}
93 text={currentAddress}>
94 <Box onClick={goHome}>{displayAddress}</Box>
95 </CopiableAddressWrap>
96 <Box className="divider" />
97 <Box className="points">
98 {displayedPoints.map(({ value, layer, patp }) => (
100 className={`entry point ${value === point.value ? 'selected' : ''}`}
101 onClick={selectPoint(value)}
102 key={`point-${value}`}>
108 selected={value === point.value}
114 <Box className="divider" />
115 {showMigrateOption && (
116 <Row className="entry" onClick={goMigrate}>
118 <Row className="layer-migration">
119 <LayerIndicator layer={1} size="sm" />
120 <Icon icon="ArrowEast" />
121 <LayerIndicator layer={2} size="sm" />
126 <Row className="entry" onClick={goBitcoin}>
128 <Icon icon="Bitcoin" />
131 {point.isParent && point.canSpawn && point.isL1 && (
132 <Row className="entry" onClick={goSpawn}>
133 <Box>Spawn{point.isStar ? ' Planets' : ' Stars'}</Box>
137 <Row className="entry" onClick={onLogout}>
139 <Icon icon="LogOut" />
145export default AccountsDropdown;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list