Skip to content

Commit

Permalink
fixed walletconnect v2 session approval, fixed reported accounts now …
Browse files Browse the repository at this point in the history
…--from account will actually be used, fixed deprecated new Buffer() call
  • Loading branch information
r001 committed Nov 2, 2023
1 parent 5d689ea commit 9b2468b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions utils/eth/walletconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ async function walletconnectv2 (args, uri) {
});

const walletConnectV2 = await Web3Wallet.init({

core, // <- pass the shared `core` instance
metadata: {
name: "cceb",
Expand All @@ -56,6 +55,8 @@ async function walletconnectv2 (args, uri) {
},
});

var namespaces

walletConnectV2.on("session_proposal", async sessionProposal => {
log.info(`Session Proposal`)
log.debug(`Session Proposal: ${JSON.stringify(sessionProposal, null, 2)}`)
Expand All @@ -66,7 +67,7 @@ async function walletconnectv2 (args, uri) {
args.accounts.map(async account => await w3.getAddress(account))
)

const account0 = accounts[0]
const account0 = args.from || accounts[0]

const chains = Object
.keys(config.get(`web3.networks`))
Expand Down Expand Up @@ -98,7 +99,7 @@ async function walletconnectv2 (args, uri) {
log.debug(`optionalNamespaces: ${JSON.stringify(params.optionalNamespaces)}`)
log.debug(`Proposer: ${JSON.stringify(params.proposer)}`)
log.debug(`namespacesCandidate: ${JSON.stringify(namespacesCandidate)}`)
var namespaces = buildApprovedNamespaces(namespacesCandidate)
namespaces = buildApprovedNamespaces(namespacesCandidate)


await walletConnectV2.approveSession({
Expand All @@ -110,11 +111,9 @@ async function walletconnectv2 (args, uri) {

process && process.on('SIGINT', async () => {
log.info("Caught interrupt signal");
await walletConnectV2.killSession()
await walletConnectV2.core.pairing.disconnect({topic: walletConnectV2.core.pairing.topic})
log.info("Session killed");
walletConnectV2.transportClose()
log.info("Transport closed");
process.exit(0)
process && process.exit(0)
});
});

Expand All @@ -128,7 +127,7 @@ async function walletconnectv2 (args, uri) {
log.info(`Session Deleted`)
walletConnectV2.core.pairing.disconnect({topic: walletConnectV2.core.pairing.topic})
log.info("Transport closed");
process || process.exit(0)
process && process.exit(0)
});

await walletConnectV2.core.pairing.pair({uri});
Expand Down
4 changes: 2 additions & 2 deletions utils/eth/wcutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ function approveRequest (walletConnect, payload, result) {
log.info(`Request approved`)
}

function approveRequestV2 (walletConnect, topic, id, signature) {
function approveRequestV2 (walletConnectV2, topic, id, signature) {

let response =
{
Expand All @@ -567,7 +567,7 @@ function approveRequestV2 (walletConnect, topic, id, signature) {

log.debug(`approved: ${JSON.stringify(response)}`)

walletConnect.approveRequest(response)
walletConnectV2.respondSessionRequest(response)

log.info(`Request approved`)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ async function access (web3, block, to, funcName, args = [], abi, from, value, g

process.on('uncaughtException', function (err) {
var value = err.message.match(/0x([a-zA-Z0-9]*)/)[1]
value = new Buffer(value, 'hex')
value = Buffer.from(value, 'hex')
//log.error(err.message)
log.error(value.toString().replace(/[^-A-Za-z0-9/. ]/g, ''));
process.exit(0)
Expand Down

0 comments on commit 9b2468b

Please sign in to comment.