fix(WalletConnect): Fixing crash on authentication screen when the app resumes from a few minutes of inactivity

The root cause in this case was the usage of js stored QObjects coming from the model.

(cherry picked from commit 24a386d078)
This commit is contained in:
Alex Jbanca 2024-08-09 13:39:24 +03:00 committed by Alex Jbanca
parent 8d78f0fab2
commit f00d7f3ec4
2 changed files with 55 additions and 4 deletions

View File

@ -271,7 +271,20 @@ SQUtils.QObject {
const account = SQUtils.ModelUtils.getFirstModelEntryIf(root.accountsModel, (account) => { const account = SQUtils.ModelUtils.getFirstModelEntryIf(root.accountsModel, (account) => {
return account.address.toLowerCase() === address.toLowerCase(); return account.address.toLowerCase() === address.toLowerCase();
}) })
return { account, success: true }
if (!account) {
return { account: null, success: true }
}
// deep copy to avoid operations on the original object
try {
const accountCopy = JSON.parse(JSON.stringify(account))
return { account: accountCopy, success: true }
}
catch (e) {
console.error("Error parsing account", e)
return { account: null, success: false }
}
} }
/// Returns null if the network is not found /// Returns null if the network is not found
@ -280,7 +293,19 @@ SQUtils.QObject {
return null return null
} }
const chainId = DAppsHelpers.chainIdFromEip155(event.params.chainId) const chainId = DAppsHelpers.chainIdFromEip155(event.params.chainId)
return SQUtils.ModelUtils.getByKey(root.networksModel, "chainId", chainId) const network = SQUtils.ModelUtils.getByKey(root.networksModel, "chainId", chainId)
if (!network) {
return null
}
// deep copy to avoid operations on the original object
try {
return JSON.parse(JSON.stringify(network))
} catch (e) {
console.error("Error parsing network", network)
return null
}
} }
/// Returns null if the network is not found /// Returns null if the network is not found

View File

@ -148,9 +148,22 @@ WalletConnectSDKBase {
} }
address = event.params.request.params[0] address = event.params.request.params[0]
} }
return SQUtils.ModelUtils.getFirstModelEntryIf(root.wcService.validAccounts, (account) => { const account = SQUtils.ModelUtils.getFirstModelEntryIf(root.wcService.validAccounts, (account) => {
return account.address.toLowerCase() === address.toLowerCase(); return account.address.toLowerCase() === address.toLowerCase();
}) })
if (!account) {
return null
}
// deep copy to avoid operations on the original object
try {
return JSON.parse(JSON.stringify(account))
}
catch (e) {
console.error("Error parsing account", e.message)
return null
}
} }
/// Returns null if the network is not found /// Returns null if the network is not found
@ -159,7 +172,20 @@ WalletConnectSDKBase {
return null return null
} }
const chainId = DAppsHelpers.chainIdFromEip155(event.params.chainId) const chainId = DAppsHelpers.chainIdFromEip155(event.params.chainId)
return SQUtils.ModelUtils.getByKey(networksModule.flatNetworks, "chainId", chainId) const network = SQUtils.ModelUtils.getByKey(networksModule.flatNetworks, "chainId", chainId)
if (!network) {
return null
}
// deep copy to avoid operations on the original object
try {
return JSON.parse(JSON.stringify(network))
}
catch (e) {
console.error("Error parsing network", e)
return null
}
} }
function extractMethodData(event, method) { function extractMethodData(event, method) {