diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml b/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml index 38ef6e4e87..4ea9064aab 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/DAppsRequestHandler.qml @@ -255,7 +255,20 @@ SQUtils.QObject { const account = SQUtils.ModelUtils.getFirstModelEntryIf(root.accountsModel, (account) => { 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 @@ -264,7 +277,19 @@ SQUtils.QObject { return null } 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 diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml b/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml index 76f7698f92..86dcd4836b 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/DappsConnectorSDK.qml @@ -148,9 +148,22 @@ WalletConnectSDKBase { } 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(); }) + + 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 @@ -159,7 +172,20 @@ WalletConnectSDKBase { return null } 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) {