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

Add eth_unsubscribe support #6

Merged
merged 1 commit into from
Dec 12, 2022
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
3 changes: 3 additions & 0 deletions request.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ <h1>window.ethereum.request</h1>
<li><a href="javascript:request('wallet_getPermissions')">walet_getPermissions</a>
<li><a href="javascript:request('wallet_watchAsset', addTokenParams)">wallet_watchAsset</a></li>
<li><a href="javascript:request('eth_subscribe', ['newHeads'])">eth_subscribe (newHeads)</a></li>
<li><a href="javascript:ethUnsubscribe('request', '#request-subscription-id')">eth_unsubscribe</a> subscription ID: <input id="request-subscription-id"></li>
</ul>

<h1>window.ethereum.sendAsync</h1>
Expand All @@ -53,6 +54,7 @@ <h1>window.ethereum.sendAsync</h1>
<li><a href="javascript:sendAsync('wallet_getPermissions')">walet_getPermissions</a>
<li><a href="javascript:sendAsync('wallet_watchAsset', addTokenParams)">wallet_watchAsset</a></li>
<li><a href="javascript:sendAsync('eth_subscribe', ['newHeads'])">eth_subscribe (newHeads)</a></li>
<li><a href="javascript:ethUnsubscribe('sendAsync', '#sendAsync-subscription-id')">eth_unsubscribe</a> subscription ID: <input id="sendAsync-subscription-id"></li>
</ul>

<h1>window.ethereum.send</h1>
Expand All @@ -77,6 +79,7 @@ <h1>window.ethereum.send</h1>
<li><a href="javascript:send('wallet_getPermissions')">walet_getPermissions</a>
<li><a href="javascript:send('wallet_watchAsset', addTokenParams)">wallet_watchAsset</a></li>
<li><a href="javascript:send('eth_subscribe', ['newHeads'])">eth_subscribe (newHeads)</a></li>
<li><a href="javascript:ethUnsubscribe('send', '#send-subscription-id')">eth_unsubscribe</a> subscription ID: <input id="send-subscription-id"></li>
</ul>
</ul>
<h1>Other functions</h1>
Expand Down
15 changes: 15 additions & 0 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ async function sendRawTransaction(method, txInput) {
}
}

async function ethUnsubscribe(method, txInput) {
const subscriptionId = document.querySelector(txInput).value
const params = [subscriptionId]

if (method == 'request') {
return request('eth_unsubscribe', params)
}
if (method == 'sendAsync') {
return sendAsync('eth_unsubscribe', params)
}
if (method == 'send') {
return send('eth_unsubscribe', params)
}
}

async function sign(method, messageInput) {
const message = document.querySelector(messageInput).value
const accounts = await window.ethereum.request({
Expand Down