Skip to content

Commit

Permalink
Merge pull request #1608 from oasisprotocol/lw/shuffle-active
Browse files Browse the repository at this point in the history
Don't shuffle inactive validators to the top
  • Loading branch information
lukaw3d authored Aug 24, 2023
2 parents 1e99434 + ac4906d commit b800969
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,28 +802,28 @@ exports[`<ValidatorList /> list should match snapshot 1`] = `
</div>
<div
class="c16 rdt_TableRow"
id="row-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
id="row-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
role="row"
>
<div
class="c17 c9 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-icon-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
id="cell-icon-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
role="gridcell"
/>
<div
class="c17 c9 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-status-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
id="cell-status-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
role="gridcell"
>
<svg
aria-label="Status is critical"
aria-label="Status is unknown"
class="c21"
viewBox="0 0 24 24"
>
<path
d="M12.703 2.703a.99.99 0 0 0-1.406 0l-8.594 8.594a.99.99 0 0 0 0 1.406l8.594 8.594a.99.99 0 0 0 1.406 0l8.594-8.594a.99.99 0 0 0 0-1.406l-8.594-8.594zM8.983 14.7 14.7 8.983m-5.717 0L14.7 14.7"
d="M2 3.99C2 2.892 2.898 2 3.99 2h16.02C21.108 2 22 2.898 22 3.99v16.02c0 1.099-.898 1.99-1.99 1.99H3.99A1.995 1.995 0 0 1 2 20.01V3.99zM12 15v-1c0-1 0-1.5 1-2s2-1 2-2.5c0-1-1-2.5-3-2.5s-3 1.264-3 3m3 6v2"
fill="none"
stroke="#000"
stroke-width="2"
Expand All @@ -833,15 +833,15 @@ exports[`<ValidatorList /> list should match snapshot 1`] = `
<div
class="c17 c10 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-name-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
id="cell-name-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
role="gridcell"
>
test-validator2
test-validator3
</div>
<div
class="c17 c13 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-escrow-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
id="cell-escrow-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
role="gridcell"
>
<span>
Expand All @@ -863,36 +863,36 @@ exports[`<ValidatorList /> list should match snapshot 1`] = `
<div
class="c17 c14 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-fee-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
id="cell-fee-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
role="gridcell"
>
20%
</div>
</div>
<div
class="c16 rdt_TableRow"
id="row-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
id="row-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
role="row"
>
<div
class="c17 c9 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-icon-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
id="cell-icon-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
role="gridcell"
/>
<div
class="c17 c9 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-status-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
id="cell-status-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
role="gridcell"
>
<svg
aria-label="Status is unknown"
aria-label="Status is critical"
class="c21"
viewBox="0 0 24 24"
>
<path
d="M2 3.99C2 2.892 2.898 2 3.99 2h16.02C21.108 2 22 2.898 22 3.99v16.02c0 1.099-.898 1.99-1.99 1.99H3.99A1.995 1.995 0 0 1 2 20.01V3.99zM12 15v-1c0-1 0-1.5 1-2s2-1 2-2.5c0-1-1-2.5-3-2.5s-3 1.264-3 3m3 6v2"
d="M12.703 2.703a.99.99 0 0 0-1.406 0l-8.594 8.594a.99.99 0 0 0 0 1.406l8.594 8.594a.99.99 0 0 0 1.406 0l8.594-8.594a.99.99 0 0 0 0-1.406l-8.594-8.594zM8.983 14.7 14.7 8.983m-5.717 0L14.7 14.7"
fill="none"
stroke="#000"
stroke-width="2"
Expand All @@ -902,15 +902,15 @@ exports[`<ValidatorList /> list should match snapshot 1`] = `
<div
class="c17 c10 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-name-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
id="cell-name-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
role="gridcell"
>
test-validator3
test-validator2
</div>
<div
class="c17 c13 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-escrow-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
id="cell-escrow-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
role="gridcell"
>
<span>
Expand All @@ -932,7 +932,7 @@ exports[`<ValidatorList /> list should match snapshot 1`] = `
<div
class="c17 c14 c18 rdt_TableCell"
data-tag="allowRowEvents"
id="cell-fee-oasis1qrfe9n26nq3t6vc9hlu9gnupwf4rm6wr0uglh3r7"
id="cell-fee-oasis1qzyqaxestzlum26e2vdgvkerm6d9qgdp7gh2pxqe"
role="gridcell"
>
20%
Expand Down
12 changes: 10 additions & 2 deletions src/app/state/staking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ErrorPayload } from 'types/errors'
import { createSlice } from 'utils/@reduxjs/toolkit'

import { DebondingDelegation, Delegation, StakingState, Validators, ValidatorDetails } from './types'
import shuffle from 'lodash/shuffle'
import { sortByStatus } from '../../../vendors/helpers'

export const initialState: StakingState = {
debondingDelegations: null,
Expand All @@ -25,11 +27,17 @@ const slice = createSlice({
fetchAccount(state, action: PayloadAction<string>) {},
updateValidators(state, action: PayloadAction<Validators>) {
state.updateValidatorsError = undefined
state.validators = action.payload
state.validators = {
...action.payload,
list: shuffle(action.payload.list).sort(sortByStatus),
}
},
updateValidatorsError(state, action: PayloadAction<{ error: ErrorPayload; validators: Validators }>) {
state.updateValidatorsError = action.payload.error
state.validators = action.payload.validators
state.validators = {
...action.payload.validators,
list: shuffle(action.payload.validators.list).sort(sortByStatus),
}
},
updateDelegations(
state,
Expand Down
18 changes: 7 additions & 11 deletions src/app/state/staking/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import { addressToPublicKey, publicKeyToAddress } from 'app/lib/helpers'
import { NetworkType } from 'app/state/network/types'
import { call, put, select, takeLatest } from 'typed-redux-saga'
import { WalletError, WalletErrors } from 'types/errors'
import { sortByStatus } from 'vendors/helpers'
import { parseValidatorsList } from 'vendors/oasisscan'

import { stakingActions } from '.'
import { getExplorerAPIs, getOasisNic } from '../network/saga'
import { selectEpoch, selectSelectedNetwork } from '../network/selectors'
import { selectValidators, selectValidatorsNetwork } from './selectors'
import { CommissionBound, DebondingDelegation, Delegation, Validators } from './types'
import shuffle from 'lodash/shuffle'

function* loadDelegations(address: string) {
const nic = yield* call(getOasisNic)
Expand Down Expand Up @@ -59,7 +57,7 @@ export function* refreshValidators() {
stakingActions.updateValidators({
timestamp: yield* call(now),
network: network,
list: shuffle(validators),
list: validators,
}),
)
} catch (errorApi: any) {
Expand Down Expand Up @@ -133,14 +131,12 @@ function* getFallbackValidators(network: NetworkType, errorApi: Error) {
}
fallbackValidators = {
...fallbackValidators,
list: fallbackValidators.list
.map(v => {
return {
...v,
status: activeNodes[v.nodeAddress] ? ('active' as const) : ('inactive' as const),
}
})
.sort(sortByStatus),
list: fallbackValidators.list.map(v => {
return {
...v,
status: activeNodes[v.nodeAddress] ? ('active' as const) : ('inactive' as const),
}
}),
}
return {
error: errorApi,
Expand Down
24 changes: 12 additions & 12 deletions src/vendors/__tests__/__snapshots__/monitor.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ exports[`monitor parse validators 1`] = `
"rank": 1,
"status": "active",
},
{
"address": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm",
"current_rate": 0.1,
"escrow": "326477290615842944",
"media": {
"website_link": "https://www.b.com",
},
"name": "b",
"nodeAddress": "oasis1qqp0h2h92eev7nsxgqctvuegt8ge3vyg0qyluc4k",
"rank": 2,
"status": "inactive",
},
{
"address": "oasis1qr0jwz65c29l044a204e3cllvumdg8cmsgt2k3ql",
"current_rate": 0.15,
Expand All @@ -247,17 +259,5 @@ exports[`monitor parse validators 1`] = `
"rank": 3,
"status": "active",
},
{
"address": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm",
"current_rate": 0.1,
"escrow": "326477290615842944",
"media": {
"website_link": "https://www.b.com",
},
"name": "b",
"nodeAddress": "oasis1qqp0h2h92eev7nsxgqctvuegt8ge3vyg0qyluc4k",
"rank": 2,
"status": "inactive",
},
]
`;
30 changes: 15 additions & 15 deletions src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,6 @@ exports[`oasisscan parse validators 1`] = `
"rank": 1,
"status": "active",
},
{
"address": "oasis1qr0jwz65c29l044a204e3cllvumdg8cmsgt2k3ql",
"current_rate": 0.15,
"escrow": "261889743040000000",
"media": {
"email_address": "[email protected]",
"logotype": "https://s3.amazonaws.com/keybase_processed_uploads/d48739023a250815c4ac564c9870ec05_360_360.jpg",
"twitter_acc": "StakingFund",
"website_link": "https://staking.fund",
},
"name": "Staking Fund",
"nodeAddress": "oasis1qp0lt6y2kq8g7ffzy49acga2l8uefngz0yf9v0jk",
"rank": 3,
"status": "active",
},
{
"address": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm",
"current_rate": 0.1,
Expand All @@ -284,5 +269,20 @@ exports[`oasisscan parse validators 1`] = `
"rank": 2,
"status": "inactive",
},
{
"address": "oasis1qr0jwz65c29l044a204e3cllvumdg8cmsgt2k3ql",
"current_rate": 0.15,
"escrow": "261889743040000000",
"media": {
"email_address": "[email protected]",
"logotype": "https://s3.amazonaws.com/keybase_processed_uploads/d48739023a250815c4ac564c9870ec05_360_360.jpg",
"twitter_acc": "StakingFund",
"website_link": "https://staking.fund",
},
"name": "Staking Fund",
"nodeAddress": "oasis1qp0lt6y2kq8g7ffzy49acga2l8uefngz0yf9v0jk",
"rank": 3,
"status": "active",
},
]
`;
3 changes: 1 addition & 2 deletions src/vendors/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'vendors/explorer'
import { addressToPublicKey } from 'app/lib/helpers'

import { sortByStatus, throwAPIErrors } from './helpers'
import { throwAPIErrors } from './helpers'

export function getMonitorAPIs(url: string | 'https://monitor.oasis.dev') {
const explorerConfig = new Configuration({
Expand Down Expand Up @@ -101,7 +101,6 @@ export function parseValidatorsList(validators: ValidatorRow[]): Validator[] {
}
return parsed
})
.sort(sortByStatus)
)
}

Expand Down
40 changes: 19 additions & 21 deletions src/vendors/oasisscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
RuntimeTransactionInfoRow,
} from 'vendors/oasisscan/index'

import { throwAPIErrors, sortByStatus } from './helpers'
import { throwAPIErrors } from './helpers'

export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainnet') {
const explorerConfig = new Configuration({
Expand Down Expand Up @@ -98,26 +98,24 @@ export function parseAccount(account: AccountsRow): Account {
}

export function parseValidatorsList(validators: ValidatorRow[]): Validator[] {
return validators
.map(v => {
const parsed: Validator = {
address: v.entityAddress,
name: v.name ?? undefined,
nodeAddress: v.nodeAddress,
escrow: parseRoseStringToBaseUnitString(v.escrow),
current_rate: v.commission,
status: v.status ? 'active' : 'inactive',
media: {
email_address: v.email ?? undefined,
logotype: v.icon ?? undefined,
twitter_acc: v.twitter ?? undefined,
website_link: v.website ?? undefined,
},
rank: v.rank,
}
return parsed
})
.sort(sortByStatus)
return validators.map(v => {
const parsed: Validator = {
address: v.entityAddress,
name: v.name ?? undefined,
nodeAddress: v.nodeAddress,
escrow: parseRoseStringToBaseUnitString(v.escrow),
current_rate: v.commission,
status: v.status ? 'active' : 'inactive',
media: {
email_address: v.email ?? undefined,
logotype: v.icon ?? undefined,
twitter_acc: v.twitter ?? undefined,
website_link: v.website ?? undefined,
},
rank: v.rank,
}
return parsed
})
}

export const transactionMethodMap: {
Expand Down

0 comments on commit b800969

Please sign in to comment.