Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Fix disableAllActions (#1675)
Browse files Browse the repository at this point in the history
to consider `halt{BNB|LTC|BTC|BCH}Chain` + update tests
  • Loading branch information
veado authored Aug 16, 2021
1 parent d80f93c commit bb3974e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
15 changes: 8 additions & 7 deletions src/renderer/helpers/poolHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as O from 'fp-ts/lib/Option'
import { ASSETS_TESTNET } from '../../shared/mock/assets'
import { PoolDetails } from '../services/midgard/types'
import { toPoolData } from '../services/midgard/utils'
import { DEFAULT_MIMIR_HALT } from '../services/thorchain/const'
import { GetPoolsStatusEnum, PoolDetail } from '../types/generated/midgard'
import {
disableAllActions,
Expand Down Expand Up @@ -177,55 +178,55 @@ describe('helpers/poolHelper/', () => {
const result = disableAllActions({
chain: BNBChain,
haltedChains,
mimirHalt: { haltThorChain: true, haltEthChain: false }
mimirHalt: { ...DEFAULT_MIMIR_HALT, haltThorChain: true }
})
expect(result).toBeTruthy()
})
it('true if chain is not in halted list, but THORChain is halted', () => {
const result = disableAllActions({
chain: LTCChain,
haltedChains,
mimirHalt: { haltThorChain: true, haltEthChain: false }
mimirHalt: { ...DEFAULT_MIMIR_HALT, haltThorChain: true }
})
expect(result).toBeTruthy()
})
it('true for ETH if ETH chain is halted', () => {
const result = disableAllActions({
chain: ETHChain,
haltedChains,
mimirHalt: { haltThorChain: false, haltEthChain: true }
mimirHalt: { ...DEFAULT_MIMIR_HALT, haltEthChain: true }
})
expect(result).toBeTruthy()
})
it('false for a chain, if it is not in halted list, but ETH chain is halted', () => {
const result = disableAllActions({
chain: LTCChain,
haltedChains,
mimirHalt: { haltThorChain: false, haltEthChain: true }
mimirHalt: { ...DEFAULT_MIMIR_HALT, haltEthChain: true }
})
expect(result).toBeFalsy()
})
it('true if ETH is in halted list, but no mimir halt', () => {
const result = disableAllActions({
chain: ETHChain,
haltedChains,
mimirHalt: { haltThorChain: false, haltEthChain: false }
mimirHalt: DEFAULT_MIMIR_HALT
})
expect(result).toBeTruthy()
})
it('true if BNB is in halted list, but no mimir halt', () => {
const result = disableAllActions({
chain: BNBChain,
haltedChains,
mimirHalt: { haltThorChain: false, haltEthChain: false }
mimirHalt: DEFAULT_MIMIR_HALT
})
expect(result).toBeTruthy()
})
it('false if no mimir halt + chain is not in halted list', () => {
const result = disableAllActions({
chain: LTCChain,
haltedChains,
mimirHalt: { haltThorChain: false, haltEthChain: false }
mimirHalt: DEFAULT_MIMIR_HALT
})
expect(result).toBeFalsy()
})
Expand Down
22 changes: 17 additions & 5 deletions src/renderer/helpers/poolHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { PoolDetail } from '../types/generated/midgard'
import { PoolTableRowData, PoolTableRowsData, PricePool } from '../views/pools/Pools.types'
import { getPoolTableRowData } from '../views/pools/Pools.utils'
import { isRuneNativeAsset, convertBaseAmountDecimal, to1e8BaseAmount } from './assetHelper'
import { isEthChain } from './chainHelper'
import { isBchChain, isBnbChain, isBtcChain, isEthChain, isLtcChain } from './chainHelper'
import { eqChain } from './fp/eq'
import { ordBaseAmount } from './fp/ord'
import { sequenceTOption, sequenceTOptionFromArray } from './fpHelpers'
Expand Down Expand Up @@ -169,19 +169,31 @@ const isChainElem = A.elem(eqChain)
export const disableAllActions = ({
chain,
haltedChains,
mimirHalt: { haltThorChain, haltEthChain }
mimirHalt: { haltThorChain, haltEthChain, haltBnbChain, haltLtcChain, haltBtcChain, haltBchChain }
}: {
chain: Chain
haltedChains: Chain[]
mimirHalt: MimirHaltChain
}) => {
// 1. Check `haltThorChain` (provided by `mimir` endpoint) to disable all actions for all pools
// Check `haltThorChain` (provided by `mimir` endpoint) to disable all actions for all pools
if (haltThorChain) return true

// 2. Check `haltEthChain` (provided by `mimir` endpoint) to disable all actions for ETH pools
// Check `haltBnbChain` (provided by `mimir` endpoint) to disable all actions for BNB pools
if (isBnbChain(chain) && haltBnbChain) return true

// Check `haltBtcChain` (provided by `mimir` endpoint) to disable all actions for BTC pools
if (isBtcChain(chain) && haltBtcChain) return true

// Check `haltBchChain` (provided by `mimir` endpoint) to disable all actions for BCH pools
if (isBchChain(chain) && haltBchChain) return true

// Check `haltLtcChain` (provided by `mimir` endpoint) to disable all actions for LTC pools
if (isLtcChain(chain) && haltLtcChain) return true

// Check `haltEthChain` (provided by `mimir` endpoint) to disable all actions for ETH pools
if (isEthChain(chain) && haltEthChain) return true

// 3. Check `chain` is included in `haltedChains` (provided by `inbound_addresses` endpoint)
// Check `chain` is included in `haltedChains` (provided by `inbound_addresses` endpoint)
return FP.pipe(haltedChains, isChainElem(chain))
}

Expand Down

0 comments on commit bb3974e

Please sign in to comment.