chore: Migrate to the new WC packages
Migrate from `Web3Wallet` to `WalletKit`. More details in the WC docs https://docs.reown.com/walletkit/upgrade/from-web3wallet-web
This commit is contained in:
parent
28e9b6da27
commit
e99f817ccc
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -4,9 +4,9 @@
|
||||||
"description": "Wallet Connect integration for status-desktop",
|
"description": "Wallet Connect integration for status-desktop",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"webpack": "^5.93.0",
|
"webpack": "^5.95.0",
|
||||||
"webpack-cli": "^5.1.4",
|
"webpack-cli": "^5.1.4",
|
||||||
"webpack-dev-server": "^5.0.4"
|
"webpack-dev-server": "^5.1.0"
|
||||||
},
|
},
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -16,6 +16,9 @@
|
||||||
"start": "webpack serve --mode development --open"
|
"start": "webpack serve --mode development --open"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@walletconnect/web3wallet": "^1.13.0"
|
"@reown/walletkit": "^1.1.0",
|
||||||
|
"@walletconnect/utils": "^2.17.0",
|
||||||
|
"@walletconnect/jsonrpc-utils": "^1.0.8",
|
||||||
|
"@walletconnect/core": "^2.17.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Core } from "@walletconnect/core";
|
import { Core } from "@walletconnect/core";
|
||||||
import { Web3Wallet } from "@walletconnect/web3wallet";
|
import { WalletKit } from "@reown/walletkit";
|
||||||
|
|
||||||
// import the builder util
|
// import the builder util
|
||||||
import { buildApprovedNamespaces, getSdkError } from "@walletconnect/utils";
|
import { buildApprovedNamespaces, getSdkError } from "@walletconnect/utils";
|
||||||
|
@ -7,7 +7,7 @@ import { formatJsonRpcResult, formatJsonRpcError } from "@walletconnect/jsonrpc-
|
||||||
|
|
||||||
window.wc = {
|
window.wc = {
|
||||||
core: null,
|
core: null,
|
||||||
web3wallet: null,
|
walletKit: null,
|
||||||
statusObject: null,
|
statusObject: null,
|
||||||
|
|
||||||
init: function (projectId) {
|
init: function (projectId) {
|
||||||
|
@ -35,7 +35,7 @@ window.wc = {
|
||||||
const coreInst = new Core({
|
const coreInst = new Core({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
window.wc.web3wallet = await Web3Wallet.init({
|
window.wc.walletKit = await WalletKit.init({
|
||||||
core: coreInst, // <- pass the shared `core` instance
|
core: coreInst, // <- pass the shared `core` instance
|
||||||
metadata: {
|
metadata: {
|
||||||
name: "Status",
|
name: "Status",
|
||||||
|
@ -47,52 +47,52 @@ window.wc = {
|
||||||
window.wc.core = coreInst
|
window.wc.core = coreInst
|
||||||
|
|
||||||
// connect session responses https://specs.walletconnect.com/2.0/specs/clients/sign/session-events#events
|
// connect session responses https://specs.walletconnect.com/2.0/specs/clients/sign/session-events#events
|
||||||
window.wc.web3wallet.on("session_proposal", (details) => {
|
window.wc.walletKit.on("session_proposal", (details) => {
|
||||||
wc.statusObject.onSessionProposal(details)
|
wc.statusObject.onSessionProposal(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_update", (details) => {
|
window.wc.walletKit.on("session_update", (details) => {
|
||||||
wc.statusObject.onSessionUpdate(details)
|
wc.statusObject.onSessionUpdate(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_extend", (details) => {
|
window.wc.walletKit.on("session_extend", (details) => {
|
||||||
wc.statusObject.onSessionExtend(details)
|
wc.statusObject.onSessionExtend(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_ping", (details) => {
|
window.wc.walletKit.on("session_ping", (details) => {
|
||||||
wc.statusObject.onSessionPing(details)
|
wc.statusObject.onSessionPing(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_delete", (details) => {
|
window.wc.walletKit.on("session_delete", (details) => {
|
||||||
wc.statusObject.onSessionDelete(details)
|
wc.statusObject.onSessionDelete(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_expire", (details) => {
|
window.wc.walletKit.on("session_expire", (details) => {
|
||||||
wc.statusObject.onSessionExpire(details)
|
wc.statusObject.onSessionExpire(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_request", (details) => {
|
window.wc.walletKit.on("session_request", (details) => {
|
||||||
wc.statusObject.onSessionRequest(details)
|
wc.statusObject.onSessionRequest(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_request_sent", (details) => {
|
window.wc.walletKit.on("session_request_sent", (details) => {
|
||||||
wc.statusObject.onSessionRequestSent(details)
|
wc.statusObject.onSessionRequestSent(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("session_event", (details) => {
|
window.wc.walletKit.on("session_event", (details) => {
|
||||||
wc.statusObject.onSessionEvent(details)
|
wc.statusObject.onSessionEvent(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
window.wc.web3wallet.on("proposal_expire", (details) => {
|
window.wc.walletKit.on("proposal_expire", (details) => {
|
||||||
wc.statusObject.onProposalExpire(details)
|
wc.statusObject.onProposalExpire(details)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Debug event handlers
|
// Debug event handlers
|
||||||
window.wc.web3wallet.on("pairing_expire", (event) => {
|
window.wc.walletKit.on("pairing_expire", (event) => {
|
||||||
wc.statusObject.echo("debug", `WC unhandled event: "pairing_expire" ${JSON.stringify(event)}`);
|
wc.statusObject.echo("debug", `WC unhandled event: "pairing_expire" ${JSON.stringify(event)}`);
|
||||||
// const { topic } = event;
|
// const { topic } = event;
|
||||||
});
|
});
|
||||||
window.wc.web3wallet.on("session_request_expire", (event) => {
|
window.wc.walletKit.on("session_request_expire", (event) => {
|
||||||
const { id } = event
|
const { id } = event
|
||||||
wc.statusObject.onSessionRequestExpire(id)
|
wc.statusObject.onSessionRequestExpire(id)
|
||||||
});
|
});
|
||||||
|
@ -112,19 +112,19 @@ window.wc = {
|
||||||
|
|
||||||
// TODO: there is a corner case when attempting to pair with a link that is already paired or was rejected won't trigger any event back
|
// TODO: there is a corner case when attempting to pair with a link that is already paired or was rejected won't trigger any event back
|
||||||
pair: async function (uri) {
|
pair: async function (uri) {
|
||||||
await window.wc.web3wallet.pair({ uri });
|
await window.wc.walletKit.pair({ uri });
|
||||||
},
|
},
|
||||||
|
|
||||||
getPairings: function () {
|
getPairings: function () {
|
||||||
return window.wc.web3wallet.core.pairing.getPairings();
|
return window.wc.walletKit.core.pairing.getPairings();
|
||||||
},
|
},
|
||||||
|
|
||||||
getActiveSessions: function () {
|
getActiveSessions: function () {
|
||||||
return window.wc.web3wallet.getActiveSessions();
|
return window.wc.walletKit.getActiveSessions();
|
||||||
},
|
},
|
||||||
|
|
||||||
disconnect: async function (topic) {
|
disconnect: async function (topic) {
|
||||||
await window.wc.web3wallet.disconnectSession(
|
await window.wc.walletKit.disconnectSession(
|
||||||
{
|
{
|
||||||
topic,
|
topic,
|
||||||
reason: getSdkError('USER_DISCONNECTED')
|
reason: getSdkError('USER_DISCONNECTED')
|
||||||
|
@ -133,7 +133,7 @@ window.wc = {
|
||||||
},
|
},
|
||||||
|
|
||||||
ping: async function (topic) {
|
ping: async function (topic) {
|
||||||
await window.wc.web3wallet.engine.signClient.ping({ topic });
|
await window.wc.walletKit.engine.signClient.ping({ topic });
|
||||||
},
|
},
|
||||||
|
|
||||||
buildApprovedNamespaces: async function (params, supportedNamespaces) {
|
buildApprovedNamespaces: async function (params, supportedNamespaces) {
|
||||||
|
@ -148,7 +148,7 @@ window.wc = {
|
||||||
|
|
||||||
const { relays } = params
|
const { relays } = params
|
||||||
|
|
||||||
return await window.wc.web3wallet.approveSession(
|
return await window.wc.walletKit.approveSession(
|
||||||
{
|
{
|
||||||
id,
|
id,
|
||||||
relayProtocol: relays[0].protocol,
|
relayProtocol: relays[0].protocol,
|
||||||
|
@ -158,7 +158,7 @@ window.wc = {
|
||||||
},
|
},
|
||||||
|
|
||||||
rejectSession: async function (id) {
|
rejectSession: async function (id) {
|
||||||
await window.wc.web3wallet.rejectSession(
|
await window.wc.walletKit.rejectSession(
|
||||||
{
|
{
|
||||||
id,
|
id,
|
||||||
reason: getSdkError("USER_REJECTED"), // TODO USER_REJECTED_METHODS, USER_REJECTED_CHAINS, USER_REJECTED_EVENTS
|
reason: getSdkError("USER_REJECTED"), // TODO USER_REJECTED_METHODS, USER_REJECTED_CHAINS, USER_REJECTED_EVENTS
|
||||||
|
@ -169,7 +169,7 @@ window.wc = {
|
||||||
respondSessionRequest: async function (topic, id, signature) {
|
respondSessionRequest: async function (topic, id, signature) {
|
||||||
const response = formatJsonRpcResult(id, signature)
|
const response = formatJsonRpcResult(id, signature)
|
||||||
|
|
||||||
await window.wc.web3wallet.respondSessionRequest(
|
await window.wc.walletKit.respondSessionRequest(
|
||||||
{
|
{
|
||||||
topic: topic,
|
topic: topic,
|
||||||
response: response
|
response: response
|
||||||
|
@ -180,7 +180,7 @@ window.wc = {
|
||||||
rejectSessionRequest: async function (topic, id, error = false) {
|
rejectSessionRequest: async function (topic, id, error = false) {
|
||||||
const errorType = error ? "SESSION_SETTLEMENT_FAILED" : "USER_REJECTED";
|
const errorType = error ? "SESSION_SETTLEMENT_FAILED" : "USER_REJECTED";
|
||||||
|
|
||||||
await window.wc.web3wallet.respondSessionRequest(
|
await window.wc.walletKit.respondSessionRequest(
|
||||||
{
|
{
|
||||||
topic: topic,
|
topic: topic,
|
||||||
response: formatJsonRpcError(id, getSdkError(errorType)),
|
response: formatJsonRpcError(id, getSdkError(errorType)),
|
||||||
|
|
Loading…
Reference in New Issue