Skip to content

Commit

Permalink
Merge pull request #193 from sesame-seed/master
Browse files Browse the repository at this point in the history
Sesameseed: Fixed translation from Hex Little Endian to Decimal
  • Loading branch information
MickWang authored Aug 23, 2019
2 parents d4c617d + e44c09b commit bd914d6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/renderer/store/modules/NodeAuthorizationSesameseed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {utils} from 'ontology-ts-sdk'
import { utils } from 'ontology-ts-sdk'
import axios from 'axios';

const state = {
Expand All @@ -18,33 +18,35 @@ const mutations = {
}

const actions = {
async fetchSSPerInfo({commit}, address) {
async fetchSSPerInfo({ commit }, address) {
try {
const baseUrl = 'https://dappnode1.ont.io:10334/api/v1/storage/a63c33d2209854feafbf40685a33d4846ee82556/'

const hexAddress = utils.str2hexstr(address)
const pendingHexAddress = utils.str2hexstr('1' + address)

const pendingWithdrawalsPromise = axios.get(baseUrl + pendingHexAddress)
const votesPromise = axios.get(baseUrl + hexAddress)
const [pendingWithdrawalsResponse, votesResponse] = await Promise.all([ pendingWithdrawalsPromise, votesPromise ])

const [pendingWithdrawalsResponse, votesResponse] = await Promise.all([pendingWithdrawalsPromise, votesPromise])

let votes = 0
let pendingWithdrawals = 0

if (pendingWithdrawalsResponse.status === 200 && pendingWithdrawalsResponse.data) {
const resultPending = pendingWithdrawalsResponse.data
const pendingWithdrawalsHex = resultPending.Result ? resultPending.Result : 0
pendingWithdrawals = parseInt(pendingWithdrawalsHex, 16)
const reversedHex = pendingWithdrawalsHex.toString().length > 2 ? utils.reverseHex(pendingWithdrawalsHex) : pendingWithdrawalsHex
pendingWithdrawals = parseInt(reversedHex, 16)
}

if (votesResponse.status === 200 && votesResponse.data) {
const resultVotes = votesResponse.data
const votesHex = resultVotes.Result ? resultVotes.Result : 0
votes = parseInt(votesHex, 16)
const reversedHex = votesHex.toString().length > 2 ? utils.reverseHex(votesHex) : votesHex
votes = parseInt(reversedHex, 16)
}

commit('UPDATE_CURRENT_SS_PEER', { votes, pendingWithdrawals })
return { votes, pendingWithdrawals };
} catch (err) {
Expand Down

0 comments on commit bd914d6

Please sign in to comment.