From 8326081ec81ae6e8dc301f5cdd7a254017153921 Mon Sep 17 00:00:00 2001 From: Gancho Radkov <43912948+ganchoradkov@users.noreply.github.com> Date: Fri, 17 Mar 2023 11:47:06 +0200 Subject: [PATCH] fix: chains in approved namespaces (#137) * fix: adds chains to approved namespaces * fix: session update * fix: generate random address to update --- wallets/react-wallet-v2/src/pages/session.tsx | 36 +++++++++---------- .../src/views/SessionProposalModal.tsx | 1 + 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/wallets/react-wallet-v2/src/pages/session.tsx b/wallets/react-wallet-v2/src/pages/session.tsx index 5e4c54c..19c4a3c 100644 --- a/wallets/react-wallet-v2/src/pages/session.tsx +++ b/wallets/react-wallet-v2/src/pages/session.tsx @@ -57,26 +57,26 @@ export default function SessionPage() { setLoading(false) } - const newNs = { - eip155: { - accounts: [ - 'eip155:1:0x70012948c348CBF00806A3C79E3c5DAdFaAa347B', - 'eip155:137:0x70012948c348CBF00806A3C79E3c5DAdFaAa347B' - ], - methods: [ - 'eth_sendTransaction', - 'eth_signTransaction', - 'eth_sign', - 'personal_sign', - 'eth_signTypedData' - ], - events: ['chainChanged', 'accountsChanged'] - } - } - async function onSessionUpdate() { setLoading(true) - const { acknowledged } = await signClient.update({ topic, namespaces: newNs }) + const session = signClient.session.get(topic) + const baseAddress = '0x70012948c348CBF00806A3C79E3c5DAdFaAa347' + const namespaceKeyToUpdate = Object.keys(session?.namespaces)[0] + const namespaceToUpdate = session?.namespaces[namespaceKeyToUpdate] + const { acknowledged } = await signClient.update({ + topic, + namespaces: { + ...session?.namespaces, + [namespaceKeyToUpdate]: { + ...session?.namespaces[namespaceKeyToUpdate], + accounts: namespaceToUpdate.accounts.concat( + `${namespaceToUpdate.chains?.[0]}:${baseAddress}${Math.floor( + Math.random() * (9 - 1 + 1) + 0 + )}` + ) // generates random number between 0 and 9 + } + } + }) await acknowledged() setUpdated(new Date()) setLoading(false) diff --git a/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx b/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx index 6534b76..d1aefa5 100644 --- a/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx +++ b/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx @@ -69,6 +69,7 @@ export default function SessionProposalModal() { }) namespaces[key] = { accounts, + chains: key.includes(':') ? [key] : requiredNamespaces[key].chains, methods: requiredNamespaces[key].methods, events: requiredNamespaces[key].events }