UNPKG

@ledgerhq/coin-hedera

Version:
35 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRewards = getRewards; const api_1 = require("../network/api"); /** * Fetch staking rewards for a given Hedera account. */ async function getRewards(address, cursor) { const mirrorTransactions = await api_1.apiClient.getAccountTransactions({ address, fetchAllPages: false, pagingToken: cursor ?? null, limit: 100, order: "desc", }); const rewards = mirrorTransactions.transactions.reduce((acc, tx) => { const reward = tx.staking_reward_transfers.find(r => r.account === address); if (!reward) return acc; const timestamp = new Date(Number.parseInt(tx.consensus_timestamp.split(".")[0], 10) * 1000); acc.push({ stake: address, asset: { type: "native" }, amount: BigInt(reward.amount), receivedAt: timestamp, transactionHash: tx.transaction_hash, }); return acc; }, []); return { items: rewards, ...(mirrorTransactions.nextCursor && { next: mirrorTransactions.nextCursor }), }; } //# sourceMappingURL=getRewards.js.map