Skip to content

Commit

Permalink
Fabo/polkadot overview (#450)
Browse files Browse the repository at this point in the history
* add first steps towards overview

* correct total

* fixed total

* fix getaccountinfo is not a funciton

* delete hardcoded node rpc url

* endpoint back to normal

Co-authored-by: Bitcoinera <[email protected]>
  • Loading branch information
faboweb and Bitcoinera authored Mar 13, 2020
1 parent 12ecc95 commit 6c33f18
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/block-listeners/polkadot-node-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion lib/reducers/polkadotV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
Expand Down
28 changes: 24 additions & 4 deletions lib/source/polkadotV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(
Expand Down

0 comments on commit 6c33f18

Please sign in to comment.