rpc-cap@3.0.0 (#8924)

* rpc-cap@3.0.0

* adapt use of rpc-cap for new major version
feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent e20e42bb17
commit 8bc02d4b5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      app/scripts/controllers/permissions/index.js
  2. 2
      app/scripts/metamask-controller.js
  3. 2
      package.json
  4. 7
      test/unit/app/controllers/permissions/permissions-controller-test.js
  5. 8
      ui/app/pages/connected-sites/connected-sites.container.js
  6. 4
      ui/app/store/actions.js
  7. 8
      yarn.lock

@ -110,12 +110,12 @@ export class PermissionsController {
/** /**
* Request {@code eth_accounts} permissions * Request {@code eth_accounts} permissions
* @param {string} origin - The origin * @param {string} origin - The requesting origin
* @returns {Promise<string>} the request ID * @returns {Promise<string>} The permissions request ID
*/ */
async requestAccountsPermission (origin) { async requestAccountsPermissionWithId (origin) {
const id = nanoid() const id = nanoid()
this._requestPermissions({ origin, id }, { eth_accounts: {} }) this._requestPermissions({ origin }, { eth_accounts: {} }, id)
return id return id
} }
@ -168,18 +168,26 @@ export class PermissionsController {
/** /**
* Submits a permissions request to rpc-cap. Internal, background use only. * Submits a permissions request to rpc-cap. Internal, background use only.
* *
* @param {IOriginMetadata} metadata - The origin metadata. * @param {IOriginMetadata} domain - The external domain metadata.
* @param {IRequestedPermissions} permissions - The requested permissions. * @param {IRequestedPermissions} permissions - The requested permissions.
* @param {string} [id] - The desired id of the permissions request, if any.
* @returns {Promise<IOcapLdCapability[]>} A Promise that resolves with the
* approved permissions, or rejects with an error.
*/ */
_requestPermissions (metadata, permissions) { _requestPermissions (domain, permissions, id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// rpc-cap assigns an id to the request if there is none, as expected by // rpc-cap assigns an id to the request if there is none, as expected by
// requestUserApproval below // requestUserApproval below
const req = { method: 'wallet_requestPermissions', params: [permissions] } const req = {
id,
method: 'wallet_requestPermissions',
params: [permissions],
}
const res = {} const res = {}
this.permissions.providerMiddlewareFunction( this.permissions.providerMiddlewareFunction(
metadata, req, res, () => {}, _end domain, req, res, () => {}, _end
) )
function _end (_err) { function _end (_err) {
@ -716,7 +724,7 @@ export class PermissionsController {
* @param {string} req - The internal rpc-cap user request object. * @param {string} req - The internal rpc-cap user request object.
*/ */
requestUserApproval: async (req) => { requestUserApproval: async (req) => {
const { origin, metadata: { id } } = req const { metadata: { id, origin } } = req
if (this.pendingApprovalOrigins.has(origin)) { if (this.pendingApprovalOrigins.has(origin)) {
throw ethErrors.rpc.resourceUnavailable( throw ethErrors.rpc.resourceUnavailable(

@ -563,7 +563,7 @@ export default class MetamaskController extends EventEmitter {
removePermissionsFor: permissionsController.removePermissionsFor.bind(permissionsController), removePermissionsFor: permissionsController.removePermissionsFor.bind(permissionsController),
addPermittedAccount: nodeify(permissionsController.addPermittedAccount, permissionsController), addPermittedAccount: nodeify(permissionsController.addPermittedAccount, permissionsController),
removePermittedAccount: nodeify(permissionsController.removePermittedAccount, permissionsController), removePermittedAccount: nodeify(permissionsController.removePermittedAccount, permissionsController),
requestAccountsPermission: nodeify(permissionsController.requestAccountsPermission, permissionsController), requestAccountsPermissionWithId: nodeify(permissionsController.requestAccountsPermissionWithId, permissionsController),
} }
} }

@ -168,7 +168,7 @@
"redux": "^4.0.5", "redux": "^4.0.5",
"redux-thunk": "^2.3.0", "redux-thunk": "^2.3.0",
"reselect": "^3.0.1", "reselect": "^3.0.1",
"rpc-cap": "^2.1.0", "rpc-cap": "^3.0.0",
"safe-event-emitter": "^1.0.1", "safe-event-emitter": "^1.0.1",
"safe-json-stringify": "^1.2.0", "safe-json-stringify": "^1.2.0",
"single-call-balance-checker-abi": "^1.0.0", "single-call-balance-checker-abi": "^1.0.0",

@ -1526,12 +1526,13 @@ describe('permissions controller', function () {
permController = initPermController() permController = initPermController()
}) })
it('requestAccountsPermission calls _requestAccountsPermission with an explicit request ID', async function () { it('requestAccountsPermissionWithId calls _requestAccountsPermission with an explicit request ID', async function () {
const _requestPermissions = sinon.stub(permController, '_requestPermissions').resolves() const _requestPermissions = sinon.stub(permController, '_requestPermissions').resolves()
await permController.requestAccountsPermission('example.com') await permController.requestAccountsPermissionWithId('example.com')
assert.ok(_requestPermissions.calledOnceWithExactly( assert.ok(_requestPermissions.calledOnceWithExactly(
sinon.match.object.and(sinon.match.has('origin')).and(sinon.match.has('id')), sinon.match.object.and(sinon.match.has('origin')),
{ eth_accounts: {} }, { eth_accounts: {} },
sinon.match.string.and(sinon.match.truthy),
)) ))
_requestPermissions.restore() _requestPermissions.restore()
}) })

@ -2,7 +2,7 @@ import { connect } from 'react-redux'
import ConnectedSites from './connected-sites.component' import ConnectedSites from './connected-sites.component'
import { import {
getOpenMetamaskTabsIds, getOpenMetamaskTabsIds,
requestAccountsPermission, requestAccountsPermissionWithId,
removePermissionsFor, removePermissionsFor,
removePermittedAccount, removePermittedAccount,
} from '../../store/actions' } from '../../store/actions'
@ -61,7 +61,7 @@ const mapDispatchToProps = (dispatch) => {
[domainKey]: permissionMethodNames, [domainKey]: permissionMethodNames,
})) }))
}, },
requestAccountsPermission: (origin) => dispatch(requestAccountsPermission(origin)), requestAccountsPermissionWithId: (origin) => dispatch(requestAccountsPermissionWithId(origin)),
} }
} }
@ -76,7 +76,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
const { const {
disconnectAccount, disconnectAccount,
disconnectAllAccounts, disconnectAllAccounts,
requestAccountsPermission: dispatchRequestAccountsPermission, requestAccountsPermissionWithId,
} = dispatchProps } = dispatchProps
const { history } = ownProps const { history } = ownProps
@ -100,7 +100,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
} }
}, },
requestAccountsPermission: async () => { requestAccountsPermission: async () => {
const id = await dispatchRequestAccountsPermission(tabToConnect.origin) const id = await requestAccountsPermissionWithId(tabToConnect.origin)
history.push(`${CONNECT_ROUTE}/${id}`) history.push(`${CONNECT_ROUTE}/${id}`)
}, },
} }

@ -2056,9 +2056,9 @@ export function setPendingTokens (pendingTokens) {
// Permissions // Permissions
export function requestAccountsPermission (origin) { export function requestAccountsPermissionWithId (origin) {
return async (dispatch) => { return async (dispatch) => {
const id = await promisifiedBackground.requestAccountsPermission(origin) const id = await promisifiedBackground.requestAccountsPermissionWithId(origin)
await forceUpdateMetamaskState(dispatch) await forceUpdateMetamaskState(dispatch)
return id return id
} }

@ -23895,10 +23895,10 @@ rn-host-detect@^1.1.5:
resolved "https://registry.yarnpkg.com/rn-host-detect/-/rn-host-detect-1.1.5.tgz#fbecb982b73932f34529e97932b9a63e58d8deb6" resolved "https://registry.yarnpkg.com/rn-host-detect/-/rn-host-detect-1.1.5.tgz#fbecb982b73932f34529e97932b9a63e58d8deb6"
integrity sha512-ufk2dFT3QeP9HyZ/xTuMtW27KnFy815CYitJMqQm+pgG3ZAtHBsrU8nXizNKkqXGy3bQmhEoloVbrfbvMJMqkg== integrity sha512-ufk2dFT3QeP9HyZ/xTuMtW27KnFy815CYitJMqQm+pgG3ZAtHBsrU8nXizNKkqXGy3bQmhEoloVbrfbvMJMqkg==
rpc-cap@^2.1.0: rpc-cap@^3.0.0:
version "2.1.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/rpc-cap/-/rpc-cap-2.1.0.tgz#c53e9bd925cb23c86b1591d621a68692c58070c0" resolved "https://registry.yarnpkg.com/rpc-cap/-/rpc-cap-3.0.0.tgz#d929573d687d018403a10f0009e470b70b3dd857"
integrity sha512-k4GLWk3IT6r5zETyhiH9tjHqX2sEJ8MdGWv5C4v7wL32hCsx+AnEykbkeVG+EfMox+Vf32C9ieTQPNLKzKwS7A== integrity sha512-YU8/0WFDlYDmxseaP5VQjY8SB/iGq6RRTJHko5PXVOeNfns5BZOumxiYj4sVRqS4uZ8q/VTG11yHGVZAzEaHjw==
dependencies: dependencies:
clone "^2.1.2" clone "^2.1.2"
eth-json-rpc-errors "^2.0.2" eth-json-rpc-errors "^2.0.2"

Loading…
Cancel
Save