|
1 | 1 | import throttle from 'lodash.throttle';
|
2 | 2 | import { action, computed, makeObservable, observable, override, reaction } from 'mobx';
|
| 3 | +import { computedFn } from 'mobx-utils'; |
3 | 4 |
|
4 | 5 | import { Money } from '@deriv/components';
|
5 | 6 | import {
|
@@ -57,7 +58,7 @@ export default class PortfolioStore extends BaseStore {
|
57 | 58 |
|
58 | 59 | active_positions = [];
|
59 | 60 |
|
60 |
| - getPositionByIdCache = observable.map(); |
| 61 | + getPositionById = computedFn(id => this.positions.find(position => +position.id === +id)); |
61 | 62 |
|
62 | 63 | constructor(root_store) {
|
63 | 64 | // TODO: [mobx-undecorate] verify the constructor arguments and the arguments of this automatically generated super call
|
@@ -110,17 +111,6 @@ export default class PortfolioStore extends BaseStore {
|
110 | 111 | this.root_store = root_store;
|
111 | 112 | }
|
112 | 113 |
|
113 |
| - getPositionById(id) { |
114 |
| - // Check if we already have a cached position for the given ID. |
115 |
| - if (!this.getPositionByIdCache.has(id)) { |
116 |
| - // Compute the position and store it in the cache. |
117 |
| - const position = this.positions.find(position => +position.id === +id); |
118 |
| - this.getPositionByIdCache.set(id, position); |
119 |
| - } |
120 |
| - |
121 |
| - return this.getPositionByIdCache.get(id); |
122 |
| - } |
123 |
| - |
124 | 114 | async initializePortfolio() {
|
125 | 115 | if (this.has_subscribed_to_poc_and_transaction) {
|
126 | 116 | this.clearTable();
|
@@ -594,9 +584,6 @@ export default class PortfolioStore extends BaseStore {
|
594 | 584 | }
|
595 | 585 |
|
596 | 586 | updatePositions = () => {
|
597 |
| - // Whenever positions are updated, clear the cache to ensure consistency. |
598 |
| - this.getPositionByIdCache.clear(); |
599 |
| - |
600 | 587 | this.responseQueue.forEach(res => this.proposalOpenContractHandler(res));
|
601 | 588 | this.responseQueue = [];
|
602 | 589 | this.setActivePositions();
|
|
0 commit comments