import React, { PureComponent } from 'react'; import QRCode from 'qrcode.react'; import dateformat from 'dateformat'; import cstyles from './Common.module.css'; import styles from './WormholeConnection.module.css'; import CompanionAppListener from '../companion'; import { ConnectedCompanionApp } from './AppState'; type Props = { companionAppListener: CompanionAppListener, connectedCompanionApp: ConnectedCompanionApp | null }; type State = { tempKeyHex: string }; export default class WormholeConnection extends PureComponent { constructor(props) { super(props); this.state = { tempKeyHex: null }; } componentDidMount() { // If there is no temp key, create one const { companionAppListener } = this.props; const { tempKeyHex } = this.state; if (!tempKeyHex) { const newKey = companionAppListener.genNewKeyHex(); companionAppListener.createTmpClient(newKey); this.setState({ tempKeyHex: newKey }); } } componentWillUnmount() { const { companionAppListener } = this.props; companionAppListener.closeTmpClient(); } disconnectCurrentMobile = () => { const { companionAppListener } = this.props; companionAppListener.disconnectLastClient(); }; render() { const { tempKeyHex } = this.state; const { connectedCompanionApp } = this.props; const clientName = (connectedCompanionApp && connectedCompanionApp.name) || null; const lastSeen = (connectedCompanionApp && connectedCompanionApp.lastSeen) || null; let datePart = null; let timePart = null; if (lastSeen) { const txDate = new Date(lastSeen); datePart = dateformat(txDate, 'mmm dd, yyyy'); timePart = dateformat(txDate, 'hh:MM tt'); } const connStr = `ws://127.0.0.1:7070,${tempKeyHex},1`; return (
Connect Mobile App
This is your connection code. Scan this QR code from the Zecwallet Companion App.
{connStr}
{clientName && (
Current App Connected:
{clientName}
Last Seen:
{datePart} {timePart}
)} {!clientName &&
No Companion App Connected
}
); } }