import { Just, Nothing } from 'folktale/maybe';
import React from 'react';
import * as azimuth from 'azimuth-js';
import * as need from 'lib/need';
import View from 'components/View';
import {
InnerLabel,
Warning,
TicketInput,
VerifyTicketInput,
Button,
Passport,
} from '../components/old/Base';
import { randomPatq, compose } from '../lib/lib';
import { ROUTE_NAMES } from '../lib/routeNames';
import { withHistory } from '../store/history';
import {
DEFAULT_HD_PATH,
ownershipWalletFromTicket,
walletFromMnemonic,
} from '../lib/wallet';
import { BRIDGE_ERROR } from '../lib/error';
import {
INVITE_STAGES,
WALLET_STATES,
TRANSACTION_STATES,
} from '../lib/invite';
import { generateWallet, startTransactions } from '../lib/invite';
import { withNetwork } from '../store/network';
import { withWallet } from '../store/wallet';
import Grid from 'components/Grid';
class InviteTicket extends React.Component {
constructor(props) {
super(props);
this.state = {
inviteTicket: '',
inviteWallet: Nothing(),
verifyTicket: '',
realTicket: '',
realPoint: Nothing(),
realWallet: Nothing(),
walletReady: false,
walletStates: [],
errors: [],
stage: INVITE_STAGES.INVITE_LOGIN,
transactionProgress: TRANSACTION_STATES.GENERATING,
};
this.pointPlaceholder = randomPatq(4);
this.ticketPlaceholder = randomPatq(12);
this.handleInviteTicketInput = this.handleInviteTicketInput.bind(this);
this.handleVerifyTicketInput = this.handleVerifyTicketInput.bind(this);
this.updateProgress = this.updateProgress.bind(this);
this.pushWalletState = this.pushWalletState.bind(this);
this.navigateLogin = this.navigateLogin.bind(this);
}
pushWalletState(walletState) {
this.setState({
walletStates: this.state.walletStates.concat(walletState),
});
}
navigateLogin() {
this.props.history.pop();
this.props.history.push(ROUTE_NAMES.NETWORK);
}
handleInviteTicketInput(inviteTicket) {
this.setState({ inviteTicket });
}
handleVerifyTicketInput(verifyTicket) {
this.setState({ verifyTicket });
}
updateTransactionProgress(transactionProgress) {
this.setState({ transactionProgress });
}
async unlockInviteWallet(inviteTicket) {
this.setState({
walletStates: this.state.walletStates.concat(WALLET_STATES.UNLOCKING),
stage: INVITE_STAGES.INVITE_WALLET,
});
//NOTE ~zod because tmp wallet
const ownership = await ownershipWalletFromTicket(inviteTicket, 0);
const mnemonic = ownership.seed;
//TODO isn't all this accessible in the ownership object?
const inviteWallet = walletFromMnemonic(
mnemonic,
DEFAULT_HD_PATH
).matchWith({
Just: w => w.value,
Nothing: () => {
throw BRIDGE_ERROR.MISSING_WALLET;
},
});
const addr = inviteWallet.address;
const contracts = need.contracts(this.props.contracts);
const incoming = await azimuth.azimuth.getTransferringFor(contracts, addr);
this.setState({
walletStates: this.state.walletStates.concat(WALLET_STATES.GENERATING),
});
let realPoint = Nothing();
let realWallet = Nothing();
let errors = [];
if (incoming.length > 0) {
let pointNum = parseInt(incoming[0], 10);
realPoint = Just(pointNum);
this.setState({
realPoint,
});
let genWallet = await generateWallet(pointNum);
realWallet = Just(genWallet);
if (incoming.length > 1) {
//TODO notify user "...and others / ticket reusable"
}
} else {
errors = [
'Invite code has no claimable ship. Check your invite code and try again.',
];
}
this.setState({
realWallet,
inviteWallet: Just(inviteWallet),
// dev mode: uncomment this out to autofill verified ticket
verifyTicket: !Nothing.hasInstance(realWallet)
? realWallet.value.ticket
: '',
walletStates: this.state.walletStates.concat(WALLET_STATES.RENDERING),
errors,
});
}
getTicketElement() {
const phTick = this.ticketPlaceholder;
let isLogin = this.state.stage === INVITE_STAGES.INVITE_LOGIN;
let isVerify = this.state.stage === INVITE_STAGES.INVITE_VERIFY;
if (isLogin || isVerify) {
let value = isLogin ? this.state.inviteTicket : this.state.verifyTicket;
let handler = isLogin
? this.handleInviteTicketInput
: this.handleVerifyTicketInput;
let label = isLogin ? 'Activation code' : 'ticket';
// if realWallet is Just, then VerifyTicketInput appropriate contents; if Nothing, remain Nothing
const Verified = this.state.realWallet.map(realWallet =>
VerifyTicketInput(realWallet.ticket)
);
// Verified.getOrElse(TicketInput) falls back to TicketInput if Verified is Nothing
const TicketElem = isVerify
? Verified.getOrElse(TicketInput)
: TicketInput;
return (
A passport is your digital identity. You will use your passport to access your true computer, send payments, and administer your identity. So naturally, you must keep this secure.
After you’ve downloaded your passport, back up the ticket manually or store on a trusted device.
Afer you download your passport, verify your custody. Your passport should be a folder of image files. One of them is your Master Ticket. Open it and enter the 4 word phrase below (with hyphens).
Transferring to Bridge...
This step can take up to five minutes. Please do not leave this page until the transactions are complete.