From 246ab4e251f205cb48d785ae01ba8caad65f67c9 Mon Sep 17 00:00:00 2001 From: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com> Date: Tue, 26 May 2020 19:23:32 +0200 Subject: [PATCH] Pin Polkadot CC1 ahead of Kusama (#265) --- frontend/src/App.tsx | 10 ++++------ frontend/src/Connection.ts | 4 ++-- frontend/src/state.ts | 12 +++++++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 5671240..6ab7955 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -4,7 +4,7 @@ import { AllChains, Chains, Chain, Ago, OfflineIndicator } from './components'; import { Row, Column } from './components/List'; import { Connection } from './Connection'; import { Persistent, PersistentObject, PersistentSet } from './persist'; -import { State, Node, ChainData, PINNED_CHAIN } from './state'; +import { State, Node, ChainData, comparePinnedChains } from './state'; import { getHashData } from './utils'; import stable from 'stable'; @@ -203,12 +203,10 @@ export default class App extends React.Component<{}, State> { this.chainsCache = stable.inplace( Array.from(this.state.chains.values()), (a, b) => { - if (a.label === PINNED_CHAIN) { - return -1; - } + const pinned = comparePinnedChains(a.label, b.label); - if (b.label === PINNED_CHAIN) { - return 1; + if (pinned !== 0) { + return pinned; } return b.nodeCount - a.nodeCount; diff --git a/frontend/src/Connection.ts b/frontend/src/Connection.ts index 52e45e3..7ae60af 100644 --- a/frontend/src/Connection.ts +++ b/frontend/src/Connection.ts @@ -5,7 +5,7 @@ import { Node, UpdateBound, ChainData, - PINNED_CHAIN, + PINNED_CHAINS, } from './state'; import { PersistentSet } from './persist'; import { getHashData, setHashData } from './utils'; @@ -518,7 +518,7 @@ export class Connection { let topChain: Maybe = null; for (const chain of chains.values()) { - if (chain.label === PINNED_CHAIN) { + if (PINNED_CHAINS[chain.label] === 1) { topChain = chain; break; } diff --git a/frontend/src/state.ts b/frontend/src/state.ts index 2f8f953..a5153db 100644 --- a/frontend/src/state.ts +++ b/frontend/src/state.ts @@ -1,7 +1,17 @@ import { Types, Maybe, SortedCollection } from './common'; import { Column } from './components/List'; -export const PINNED_CHAIN = 'Kusama'; +export const PINNED_CHAINS = { + Kusama: 2, + 'Polkadot CC1': 1, +}; + +export function comparePinnedChains(a: string, b: string) { + const aWeight = PINNED_CHAINS[a] || 1024; + const bWeight = PINNED_CHAINS[b] || 1024; + + return aWeight - bWeight; +} export class Node { public static compare(a: Node, b: Node): number {