From e44c09bf70ab2360904515041389dfd8d21f0a15 Mon Sep 17 00:00:00 2001 From: Daniel Blanco Parla Date: Fri, 23 Aug 2019 00:37:17 +0200 Subject: [PATCH] Sesameseed: Fixed translation from Hex Little Endian to Decimal --- .../modules/NodeAuthorizationSesameseed.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/renderer/store/modules/NodeAuthorizationSesameseed.js b/src/renderer/store/modules/NodeAuthorizationSesameseed.js index 5a5c11f..e507863 100644 --- a/src/renderer/store/modules/NodeAuthorizationSesameseed.js +++ b/src/renderer/store/modules/NodeAuthorizationSesameseed.js @@ -1,4 +1,4 @@ -import {utils} from 'ontology-ts-sdk' +import { utils } from 'ontology-ts-sdk' import axios from 'axios'; const state = { @@ -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) {