fix: chains in approved namespaces (#137)

* fix: adds chains to approved namespaces

* fix: session update

* fix: generate random address to update
This commit is contained in:
Gancho Radkov 2023-03-17 11:47:06 +02:00 committed by GitHub
parent bd60654e16
commit 8326081ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View File

@ -57,26 +57,26 @@ export default function SessionPage() {
setLoading(false) 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() { async function onSessionUpdate() {
setLoading(true) 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() await acknowledged()
setUpdated(new Date()) setUpdated(new Date())
setLoading(false) setLoading(false)

View File

@ -69,6 +69,7 @@ export default function SessionProposalModal() {
}) })
namespaces[key] = { namespaces[key] = {
accounts, accounts,
chains: key.includes(':') ? [key] : requiredNamespaces[key].chains,
methods: requiredNamespaces[key].methods, methods: requiredNamespaces[key].methods,
events: requiredNamespaces[key].events events: requiredNamespaces[key].events
} }