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E,QAAc,IAAdA,OAAc,EAAdA,EAAgBC,cACjC,CAGEvE,GACA2B,IACiB,QAAjBwC,EAAAT,OAAO/B,UAAU,IAAAwC,GAAY,QAAZC,EAAjBD,EAAmBlC,MAAM,YAAI,IAAAmC,GAAK,QAALC,EAA7BD,EAAgC,UAAE,IAAAC,OAAjB,EAAjBA,EAAoChE,QAASL,IAE7CkE,EAAmBM,OAAO7C,GAAWS,QAAQpC,GAEjD,CAEAN,EAAM8B,GAAY0C,CACpB,CAGF,OAAOxE,EAAM8B,EACf,CArEK5B,GACHM,EAAWP,E","sources":["services/get-permissible-odds.ts","utils/betslip/odd-formats-helper.ts"],"sourcesContent":["import { CommandNames } from 'utils/constants/swarm/swarm-command-names';\nimport RidGenerator from 'utils/swarm/rid-generator';\nimport { WebsocketEnhanced } from 'interfaces/spring-websocket-interfaces';\nimport { connectingWS } from 'hooks/useSpringConnect';\n\nconst permissibleOddsCommand = async (\n  commandObj: any,\n  rid: string,\n  callback: Function,\n  updateCallback: Function,\n  callbackError: Function | null\n) => {\n  connectingWS.then((socket: WebsocketEnhanced) => {\n    socket.sendCommand(\n      commandObj,\n      rid,\n      callback,\n      updateCallback,\n      callbackError\n    );\n  });\n};\n\nexport const getPermissibleOdds = (\n  callback: Function,\n  callbackError: Function | null\n): void => {\n  const command = {\n    command: CommandNames.GET_PERMISSIBLE_ODDS,\n    params: {},\n    rid: RidGenerator.gForCommand()\n  };\n\n  permissibleOddsCommand(command, '', callback, () => undefined, callbackError);\n};\n","import { CALCULATE_POWER_OF_10 } from 'utils/constants/app/general';\nimport { ODD_FORMATS } from 'utils/constants/betslip/odd-formats';\nimport SpringConfigs from 'utils/constants/swarm/spring-configs';\nimport { Ladder, PermissibleOdds } from 'interfaces/bet-data';\nimport { getPermissibleOdds } from 'services/get-permissible-odds';\nimport Store from 'store';\nimport { ladderIsLoaded, updateOddFormat } from 'store/actions/betslip';\n\n/*eslint no-magic-numbers:*/\n// TODO check after betslip refactor\n\nconst Config = {\n  decimalFormatRemove3Digit: false,\n  roundDecimalCoeficients: SpringConfigs.ODD_ROUNDING,\n  useLadderForFractionalFormat: true\n};\n\nconst cache: { [key: string]: string } = {};\n\nconst {\n  oddFormat,\n  ladderLoaded\n}: { oddFormat: number; ladderLoaded: boolean } = Store.getState().betSlip;\n\nlet priceDecimal: number | undefined;\n\nlet ladder: Ladder[] | boolean = false;\n\nexport async function loadLadder(id = 0): Promise<void> {\n  Store.dispatch(ladderIsLoaded());\n  getPermissibleOdds(\n    (response: PermissibleOdds) => {\n      if (response?.details) {\n        ladder = response.details;\n        Store.dispatch(updateOddFormat(id));\n      } else {\n        ladder = [];\n      }\n    },\n    () => {\n      ladder = [];\n    }\n  );\n}\n\nif (!ladderLoaded) {\n  loadLadder(oddFormat);\n}\n\n/**\n * Odd converter\n * returns a function to convert decimal odds to corresponding format\n * Usage:\n * convert(odd, formatID)\n * e.g.  const coeficient = convert(1.01, 2)\n */\nexport function convert(\n  val: string | number,\n  formatID: number | string,\n  type = ''\n): string {\n  if (isNaN(+val) || +val === Infinity) {\n    return '-';\n  }\n\n  if ((formatID === 1 || formatID === 'fractional') && !ladder) {\n    return '-';\n  }\n\n  const format =\n    ODD_FORMATS.find(\n      format => format.value === formatID || format.id === formatID\n    )?.value || 'decimal';\n\n  const value = parseFloat(`${val}`);\n  const cacheKey = `${format}${value}`;\n\n  if (isNaN(value)) {\n    return '';\n  }\n\n  if (cache[cacheKey] === undefined) {\n    if (\n      format === 'fractional' &&\n      Config.useLadderForFractionalFormat &&\n      type === 'fictional' &&\n      value !== undefined\n    ) {\n      // use it to calculate express odds as you see on bet365 :)\n      cache[cacheKey] = `${Math.round((value - 1) * 100 || 0) / 100}/1`;\n    } else {\n      const converted = convertLog(value, format, ladder as Ladder[]);\n      let roundedConverted = String(converted) || '';\n\n      if (converted && format === 'decimal') {\n        if (!priceDecimal) {\n          const partnerConfigs = Store.getState().socket.partnerConfigs;\n          priceDecimal = partnerConfigs?.price_decimals;\n        }\n\n        if (\n          priceDecimal &&\n          converted &&\n          String(converted)?.split('.')?.[1]?.length > priceDecimal\n        ) {\n          roundedConverted = Number(converted).toFixed(priceDecimal);\n        }\n      }\n\n      cache[cacheKey] = roundedConverted;\n    }\n  }\n\n  return cache[cacheKey];\n}\n\nfunction convertLog(value: number, format: string, ladder: Ladder[]) {\n  const fValue = value;\n  const iValue = Math.floor(value);\n  const rValue =\n    value !== undefined ? Math.round(fValue * 100 || 0) / 100 : value;\n\n  switch (format) {\n    case 'decimal':\n      return decimalValue(value, iValue, fValue);\n\n    case 'fractional':\n      return fractionalValue(value, fValue, rValue, ladder);\n\n    case 'american':\n      return americanValue(value, rValue);\n\n    case 'hongkong':\n      return hongKongValue(value, iValue, fValue);\n\n    case 'malay':\n      return malayValue(fValue);\n\n    case 'indo':\n      return indoValue(fValue);\n\n    default:\n      return rValue;\n  }\n}\n\nfunction decimalValue(value: number, iValue: number, fValue: number) {\n  return value !== undefined\n    ? iValue !== fValue &&\n      value.toString().split('.')[1] &&\n      value.toString().split('.')[1].length > 2 &&\n      !Config.decimalFormatRemove3Digit\n      ? Math.round(\n          value *\n            Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n        ) / Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n      : fValue.toFixed(2)\n    : value;\n}\n\nfunction fractionalValue(\n  value: number,\n  fValue: number,\n  rValue: number,\n  ladder: Ladder[]\n) {\n  if (value && Config.useLadderForFractionalFormat) {\n    const fracFL = dec2fracFromLadder(fValue, ladder);\n\n    if (fracFL) {\n      return fracFL;\n    } else {\n      const frac = dec2frac(rValue);\n\n      if (frac) {\n        return frac;\n      }\n    }\n\n    return value;\n  } else {\n    return '-';\n  }\n}\n\nfunction americanValue(value: number, rValue: number) {\n  return value\n    ? rValue > 2\n      ? `+${(100 * (rValue - 1)).toString().split('.')[0]}`\n      : rValue !== 1\n      ? (-100 / (rValue - 1)).toString().split('.')[0]\n      : '-'\n    : rValue;\n}\n\nfunction hongKongValue(value: number, iValue: number, fValue: number) {\n  return value !== undefined\n    ? iValue !== fValue && value.toString().split('.')[1].length > 2\n      ? Math.round(\n          (value - 1) *\n            Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n        ) / Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n      : (fValue - 1.0).toFixed(2)\n    : value;\n}\n\nfunction malayValue(fValue: number) {\n  if (fValue === 2) {\n    return '0.000';\n  } else if (fValue > 2) {\n    return (\n      Math.round(\n        +(1 / (1 - fValue)).toFixed(Config.roundDecimalCoeficients + 1) *\n          Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n      ) / Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n    ).toFixed(Config.roundDecimalCoeficients);\n  } else {\n    return (fValue - 1).toFixed(Config.roundDecimalCoeficients);\n  }\n}\n\nfunction indoValue(fValue: number) {\n  if (fValue === 2) {\n    return '0.000';\n  } else if (fValue > 2) {\n    return (fValue - 1).toFixed(Config.roundDecimalCoeficients);\n  } else {\n    return (\n      Math.round(\n        +(1 / (1 - fValue)).toFixed(Config.roundDecimalCoeficients + 1) *\n          Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n      ) / Math.pow(CALCULATE_POWER_OF_10, Config.roundDecimalCoeficients)\n    ).toFixed(Config.roundDecimalCoeficients);\n  }\n}\n\nfunction dec2fracFromLadder(dec: number, ladder: Ladder[]) {\n  let frac = '';\n\n  if (ladder.length) {\n    let price = 0;\n    let issetPriceArray = ladder.find(({ Price }) => Price === dec);\n\n    if (issetPriceArray) {\n      frac = `${issetPriceArray.Numerator}/${issetPriceArray.Denominator}`;\n    } else {\n      for (let i = 0; i < ladder.length; i++) {\n        if (ladder[i].Price > price && ladder[i].Price < dec) {\n          price = ladder[i].Price;\n        }\n      }\n\n      issetPriceArray = ladder.find(({ Price }) => Price === price);\n\n      if (issetPriceArray) {\n        frac = `${issetPriceArray.Numerator}/${issetPriceArray.Denominator}`;\n      }\n    }\n  }\n\n  return frac;\n}\n\nfunction dec2frac(decVal: number) {\n  let Znxt: number;\n  let Dnxt: number;\n  let Nnxt: number;\n\n  function recCalc(Zcur: number, Dcur?: number, Dprev?: number): string {\n    Dcur = Dcur !== undefined ? Dcur : 1;\n    Dprev = Dprev !== undefined ? Dprev : 0;\n    Znxt = 1 / (Zcur - Math.floor(Zcur));\n    Dnxt = Dcur * Math.floor(Znxt) + Dprev;\n    Nnxt = Math.round(decVal * Dnxt);\n\n    return Nnxt / Dnxt === decVal\n      ? `${Nnxt.toString()}/${Dnxt.toString()}`\n      : recCalc(Znxt, Dnxt, Dcur);\n  }\n\n  // Use this casting method because of JS number bug for example \"2.2 - 1 = 1.1999(9)\"\n  if (decVal !== Math.floor(decVal)) {\n    decVal = parseFloat(\n      `${(Math.floor(decVal) - 1).toString()}.${String(decVal).split('.')[1]}`\n    );\n  } else {\n    decVal = decVal - 1;\n  }\n\n  return decVal % 1 === 0 ? `${String(decVal)}/1` : String(recCalc(decVal));\n}\n"],"names":["getPermissibleOdds","callback","callbackError","async","commandObj","rid","updateCallback","connectingWS","then","socket","sendCommand","permissibleOddsCommand","command","CommandNames","GET_PERMISSIBLE_ODDS","params","RidGenerator","gForCommand","Config","decimalFormatRemove3Digit","roundDecimalCoeficients","SpringConfigs","ODD_ROUNDING","useLadderForFractionalFormat","cache","oddFormat","ladderLoaded","Store","getState","betSlip","priceDecimal","ladder","loadLadder","id","arguments","length","undefined","dispatch","ladderIsLoaded","response","details","updateOddFormat","convert","val","formatID","_ODD_FORMATS$find","type","isNaN","Infinity","format","ODD_FORMATS","find","value","parseFloat","cacheKey","Math","round","converted","fValue","iValue","floor","rValue","toString","split","pow","CALCULATE_POWER_OF_10","toFixed","decimalValue","fracFL","dec","frac","price","issetPriceArray","_ref","Price","Numerator","Denominator","i","_ref2","dec2fracFromLadder","decVal","Znxt","Dnxt","Nnxt","recCalc","Zcur","Dcur","Dprev","String","dec2frac","fractionalValue","americanValue","hongKongValue","malayValue","indoValue","convertLog","roundedConverted","_String","_String$split","_String$split$","partnerConfigs","price_decimals","Number"],"sourceRoot":""}