From 87cb5fe36b47065f2b929c8c313eae04b4cd9dc5 Mon Sep 17 00:00:00 2001 From: Jernej Pregelj Date: Mon, 4 Mar 2019 11:58:52 +0100 Subject: [PATCH] balances, network to context --- src/App.tsx | 20 +++++++++++++++++--- src/context/User.ts | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 67c71c6..31a3df1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -32,6 +32,9 @@ interface AppState { isLoading: boolean isWeb3: boolean account: string + balanceEth: number + balanceOcn: number + network: string web3: Web3 ocean: {} startLogin: () => void @@ -63,7 +66,7 @@ class App extends Component<{}, AppState> { } ) } catch (error) { - Logger.log(error) + Logger.log('requestFromFaucet', error) } } else { // no account found @@ -74,6 +77,9 @@ class App extends Component<{}, AppState> { isLogged: false, isLoading: true, isWeb3: false, + balanceEth: 0, + balanceOcn: 0, + network: '', web3: new Web3( new Web3.providers.HttpProvider( `${nodeScheme}://${nodeHost}:${nodePort}` @@ -141,7 +147,7 @@ class App extends Component<{}, AppState> { }) } } catch (e) { - // continue with default + Logger.log('web3 error', e) } } try { @@ -150,8 +156,16 @@ class App extends Component<{}, AppState> { isLoading: false, 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) { - // show loading error / unable to initialize ocean + Logger.log('ocean/balance error', e) this.setState({ isLoading: false }) diff --git a/src/context/User.ts b/src/context/User.ts index d3b3a21..03b7ec4 100644 --- a/src/context/User.ts +++ b/src/context/User.ts @@ -7,6 +7,9 @@ export const User = React.createContext({ account: '', web3: {}, ocean: {}, + balanceEth: 0, + balanceOcn: 0, + network: '', startLogin: () => { /* empty */ },