This commit is contained in:
Chris Troutner
2022-07-03 11:35:47 -07:00
parent 30df1bf59a
commit 30281b9108
5 changed files with 35 additions and 36 deletions
+2 -3
View File
@@ -14,7 +14,6 @@ import WaitingModal from './components/waiting-modal'
import AsyncLoad from './services/async-load' import AsyncLoad from './services/async-load'
import ServerSelect from './components/servers' import ServerSelect from './components/servers'
import Footer from './components/footer' import Footer from './components/footer'
import GetBalance from './components/balance'
import NavMenu from './components/nav-menu' import NavMenu from './components/nav-menu'
import AppBody from './components/app-body' import AppBody from './components/app-body'
@@ -81,7 +80,7 @@ class App extends React.Component {
<> <>
<GetRestUrl /> <GetRestUrl />
<LoadScripts /> <LoadScripts />
<NavMenu menuHandler={this.handleMenuClick}/> <NavMenu menuHandler={this.onMenuClick} />
{this.state.walletInitialized ? <InitializedView wallet={this.state.wallet} menuState={this.state.menuState} /> : <UninitializedView modalBody={this.state.modalBody} hideSpinner={this.state.hideSpinner} />} {this.state.walletInitialized ? <InitializedView wallet={this.state.wallet} menuState={this.state.menuState} /> : <UninitializedView modalBody={this.state.modalBody} hideSpinner={this.state.hideSpinner} />}
<ServerSelect /> <ServerSelect />
<Footer /> <Footer />
@@ -101,7 +100,7 @@ class App extends React.Component {
// This handler is passed into the child menu component. When an item in the // This handler is passed into the child menu component. When an item in the
// nav menu is clicked, this handler will update the state. The state is // nav menu is clicked, this handler will update the state. The state is
// used by the AppBody component to determine which View component to display. // used by the AppBody component to determine which View component to display.
handleMenuClick(menuState) { onMenuClick (menuState) {
// console.log('menuState: ', menuState) // console.log('menuState: ', menuState)
_this.setState({ _this.setState({
+7 -9
View File
@@ -16,7 +16,7 @@ import TakePicture from '../take-picture'
let _this let _this
class AppBody extends React.Component { class AppBody extends React.Component {
constructor(props) { constructor (props) {
super(props) super(props)
this.state = { this.state = {
@@ -28,28 +28,26 @@ class AppBody extends React.Component {
_this = this _this = this
} }
render() { render () {
// console.log(`AppBody menu state: ${this.props.menuState}`) // console.log(`AppBody menu state: ${this.props.menuState}`)
return( return (
<> <>
{this.chooseView(this.props.menuState)} {this.chooseView(this.props.menuState)}
</> </>
) )
} }
chooseView(menuState) { chooseView (menuState) {
// console.log(`chooseView() menuState: ${menuState}`) // console.log(`chooseView() menuState: ${menuState}`)
switch(menuState) { switch (menuState) {
case 0: case 0:
return(<GetBalance wallet={_this.state.wallet} />) return (<GetBalance wallet={_this.state.wallet} />)
break
case 1: case 1:
return (<TakePicture />) return (<TakePicture />)
break
default: default:
return(<GetBalance wallet={_this.state.wallet} />) return (<GetBalance wallet={_this.state.wallet} />)
} }
} }
} }
+7 -7
View File
@@ -9,7 +9,7 @@ import { Container, Row, Col, Form, Button, Spinner } from 'react-bootstrap'
let _this let _this
class GetBalance extends React.Component { class GetBalance extends React.Component {
constructor(props) { constructor (props) {
super(props) super(props)
this.state = { this.state = {
@@ -31,10 +31,10 @@ class GetBalance extends React.Component {
<Form> <Form>
<Form.Group className='mb-3' controlId='formBasicEmail'> <Form.Group className='mb-3' controlId='formBasicEmail'>
<Form.Label>Enter a BCH address to check the balance.</Form.Label> <Form.Label>Enter a BCH address to check the balance.</Form.Label>
<Form.Control type='text' placeholder='bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d' onChange={e => this.setState({textInput: e.target.value})} /> <Form.Control type='text' placeholder='bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d' onChange={e => this.setState({ textInput: e.target.value })} />
</Form.Group> </Form.Group>
<Button variant='primary' onClick={this.getBalance}> <Button variant='primary' onClick={this.handleGetBalance}>
Check Balance Check Balance
</Button> </Button>
</Form> </Form>
@@ -51,13 +51,13 @@ class GetBalance extends React.Component {
) )
} }
async getBalance(event) { async handleGetBalance (event) {
try { try {
const textInput = _this.state.textInput const textInput = _this.state.textInput
// Exit on invalid input // Exit on invalid input
if(!textInput) return if (!textInput) return
if(!textInput.includes('bitcoincash:')) return if (!textInput.includes('bitcoincash:')) return
_this.setState({ _this.setState({
balance: (<span>Retrieving balance... <Spinner animation='border' /></span>) balance: (<span>Retrieving balance... <Spinner animation='border' /></span>)
@@ -71,7 +71,7 @@ class GetBalance extends React.Component {
_this.setState({ _this.setState({
balance: `Balance: ${balance} sats, ${bchBalance} BCH` balance: `Balance: ${balance} sats, ${bchBalance} BCH`
}) })
} catch(err) { } catch (err) {
_this.setState({ _this.setState({
balance: `Error: ${err.message}` balance: `Error: ${err.message}`
}) })
+14 -14
View File
@@ -7,11 +7,11 @@
// Global npm libraries // Global npm libraries
import React from 'react' import React from 'react'
import { Nav, Navbar, Image } from "react-bootstrap" import { Nav, Navbar, Image } from 'react-bootstrap'
import Logo from './psf-logo.png' import Logo from './psf-logo.png'
class NavMenu extends React.Component { class NavMenu extends React.Component {
constructor(props) { constructor (props) {
super(props) super(props)
// This is the event handler passed in from the Parent component. // This is the event handler passed in from the Parent component.
@@ -22,24 +22,24 @@ class NavMenu extends React.Component {
// } // }
} }
render() { render () {
// console.log(`selectedMenuItem: ${this.state.selectedMenuItem}`) // console.log(`selectedMenuItem: ${this.state.selectedMenuItem}`)
// this.handleMenuClick(this.state.selectedMenuItem) // this.handleMenuClick(this.state.selectedMenuItem)
return( return (
<> <>
<Navbar collapseOnSelect expand="xxxl" bg="dark" variant="dark" style={{paddingRight: '20px'}} > <Navbar collapseOnSelect expand='xxxl' bg='dark' variant='dark' style={{ paddingRight: '20px' }}>
<Navbar.Brand href="#home" style={{paddingLeft: '20px'}}> <Navbar.Brand href='#home' style={{ paddingLeft: '20px' }}>
<Image src={Logo} thumbnail width="50" />{' '} <Image src={Logo} thumbnail width='50' />{' '}
PSF Web3 Demo PSF Web3 Demo
</Navbar.Brand> </Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" /> <Navbar.Toggle aria-controls='responsive-navbar-nav' />
<Navbar.Collapse id="responsive-navbar-nav"> <Navbar.Collapse id='responsive-navbar-nav'>
<Nav className="mr-auto"> <Nav className='mr-auto'>
<Nav.Link href="#" onClick={() => this.handleClickEvent(0)}>Check Balance</Nav.Link> <Nav.Link href='#' onClick={() => this.handleClickEvent(0)}>Check Balance</Nav.Link>
<Nav.Link href="#" onClick={() => this.handleClickEvent(1)}>Take Picture</Nav.Link> <Nav.Link href='#' onClick={() => this.handleClickEvent(1)}>Take Picture</Nav.Link>
<Nav.Link href="#">Placeholder 3</Nav.Link> <Nav.Link href='#'>Placeholder 3</Nav.Link>
</Nav> </Nav>
</Navbar.Collapse> </Navbar.Collapse>
</Navbar> </Navbar>
@@ -47,7 +47,7 @@ class NavMenu extends React.Component {
) )
} }
handleClickEvent(menuItem) { handleClickEvent (menuItem) {
// Update the // Update the
// this.setState({selectedMenuItem: menuItem}) // this.setState({selectedMenuItem: menuItem})
+5 -3
View File
@@ -7,17 +7,19 @@
import React from 'react' import React from 'react'
class TakePicture extends React.Component { class TakePicture extends React.Component {
constructor(props) { constructor (props) {
super(props) super(props)
console.log('Take Picture component loaded')
// this.state = { // this.state = {
// activeView: 0, // activeView: 0,
// menuState: props.menuState // menuState: props.menuState
// } // }
} }
render() { render () {
return( return (
<> <>
<p>Take Picture Component Placeholder</p> <p>Take Picture Component Placeholder</p>
</> </>