import React, { useCallback, useState } from 'react';
import { P, H4, H5, Grid, Text, Button, Flex, LinkButton } from 'indigo-react';
import { Just } from 'folktale/maybe';
import ob from 'urbit-ob';
import { version } from '../../package.json';
import { useHistory } from 'store/history';
import { useWallet } from 'store/wallet';
import { usePointCursor } from 'store/pointCursor';
import { WALLET_TYPES } from 'lib/wallet';
import { COMMANDS, useFlowCommand } from 'lib/flowCommand';
import View from 'components/View';
import Tabs from 'components/Tabs';
import Crumbs from 'components/Crumbs';
import Footer from 'components/Footer';
import { ForwardButton, OfflineButton } from 'components/Buttons';
import Ticket from './Login/Ticket';
import Other from './Login/Other';
const NAMES = {
TICKET: 'TICKET',
OTHER: 'OTHER',
};
const VIEWS = {
[NAMES.TICKET]: Ticket,
[NAMES.OTHER]: Other,
};
const OPTIONS = [
{ text: 'Master Ticket', value: NAMES.TICKET },
{ text: 'Other', value: NAMES.OTHER },
];
const walletTypeToViewName = walletType => {
if (walletType === WALLET_TYPES.TICKET || !walletType) {
return NAMES.TICKET;
}
return NAMES.OTHER;
};
export default function Login() {
// globals
const { pop, push, names } = useHistory();
const { walletType } = useWallet();
const { setPointCursor } = usePointCursor();
const flow = useFlowCommand();
// inputs
const [isOther, setisOther] = useState(false);
const goToActivate = useCallback(() => push(names.ACTIVATE), [
push,
names.ACTIVATE,
]);
const goHome = useCallback(() => {
if (!flow) {
push(names.POINTS);
} else {
switch (flow.kind) {
case COMMANDS.INVITE:
setPointCursor(Just(ob.patp2dec(flow.as)));
push(names.JUST_INVITE);
break;
//
default:
throw new Error('unimplemented flow ' + flow.kind);
break;
}
}
}, [flow, push, names]);
const flowDescription = command => {
switch (command.kind) {
case COMMANDS.INVITE:
return (
<>
To send an invite, please sign in as {command.as}.
>
);
break;
}
};
return (
Urbit ID /
Login
{flow && (
{flowDescription(flow)}
)}
{!isOther && (
<>
or
setisOther(true)}>
Metamask, Mnemonic, Hardware Wallet...
{!flow && (
New Urbit ID?
Activate
)}
>
)}
{isOther && (
setisOther(false)}
full
className="t-center underline f6 mt8">
Back
)}
);
}