Skip to content

Commit

Permalink
Merge branch 'V3' into feat/connect-test
Browse files Browse the repository at this point in the history
  • Loading branch information
arein authored Dec 20, 2023
2 parents 2efc7ac + 9cea47e commit 26ea6b0
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/scaffold/src/views/w3m-networks-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,30 @@ export class W3mNetworksView extends LitElement {
const { approvedCaipNetworkIds, requestedCaipNetworks, supportsAllNetworks } =
NetworkController.state
const approvedIds = approvedCaipNetworkIds
const requested = requestedCaipNetworks
const requestedNetworks = requestedCaipNetworks
const approvedIndexMap: Record<string, number> = {}
if (requestedNetworks && approvedIds) {
approvedIds.forEach((id, index) => {
approvedIndexMap[id] = index
})

if (approvedIds?.length) {
requested?.sort((a, b) => approvedIds.indexOf(b.id) - approvedIds.indexOf(a.id))
requestedNetworks.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(
return requestedNetworks?.map(
network => html`
<wui-card-select
.selected=${this.caipNetwork?.id === network.id}
Expand Down

0 comments on commit 26ea6b0

Please sign in to comment.