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

balances, network to context

This commit is contained in:
Jernej Pregelj 2019-03-04 11:58:52 +01:00
parent 37bff21e4b
commit 87cb5fe36b
2 changed files with 20 additions and 3 deletions

View File

@ -32,6 +32,9 @@ interface AppState {
isLoading: boolean isLoading: boolean
isWeb3: boolean isWeb3: boolean
account: string account: string
balanceEth: number
balanceOcn: number
network: string
web3: Web3 web3: Web3
ocean: {} ocean: {}
startLogin: () => void startLogin: () => void
@ -63,7 +66,7 @@ class App extends Component<{}, AppState> {
} }
) )
} catch (error) { } catch (error) {
Logger.log(error) Logger.log('requestFromFaucet', error)
} }
} else { } else {
// no account found // no account found
@ -74,6 +77,9 @@ class App extends Component<{}, AppState> {
isLogged: false, isLogged: false,
isLoading: true, isLoading: true,
isWeb3: false, isWeb3: false,
balanceEth: 0,
balanceOcn: 0,
network: '',
web3: new Web3( web3: new Web3(
new Web3.providers.HttpProvider( new Web3.providers.HttpProvider(
`${nodeScheme}://${nodeHost}:${nodePort}` `${nodeScheme}://${nodeHost}:${nodePort}`
@ -141,7 +147,7 @@ class App extends Component<{}, AppState> {
}) })
} }
} catch (e) { } catch (e) {
// continue with default Logger.log('web3 error', e)
} }
} }
try { try {
@ -150,8 +156,16 @@ class App extends Component<{}, AppState> {
isLoading: false, isLoading: false,
ocean ocean
}) })
// TODO: squid-js balance retrieval fix
const accounts = await ocean.getAccounts()
const balance = await accounts[0].getBalance()
this.setState({
balanceEth: balance.eth,
balanceOcn: balance.ocn
})
// TODO: squid-js expose keeper for getNetworkName
} catch (e) { } catch (e) {
// show loading error / unable to initialize ocean Logger.log('ocean/balance error', e)
this.setState({ this.setState({
isLoading: false isLoading: false
}) })

View File

@ -7,6 +7,9 @@ export const User = React.createContext({
account: '', account: '',
web3: {}, web3: {},
ocean: {}, ocean: {},
balanceEth: 0,
balanceOcn: 0,
network: '',
startLogin: () => { startLogin: () => {
/* empty */ /* empty */
}, },