UNPKG

@ledgerhq/coin-near

Version:
41 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sync = exports.getAccountShape = void 0; const accountId_1 = require("@ledgerhq/coin-framework/account/accountId"); const jsHelpers_1 = require("@ledgerhq/coin-framework/bridge/jsHelpers"); const api_1 = require("./api"); const getAccountShape = async (info) => { const { address, initialAccount, currency, derivationMode } = info; const oldOperations = initialAccount?.operations || []; const accountId = (0, accountId_1.encodeAccountId)({ type: "js", version: "2", currencyId: currency.id, xpubOrAddress: address, derivationMode, }); const { blockHeight, balance, spendableBalance, nearResources } = await (0, api_1.getAccount)(address); const newOperations = await (0, api_1.getOperations)(accountId, address); const operations = (0, jsHelpers_1.mergeOps)(oldOperations, newOperations); const shape = { id: accountId, balance, spendableBalance, operationsCount: operations.length, blockHeight, nearResources, }; return { ...shape, operations }; }; exports.getAccountShape = getAccountShape; const postSync = (initial, synced) => { const pendingOperations = initial.pendingOperations || []; if (pendingOperations.length === 0) { return synced; } const { operations } = synced; synced.pendingOperations = pendingOperations.filter(po => !operations.some(o => o.hash === po.hash)); return synced; }; exports.sync = (0, jsHelpers_1.makeSync)({ getAccountShape: exports.getAccountShape, postSync }); //# sourceMappingURL=synchronisation.js.map