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.
This commit is contained in:
Alex Jbanca 2024-08-09 13:39:24 +03:00 committed by Anthony Laibe
parent 21227893c2
commit 24a386d078
2 changed files with 55 additions and 4 deletions

View File

@ -255,7 +255,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
@ -264,7 +277,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) {