@ledgerhq/coin-hedera
Version:
Ledger Hedera Coin integration
39 lines • 1.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStakes = getStakes;
const api_1 = require("../network/api");
/**
* Fetch stakes for a given Hedera account.
*/
async function getStakes(address) {
const mirrorAccount = await api_1.apiClient.getAccount(address);
const stakedNodeId = mirrorAccount.staked_node_id;
if (typeof stakedNodeId !== "number") {
return { items: [] };
}
// -1 is used by the mirror node to indicate the account is no longer delegated
// to any node (e.g. after an undelegation). In that case we skip the node lookup.
const delegatedNode = stakedNodeId >= 0 ? await api_1.apiClient.getNode(stakedNodeId) : null;
const balance = BigInt(mirrorAccount.balance.balance);
const pendingReward = BigInt(mirrorAccount.pending_reward);
const stake = {
uid: address,
address,
asset: { type: "native" },
state: delegatedNode ? "active" : "inactive",
amount: balance + pendingReward,
amountDeposited: balance,
amountRewarded: pendingReward,
details: {
stakedNodeId,
overstaked: delegatedNode
? BigInt(delegatedNode.stake) >= BigInt(delegatedNode.max_stake)
: null,
},
...(delegatedNode && {
delegate: delegatedNode.node_account_id,
}),
};
return { items: [stake] };
}
//# sourceMappingURL=getStakes.js.map