Skip to content

Commit e46ec11

Browse files
author
Fabien
authored
Merge pull request #179 from steemit/remove-async-await
Remove async await
2 parents 23fa3b7 + 8b43a6b commit e46ec11

5 files changed

Lines changed: 59 additions & 67 deletions

File tree

.babelrc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@
22
"presets": [
33
"es2015",
44
"es2017"
5-
],
6-
"plugins": [
7-
"transform-async-to-generator",
8-
"transform-regenerator"
95
]
106
}

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require("babel-polyfill");
2-
31
const api = require("./lib/api");
42
const auth = require("./lib/auth");
53
const broadcast = require("./lib/broadcast");

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "steem",
3-
"version": "0.5.16",
3+
"version": "0.5.17",
44
"description": "Steem.js the JavaScript API for Steem blockchain",
55
"main": "index.js",
66
"scripts": {
@@ -53,9 +53,7 @@
5353
"babel-cli": "^6.16.0",
5454
"babel-eslint": "^7.1.1",
5555
"babel-loader": "^6.2.5",
56-
"babel-plugin-transform-async-to-generator": "^6.24.1",
57-
"babel-plugin-transform-regenerator": "^6.24.1",
58-
"babel-polyfill": "^6.16.0",
56+
"babel-polyfill": "^6.23.0",
5957
"babel-preset-es2015": "^6.16.0",
6058
"babel-preset-es2017": "^6.16.0",
6159
"babel-register": "^6.14.0",
@@ -77,4 +75,4 @@
7775
"Nilesh Suthar (https://github.com/nil1511)",
7876
"Pedro Tacla Yamada (https://github.com/yamadapc)"
7977
]
80-
}
78+
}

src/broadcast/helpers.js

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,79 @@ import api from "../api";
33
const defaultWeight = 1;
44

55
exports = module.exports = steemBroadcast => {
6-
steemBroadcast.addAccountAuth = async (
6+
steemBroadcast.addAccountAuth = (
77
activeWif,
88
username,
99
authorizedUsername,
1010
role = "posting",
1111
cb
1212
) => {
13-
const [userAccount] = await api.getAccountsAsync([username]);
13+
api.getAccountsAsync([username]).then(([userAccount]) => {
14+
const updatedAuthority = userAccount[role];
15+
const authorizedAccounts = updatedAuthority.account_auths.map(
16+
auth => auth[0]
17+
);
18+
const hasAuthority =
19+
authorizedAccounts.indexOf(authorizedUsername) !== -1;
1420

15-
const updatedAuthority = userAccount[role];
16-
const authorizedAccounts = updatedAuthority.account_auths.map(
17-
auth => auth[0]
18-
);
19-
const hasAuthority = authorizedAccounts.indexOf(authorizedUsername) !== -1;
20-
21-
if (hasAuthority) {
22-
// user does already exist in authorized list
23-
return cb(null, null);
24-
}
25-
updatedAuthority.account_auths.push([authorizedUsername, defaultWeight]);
26-
const owner = role === "owner" ? updatedAuthority : undefined;
27-
const active = role === "active" ? updatedAuthority : undefined;
28-
const posting = role === "posting" ? updatedAuthority : undefined;
29-
/** Add authority on user account */
30-
steemBroadcast.accountUpdate(
31-
activeWif,
32-
userAccount.name,
33-
owner,
34-
active,
35-
posting,
36-
userAccount.memo_key,
37-
userAccount.json_metadata,
38-
cb
39-
);
21+
if (hasAuthority) {
22+
// user does already exist in authorized list
23+
return cb(null, null);
24+
}
25+
updatedAuthority.account_auths.push([authorizedUsername, defaultWeight]);
26+
const owner = role === "owner" ? updatedAuthority : undefined;
27+
const active = role === "active" ? updatedAuthority : undefined;
28+
const posting = role === "posting" ? updatedAuthority : undefined;
29+
/** Add authority on user account */
30+
steemBroadcast.accountUpdate(
31+
activeWif,
32+
userAccount.name,
33+
owner,
34+
active,
35+
posting,
36+
userAccount.memo_key,
37+
userAccount.json_metadata,
38+
cb
39+
);
40+
});
4041
};
4142

42-
steemBroadcast.removeAccountAuth = async (
43+
steemBroadcast.removeAccountAuth = (
4344
activeWif,
4445
username,
4546
authorizedUsername,
4647
role = "posting",
4748
cb
4849
) => {
49-
const [userAccount] = await api.getAccountsAsync([username]);
50-
const updatedAuthority = userAccount[role];
51-
const totalAuthorizedUser = updatedAuthority.account_auths.length;
52-
for (let i = 0; i < totalAuthorizedUser; i++) {
53-
const user = updatedAuthority.account_auths[i];
54-
if (user[0] === authorizedUsername) {
55-
updatedAuthority.account_auths.splice(i, 1);
56-
break;
50+
api.getAccountsAsync([username]).then(([userAccount]) => {
51+
const updatedAuthority = userAccount[role];
52+
const totalAuthorizedUser = updatedAuthority.account_auths.length;
53+
for (let i = 0; i < totalAuthorizedUser; i++) {
54+
const user = updatedAuthority.account_auths[i];
55+
if (user[0] === authorizedUsername) {
56+
updatedAuthority.account_auths.splice(i, 1);
57+
break;
58+
}
59+
}
60+
// user does not exist in authorized list
61+
if (totalAuthorizedUser === updatedAuthority.account_auths.length) {
62+
return cb(null, null);
5763
}
58-
}
59-
// user does not exist in authorized list
60-
if (totalAuthorizedUser === updatedAuthority.account_auths.length) {
61-
return cb(null, null);
62-
}
6364

64-
const owner = role === "owner" ? updatedAuthority : undefined;
65-
const active = role === "active" ? updatedAuthority : undefined;
66-
const posting = role === "posting" ? updatedAuthority : undefined;
65+
const owner = role === "owner" ? updatedAuthority : undefined;
66+
const active = role === "active" ? updatedAuthority : undefined;
67+
const posting = role === "posting" ? updatedAuthority : undefined;
6768

68-
steemBroadcast.accountUpdate(
69-
activeWif,
70-
userAccount.name,
71-
owner,
72-
active,
73-
posting,
74-
userAccount.memo_key,
75-
userAccount.json_metadata,
76-
cb
77-
);
69+
steemBroadcast.accountUpdate(
70+
activeWif,
71+
userAccount.name,
72+
owner,
73+
active,
74+
posting,
75+
userAccount.memo_key,
76+
userAccount.json_metadata,
77+
cb
78+
);
79+
});
7880
};
7981
};

src/browser.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require("babel-polyfill");
2-
31
const api = require("./api");
42
const auth = require("./auth");
53
const broadcast = require("./broadcast");

0 commit comments

Comments
 (0)