@ledgerhq/coin-cardano
Version:
Ledger Cardano Coin integration
31 lines • 1.41 kB
JavaScript
/**
* Code reference taken from src/families/ethereum/postSyncPatch.ts
*/
// we need to preserve ADA pendingOperations because there is no mempool to do this
// we assume we need to preserve until:
// - that txid appears in operations
const postSyncPatchGen = (initial, synced, parentPendingOperation) => {
const pendingOperations = initial.pendingOperations || [];
if (pendingOperations.length === 0)
return synced;
const { operations } = synced;
synced.pendingOperations = pendingOperations.filter(op => (!parentPendingOperation || // a child pending parent need to disappear if parent ada op disappear
parentPendingOperation.some(o => o.hash === op.hash)) &&
!operations.some(o => o.hash === op.hash));
return synced;
};
export const postSyncPatch = (initial, synced) => {
const acc = postSyncPatchGen(initial, synced);
const { subAccounts, pendingOperations } = acc;
const initialSubAccounts = initial.subAccounts;
if (subAccounts && initialSubAccounts) {
acc.subAccounts = subAccounts.map(subAccount => {
const initialSubAccount = initialSubAccounts.find(a => a.id === subAccount.id);
if (!initialSubAccount)
return subAccount;
return postSyncPatchGen(initialSubAccount, subAccount, pendingOperations);
});
}
return acc;
};
//# sourceMappingURL=postSyncPatch.js.map