feat(dapps) fix missing list of dapps in wallet connect

Updates: #15126
This commit is contained in:
Stefan 2024-06-19 18:17:49 +03:00 committed by Stefan Dunca
parent 92d0420449
commit cb368ea5fb
5 changed files with 85 additions and 16 deletions

View File

@ -249,12 +249,10 @@ QtObject:
# setup other event handlers
self.eventsHandler.onFilteringDone(proc (jsonObj: JsonNode) =
echo "@dd eventsHandler.onFilteringDone: ", $jsonObj
self.processResponse(jsonObj)
)
self.eventsHandler.onFilteringUpdateDone(proc (jn: JsonNode) =
echo "@dd eventsHandler.onFilteringUpdateDone: ", $jn
if jn.kind != JArray:
error "expected an array"

View File

@ -103,7 +103,7 @@ QtObject:
return ""
if buildTxResponse.isNil or buildTxResponse.kind != JsonNodeKind.JObject or
not buildTxResponse.hasKey("txArgs") or not buildTxResponse.hasKey("messageToSign"):
error "unexpected buildTransaction response"
error "unexpected wallet_buildTransaction response"
return ""
var txToBeSigned = buildTxResponse["messageToSign"].getStr
if txToBeSigned.len != wallet_constants.TX_HASH_LEN_WITH_PREFIX:

View File

@ -54,6 +54,13 @@ const dappMetadataJsonString = `{
"url": "${dappUrl}"
}`
// https://metamask.github.io/test-dapp/ use case that doesn't have icons
const noIconsDappMetadataJsonString = `{
"description": "This is the E2e Test Dapp",
"name": "${dappName}",
"url": "${dappUrl}"
}`
const verifiedContextJsonString = `{
"verified": {
"origin": "https://app.test.org",
@ -62,7 +69,12 @@ const verifiedContextJsonString = `{
}
}`
function formatSessionProposal() {
function formatSessionProposal(custom) {
var dappMetadataJsonStringOverride = dappMetadataJsonString
if (custom && custom.dappMetadataJsonString) {
dappMetadataJsonStringOverride = custom.dappMetadataJsonString
}
return `{
"id": 1715976881734096,
"params": {
@ -71,7 +83,7 @@ function formatSessionProposal() {
"optionalNamespaces": ${optionalNamespacesJsonString},
"pairingTopic": "50fba141cdb5c015493c2907c46bacf9f7cbd7c8e3d4e97df891f18dddcff69c",
"proposer": {
"metadata": ${dappMetadataJsonString},
"metadata": ${dappMetadataJsonStringOverride},
"publicKey": "095d9992ca0eb6081cabed26faf48919162fd70cc66d639f118a60507ae0463d"
},
"relays": [
@ -98,7 +110,11 @@ function formatBuildApprovedNamespacesResult(networksArray, accountsArray) {
}`
}
function formatApproveSessionResponse(networksArray, accountsArray) {
function formatApproveSessionResponse(networksArray, accountsArray, custom) {
var dappMetadataJsonStringOverride = dappMetadataJsonString
if (custom && custom.dappMetadataJsonString) {
dappMetadataJsonStringOverride = custom.dappMetadataJsonString
}
let chainsStr = networksArray.map(chainId => `"eip155:${chainId}"`).join(',')
let accountsStr = accountsArray.map(address => networksArray.map(chainId => `"eip155:${chainId}:${address}"`).join(',')).join(',')
return `{
@ -116,7 +132,7 @@ function formatApproveSessionResponse(networksArray, accountsArray) {
"optionalNamespaces": ${optionalNamespacesJsonString},
"pairingTopic": "50fba141cdb5c015493c2907c46bacf9f7cbd7c8e3d4e97df891f18dddcff69c",
"peer": {
"metadata": ${dappMetadataJsonString},
"metadata": ${dappMetadataJsonStringOverride},
"publicKey": "095d9992ca0eb6081cabed26faf48919162fd70cc66d639f118a60507ae0463d"
},
"relay": {

View File

@ -25,7 +25,7 @@ Item {
width: 600
height: 400
// TODO #15151 fix CI crash and re-enable tests
// // TODO #15151 fix CI crash and re-enable tests
// Component {
// id: sdkComponent
@ -79,13 +79,15 @@ Item {
// id: dappsStoreComponent
// DAppsStore {
// property string dappsListReceivedJsonStr: '[]'
// signal dappsListReceived(string dappsJson)
// signal userAuthenticated(string topic, string id, string password, string pin)
// signal userAuthenticationFailed(string topic, string id)
// // By default, return no dapps in store
// function getDapps() {
// dappsListReceived('[]')
// dappsListReceived(dappsListReceivedJsonStr)
// return true
// }
@ -333,8 +335,54 @@ Item {
// }
// Component {
// id: componentUnderTest
// DAppsWorkflow {
// id: dappsListProviderComponent
// DAppsListProvider {
// }
// }
// TestCase {
// name: "DAppsListProvider"
// property DAppsListProvider provider: null
// readonly property var dappsListReceivedJsonStr: '[{"url":"https://tst1.com","name":"name1","iconUrl":"https://tst1.com/u/1"},{"url":"https://tst2.com","name":"name2","iconUrl":"https://tst2.com/u/2"}]'
// function init() {
// // Simulate the SDK not being ready
// let sdk = createTemporaryObject(sdkComponent, root, {projectId: "12ab", sdkReady: false})
// verify(!!sdk)
// let store = createTemporaryObject(dappsStoreComponent, root, {
// dappsListReceivedJsonStr: dappsListReceivedJsonStr
// })
// verify(!!store)
// provider = createTemporaryObject(dappsListProviderComponent, root, {sdk: sdk, store: store})
// verify(!!provider)
// }
// function cleanup() {
// }
// // Implemented as a regression to metamask not having icons which failed dapps list
// function test_TestUpdateDapps() {
// provider.updateDapps()
// // Validate that persistance fallback is working
// compare(provider.dappsModel.count, 2, "expected dappsModel have the right number of elements")
// let persistanceList = JSON.parse(dappsListReceivedJsonStr)
// compare(provider.dappsModel.get(0).url, persistanceList[0].url, "expected url to be set")
// compare(provider.dappsModel.get(0).iconUrl, persistanceList[0].iconUrl, "expected iconUrl to be set")
// compare(provider.dappsModel.get(1).name, persistanceList[1].name, "expected name to be set")
// // Validate that SDK's `getActiveSessions` is not called if not ready
// let sdk = provider.sdk
// compare(sdk.getActiveSessionsCallbacks.length, 0, "expected no calls to sdk.getActiveSessions yet")
// sdk.sdkReady = true
// compare(sdk.getActiveSessionsCallbacks.length, 1, "expected a call to sdk.getActiveSessions when SDK becomes ready")
// let callback = sdk.getActiveSessionsCallbacks[0].callback
// let session = JSON.parse(Testing.formatApproveSessionResponse([1, 2], ["0x1"], {dappMetadataJsonString: Testing.noIconsDappMetadataJsonString}))
// callback({"b536a": session, "b537b": session})
// compare(provider.dappsModel.count, 1, "expected dappsModel have the SDK's reported dapps")
// compare(provider.dappsModel.get(0).iconUrl, "", "expected iconUrl to be missing")
// }
// }
@ -418,7 +466,13 @@ Item {
// }
// }
// TODO #15151: this TestCase if placed before ServiceHelpers was not run with `when: windowShown`. Check if related to the CI crash
// Component {
// id: componentUnderTest
// DAppsWorkflow {
// }
// }
// // TODO #15151: this TestCase if placed before ServiceHelpers was not run with `when: windowShown`. Check if related to the CI crash
// TestCase {
// id: dappsWorkflowTest

View File

@ -54,17 +54,18 @@ QObject {
sdk.getActiveSessions((sessions) => {
root.store.dappsListReceived.disconnect(dappsListReceivedFn);
// TODO #14755: on SDK dApps refresh update the model that has data source from persistence instead of using reset
dapps.clear();
let tmpMap = {}
for (let key in sessions) {
let dapp = sessions[key].peer.metadata
if (dapp.icons.length > 0) {
if (!!dapp.icons && dapp.icons.length > 0) {
dapp.iconUrl = dapp.icons[0]
} else {
dapp.iconUrl = ""
}
tmpMap[dapp.url] = dapp;
}
// TODO #14755: on SDK dApps refresh update the model that has data source from persistence instead of using reset
dapps.clear();
// Iterate tmpMap and fill dapps
for (let key in tmpMap) {
dapps.append(tmpMap[key]);