UI 2 Approve-all for Filters (#5846)

* Approve all requests or type for token

* Approve all functionality

* Remove extra console.log
This commit is contained in:
Jaco Greeff 2017-06-15 11:59:14 +02:00 committed by GitHub
parent 58f15f1674
commit df52394871
2 changed files with 36 additions and 6 deletions

View File

@ -20,7 +20,8 @@ import { FormattedMessage } from 'react-intl';
import { Button } from '@parity/ui';
export default function Request ({ className, approveRequest, denyRequest, queueId, request: { from, method } }) {
const _onApprove = () => approveRequest(queueId);
const _onApprove = () => approveRequest(queueId, false);
const _onApproveAll = () => approveRequest(queueId, true);
const _onReject = () => denyRequest(queueId);
return (
@ -37,16 +38,25 @@ export default function Request ({ className, approveRequest, denyRequest, queue
label={
<FormattedMessage
id='dappFilter.request.buttons.approve'
defaultMessage='Approve request'
defaultMessage='Approve'
/>
}
onClick={ _onApprove }
/>
<Button
label={
<FormattedMessage
id='dappFilter.request.buttons.approveAll'
defaultMessage='Approve All'
/>
}
onClick={ _onApproveAll }
/>
<Button
label={
<FormattedMessage
id='dappFilter.request.buttons.reject'
defaultMessage='Reject request'
defaultMessage='Reject'
/>
}
onClick={ _onReject }

View File

@ -43,13 +43,25 @@ export default class Store {
this.requests = this.requests.concat([{ queueId, request }]);
}
@action approveRequest = (queueId) => {
const { request: { data, source } } = this.findRequest(queueId);
@action approveSingleRequest = ({ queueId, request: { data, source } }) => {
this.removeRequest(queueId);
this.executeOnProvider(data, source);
}
@action approveRequest = (queueId, approveAll) => {
const queued = this.findRequest(queueId);
if (approveAll) {
const { request: { data: { method, token } } } = queued;
const requests = this.findMatchingRequests(method, token);
this.addTokenPermission(method, token);
requests.forEach(this.approveSingleRequest);
} else {
this.approveSingleRequest(queued);
}
}
@action rejectRequest = (queueId) => {
const { request: { data: { id, method, token }, source } } = this.findRequest(queueId);
@ -63,6 +75,10 @@ export default class Store {
}, '*');
}
@action addTokenPermission = (method, token) => {
this.permissions.tokens[token] = Object.assign({ [method]: true }, this.permissions.tokens[token] || {});
}
@action setPermissions = (permissions) => {
this.permissions = permissions;
}
@ -71,6 +87,10 @@ export default class Store {
return this.requests.find(({ queueId }) => queueId === _queueId);
}
findMatchingRequests (_method, _token) {
return this.requests.filter(({ request: { data: { method, token } } }) => method === _method && token === _token);
}
executeOnProvider = ({ id, from, method, params, token }, source) => {
this.provider.send(method, params, (error, result) => {
source.postMessage({