Skip to content

Commit

Permalink
fix: update sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Nov 17, 2021
1 parent 426c832 commit 5abf06e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 31 deletions.
52 changes: 21 additions & 31 deletions packages/ui/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import feeds from '@/apollo/queries/feeds.gql'
import networks from '@/apollo/queries/networks.gql'
import { formatSvgName } from '../utils/formatSvgName'
import { generateSelectOptions } from '../utils/generateSelectOptions'
import { sortByNetwork } from '../utils/sortByNetwork'
export default {
apollo: {
Expand Down Expand Up @@ -63,37 +64,26 @@ export default {
},
allFeeds() {
if (this.feeds) {
return this.feeds.feeds
.map((feed) => {
return {
detailsPath: {
name: 'feeds-id',
params: { id: feed.feedFullName },
},
decimals: parseInt(feed.feedFullName.split('_').pop()) || 3,
name: feed.name,
value: feed.lastResult,
label: feed.label,
img: {
name: formatSvgName(feed.name),
alt: feed.name,
},
network: feed.network,
color: feed.color,
blockExplorer: feed.blockExplorer,
}
})
.sort((a, b) => {
if (a.network.includes('ethereum-mainnet')) {
return -1
} else if (a.network.includes('ethereum')) {
return 0
} else if (a.network < b.network) {
return 1
} else {
return 2
}
})
const allfeeds = this.feeds.feeds.map((feed) => {
return {
detailsPath: {
name: 'feeds-id',
params: { id: feed.feedFullName },
},
decimals: parseInt(feed.feedFullName.split('_').pop()) || 3,
name: feed.name,
value: feed.lastResult,
label: feed.label,
img: {
name: formatSvgName(feed.name),
alt: feed.name,
},
network: feed.network,
color: feed.color,
blockExplorer: feed.blockExplorer,
}
})
return sortByNetwork(allfeeds)
} else {
return []
}
Expand Down
23 changes: 23 additions & 0 deletions packages/ui/tests/utils/sortByNetwork.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { sortByNetwork } from '../../utils/sortByNetwork'

describe('sortByNetwork.js', () => {
it('orders ethereum-mainnet first, ethereum remainning networks in second place, and the rest alphabetically', () => {
const feeds = [
{ network: 'boba-rinkeby' },
{ network: 'conflux-testnet' },
{ network: 'ethereum-rinkeby' },
{ network: 'ethereum-mainnet' },
{ network: 'ethereum-goerli' },
]

const options = sortByNetwork(feeds)

expect(options).toStrictEqual([
{ network: 'ethereum-mainnet' },
{ network: 'ethereum-rinkeby' },
{ network: 'ethereum-goerli' },
{ network: 'boba-rinkeby' },
{ network: 'conflux-testnet' },
])
})
})
17 changes: 17 additions & 0 deletions packages/ui/utils/sortByNetwork.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function sortByNetwork(feeds) {
return feeds.sort((firstFeed, secondFeed) => {
if (
firstFeed.network.includes('ethereum-mainnet') &&
!secondFeed.network.includes('ethereum-mainnet')
) {
return -1
} else if (
firstFeed.network.includes('ethereum') &&
!secondFeed.network.includes('ethereum')
) {
return -1
} else {
return 0
}
})
}

0 comments on commit 5abf06e

Please sign in to comment.