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

add active account to user context, output in Web3 message

This commit is contained in:
Matthias Kretschmann 2019-02-12 16:23:45 +01:00
parent c54cf45b12
commit 0b7e602606
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 12 additions and 9 deletions

View File

@ -22,6 +22,7 @@ interface AppState {
isLogged: boolean isLogged: boolean
isLoading: boolean isLoading: boolean
isWeb3: boolean isWeb3: boolean
account: string
web3: Web3 web3: Web3
ocean: {} ocean: {}
startLogin: () => void startLogin: () => void
@ -44,6 +45,7 @@ class App extends Component<{}, AppState> {
`${nodeScheme}://${nodeHost}:${nodePort}` `${nodeScheme}://${nodeHost}:${nodePort}`
) )
), ),
account: '',
ocean: {}, ocean: {},
startLogin: this.startLogin startLogin: this.startLogin
} }
@ -61,6 +63,7 @@ class App extends Component<{}, AppState> {
this.setState({ this.setState({
isLogged: true, isLogged: true,
isWeb3: true, isWeb3: true,
account: accounts[0],
web3 web3
}) })
} else { } else {
@ -69,6 +72,7 @@ class App extends Component<{}, AppState> {
this.setState({ this.setState({
isLogged: true, isLogged: true,
isWeb3: true, isWeb3: true,
account: accounts[0],
web3 web3
}) })
} }
@ -90,6 +94,7 @@ class App extends Component<{}, AppState> {
if (accounts.length > 0) { if (accounts.length > 0) {
this.setState({ this.setState({
isLogged: true, isLogged: true,
account: accounts[0],
web3 web3
}) })
} }

View File

@ -42,7 +42,7 @@
} }
.account { .account {
font-family: $font-family-monospace;
display: inline-block; display: inline-block;
margin-left: $spacer / 8; margin-left: $spacer / 8;
background: none;
} }

View File

@ -14,7 +14,7 @@ export default class Web3message extends PureComponent {
: !states.isLogged : !states.isLogged
? this.unlockAccount(states) ? this.unlockAccount(states)
: states.isLogged : states.isLogged
? this.haveAccount() ? this.haveAccount(states.account)
: null : null
} }
</User.Consumer> </User.Consumer>
@ -48,17 +48,14 @@ export default class Web3message extends PureComponent {
) )
} }
public haveAccount() { public haveAccount(account: string) {
return ( return (
<div className={styles.message}> <div className={styles.message}>
<span className={styles.indicatorActive} /> Connected with <span className={styles.indicatorActive} /> Connected with
account account
<span <code className={styles.account} title={account}>
className={styles.account} {`${account.substring(0, 20)}...`}
title="0xfehz2u89nfewhji432ntio43huof42huifewhnuefwo" </code>
>
0xfehz2u89n...
</span>
</div> </div>
) )
} }

View File

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