Best JavaScript code snippet using fast-check-monorepo
usePositionsList.js
Source:usePositionsList.js
1import { useState, useEffect, useRef } from "react";2import tradeApi from "../services/tradeApiClient";3import useInterval from "./useInterval";4import {5 assign,6 cloneDeep,7 filter,8 isEmpty,9 isFunction,10 omitBy,11 partial,12 sortBy,13 uniqBy,14} from "lodash";15import useStoreSettingsSelector from "./useStoreSettingsSelector";16import useSelectedExchange from "hooks/useSelectedExchange";17import { useDispatch } from "react-redux";18import { showErrorAlert } from "../store/actions/ui";19import useStoreViewsSelector from "./useStoreViewsSelector";20import { useMediaQuery } from "@material-ui/core";21import { useTheme } from "@material-ui/core/styles";22import useFilters from "./useFilters";23/**24 * @typedef {import("../services/tradeApiClient.types").UserPositionsCollection} UserPositionsCollection25 * @typedef {"open" | "closed" | "log" | "profileOpen" | "profileClosed"} PositionsCollectionType26 * @typedef {import('../components/CustomSelect/CustomSelect').OptionType} OptionType27 * @typedef {import("../store/initialState").Filters} Filters28 * @typedef {Object<string, boolean>} UpdatingIndex29 */30/**31 * @typedef {Object} HookPositionsListData32 * @property {UserPositionsCollection} positionsAll33 * @property {UserPositionsCollection} positionsFiltered34 * @property {Function} setFilters35 * @property {function} clearFilters36 * @property {Boolean} loading37 * @property {Function} flagPositionUpdating38 * @property {Boolean} filtersVisibility39 * @property {Function} setFiltersVisibility40 * @property {Filters['dashboardPositions']} filters41 * @property {number} modifiedFilters42 * @property {Array<OptionType>} providerOptions43 * @property {Array<OptionType>} pairOptions44 * @property {Array<OptionType>} sides45 * @property {Array<OptionType>} types46 */47/**48 * @typedef {Object} PositionsState49 * @property {UserPositionsCollection} open50 * @property {UserPositionsCollection} closed51 * @property {UserPositionsCollection} log52 * @property {UserPositionsCollection} profileOpen53 * @property {UserPositionsCollection} profileClosed54 */55/**56 * Provides positions data load by collection type.57 *58 * Encapsulates the data fetch from Trade API and local state handling.59 *60 * @param {PositionsCollectionType} type Collection type to fetch.61 * @param {Position|null} [positionEntity] Position entity (optional) to narrow data to single position.62 * @param {function} [notifyPositionsUpdate] Callback to notify the updated positions list.63 * @param {"dashboardPositions"} [persistKey] Key to persist filters to store.64 * @returns {HookPositionsListData} Positions collection.65 */66const usePositionsList = (67 type,68 positionEntity = null,69 notifyPositionsUpdate = null,70 persistKey,71) => {72 const typeRef = useRef(null);73 const storeSettings = useStoreSettingsSelector();74 const selectedExchange = useSelectedExchange();75 const storeViews = useStoreViewsSelector();76 const exchangeRef = useRef(selectedExchange.exchangeId);77 const dispatch = useDispatch();78 const [loading, setLoading] = useState(true);79 const theme = useTheme();80 const isMobile = useMediaQuery(theme.breakpoints.down("sm"), {81 // Fix wrong value at first render82 noSsr: true,83 });84 /**85 * Track the position IDs that have performed an open position update action.86 */87 const [updatingIndex, setUpdatingIndex] = useState(88 /** @type {UpdatingIndex} updatingIndex */ ({}),89 );90 /**91 * @type {PositionsState}92 */93 const defaultPositionsState = {94 open: null,95 closed: null,96 log: null,97 profileOpen: null,98 profileClosed: null,99 };100 const [positions, setPositions] = useState(defaultPositionsState);101 const positionsAll = positions[type] || [];102 const [filtersVisibility, setFiltersVisibility] = useState(!isMobile);103 const extractPairOptions = () => {104 const coinsDistinct = uniqBy(positionsAll, "pair").map((position) => {105 return { label: position.pair, val: position.pair };106 });107 return [{ label: "All Pairs", val: "all" }].concat(sortBy(coinsDistinct, "label"));108 };109 const extractProviderOptions = () => {110 const providersDistinct = uniqBy(positionsAll, "providerName").map((position) => {111 return {112 label: position.providerName,113 val: position.providerId,114 };115 });116 return [{ label: "All Providers", val: "all" }].concat(sortBy(providersDistinct, "label"));117 };118 const pairOptions = extractPairOptions();119 const sides = [120 { label: "All Sides", val: "all" },121 { label: "SHORT", val: "SHORT" },122 { label: "LONG", val: "LONG" },123 ];124 const types = [125 { label: "All Types", val: "all" },126 { label: "UNSOLD", val: "unsold" },127 { label: "UNOPEN", val: "unopen" },128 ];129 const providerOptions = extractProviderOptions();130 const storeFilters = storeSettings.filters[persistKey];131 const defaultFilters = {132 providerId: "all",133 pair: "all",134 side: "all",135 type: "all",136 status: "",137 };138 const optionsFilters = {139 providerId: providerOptions,140 pair: pairOptions,141 side: sides,142 type: types,143 };144 const res = useFilters(defaultFilters, storeFilters, optionsFilters, persistKey);145 const { setFilters, clearFilters, modifiedFilters } = res;146 /**147 * @type {Filters[typeof persistKey]}148 */149 // @ts-ignore150 const filters = res.filters;151 const statusRef = useRef(filters.status);152 /**153 * Resolve a Trade API fetch method to fetch positions of a given category.154 *155 * @returns {Promise<UserPositionsCollection>} Promise method when category mapping is resolved, empty promise otherwise.156 */157 const routeFetchMethod = () => {158 const payload = {159 internalExchangeId: selectedExchange.internalId,160 };161 const providerId = storeViews.provider.id;162 // Skip request if required parameters is empty.163 if (!isEmpty(payload.internalExchangeId) || !isEmpty(providerId)) {164 if (positionEntity) {165 // On first load rely on position entity passed by parent to avoid extra request.166 return new Promise((resolve) => {167 resolve([positionEntity]);168 });169 } else if (type === "closed") {170 return tradeApi.closedPositionsGet(payload);171 } else if (type === "log") {172 if (filters.status === "all") {173 return tradeApi.logPositionsGet({ ...payload, extendedStatuses: true });174 }175 return tradeApi.logPositionsGet(payload);176 } else if (type === "open") {177 return tradeApi.openPositionsGet(payload);178 } else if (type === "profileOpen") {179 return tradeApi.providerOpenPositions(providerId);180 } else if (type === "profileClosed") {181 return tradeApi.providerSoldPositions(providerId);182 }183 }184 // Fallback to null promise when method not resolved.185 return new Promise((resolve) => {186 resolve(null);187 });188 };189 /**190 * Filter positions list by filters criteria.191 *192 * @param {UserPositionsCollection} filterPositions Positions collection.193 * @returns {UserPositionsCollection} Filtered positions collection.194 */195 const filterData = (filterPositions) => {196 /**197 * Checks if value equals to "all".198 *199 * @param {string|OptionType} value Value to check.200 * @returns {boolean} TRUE when equals, FALSE otherwise.201 */202 const isAll = (value) => {203 if (typeof value === "object") {204 return value.val === "all";205 }206 return value === "all" || value === "";207 };208 let filterValues = omitBy(filters, isAll);209 // Only use the type filter on log positions table.210 if (type !== "log") {211 delete filterValues.type;212 }213 const matches = filter(filterPositions, filterValues);214 return /** @type {UserPositionsCollection} */ (matches);215 };216 /**217 * Prepare new positions state, clearing any previous state when needed.218 *219 * @param {string} initiatorExchangeInternalId Exchange that was selected at the moment when fetch was triggered.220 * @returns {PositionsState} Positions state.221 */222 const prepareNewPositionsState = (initiatorExchangeInternalId) => {223 let newPositions = { ...positions };224 // Reset new positions state on exchange change.225 if (exchangeRef.current !== initiatorExchangeInternalId) {226 newPositions = cloneDeep(defaultPositionsState);227 exchangeRef.current = selectedExchange.internalId;228 }229 // Only show loader at initial load to avoid loader experience disruption on updates.230 if (newPositions[type] === null) {231 setLoading(true);232 }233 if (statusRef.current !== filters.status) {234 setLoading(true);235 statusRef.current = filters.status;236 }237 return newPositions;238 };239 /**240 * Get all statuses log positions.241 *242 * Fallback request when reduced statuses requests don't retrieved positions.243 *244 * @returns {Promise<UserPositionsCollection|null>} All statuses log positions.245 */246 const fallbackLogPositionsAllStatuses = async () => {247 let requestData = null;248 const payload = {249 internalExchangeId: selectedExchange.internalId,250 };251 try {252 requestData = await tradeApi.logPositionsGet({ ...payload, extendedStatuses: true });253 // If got results, activate all statuses checkbox.254 if (!isEmpty(requestData)) {255 setFilters({256 ...filters,257 status: "all",258 });259 }260 } catch (e) {261 dispatch(showErrorAlert(e));262 }263 return requestData;264 };265 /**266 * Load user positions for a given exchange.267 *268 * @param {string} initiatorExchangeInternalId Exchange that was selected at the moment when fetch was triggered.269 * @returns {function():void} Effect clean callback.270 */271 const loadPositions = (initiatorExchangeInternalId) => {272 let cancel = false;273 const fetchMethod = routeFetchMethod();274 const newPositions = prepareNewPositionsState(initiatorExchangeInternalId);275 // Check to prevent other tabs / exchanages leftover requests race condition276 // that override current tab data.277 const isOriginalInitiator = () => {278 return (279 !cancel &&280 (!typeRef.current || typeRef.current === type) &&281 (!exchangeRef.current || exchangeRef.current === initiatorExchangeInternalId)282 );283 };284 if (fetchMethod) {285 fetchMethod286 .then(async (fetchData) => {287 if (isOriginalInitiator()) {288 newPositions[type] = fetchData;289 if (type === "log" && filters.status === "" && isEmpty(fetchData)) {290 newPositions[type] = (await fallbackLogPositionsAllStatuses()) || [];291 }292 if (type === "open") {293 newPositions[type] = mutateUpdatingPositions(newPositions[type]);294 }295 setPositions(newPositions);296 if (isFunction(notifyPositionsUpdate)) {297 notifyPositionsUpdate(newPositions[type]);298 }299 }300 })301 .catch((e) => {302 if (isOriginalInitiator()) {303 if (e.code === 18 || e.code === 12) {304 newPositions[type] = [];305 setPositions(newPositions);306 } else {307 dispatch(showErrorAlert(e));308 }309 }310 })311 .finally(() => {312 if (isOriginalInitiator()) {313 setLoading(false);314 }315 });316 }317 return () => {318 cancel = true;319 };320 };321 const loadPositionsForExchange = partial(loadPositions, selectedExchange.internalId);322 useEffect(loadPositionsForExchange, [type, filters.status, selectedExchange.internalId]);323 /**324 * Load a specific position by ID.325 *326 * @param {string} initiatorExchangeInternalId Exchange that was selected at the moment when fetch was triggered.327 * @returns {boolean} false in case that required parameter was missing, true otherwise.328 */329 const loadPosition = (initiatorExchangeInternalId) => {330 const payload = {331 positionId: positionEntity.positionId,332 internalExchangeId: selectedExchange.internalId,333 };334 // Skip request if required parameters are empty.335 if (isEmpty(payload.internalExchangeId) || isEmpty(positionEntity.positionId)) {336 return false;337 }338 tradeApi339 .positionGet(payload)340 .then((data) => {341 const newPositions = {342 ...prepareNewPositionsState(initiatorExchangeInternalId),343 [type]: [data],344 };345 // If current position status type changes we need to update where its stored346 if (["open", "log", "closed"].includes(data.type) && data.type !== type) {347 // @ts-ignore348 newPositions[data.type] = [data];349 }350 setPositions(newPositions);351 // if (type === "open") {352 // newPositions[type] = mutateUpdatingPositions(newPositions[type]);353 // }354 if (isFunction(notifyPositionsUpdate)) {355 notifyPositionsUpdate(newPositions[type]);356 }357 })358 .catch((e) => {359 dispatch(showErrorAlert(e));360 })361 .finally(() => {362 setLoading(false);363 });364 return true;365 };366 const loadPositionForExchange = partial(loadPosition, selectedExchange.internalId);367 const updateData = () => {368 // Only open positions needs continuos updates.369 if (type === "open" || type === "profileOpen") {370 // Single position update.371 if (positionEntity) {372 loadPositionForExchange();373 } else {374 // Multiples position update.375 loadPositionsForExchange();376 }377 }378 };379 useInterval(updateData, 10000, true);380 const handlePositionTypeChange = () => {381 typeRef.current = type;382 };383 useEffect(handlePositionTypeChange, [type]);384 /**385 * Mutate those that started an update action as with updating flag.386 *387 * @param {UserPositionsCollection} currentPositionsCollection Current positions collection.388 * @returns {UserPositionsCollection} Mutated updating flag positions collection.389 */390 const mutateUpdatingPositions = (currentPositionsCollection) => {391 return currentPositionsCollection.map((position) => {392 if (updatingIndex[position.positionId]) {393 return { ...position, updating: true };394 }395 return position;396 });397 };398 /**399 * Flag a given position as updating.400 *401 * @param {string} positionId Position ID to flag.402 * @returns {Void} None.403 */404 const flagPositionUpdating = (positionId) => {405 // Add to updating index so this state persists even when backend have not406 // started to process and avoid that duplicated actions are performed.407 if (!updatingIndex[positionId]) {408 const newUpdatingIndex = { [positionId]: true };409 // Combine with others IDs that exists in current index state.410 setUpdatingIndex(assign(updatingIndex, newUpdatingIndex));411 }412 if (positions[type]) {413 const newPositions = mutateUpdatingPositions(positions[type]);414 setPositions({ ...positions, [type]: newPositions });415 }416 };417 return {418 positionsAll,419 positionsFiltered: filterData(positions[type] || []),420 setFilters,421 filters,422 clearFilters,423 modifiedFilters,424 loading: loading,425 flagPositionUpdating,426 filtersVisibility,427 setFiltersVisibility,428 providerOptions,429 pairOptions,430 types,431 sides,432 };433};...
providers.js
Source:providers.js
1export default [2 {3 id: "5edf6165fc869626686e8657",4 name: "Darkcryptolord",5 description: "",6 price: 50,7 website: "https://twitter.com/DarkCryptoLord",8 exchanges: ["binance", "zignaly"],9 key: false,10 disable: false,11 customerKey: false,12 public: true,13 logoUrl: "https://images-na.ssl-images-amazon.com/images/I/415U35QXrUL._AC_SX425_.jpg",14 isClone: false,15 isCopyTrading: true,16 clonedFrom: false,17 createdAt: 1591697765,18 isFromUser: false,19 quote: "BTC",20 dailyReturns: [21 {22 name: "2020-08-10T00:00:00.000Z",23 returns: -0.10366804570841,24 positions: 1,25 },26 {27 name: "2020-08-11T00:00:00.000Z",28 returns: 4.3578870818748,29 positions: 2,30 },31 {32 name: "2020-08-13T00:00:00.000Z",33 returns: -1.6941858427358,34 positions: 2,35 },36 {37 name: "2020-08-14T00:00:00.000Z",38 returns: 17.703090798742,39 positions: 1,40 },41 {42 name: "2020-08-16T00:00:00.000Z",43 returns: -0.059987579726914,44 positions: 1,45 },46 {47 name: "2020-08-17T00:00:00.000Z",48 returns: -9.141738020034675,49 positions: 3,50 },51 {52 name: "2020-08-19T00:00:00.000Z",53 returns: -4.6145408740653,54 positions: 1,55 },56 {57 name: "2020-08-21T00:00:00.000Z",58 returns: -3.327739443923819,59 positions: 3,60 },61 {62 name: "2020-08-24T00:00:00.000Z",63 returns: 8.1829597325111,64 positions: 3,65 },66 {67 name: "2020-08-26T00:00:00.000Z",68 returns: -0.01258124793894,69 positions: 4,70 },71 {72 name: "2020-08-27T00:00:00.000Z",73 returns: -2.954400487551866,74 positions: 5,75 },76 {77 name: "2020-08-31T00:00:00.000Z",78 returns: -2.59153009349535,79 positions: 2,80 },81 {82 name: "2020-09-01T00:00:00.000Z",83 returns: 9.2492410084019,84 positions: 2,85 },86 {87 name: "2020-09-03T00:00:00.000Z",88 returns: 24.33397329035,89 positions: 1,90 },91 {92 name: "2020-09-05T00:00:00.000Z",93 returns: -19.153309862788,94 positions: 2,95 },96 {97 name: "2020-09-06T00:00:00.000Z",98 returns: 24.49041293460766,99 positions: 2,100 },101 {102 name: "2020-09-07T00:00:00.000Z",103 returns: -2.2771585126574,104 positions: 2,105 },106 {107 name: "2020-09-08T00:00:00.000Z",108 returns: 6.6034475791332,109 positions: 1,110 },111 {112 name: "2020-09-09T00:00:00.000Z",113 returns: 0.252946576218415,114 positions: 4,115 },116 {117 name: "2020-09-10T00:00:00.000Z",118 returns: 3.975998191466556,119 positions: 2,120 },121 {122 name: "2020-09-11T00:00:00.000Z",123 returns: -5.0380007160393,124 positions: 1,125 },126 {127 name: "2020-09-12T00:00:00.000Z",128 returns: -0.58558771929825,129 positions: 1,130 },131 {132 name: "2020-09-13T00:00:00.000Z",133 returns: 19.3368753397267,134 positions: 2,135 },136 {137 name: "2020-09-14T00:00:00.000Z",138 returns: 1.044012683112,139 positions: 1,140 },141 {142 name: "2020-09-15T00:00:00.000Z",143 returns: -3.910915638077199,144 positions: 2,145 },146 {147 name: "2020-09-18T00:00:00.000Z",148 returns: 2.5514612805941,149 positions: 2,150 },151 {152 name: "2020-09-28T00:00:00.000Z",153 returns: -7.2492511884975,154 positions: 1,155 },156 {157 name: "2020-10-02T00:00:00.000Z",158 returns: -0.54845985778137,159 positions: 1,160 },161 {162 name: "2020-10-14T00:00:00.000Z",163 returns: -3.99568775350633,164 positions: 2,165 },166 {167 name: "2020-10-16T00:00:00.000Z",168 returns: -8.1567100056276,169 positions: 1,170 },171 {172 name: "2020-10-19T00:00:00.000Z",173 returns: -1.1366717871445,174 positions: 1,175 },176 {177 name: "2020-10-21T00:00:00.000Z",178 returns: -4.8259708763743,179 positions: 1,180 },181 {182 name: "2020-10-26T00:00:00.000Z",183 returns: 2.7150733552703,184 positions: 1,185 },186 ],187 returns: 43.4192842990359,188 risk: 0,189 followers: 683,190 floating: 0,191 openPositions: 0,192 closedPositions: 61,193 exchangeType: "spot",194 exchangeInternalId: "Zignaly1586867845_5e95ae85e21ea",195 profitSharing: false,196 profitsShare: 0,197 profitsMode: "",198 trial: false,199 list: true,200 retain: 0,201 totalSignals: 0,202 userId: {203 $oid: "5b13fe046c20cd75b5058c32",204 },205 aggregateFollowers: [],206 },207 {208 id: "5d7a026e6c20cd63ec6d1d22",209 name: "Blockchain Sparrows Titanium ",210 description: "Blockchain Sparrows Gold USDT",211 price: 35,212 website: "https://www.blockchainsparrows.com/",213 exchanges: ["zignaly", "binance"],214 key: false,215 disable: true,216 customerKey: false,217 public: true,218 logoUrl: "https://res.cloudinary.com/zignaly/image/upload/v1598685298/hsyd0qbzu7hqwrqcnnrf.png",219 isClone: false,220 isCopyTrading: true,221 clonedFrom: false,222 createdAt: 1568277102,223 isFromUser: false,224 quote: "BTC",225 dailyReturns: [226 {227 name: "2020-08-08T00:00:00.000Z",228 returns: 0.192497437091929,229 positions: 7,230 },231 {232 name: "2020-08-09T00:00:00.000Z",233 returns: 0.042491420016779,234 positions: 2,235 },236 {237 name: "2020-08-10T00:00:00.000Z",238 returns: 0.110714580657012,239 positions: 5,240 },241 {242 name: "2020-08-11T00:00:00.000Z",243 returns: 0.256067919861785,244 positions: 12,245 },246 {247 name: "2020-08-12T00:00:00.000Z",248 returns: 0.33894575634316,249 positions: 13,250 },251 {252 name: "2020-08-13T00:00:00.000Z",253 returns: 0.301267963103519,254 positions: 14,255 },256 {257 name: "2020-08-14T00:00:00.000Z",258 returns: 0.285692173422191,259 positions: 11,260 },261 {262 name: "2020-08-15T00:00:00.000Z",263 returns: 0.064081653677234,264 positions: 3,265 },266 {267 name: "2020-08-16T00:00:00.000Z",268 returns: 0.084444323120774,269 positions: 4,270 },271 {272 name: "2020-08-17T00:00:00.000Z",273 returns: 0.414403951144976,274 positions: 15,275 },276 {277 name: "2020-08-18T00:00:00.000Z",278 returns: 0.211373521544147,279 positions: 4,280 },281 {282 name: "2020-08-20T00:00:00.000Z",283 returns: 0.231116178510291,284 positions: 7,285 },286 {287 name: "2020-08-21T00:00:00.000Z",288 returns: 0.254590740743862,289 positions: 11,290 },291 {292 name: "2020-08-22T00:00:00.000Z",293 returns: 0.101095667629268,294 positions: 5,295 },296 {297 name: "2020-08-23T00:00:00.000Z",298 returns: 0.194847909223391,299 positions: 7,300 },301 {302 name: "2020-08-24T00:00:00.000Z",303 returns: 0.401560059031621,304 positions: 19,305 },306 {307 name: "2020-08-25T00:00:00.000Z",308 returns: 0.104216123637279,309 positions: 5,310 },311 {312 name: "2020-08-26T00:00:00.000Z",313 returns: 0.084685651823405,314 positions: 4,315 },316 {317 name: "2020-08-27T00:00:00.000Z",318 returns: 0.042888001983067,319 positions: 2,320 },321 {322 name: "2020-08-28T00:00:00.000Z",323 returns: 0.124093168432475,324 positions: 4,325 },326 {327 name: "2020-08-29T00:00:00.000Z",328 returns: 0.149004302621825,329 positions: 6,330 },331 {332 name: "2020-08-30T00:00:00.000Z",333 returns: 0.150080495031381,334 positions: 7,335 },336 {337 name: "2020-08-31T00:00:00.000Z",338 returns: 0.149274497617378,339 positions: 7,340 },341 {342 name: "2020-09-01T00:00:00.000Z",343 returns: 0.007169930741848,344 positions: 2,345 },346 {347 name: "2020-09-02T00:00:00.000Z",348 returns: 0.021463189090969,349 positions: 1,350 },351 {352 name: "2020-09-03T00:00:00.000Z",353 returns: 0.124656506412349,354 positions: 2,355 },356 {357 name: "2020-09-04T00:00:00.000Z",358 returns: 0.021301072725962,359 positions: 1,360 },361 {362 name: "2020-09-05T00:00:00.000Z",363 returns: 0.0439295081994909,364 positions: 3,365 },366 {367 name: "2020-09-06T00:00:00.000Z",368 returns: 0.281463976936869,369 positions: 7,370 },371 {372 name: "2020-09-08T00:00:00.000Z",373 returns: 0.0488627115721169,374 positions: 3,375 },376 {377 name: "2020-09-09T00:00:00.000Z",378 returns: 0.123950850860993,379 positions: 6,380 },381 {382 name: "2020-09-10T00:00:00.000Z",383 returns: 0.229779560902618,384 positions: 11,385 },386 {387 name: "2020-09-11T00:00:00.000Z",388 returns: 0.193110056011764,389 positions: 9,390 },391 {392 name: "2020-09-12T00:00:00.000Z",393 returns: 0.109200374170581,394 positions: 5,395 },396 {397 name: "2020-09-13T00:00:00.000Z",398 returns: 0.021310959536543,399 positions: 1,400 },401 {402 name: "2020-09-14T00:00:00.000Z",403 returns: 0.091854853361351,404 positions: 3,405 },406 {407 name: "2020-09-16T00:00:00.000Z",408 returns: 0.064386950900105,409 positions: 1,410 },411 {412 name: "2020-09-17T00:00:00.000Z",413 returns: 0.036373628226586,414 positions: 1,415 },416 {417 name: "2020-09-18T00:00:00.000Z",418 returns: 0.018610434862274,419 positions: 1,420 },421 {422 name: "2020-09-19T00:00:00.000Z",423 returns: 0.019371336715694,424 positions: 1,425 },426 {427 name: "2020-09-21T00:00:00.000Z",428 returns: 0.022670749072441,429 positions: 1,430 },431 {432 name: "2020-09-22T00:00:00.000Z",433 returns: 0.070268397477959,434 positions: 1,435 },436 {437 name: "2020-09-28T00:00:00.000Z",438 returns: 0.144981125979709,439 positions: 6,440 },441 {442 name: "2020-09-30T00:00:00.000Z",443 returns: 0.12818531531308,444 positions: 6,445 },446 {447 name: "2020-10-01T00:00:00.000Z",448 returns: 0.098783351465154,449 positions: 3,450 },451 {452 name: "2020-10-03T00:00:00.000Z",453 returns: 0.125762953551972,454 positions: 2,455 },456 {457 name: "2020-10-04T00:00:00.000Z",458 returns: 0.021237199625865,459 positions: 1,460 },461 {462 name: "2020-10-05T00:00:00.000Z",463 returns: 0.082934318975781,464 positions: 3,465 },466 {467 name: "2020-10-06T00:00:00.000Z",468 returns: 0.019073806646117,469 positions: 1,470 },471 {472 name: "2020-10-07T00:00:00.000Z",473 returns: 0.063216562937469,474 positions: 1,475 },476 {477 name: "2020-10-08T00:00:00.000Z",478 returns: 0.126593795785219,479 positions: 4,480 },481 {482 name: "2020-10-09T00:00:00.000Z",483 returns: 0.302563538402049,484 positions: 8,485 },486 {487 name: "2020-10-10T00:00:00.000Z",488 returns: 0.348366416626792,489 positions: 6,490 },491 {492 name: "2020-10-11T00:00:00.000Z",493 returns: 0.125934951916367,494 positions: 4,495 },496 {497 name: "2020-10-12T00:00:00.000Z",498 returns: 0.229123469380424,499 positions: 5,500 },501 {502 name: "2020-10-13T00:00:00.000Z",503 returns: 0.021334875738569,504 positions: 1,505 },506 {507 name: "2020-10-14T00:00:00.000Z",508 returns: 0.04262215158507,509 positions: 2,510 },511 {512 name: "2020-10-16T00:00:00.000Z",513 returns: 0.021069029617466,514 positions: 1,515 },516 {517 name: "2020-10-18T00:00:00.000Z",518 returns: 0.127014470344545,519 positions: 2,520 },521 {522 name: "2020-10-19T00:00:00.000Z",523 returns: 0.041295802720911,524 positions: 2,525 },526 {527 name: "2020-10-20T00:00:00.000Z",528 returns: 0.085470825791307,529 positions: 2,530 },531 {532 name: "2020-10-23T00:00:00.000Z",533 returns: 0.064746198500891,534 positions: 1,535 },536 {537 name: "2020-10-25T00:00:00.000Z",538 returns: 0.021399708651085,539 positions: 1,540 },541 {542 name: "2020-10-26T00:00:00.000Z",543 returns: 0.021213456421827,544 positions: 1,545 },546 {547 name: "2020-10-29T00:00:00.000Z",548 returns: 0.062974277945283,549 positions: 1,550 },551 {552 name: "2020-10-30T00:00:00.000Z",553 returns: 0.063210878589283,554 positions: 1,555 },556 {557 name: "2020-11-01T00:00:00.000Z",558 returns: 0.064476623627932,559 positions: 1,560 },561 {562 name: "2020-11-02T00:00:00.000Z",563 returns: 0.055423260929119,564 positions: 1,565 },566 ],567 returns: 8.348176911116548,568 risk: 0,569 followers: 634,570 floating: -32.09286046915455,571 openPositions: 29,572 closedPositions: 301,573 exchangeType: "spot",574 exchangeInternalId: "",575 profitSharing: false,576 profitsShare: 0,577 profitsMode: "",578 trial: false,579 list: true,580 retain: 0,581 totalSignals: 0,582 userId: {583 $oid: "5b13fe046c20cd75b5058c32",584 },585 aggregateFollowers: [],586 },...
board.dame.possible.moves.ts
Source:board.dame.possible.moves.ts
1import {Piece, PiecePosition, Position} from '../piece/piece';2import {ChangeValue, createPossiblePositions, decrementValue, incrementValue, MAX_ROW, MIN_ROW} from './board.dame.possible.beating.moves';3import {getPieceByPosition, PossiblePositions} from './board.calculator';4function addAllPositionsIfNoObstacleOccur(possibleDamePositions: Position[], possiblePositions: PossiblePositions) {5 Array.from(possibleDamePositions).forEach(position => {6 possiblePositions.positions.push(position);7 });8}9function addPositionsIncrementingRows(possibleDamePositions: Position[], firstObstacle, possiblePositions: PossiblePositions) {10 Array.from(possibleDamePositions).filter(position => position.row < firstObstacle.row).forEach(position => {11 possiblePositions.positions.push(position);12 });13}14function addPositionsDecrementingRows(possibleDamePositions: Position[], firstObstacle, possiblePositions: PossiblePositions) {15 Array.from(possibleDamePositions).filter(position => position.row > firstObstacle.row).forEach(position => {16 possiblePositions.positions.push(position);17 });18}19function filterPossibleDamePositions(positions: Map<Position, Piece>, currentPosition: PiecePosition, possibleDamePositions: Position[], possiblePositions: PossiblePositions) {20 if (possibleDamePositions.length > 0) {21 const firstObstacle = possibleDamePositions.find(position => !!getPieceByPosition(positions, position).piece);22 if (firstObstacle) {23 if (currentPosition.position.row < possibleDamePositions[0].row) {24 addPositionsIncrementingRows(possibleDamePositions, firstObstacle, possiblePositions);25 } else {26 addPositionsDecrementingRows(possibleDamePositions, firstObstacle, possiblePositions);27 }28 } else {29 addAllPositionsIfNoObstacleOccur(possibleDamePositions, possiblePositions);30 }31 }32}33function removeCurrentPosition(possibleDamePositions: Position[], currentPosition: PiecePosition) {34 return Array35 .from(possibleDamePositions)36 .filter(position => position.column !== currentPosition.position.column && position.row !== currentPosition.position.row);37}38function addPossibleDamePositions(currentPosition: PiecePosition, positions: Map<Position, Piece>, possiblePositions: PossiblePositions, changeValueForRow: ChangeValue, changeValueForColumn: ChangeValue, edgeRow: number) {39 const possibleDamePositions = createPossiblePositions(currentPosition, changeValueForRow, changeValueForColumn, edgeRow);40 const possibleDamePositionsWithoutCurrentPosition = removeCurrentPosition(possibleDamePositions, currentPosition);41 filterPossibleDamePositions(positions, currentPosition, possibleDamePositionsWithoutCurrentPosition, possiblePositions);42}43function calculateContinuousIncRowIncColumnDamePositions(positions: Map<Position, Piece>, currentPosition: PiecePosition, possiblePositions: PossiblePositions) {44 addPossibleDamePositions(currentPosition, positions, possiblePositions, incrementValue, incrementValue, MAX_ROW);45}46function calculateContinuousIncRowDecColumnDamePositions(positions: Map<Position, Piece>, currentPosition: PiecePosition, possiblePositions: PossiblePositions) {47 addPossibleDamePositions(currentPosition, positions, possiblePositions, incrementValue, decrementValue, MAX_ROW);48}49function calculateContinuousDecRowIncColumnDamePositions(positions: Map<Position, Piece>, currentPosition: PiecePosition, possiblePositions: PossiblePositions) {50 addPossibleDamePositions(currentPosition, positions, possiblePositions, decrementValue, incrementValue, MIN_ROW);51}52function calculateContinuousDecRowDecColumnDamePositions(positions: Map<Position, Piece>, currentPosition: PiecePosition, possiblePositions: PossiblePositions) {53 addPossibleDamePositions(currentPosition, positions, possiblePositions, decrementValue, decrementValue, MIN_ROW);54}55export function handlePossibleMovesForDame(positions: Map<Position, Piece>, currentPosition: PiecePosition, possiblePositions: PossiblePositions) {56 calculateContinuousIncRowIncColumnDamePositions(positions, currentPosition, possiblePositions);57 calculateContinuousIncRowDecColumnDamePositions(positions, currentPosition, possiblePositions);58 calculateContinuousDecRowIncColumnDamePositions(positions, currentPosition, possiblePositions);59 calculateContinuousDecRowDecColumnDamePositions(positions, currentPosition, possiblePositions);...
Using AI Code Generation
1const fc = require('fast-check');2const positions = require('fast-check-monorepo').positions;3fc.assert(4 fc.property(positions(), (pos) => {5 return typeof pos === 'number';6 })7);
Using AI Code Generation
1const fc = require('fast-check');2const positions = require('fast-check-monorepo').positions;3const positionsArb = positions({min: 1, max: 10});4fc.assert(fc.property(positionsArb, (positions) => {5}));6const fc = require('fast-check');7const positions = require('fast-check-monorepo').positions;8const positionsArb = positions({min: 1, max: 10});9fc.assert(fc.property(positionsArb, (positions) => {10}));11const fc = require('fast-check');12const positions = require('fast-check-monorepo').positions;13const positionsArb = positions({min: 1, max: 10});14fc.assert(fc.property(positionsArb, (positions) => {15}));16const fc = require('fast-check');17const positions = require('fast-check-monorepo').positions;18const positionsArb = positions({min: 1, max: 10});19fc.assert(fc.property(positionsArb, (positions) => {20}));21const fc = require('fast-check');22const positions = require('fast-check-monorepo').positions;23const positionsArb = positions({min: 1, max: 10});24fc.assert(fc.property(positionsArb, (positions) => {25}));26const fc = require('fast-check');27const positions = require('fast-check-monorepo').positions;28const positionsArb = positions({min: 1, max: 10});29fc.assert(fc.property(positionsArb, (positions) => {30}));31const fc = require('fast
Using AI Code Generation
1const { positions } = require('fast-check-monorepo');2const pos = positions();3console.log(pos);4{5 "dependencies": {6 }7}
Using AI Code Generation
1import {positions} from 'fast-check-monorepo';2const positions1 = positions(3, 3);3console.log(positions1);4const positions2 = positions(3, 3, 3);5console.log(positions2);6const positions3 = positions(3, 3, 3, 3);7console.log(positions3);8const positions4 = positions(3, 3, 3, 3, 3);9console.log(positions4);10const positions5 = positions(3, 3, 3, 3, 3, 3);11console.log(positions5);12const positions6 = positions(3, 3, 3, 3, 3, 3, 3);13console.log(positions6);14const positions7 = positions(3, 3, 3, 3, 3, 3, 3, 3);15console.log(positions7);16const positions8 = positions(3, 3, 3, 3, 3, 3, 3, 3, 3);17console.log(positions8);18const positions9 = positions(3, 3, 3, 3, 3, 3, 3, 3, 3, 3);19console.log(positions9);
Using AI Code Generation
1import { positions } from "fast-check-monorepo";2console.log(positions(1, 1, 1, 1, 1));3import { positions } from "fast-check-monorepo";4console.log(positions(1, 1, 1, 1, 1));5import { positions } from "fast-check-monorepo";6console.log(positions(1, 1, 1, 1, 1));7import { positions } from "fast-check-monorepo";8console.log(positions(1, 1, 1, 1, 1));9import { positions } from "fast-check-monorepo";10console.log(positions(1, 1, 1, 1, 1));11import { positions } from "fast-check-monorepo";12console.log(positions(1, 1, 1, 1, 1));13import { positions } from "fast-check-monorepo";14console.log(positions(1, 1, 1, 1, 1));15import { positions } from "fast-check-monorepo";16console.log(positions(1, 1, 1, 1, 1));17import { positions } from "fast-check-monorepo";18console.log(positions(1, 1, 1, 1, 1));19import { positions } from "fast-check-monorepo";20console.log(positions(1, 1, 1, 1, 1));21import { positions } from "fast-check-monorepo";22console.log(positions(1, 1, 1, 1, 1));23import { positions } from "fast-check-monorepo";
Using AI Code Generation
1import {positions} from 'fast-check-monorepo';2const pos = positions();3pos.then((value) => {console.log(value)});4{5 "scripts": {6 },7 "dependencies": {8 }9}10[ { x: -0.8598585132503692, y: -0.5105821061278149 },11 { x: 0.8598585132503692, y: 0.5105821061278149 } ]
Using AI Code Generation
1const fc = require('fast-check');2const positions = require('fast-check-monorepo').positions;3const pos = positions([10, 20, 30], [2, 3, 4], [5, 6, 7]);4fc.assert(5 fc.property(pos, ([x, y, z]) => {6 return x === 10 && y === 20 && z === 30;7 })8);9console.log('ok');10const fc = require('fast-check');11const { get } = require('./myFunc');12 .record({13 id: fc.string(),14 })15 .chain((obj) => {16 return fc.constantFrom(obj, { ...obj, id: `${obj.id}1` });17 });18fc.assert(19 fc.property(myArb, async (obj) => {20 const result = await get(obj.id);21 if (obj.id.endsWith('1')) {22 expect(result).toStrictEqual(obj);23 } else {24 expect(result).toBeUndefined();25 }26 })27);28const fc = require('fast-check');29const { get } = require('./myFunc');30 .record({31 id: fc.string(),32 })33 .chain((obj) => {34 return fc.constantFrom(obj, { ...obj, id: `${obj.id}1` });
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!