1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

Merge branch 'master' into feature/search-tweaks

This commit is contained in:
Matthias Kretschmann 2019-04-05 17:16:06 +02:00 committed by GitHub
commit e81e2c866b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 81 additions and 48 deletions

View File

@ -31,6 +31,7 @@ interface AppState {
isLogged: boolean isLogged: boolean
isLoading: boolean isLoading: boolean
isWeb3: boolean isWeb3: boolean
isNile: boolean
account: string account: string
balance: { balance: {
eth: number eth: number
@ -82,6 +83,7 @@ class App extends Component<{}, AppState> {
isLogged: false, isLogged: false,
isLoading: true, isLoading: true,
isWeb3: false, isWeb3: false,
isNile: false,
balance: { balance: {
eth: 0, eth: 0,
ocn: 0 ocn: 0
@ -167,7 +169,8 @@ class App extends Component<{}, AppState> {
const accounts = await ocean.accounts.list() const accounts = await ocean.accounts.list()
const balance = await accounts[0].getBalance() const balance = await accounts[0].getBalance()
const network = await ocean.keeper.getNetworkName() const network = await ocean.keeper.getNetworkName()
this.setState({ balance, network }) const isNile = network === 'Nile'
this.setState({ balance, network, isNile })
} catch (e) { } catch (e) {
Logger.log('ocean/balance error', e) Logger.log('ocean/balance error', e)
this.setState({ this.setState({

View File

@ -35,13 +35,13 @@ interface InputProps {
interface InputState { interface InputState {
isFocused: boolean isFocused: boolean
startDate?: Date dateCreated?: Date
} }
export default class Input extends PureComponent<InputProps, InputState> { export default class Input extends PureComponent<InputProps, InputState> {
public state: InputState = { public state: InputState = {
isFocused: false, isFocused: false,
startDate: new Date() dateCreated: new Date()
} }
public inputWrapClasses() { public inputWrapClasses() {
@ -62,8 +62,15 @@ export default class Input extends PureComponent<InputProps, InputState> {
private handleDateChange = (date: Date) => { private handleDateChange = (date: Date) => {
this.setState({ this.setState({
startDate: date dateCreated: date
}) })
const event = {
currentTarget: {
name: 'dateCreated',
value: date
}
}
this.props.onChange!(event as any)
} }
public InputComponent = () => { public InputComponent = () => {
@ -151,8 +158,7 @@ export default class Input extends PureComponent<InputProps, InputState> {
return ( return (
<div className={wrapClass}> <div className={wrapClass}>
<DatePicker <DatePicker
selected={this.state.startDate} selected={this.state.dateCreated}
// TODO: this needs to be able to receive this.props.onChange too
onChange={this.handleDateChange} onChange={this.handleDateChange}
className={styles.input} className={styles.input}
onFocus={this.toggleFocus} onFocus={this.toggleFocus}

View File

@ -4,6 +4,7 @@
display: inline-block; display: inline-block;
position: relative; position: relative;
cursor: help; cursor: help;
padding: .5rem;
} }
// default: red square // default: red square

View File

@ -22,7 +22,7 @@ const Indicator = ({
{states => {states =>
!states.isWeb3 ? ( !states.isWeb3 ? (
<span className={styles.statusIndicator} /> <span className={styles.statusIndicator} />
) : !states.isLogged ? ( ) : !states.isLogged || !states.isNile ? (
<span className={styles.statusIndicatorCloseEnough} /> <span className={styles.statusIndicatorCloseEnough} />
) : states.isLogged ? ( ) : states.isLogged ? (
<span className={styles.statusIndicatorActive} /> <span className={styles.statusIndicatorActive} />

View File

@ -49,6 +49,7 @@ $popoverWidth: 18rem;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
font-family: $font-family-monospace;
} }
.balance { .balance {

View File

@ -1,59 +1,65 @@
import React from 'react' import React, { PureComponent } from 'react'
import { User } from '../../../context/User' import { User } from '../../../context/User'
import styles from './Popover.module.scss' import styles from './Popover.module.scss'
const Popover = ({ export default class Popover extends PureComponent<{
forwardedRef,
style
}: {
forwardedRef: (ref: HTMLElement | null) => void forwardedRef: (ref: HTMLElement | null) => void
style: React.CSSProperties style: React.CSSProperties
}) => ( }> {
<div className={styles.popover} ref={forwardedRef} style={style}> public render() {
<User.Consumer> const { account, balance, network, isWeb3, isNile } = this.context
{states => return (
states.account && <div
states.balance && ( className={styles.popover}
ref={this.props.forwardedRef}
style={this.props.style}
>
{account && balance && (
<div className={styles.popoverInfoline}> <div className={styles.popoverInfoline}>
<span <span
className={styles.balance} className={styles.balance}
title={(states.balance.eth / 1e18).toFixed(10)} title={(balance.eth / 1e18).toFixed(10)}
> >
<strong> <strong>
{(states.balance.eth / 1e18) {(balance.eth / 1e18).toFixed(3).slice(0, -1)}
.toFixed(3)
.slice(0, -1)}
</strong>{' '} </strong>{' '}
ETH ETH
</span> </span>
<span className={styles.balance}> <span className={styles.balance}>
<strong>{states.balance.ocn}</strong> OCEAN <strong>{balance.ocn}</strong> OCEAN
</span> </span>
</div> </div>
) )}
}
</User.Consumer>
<div className={styles.popoverInfoline}> {!isWeb3 ? (
<User.Consumer> <div className={styles.popoverInfoline}>
{states => No Web3 detected. Use a browser with MetaMask installed
states.account ? ( to publish assets.
<span className={styles.address} title={states.account}> </div>
{states.account} ) : (
</span> <>
) : ( <div className={styles.popoverInfoline}>
<em>No account selected</em> {account ? (
) <span
} className={styles.address}
</User.Consumer> title={account}
</div> >
{account}
</span>
) : (
<em>No account selected</em>
)}
</div>
<div className={styles.popoverInfoline}>
{network && !isNile
? 'Please connect to Custom RPC\n https://nile.dev-ocean.com'
: network && `Connected to ${network} network`}
</div>
</>
)}
</div>
)
}
}
<div className={styles.popoverInfoline}> Popover.contextType = User
<User.Consumer>
{states => states.network && states.network}
</User.Consumer>
</div>
</div>
)
export default Popover

View File

@ -48,6 +48,7 @@ export default class AssetsUser extends PureComponent<
public render() { public render() {
return ( return (
this.context.isNile &&
this.context.account && ( this.context.account && (
<div className={styles.assetsUser}> <div className={styles.assetsUser}>
{this.props.recent && ( {this.props.recent && (

View File

@ -20,4 +20,5 @@
.status { .status {
margin-left: -($spacer); margin-left: -($spacer);
margin-right: $spacer / 3; margin-right: $spacer / 3;
padding: 0;
} }

View File

@ -11,6 +11,8 @@ export default class Web3message extends PureComponent {
{states => {states =>
!states.isWeb3 !states.isWeb3
? this.noWeb3() ? this.noWeb3()
: !states.isNile
? this.wrongNetwork(states.network)
: !states.isLogged : !states.isLogged
? this.unlockAccount(states) ? this.unlockAccount(states)
: states.isLogged : states.isLogged
@ -57,4 +59,15 @@ export default class Web3message extends PureComponent {
</div> </div>
) )
} }
public wrongNetwork(network: string) {
return (
<div className={styles.message}>
<AccountStatus className={styles.status} /> Not connected to
Nile network, but to {network}.<br />
Please connect in MetaMask with Custom RPC{' '}
<code>{`https://nile.dev-ocean.com`}</code>
</div>
)
}
} }

View File

@ -4,6 +4,7 @@ export const User = React.createContext({
isLogged: false, isLogged: false,
isLoading: false, isLoading: false,
isWeb3: false, isWeb3: false,
isNile: false,
account: '', account: '',
web3: {}, web3: {},
ocean: {}, ocean: {},