Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Remove-aepp-rpc-client-from-wallet #912

Merged
merged 6 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions es/utils/aepp-wallet-communication/rpc/rpc-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ export const RpcClients = stampit({
getClient (id) {
return this.clients.get(id)
},
/**
* Remove and disiconnect client by ID
* @function removeClient
* @instance
* @rtype (id: (String|Number), { forceConnectionClose: boolean = false }) => boolean
* @param {(String|Number)} id Client ID
* @param forceConnectionClose
* @return {Boolean}
*/
removeClient (id, { forceConnectionClose = false } = {}) {
if (!this.hasClient(id)) throw new Error(`Wallet RpcClient with id ${id} do not exist`)
this.clients.get(id).disconnect(forceConnectionClose)
this.clients.delete(id)
return true
},
/**
* Update client info by id
* @function updateClientInfo
Expand Down
15 changes: 14 additions & 1 deletion es/utils/aepp-wallet-communication/rpc/wallet-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,25 @@ export const WalletRpc = Ae.compose(Accounts, Selector, {
getClients () {
return rpcClients
},
/**
* Remove specific RpcClient by ID
* @function removeRpcClient
* @instance
* @rtype (id: string) => Boolean
* @param {String} id Client ID
* @param {Object} [opt = {}]
* @return {Object}
*/
removeRpcClient (id, opt = { forceConnectionClose: false }) {
return rpcClients.removeClient(id, opt)
},
/**
* Add new AEPP connection
* @function addRpcClient
* @instance
* @rtype (clientConnection: Object) => Object
* @param {Object} clientConnection AEPP connection object
* @return {void}
* @return {String} Client ID
*/
addRpcClient (clientConnection) {
// @TODO detect if aepp has some history based on origin????: if yes use this instance for connection
Expand All @@ -266,6 +278,7 @@ export const WalletRpc = Ae.compose(Accounts, Selector, {
handlers: [handleMessage(this, id), this.onDisconnect]
}
)
return id
},
/**
* Share wallet info
Expand Down
25 changes: 25 additions & 0 deletions test/integration/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,31 @@ describe('Aepp<->Wallet', function () {
})
received.should.be.equal(true)
})
it('Remove rpc client', async () => {
wallet.onConnection = (aepp, actions) => {
actions.accept()
}
const id = wallet.addRpcClient(BrowserWindowMessageConnection({
connectionInfo: { id: 'from_wallet_to_aepp_2' },
self: connections.waelletConnection,
target: connections.aeppConnection
}))
await aepp.connectToWallet(BrowserWindowMessageConnection({
connectionInfo: { id: 'from_aepp_to_wallet_2' },
self: connections.aeppConnection,
target: connections.waelletConnection
}))

wallet.removeRpcClient(id).should.be.equal(true)
wallet.getClients().clients.size.should.be.equal(1)
})
it('Remove rpc client: client not found', async () => {
try {
wallet.removeRpcClient('a1')
} catch (e) {
e.message.should.be.equal('Wallet RpcClient with id a1 do not exist')
}
})
})
describe('Old RPC Wallet-AEPP', () => {
let wallet
Expand Down