Commit e46ec113 authored by Fabien's avatar Fabien Committed by GitHub

Merge pull request #179 from steemit/remove-async-await

Remove async await
parents 23fa3b78 8b43a6bf
...@@ -2,9 +2,5 @@ ...@@ -2,9 +2,5 @@
"presets": [ "presets": [
"es2015", "es2015",
"es2017" "es2017"
],
"plugins": [
"transform-async-to-generator",
"transform-regenerator"
] ]
} }
\ No newline at end of file
require("babel-polyfill");
const api = require("./lib/api"); const api = require("./lib/api");
const auth = require("./lib/auth"); const auth = require("./lib/auth");
const broadcast = require("./lib/broadcast"); const broadcast = require("./lib/broadcast");
......
{ {
"name": "steem", "name": "steem",
"version": "0.5.16", "version": "0.5.17",
"description": "Steem.js the JavaScript API for Steem blockchain", "description": "Steem.js the JavaScript API for Steem blockchain",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
...@@ -53,9 +53,7 @@ ...@@ -53,9 +53,7 @@
"babel-cli": "^6.16.0", "babel-cli": "^6.16.0",
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
"babel-loader": "^6.2.5", "babel-loader": "^6.2.5",
"babel-plugin-transform-async-to-generator": "^6.24.1", "babel-polyfill": "^6.23.0",
"babel-plugin-transform-regenerator": "^6.24.1",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0", "babel-preset-es2015": "^6.16.0",
"babel-preset-es2017": "^6.16.0", "babel-preset-es2017": "^6.16.0",
"babel-register": "^6.14.0", "babel-register": "^6.14.0",
...@@ -77,4 +75,4 @@ ...@@ -77,4 +75,4 @@
"Nilesh Suthar (https://github.com/nil1511)", "Nilesh Suthar (https://github.com/nil1511)",
"Pedro Tacla Yamada (https://github.com/yamadapc)" "Pedro Tacla Yamada (https://github.com/yamadapc)"
] ]
} }
\ No newline at end of file
...@@ -3,77 +3,79 @@ import api from "../api"; ...@@ -3,77 +3,79 @@ import api from "../api";
const defaultWeight = 1; const defaultWeight = 1;
exports = module.exports = steemBroadcast => { exports = module.exports = steemBroadcast => {
steemBroadcast.addAccountAuth = async ( steemBroadcast.addAccountAuth = (
activeWif, activeWif,
username, username,
authorizedUsername, authorizedUsername,
role = "posting", role = "posting",
cb cb
) => { ) => {
const [userAccount] = await api.getAccountsAsync([username]); api.getAccountsAsync([username]).then(([userAccount]) => {
const updatedAuthority = userAccount[role];
const authorizedAccounts = updatedAuthority.account_auths.map(
auth => auth[0]
);
const hasAuthority =
authorizedAccounts.indexOf(authorizedUsername) !== -1;
const updatedAuthority = userAccount[role]; if (hasAuthority) {
const authorizedAccounts = updatedAuthority.account_auths.map( // user does already exist in authorized list
auth => auth[0] return cb(null, null);
); }
const hasAuthority = authorizedAccounts.indexOf(authorizedUsername) !== -1; updatedAuthority.account_auths.push([authorizedUsername, defaultWeight]);
const owner = role === "owner" ? updatedAuthority : undefined;
if (hasAuthority) { const active = role === "active" ? updatedAuthority : undefined;
// user does already exist in authorized list const posting = role === "posting" ? updatedAuthority : undefined;
return cb(null, null); /** Add authority on user account */
} steemBroadcast.accountUpdate(
updatedAuthority.account_auths.push([authorizedUsername, defaultWeight]); activeWif,
const owner = role === "owner" ? updatedAuthority : undefined; userAccount.name,
const active = role === "active" ? updatedAuthority : undefined; owner,
const posting = role === "posting" ? updatedAuthority : undefined; active,
/** Add authority on user account */ posting,
steemBroadcast.accountUpdate( userAccount.memo_key,
activeWif, userAccount.json_metadata,
userAccount.name, cb
owner, );
active, });
posting,
userAccount.memo_key,
userAccount.json_metadata,
cb
);
}; };
steemBroadcast.removeAccountAuth = async ( steemBroadcast.removeAccountAuth = (
activeWif, activeWif,
username, username,
authorizedUsername, authorizedUsername,
role = "posting", role = "posting",
cb cb
) => { ) => {
const [userAccount] = await api.getAccountsAsync([username]); api.getAccountsAsync([username]).then(([userAccount]) => {
const updatedAuthority = userAccount[role]; const updatedAuthority = userAccount[role];
const totalAuthorizedUser = updatedAuthority.account_auths.length; const totalAuthorizedUser = updatedAuthority.account_auths.length;
for (let i = 0; i < totalAuthorizedUser; i++) { for (let i = 0; i < totalAuthorizedUser; i++) {
const user = updatedAuthority.account_auths[i]; const user = updatedAuthority.account_auths[i];
if (user[0] === authorizedUsername) { if (user[0] === authorizedUsername) {
updatedAuthority.account_auths.splice(i, 1); updatedAuthority.account_auths.splice(i, 1);
break; break;
}
}
// user does not exist in authorized list
if (totalAuthorizedUser === updatedAuthority.account_auths.length) {
return cb(null, null);
} }
}
// user does not exist in authorized list
if (totalAuthorizedUser === updatedAuthority.account_auths.length) {
return cb(null, null);
}
const owner = role === "owner" ? updatedAuthority : undefined; const owner = role === "owner" ? updatedAuthority : undefined;
const active = role === "active" ? updatedAuthority : undefined; const active = role === "active" ? updatedAuthority : undefined;
const posting = role === "posting" ? updatedAuthority : undefined; const posting = role === "posting" ? updatedAuthority : undefined;
steemBroadcast.accountUpdate( steemBroadcast.accountUpdate(
activeWif, activeWif,
userAccount.name, userAccount.name,
owner, owner,
active, active,
posting, posting,
userAccount.memo_key, userAccount.memo_key,
userAccount.json_metadata, userAccount.json_metadata,
cb cb
); );
});
}; };
}; };
require("babel-polyfill");
const api = require("./api"); const api = require("./api");
const auth = require("./auth"); const auth = require("./auth");
const broadcast = require("./broadcast"); const broadcast = require("./broadcast");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment