Save permissions (#5970)

This commit is contained in:
Jaco Greeff 2017-07-03 10:03:29 +02:00 committed by GitHub
parent 9f8467aa80
commit 15d4bc9d6d

View File

@ -15,17 +15,24 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { action, observable } from 'mobx'; import { action, observable } from 'mobx';
import store from 'store';
import { sha3 } from '@parity/api/util/sha3'; import { sha3 } from '@parity/api/util/sha3';
import filteredRequests from '../DappRequests/filteredRequests'; import filteredRequests from '../DappRequests/filteredRequests';
const LS_PERMISSIONS = '_parity::dapps::methods';
export default class Store { export default class Store {
@observable filteredRequests = Object.keys(filteredRequests); @observable filteredRequests = Object.keys(filteredRequests);
@observable modalOpen = false; @observable modalOpen = false;
@observable permissions = {}; @observable permissions = {};
@observable tokens = {}; @observable tokens = {};
constructor () {
this.permissions = store.get(LS_PERMISSIONS) || {};
}
@action closeModal = () => { @action closeModal = () => {
this.modalOpen = false; this.modalOpen = false;
} }
@ -50,6 +57,7 @@ export default class Store {
this.permissions = Object.assign({}, this.permissions, { this.permissions = Object.assign({}, this.permissions, {
[id]: true [id]: true
}); });
this.savePermissions();
} }
@action toggleAppPermission = (method, appId) => { @action toggleAppPermission = (method, appId) => {
@ -58,6 +66,7 @@ export default class Store {
this.permissions = Object.assign({}, this.permissions, { this.permissions = Object.assign({}, this.permissions, {
[id]: !this.permissions[id] [id]: !this.permissions[id]
}); });
this.savePermissions();
} }
hasTokenPermission = (method, token) => { hasTokenPermission = (method, token) => {
@ -68,6 +77,10 @@ export default class Store {
return this.permissions[`${method}:${appId}`] || false; return this.permissions[`${method}:${appId}`] || false;
} }
savePermissions = () => {
store.set(LS_PERMISSIONS, this.permissions);
}
static instance = null; static instance = null;
static get () { static get () {