Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async loadFromJson(json) {
const { addNode, addLink, clearDatabase, updateNode } = this.props;
this.setPercent(10); // Loading started!
clearDatabase();
const [error, response] = await to(loadPorkFile(json, this.setPercent));
if (error) {
console.log(
"Error reading Porcupine Config file! Either data is missing or format is incorrect"
);
return;
} else {
this.setPercent(-1);
}
const { nodes, links } = response;
try {
let i = 0;
nodes.forEach(node => {
addNode(node);
updateNode(node.id);
this.setPercent(50 + (30 * i++) / nodes.length);
});
export const readFile = async (file: string): Promise => {
const [err] = await to(fileExists(file));
if (err) {
throw err;
}
const [rfErr, data] = await to(rF(file));
if (rfErr) {
throw new VError(rfErr, `while reading file: ${file}`);
}
if (!data) {
return "";
}
return data.toString();
};
}) => async (dispatch, getState) => {
dispatch(loadingStarted(actionTypes.getTransactions));
const networkConfig = getState().network;
if (networkConfig) {
const [error, response] = await to(transactionsAPI.getTransactions({
networkConfig, address, filters, limit, offset,
}));
if (error) {
dispatch({
type: actionTypes.transactionLoadFailed,
data: {
error,
},
});
} else {
dispatch({
type: offset > 0 ? actionTypes.updateTransactions : actionTypes.getTransactionsSuccess,
data: {
address,
confirmed: response.data,
const filteredFiles = files.filter(file =>
Boolean(this.allowedFilesRegex.exec(file)),
);
const extractedMetadata = filteredFiles.map(
async (file: string): Promise => {
const [e, result] = await to(readFile(file, "utf8"));
if (e) {
throw new VError(e, `cannot read file: ${file}`);
}
return fm(result).attributes;
},
);
let capabilities: any;
[err, capabilities] = await to(Promise.all(extractedMetadata));
if (err) {
throw new VError(err, `while extracting metadata from capabilities`);
}
return capabilities as Capability[];
};
}
private copy = async (source: string, output: string) => {
const copyRegex: string = `([A-z0-9-_.&]*\.md|assets\/[A-z0-9-_.&]*\.(png|jpg|gif|jpeg|svg|yaml|yml|json))`;
const [err] = await to(
ClusterDocsTopicSerializer.do(source, output, { copyRegex }),
);
if (err) {
throw err;
}
};
}
static async hashPassword(user: User) {
let err;
if (user.changed('password')){
let salt, hash;
[err, salt] = await to(bcrypt.genSalt(10));
if(err) {
throw err;
}
[err, hash] = await to(bcrypt.hash(user.password, salt));
if(err) {
throw err;
}
user.password = hash;
}
}
getLatestCommitFromBranch = async (branch: string) => {
const [err, response] = await to>(
this.octokit.repos.getBranch({
owner: this.config.organization,
repo: this.config.repository,
branch,
}),
);
if (err) {
throw new VError(err, `while getting data from branch: ${branch}`);
}
return response ? response.data.commit.sha : null;
};
export const transactionCreated = data => async (dispatch, getState) => {
const {
account, settings, network, ...state
} = getState();
const timeOffset = getTimeOffset(state);
const activeToken = settings.token.active;
const [error, tx] = account.loginType === loginType.normal
? await to(transactionsAPI.create(
activeToken,
{ ...data, timeOffset, network },
createTransactionType.transaction,
))
: await to(signSendTransaction(account, { ...data, timeOffset }));
if (error) {
return dispatch({
type: actionTypes.transactionCreatedError,
data: error,
});
}
return dispatch({
type: actionTypes.transactionCreatedSuccess,
data: tx,
});
};
checkoutTag = async (tag: string) => {
const [err] = await to(this.checkout(`tags/${tag}`));
if (err) {
throw err;
}
};
private writeManifest = async (output: string, manifest: Manifest) => {
const [err] = await to(writeToYaml(`${output}/manifest.yaml`, manifest));
if (err) {
throw new VError(err, "while writing manifest");
}
};