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 }