From e6dafab84dcb981ffb6e524551c2477163ce0e69 Mon Sep 17 00:00:00 2001 From: Sven Date: Fri, 15 Dec 2023 13:09:51 +0100 Subject: [PATCH 1/2] fix order --- .../src/views/w3m-networks-view/index.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/scaffold/src/views/w3m-networks-view/index.ts b/packages/scaffold/src/views/w3m-networks-view/index.ts index cea91208b5..2fea5ace42 100644 --- a/packages/scaffold/src/views/w3m-networks-view/index.ts +++ b/packages/scaffold/src/views/w3m-networks-view/index.ts @@ -63,9 +63,26 @@ export class W3mNetworksView extends LitElement { NetworkController.state const approvedIds = approvedCaipNetworkIds const requested = requestedCaipNetworks + const approvedIndexMap: Record = {} + if (requested && approvedIds) { + approvedIds.forEach((id, index) => { + approvedIndexMap[id] = index + }) - if (approvedIds?.length) { - requested?.sort((a, b) => approvedIds.indexOf(b.id) - approvedIds.indexOf(a.id)) + requested.sort((a, b) => { + const indexA = approvedIndexMap[a.id] + const indexB = approvedIndexMap[b.id] + + if (indexA !== undefined && indexB !== undefined) { + return indexA - indexB + } else if (indexA !== undefined) { + return -1 + } else if (indexB !== undefined) { + return 1 + } + + return 0 + }) } return requested?.map( From eea6b251fe996de1ff8007c310cc1a56f59af6ee Mon Sep 17 00:00:00 2001 From: Sven Date: Fri, 15 Dec 2023 14:29:44 +0100 Subject: [PATCH 2/2] fix name --- packages/scaffold/src/views/w3m-networks-view/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/scaffold/src/views/w3m-networks-view/index.ts b/packages/scaffold/src/views/w3m-networks-view/index.ts index 2fea5ace42..7935dbcbb9 100644 --- a/packages/scaffold/src/views/w3m-networks-view/index.ts +++ b/packages/scaffold/src/views/w3m-networks-view/index.ts @@ -62,14 +62,14 @@ export class W3mNetworksView extends LitElement { const { approvedCaipNetworkIds, requestedCaipNetworks, supportsAllNetworks } = NetworkController.state const approvedIds = approvedCaipNetworkIds - const requested = requestedCaipNetworks + const requestedNetworks = requestedCaipNetworks const approvedIndexMap: Record = {} - if (requested && approvedIds) { + if (requestedNetworks && approvedIds) { approvedIds.forEach((id, index) => { approvedIndexMap[id] = index }) - requested.sort((a, b) => { + requestedNetworks.sort((a, b) => { const indexA = approvedIndexMap[a.id] const indexB = approvedIndexMap[b.id] @@ -85,7 +85,7 @@ export class W3mNetworksView extends LitElement { }) } - return requested?.map( + return requestedNetworks?.map( network => html`