Skip to content

Commit

Permalink
Merge pull request #641 from alexstotsky/improve-test-pairs-symb-hand…
Browse files Browse the repository at this point in the history
…ling

(improvements) Symbols and pairs handling
  • Loading branch information
prdn authored May 2, 2023
2 parents b4c67b9 + 1b7e823 commit 8d3afbe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
33 changes: 29 additions & 4 deletions src/state/symbols/reducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import authTypes from 'state/auth/constants'
import { formatPair, mapPair, mapSymbol } from 'state/symbols/utils'
import {
formatPair, mapPair, mapSymbol, isTestSymbol,
} from 'state/symbols/utils'
import _map from 'lodash/map'
import _join from 'lodash/join'
import _split from 'lodash/split'
import _reduce from 'lodash/reduce'
import _replace from 'lodash/replace'
import _includes from 'lodash/includes'

import SymbolMap from './map'
import types from './constants'
Expand Down Expand Up @@ -37,13 +44,16 @@ export function symbolsReducer(state = initialState, action) {
let { symbol } = currency

if (symbol && id !== symbol) {
if (id.includes('TEST')) {
symbol = `${symbol} (Test)`
}
if (id.includes('F0')) {
symbol = `${symbol} (deriv)`
}
if (symbol === 'USDt') {
symbolMapping.UST = symbol
} else {
symbolMapping[_replace(id, 'TEST', '')] = symbol
symbolMapping[id] = symbol
}

explorersDict[symbol] = explorer
Expand All @@ -59,7 +69,13 @@ export function symbolsReducer(state = initialState, action) {

const preparedCoins = [...new Set(coins)].sort()

const pairMapping = mapSymbols.reduce((acc, symbol) => {
const preparedMapSymbols = _map(mapSymbols, item => {
const [itemId, itemName] = item
if (_includes(itemId, 'TEST')) return [itemId, `${itemName} (Test)`]
return item
})

const pairMapping = _reduce(preparedMapSymbols, (acc, symbol) => {
const [from, to] = symbol
acc[from] = to
return acc
Expand All @@ -72,6 +88,15 @@ export function symbolsReducer(state = initialState, action) {
const formattedPairs = pairs.map(formatPair).map(mapPair).sort()
const formattedInactivePairs = inactiveSymbols.map(formatPair).map(mapPair).sort()


const preparedPairs = _map(formattedPairs, pair => {
const [firstSymbol, secondSymbol] = _split(pair, ':')
if (isTestSymbol(firstSymbol) && isTestSymbol(secondSymbol)) {
return _join([_replace(firstSymbol, ' (Test)', ''), secondSymbol], ':')
}
return pair
})

return {
...state,
coins: preparedCoins,
Expand All @@ -80,7 +105,7 @@ export function symbolsReducer(state = initialState, action) {
inactiveCurrencies: formattedInactiveCurrencies,
inactivePairs: formattedInactivePairs,
isFetched: true,
pairs: formattedPairs,
pairs: preparedPairs,
}
}
case authTypes.LOGOUT:
Expand Down
3 changes: 3 additions & 0 deletions src/state/symbols/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export const formatRawSymbols = (symbols, isFunding) => {
: symbolsArray[0]
}

export const isTestSymbol = (symbol) => _includes(symbol, ' (Test)')

export default {
formatPair,
formatRawSymbols,
Expand All @@ -87,4 +89,5 @@ export default {
isFundingSymbol,
isTradingPair,
removePrefix,
isTestSymbol,
}
15 changes: 14 additions & 1 deletion src/state/symbols/utils/mapping.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import _join from 'lodash/join'
import _split from 'lodash/split'
import _includes from 'lodash/includes'
import _castArray from 'lodash/castArray'

import { isTestSymbol } from 'state/symbols/utils'

import SymbolMap from '../map'

const preparePair = (pair) => {
const [firstSymbol, secondSymbol] = _split(pair, ':')
if (isTestSymbol(secondSymbol)) {
return _join([`${firstSymbol} (Test)`, secondSymbol], ':')
}
return pair
}

// BAB -> BCH
export const mapSymbol = symbol => SymbolMap.symbols[symbol] || symbol

Expand Down Expand Up @@ -51,7 +63,8 @@ export const demapPairs = (pairs, returnString = false) => {
if (SymbolMap.pairsDemap[pair]) {
return SymbolMap.pairsDemap[pair]
}
return demapSymbols(pair.split(':')).join(':')
const preparedPair = preparePair(pair)
return demapSymbols(preparedPair.split(':')).join(':')
})

return returnString
Expand Down

0 comments on commit 8d3afbe

Please sign in to comment.