@@ -3,77 +3,79 @@ import api from "../api";
33const defaultWeight = 1 ;
44
55exports = 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} ;
0 commit comments