diff --git a/lib/block-listeners/polkadot-node-subscription.js b/lib/block-listeners/polkadot-node-subscription.js index a4af528940..0e1e162356 100644 --- a/lib/block-listeners/polkadot-node-subscription.js +++ b/lib/block-listeners/polkadot-node-subscription.js @@ -32,11 +32,13 @@ class PolkadotNodeSubscription { // here we init the polkadot rpc once for all processes // the class gets stored in the store to be used by all instances async initPolkadotRPC() { + console.time('init polkadot') this.api = new ApiPromise({ provider: new WsProvider(this.network.rpc_url) }) this.store.polkadotRPC = this.api await this.api.isReady + console.timeEnd('init polkadot') } async subscribeForNewBlock() { diff --git a/lib/reducers/polkadotV0-reducers.js b/lib/reducers/polkadotV0-reducers.js index 35681956a4..8cc2c5735a 100644 --- a/lib/reducers/polkadotV0-reducers.js +++ b/lib/reducers/polkadotV0-reducers.js @@ -57,13 +57,16 @@ function validatorReducer(network, validator) { } } -function balanceReducer(network, balance) { +function balanceReducer(network, balance, total) { // hack. We convert the balance into an Array to make it an Iterable return [ { amount: BigNumber(balance) .times(network.coinLookup[0].chainToViewConversionFactor) .toFixed(4), + total: BigNumber(total) + .times(network.coinLookup[0].chainToViewConversionFactor) + .toFixed(4), denom: network.coinLookup[0].viewDenom } ] diff --git a/lib/source/polkadotV0-source.js b/lib/source/polkadotV0-source.js index bab304d5ae..a10b34a544 100644 --- a/lib/source/polkadotV0-source.js +++ b/lib/source/polkadotV0-source.js @@ -172,7 +172,14 @@ class polkadotAPI { const api = await this.getAPI() const account = await api.query.system.account(address) const freeBalance = account.data.free - return this.reducers.balanceReducer(this.network, freeBalance.toString()) + const totalBalance = BigNumber(account.data.free.toString()).plus( + account.data.reserved.toString() + ) + return this.reducers.balanceReducer( + this.network, + freeBalance.toString(), + totalBalance.toString() + ) } async getExpectedReturns() { @@ -184,9 +191,22 @@ class polkadotAPI { } async getOverview(delegatorAddress) { - const api = await this.getAPI() - const accountBalances = await api.query.staking.bonded(delegatorAddress) // or stashId? - console.log('ACCOUNT', JSON.stringify(accountBalances)) + const accountBalances = await this.getBalancesFromAddress(delegatorAddress) + + return { + networkId: this.networkId, + address: delegatorAddress, + totalStake: accountBalances[0].total, + totalStakeFiatValue: '', + liquidStake: accountBalances[0].amount, + totalRewards: '', + rewards: undefined, + accountInformation: undefined + } + } + + getAccountInfo() { + return null } async getDelegationsForDelegatorAddress(