fix(dapps): failure if case sensitivity mismatch in account address

Update: #15126
This commit is contained in:
Stefan 2024-06-20 23:34:59 +03:00 committed by Stefan Dunca
parent cb368ea5fb
commit 8cca2664e4
3 changed files with 53 additions and 3 deletions

View File

@ -78,6 +78,7 @@ Item {
// Component { // Component {
// id: dappsStoreComponent // id: dappsStoreComponent
// DAppsStore { // DAppsStore {
// property string dappsListReceivedJsonStr: '[]' // property string dappsListReceivedJsonStr: '[]'
@ -133,7 +134,7 @@ Item {
// emoji: "😋" // emoji: "😋"
// color: "#2A4AF5" // color: "#2A4AF5"
// } // }
// ListElement { address: "0x3" } // ListElement { address: "0x3a" }
// } // }
// readonly property ListModel ownAccounts: accounts // readonly property ListModel ownAccounts: accounts
// } // }
@ -183,6 +184,23 @@ Item {
// compare(store.signMessageCalls.length, 1, "expected a call to store.signMessage") // compare(store.signMessageCalls.length, 1, "expected a call to store.signMessage")
// compare(store.signMessageCalls[0].message, td.request.data) // compare(store.signMessageCalls[0].message, td.request.data)
// } // }
// function test_onSessionRequestEventDifferentCaseForAddress() {
// let sdk = handler.sdk
// let testAddressUpper = "0x3A"
// let chainId = 2
// let method = "personal_sign"
// let message = "hello world"
// let params = [Helpers.strToHex(message), testAddressUpper]
// let topic = "b536a"
// let session = JSON.parse(Testing.formatSessionRequest(chainId, method, params, topic))
// // Expect to have calls to getActiveSessions from service initialization
// let prevRequests = sdk.getActiveSessionsCallbacks.length
// sdk.sessionRequestEvent(session)
// compare(sdk.getActiveSessionsCallbacks.length, 1, "expected DAppsRequestHandler call sdk.getActiveSessions")
// }
// } // }
// TestCase { // TestCase {
@ -298,7 +316,7 @@ Item {
// let walletStore = service.walletStore // let walletStore = service.walletStore
// let store = service.store // let store = service.store
// let testAddress = "0x3" // let testAddress = "0x3a"
// let chainId = 2 // let chainId = 2
// let method = "personal_sign" // let method = "personal_sign"
// let message = "hello world" // let message = "hello world"

View File

@ -138,4 +138,22 @@ QtObject {
function roleNames(model) { function roleNames(model) {
return Internal.ModelUtils.roleNames(model) return Internal.ModelUtils.roleNames(model)
} }
/// Returns the first model entry that satisfies the condition function or null if none is found.
function getFirstModelEntryIf(model, conditionFn) {
if (!model)
return null
const count = model.rowCount()
for (let i = 0; i < count; i++) {
const modelItem = Internal.ModelUtils.get(model, i)
if (conditionFn(modelItem)) {
return modelItem
}
}
return null
}
} }

View File

@ -112,8 +112,20 @@ QObject {
function resolveAsync(event) { function resolveAsync(event) {
let method = event.params.request.method let method = event.params.request.method
let account = lookupAccountFromEvent(event, method) let account = lookupAccountFromEvent(event, method)
if(!account) {
console.error("Error finding account for event", JSON.stringify(event))
return null
}
let network = lookupNetworkFromEvent(event, method) let network = lookupNetworkFromEvent(event, method)
if(!network) {
console.error("Error finding network for event", JSON.stringify(event))
return null
}
let data = extractMethodData(event, method) let data = extractMethodData(event, method)
if(!data) {
console.error("Error in event data lookup", JSON.stringify(event))
return null
}
let obj = sessionRequestComponent.createObject(null, { let obj = sessionRequestComponent.createObject(null, {
event, event,
topic: event.topic, topic: event.topic,
@ -175,7 +187,9 @@ QObject {
} }
address = event.params.request.params[0].from address = event.params.request.params[0].from
} }
return ModelUtils.getByKey(walletStore.ownAccounts, "address", address) return ModelUtils.getFirstModelEntryIf(walletStore.ownAccounts, (account) => {
return account.address.toLowerCase() === address.toLowerCase()
})
} }
/// Returns null if the network is not found /// Returns null if the network is not found