Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sync = () => {
if (initialAccount.name.includes("crash")) {
o.error(new SyncError("mock failure"));
return;
}
const ops = broadcasted[accountId] || [];
broadcasted[accountId] = [];
o.next(acc => {
const balance = ops.reduce(
(sum, op) => sum.plus(getOperationAmountNumber(op)),
acc.balance
);
return {
...acc,
blockHeight: acc.blockHeight + 1,
lastSyncDate: new Date(),
operations: ops.concat(acc.operations.slice(0)),
pendingOperations: [],
balance,
async function job() {
if (Math.random() > scanAccountDeviceSuccessRate) {
await delay(1000);
if (!unsubscribed) o.error(new SyncError("scan failed"));
return;
}
const nbAccountToGen = 3;
for (let i = 0; i < nbAccountToGen && !unsubscribed; i++) {
const isLast = i === 2;
await delay(500);
const account = genAccount(`${MOCK_DATA_SEED}_${currency.id}_${i}`, {
operationsSize: isLast ? 0 : transactionsSizeTarget,
currency
});
account.unit = currency.units[0];
account.index = i;
account.operations = isLast
? []
: account.operations.map(operation => ({
...operation,
const account = await buildAccount({
coreWallet,
coreAccount,
currency,
accountIndex,
derivationMode,
seedIdentifier,
existingAccount,
logId,
syncConfig
});
return account;
} catch (e) {
if (e.name !== "Error") throw remapLibcoreErrors(e);
throw new SyncError(e.message);
}
}
const sync = () => {
if (initialAccount.name.includes("crash")) {
o.error(new SyncError("mock failure"));
return;
}
const ops = broadcasted[accountId] || [];
broadcasted[accountId] = [];
o.next(acc => {
const account = { ...acc };
account.lastSyncDate = new Date();
account.blockHeight++;
for (const op of ops) {
account.balance = account.balance.plus(
getOperationAmountNumber(op)
);
account.operations = ops.concat(
account.operations.slice(0).reverse()
);
account.pendingOperations = [];