2017-08-09 13:03:26 +02:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-12-01 12:30:13 +01:00
|
|
|
import * as mobx from 'mobx';
|
2017-08-09 13:03:26 +02:00
|
|
|
import flatten from 'lodash.flatten';
|
|
|
|
|
2017-12-12 17:35:21 +01:00
|
|
|
import DappsStore from '@parity/shared/lib/mobx/dappsStore';
|
2017-08-09 13:03:26 +02:00
|
|
|
import RequestStore from './DappRequests/store';
|
2017-11-21 15:50:38 +01:00
|
|
|
import methodGroups from './DappRequests/methodGroups';
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-08-09 13:17:52 +02:00
|
|
|
export default function execute (appId, method, params, callback) {
|
2017-12-12 17:35:21 +01:00
|
|
|
const dappsStore = DappsStore.get();
|
2017-08-09 13:03:26 +02:00
|
|
|
const requestStore = RequestStore.get();
|
|
|
|
|
|
|
|
switch (method) {
|
2017-12-12 17:35:21 +01:00
|
|
|
case 'shell_getApps': {
|
2017-08-09 13:03:26 +02:00
|
|
|
const [displayAll] = params;
|
|
|
|
|
2017-11-21 15:50:38 +01:00
|
|
|
callback(
|
|
|
|
null,
|
|
|
|
displayAll
|
2017-12-12 17:35:21 +01:00
|
|
|
? dappsStore.allApps.slice().map(mobx.toJS)
|
|
|
|
: dappsStore.visibleApps.slice().map(mobx.toJS)
|
2017-08-09 13:03:26 +02:00
|
|
|
);
|
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-12-12 17:35:21 +01:00
|
|
|
case 'shell_getFilteredMethods': {
|
2017-11-21 15:50:38 +01:00
|
|
|
callback(
|
|
|
|
null,
|
|
|
|
flatten(Object.keys(methodGroups).map(key => methodGroups[key].methods))
|
|
|
|
);
|
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-11-21 15:50:38 +01:00
|
|
|
|
2017-12-12 17:35:21 +01:00
|
|
|
case 'shell_getMethodGroups': {
|
2017-11-21 15:50:38 +01:00
|
|
|
callback(
|
|
|
|
null,
|
|
|
|
methodGroups
|
|
|
|
);
|
2017-08-09 13:03:26 +02:00
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-12-12 17:35:21 +01:00
|
|
|
case 'shell_getMethodPermissions': {
|
2017-11-21 15:50:38 +01:00
|
|
|
callback(null, mobx.toJS(requestStore.permissions));
|
2017-08-09 13:03:26 +02:00
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-12-12 17:35:21 +01:00
|
|
|
case 'shell_loadApp': {
|
2017-12-12 12:09:24 +01:00
|
|
|
const [loadId, loadParams] = params;
|
2017-08-09 13:03:26 +02:00
|
|
|
const loadUrl = `/${loadId}/${loadParams || ''}`;
|
|
|
|
|
|
|
|
window.location.hash = loadUrl;
|
|
|
|
|
|
|
|
callback(null, true);
|
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-12-12 17:35:21 +01:00
|
|
|
case 'shell_requestNewToken': {
|
2017-08-09 13:03:26 +02:00
|
|
|
callback(null, requestStore.createToken(appId));
|
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-12-13 12:02:31 +01:00
|
|
|
case 'shell_setAppPinned': {
|
|
|
|
const [appId, pinned] = params;
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-11-21 15:50:38 +01:00
|
|
|
callback(
|
|
|
|
null,
|
2017-12-13 12:02:31 +01:00
|
|
|
pinned
|
|
|
|
? dappsStore.pinApp(appId)
|
|
|
|
: dappsStore.unpinApp(appId)
|
2017-12-12 17:35:21 +01:00
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-13 12:02:31 +01:00
|
|
|
case 'shell_setAppVisibility': {
|
|
|
|
const [appId, visibility] = params;
|
2017-12-12 17:35:21 +01:00
|
|
|
|
|
|
|
callback(
|
|
|
|
null,
|
2017-12-13 12:02:31 +01:00
|
|
|
visibility
|
|
|
|
? dappsStore.showApp(appId)
|
|
|
|
: dappsStore.hideApp(appId)
|
2017-08-09 13:03:26 +02:00
|
|
|
);
|
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-08-09 13:03:26 +02:00
|
|
|
|
2017-12-12 17:35:21 +01:00
|
|
|
case 'shell_setMethodPermissions': {
|
2017-08-09 13:03:26 +02:00
|
|
|
const [permissions] = params;
|
|
|
|
|
|
|
|
callback(null, requestStore.setPermissions(permissions));
|
|
|
|
return true;
|
2017-12-12 17:35:21 +01:00
|
|
|
}
|
2017-08-09 13:03:26 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|