Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe52c85
commit 900dbba
Showing
16 changed files
with
217 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var React = require('react'); | ||
var AdminActionCreator = require('../actions/admin_action_creator'); | ||
var AdminStore = require('../stores/admin'); | ||
|
||
function getInitialStateFromStore(accountId) { | ||
|
||
return { admin: AdminStore.get(accountId) }; | ||
} | ||
|
||
var AdminForm = React.createClass({ | ||
getInitialState: function () { | ||
return getInitialStateFromStore(this.props.account); | ||
}, | ||
onAdminChange: function (event) { | ||
this.setState({admin: event.target.checked}); | ||
AdminActionCreator.set(this.props.account, event.target.checked); | ||
}, | ||
componentWillMount: function () { | ||
AdminStore.addChangeEvent(this._onChange); | ||
}, | ||
_onChange: function() { | ||
return this.setState(getInitialStateFromStore(this.props.account)); | ||
}, | ||
render: function() { | ||
console.log(this.state); | ||
return ( | ||
<form className="pure-form"> | ||
<label forHtml="admin"> | ||
<input type="checkbox" name="admin" onChange={this.onAdminChange} checked={this.state.admin} /> | ||
Admin | ||
</label> | ||
</form> | ||
) | ||
|
||
} | ||
|
||
}); | ||
|
||
module.exports = AdminForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
var Dispatcher = require('../dispatcher/dispatcher'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var assign = require('object-assign'); | ||
var ActionTypes = require('../constants/dapps_constants').ActionTypes; | ||
var AccountStore = require('../stores/account_store'); | ||
var AdminService = require('../services/admin'); | ||
var _admins = {}; | ||
var CHANGE_EVENT = 'change'; | ||
var web3 = require('./web3'); | ||
var CurrentAccount = require('../stores/current_account'); | ||
var AdminActionCreator = require('../actions/admin_action_creator'); | ||
var Pudding = require('ether-pudding'); | ||
Pudding.setWeb3(web3); | ||
Admin.load(Pudding); | ||
|
||
var _admins = {}; | ||
var AdminStore = assign({}, EventEmitter.prototype, { | ||
get: function (account) { | ||
return _admins[account]; | ||
}, | ||
set: function (account, value) { | ||
_admins[account] = value; | ||
}, | ||
emitChange: function() { | ||
this.emit(CHANGE_EVENT); | ||
}, | ||
addChangeEvent: function (callback) { | ||
this.on(CHANGE_EVENT, callback); | ||
} | ||
}); | ||
var AdminService = function (AdminContract) { | ||
function WatchForAdminReceived(accountId) { | ||
var event = AdminContract.WatchForAdminReceived({account_id: accountId}, {toBlock: 'latest'}); | ||
event.watch(function (error, result) { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
AdminStore.dispatchToken = Dispatcher.register(function (action) { | ||
switch(action.type) { | ||
case ActionTypes.ADMIN_RECEIVED: | ||
AdminStore.set(action.account, action.admin); | ||
AdminStore.emitChange(); | ||
break; | ||
default: | ||
AdminActionCreator.updated(result.args.account, result.args.admin); | ||
event.stopWatching(); | ||
}); | ||
|
||
} | ||
}); | ||
function WatchForAdminChanged(accountId) { | ||
var event = AdminContract.OnAdminChanged({account_id: accountId}, {toBlock: 'latest'}); | ||
event.watch(function (error, result) { | ||
if (error) { | ||
throw error; | ||
} | ||
console.log('WatchForAdminChanged'); | ||
AdminActionCreator.updated(result.args.account, result.args.admin); | ||
event.stopWatching(); | ||
}); | ||
} | ||
|
||
return { | ||
get: function (account) { | ||
AdminContract.get(account, {from: CurrentAccount.get()}).then(function () { | ||
WatchForAdminReceived(account); | ||
}).catch(function (error) { | ||
throw error; | ||
}); | ||
}, | ||
set: function (account, admin) { | ||
AdminContract.set(account, admin, {from: CurrentAccount.get(), gas: 500000}).then(function () { | ||
WatchForAdminChanged(account); | ||
}).catch(function (error) { | ||
throw error; | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports = new AdminService(Admin.deployed()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var Dispatcher = require('../dispatcher/dispatcher'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var assign = require('object-assign'); | ||
var ActionTypes = require('../constants/dapps_constants').ActionTypes; | ||
var AccountStore = require('../stores/account_store'); | ||
var CurrentAccountStore = require('../stores/current_account'); | ||
var AdminService = require('../services/admin'); | ||
var _admins = {}; | ||
var CHANGE_EVENT = 'change'; | ||
|
||
var _admins = {}; | ||
var AdminStore = assign({}, EventEmitter.prototype, { | ||
get: function (account) { | ||
return _admins[account] || false; | ||
}, | ||
set: function (account, value) { | ||
_admins[account] = value; | ||
}, | ||
emitChange: function() { | ||
this.emit(CHANGE_EVENT); | ||
}, | ||
addChangeEvent: function (callback) { | ||
this.on(CHANGE_EVENT, callback); | ||
} | ||
}); | ||
|
||
AdminStore.dispatchToken = Dispatcher.register(function (action) { | ||
switch(action.type) { | ||
case ActionTypes.SET_ADMIN: | ||
AdminService.set(action.account, action.admin); | ||
break; | ||
case ActionTypes.ADMIN_RECEIVED: | ||
console.log(ActionTypes.ADMIN_RECEIVED); | ||
AdminStore.set(action.account, action.admin); | ||
AdminStore.emitChange(); | ||
break; | ||
case ActionTypes.RECEIVE_RAW_ACCOUNT: | ||
Dispatcher.waitFor([AccountStore.dispatchToken, CurrentAccountStore.dispatchToken]); | ||
action.rawAccounts.forEach(function (account) { | ||
AdminService.get(account); | ||
}); | ||
break; | ||
default: | ||
|
||
} | ||
}); | ||
|
||
module.exports = AdminStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.