Skip to content

Commit

Permalink
Merge branch 'master' into anas/implement_equtable_to_userinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
anas-deriv authored Nov 19, 2024
2 parents e88af47 + 0ff2a2e commit 664b8a3
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 39 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2024-11-13

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`deriv_mobile_chart_wrapper` - `v0.1.8+1`](#deriv_mobile_chart_wrapper---v0181)

---

#### `deriv_mobile_chart_wrapper` - `v0.1.8+1`

- **FIX**: [DRGO-1367] Apply Chart Tool Globally for Indicators and Asset-Specific for Drawing Tools ([#900](https://github.com/regentmarkets/flutter-deriv-packages/issues/900)). ([8ea63c8e](https://github.com/regentmarkets/flutter-deriv-packages/commit/8ea63c8e0c3cc73f2420e7b0069b3b60b54bf9b4))


## 2024-11-05

### Changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ deriv_ui:
| [form_builder](./packages/form_builder) | A simpler and cleaner way to create, validate and submit forms. | [v1.0.0+1](./packages/form_builder/CHANGELOG.md) |
| [update_checker](./packages/update_checker) | Check and retrieve update information from the server for the given package. | [v3.1.1](./packages/update_checker/CHANGELOG.md) |
| [deriv_feature_flag](./packages/deriv_feature_flag) | A package to provide feature flag functionality for apps. | [v0.1.2](./packages/deriv_feature_flag/CHANGELOG.md) |
| [deriv_mobile_chart_wrapper](./packages/deriv_mobile_chart_wrapper) | A wrapper package around package _**deriv_chart**_ to implement any functionality specific to mobile and can be wrapped around the main chart package. | [v0.1.8](./packages/deriv_mobile_chart_wrapper/CHANGELOG.md) |
| [deriv_mobile_chart_wrapper](./packages/deriv_mobile_chart_wrapper) | A wrapper package around package _**deriv_chart**_ to implement any functionality specific to mobile and can be wrapped around the main chart package. | [v0.1.8+1](./packages/deriv_mobile_chart_wrapper/CHANGELOG.md) |
| [deriv_cipher](./packages/deriv_cipher) | A package to encrypt and decrypt data using AES encryption.| [v0.0.2](./packages/deriv_cipher/CHANGELOG.md) |
Expand Down
4 changes: 4 additions & 0 deletions packages/deriv_mobile_chart_wrapper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.8+1

- **FIX**: [DRGO-1367] Apply Chart Tool Globally for Indicators and Asset-Specific for Drawing Tools ([#900](https://github.com/regentmarkets/flutter-deriv-packages/issues/900)). ([8ea63c8e](https://github.com/regentmarkets/flutter-deriv-packages/commit/8ea63c8e0c3cc73f2420e7b0069b3b60b54bf9b4))

## 0.1.8

- **FEAT**(analytics): Add indicator events ([#846](https://github.com/regentmarkets/flutter-deriv-packages/issues/846)). ([1d30ddc9](https://github.com/regentmarkets/flutter-deriv-packages/commit/1d30ddc9c7510e280cc90fc7e1308b945d5758ed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export 'package:deriv_chart/deriv_chart.dart';
export 'src/mobile_tools_ui/color_selector.dart';
export 'src/pages/rsi_setting_page.dart';
export 'src/indicator_event_service.dart';
export 'src/constants.dart';
6 changes: 6 additions & 0 deletions packages/deriv_mobile_chart_wrapper/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ const Set<Type> drawingToolTypesToShowInfoBar = {
LineDrawingToolConfig,
RayDrawingToolConfig,
};

/// Default key used for indicators if no custom key is provided.
const String defaultIndicatorsStoreKey = 'default_indicators_store';

/// Default key used for drawing tools if no custom key is provided.
const String defaultDrawingToolsStoreKey = 'default_drawing_tools_store';
103 changes: 66 additions & 37 deletions packages/deriv_mobile_chart_wrapper/lib/src/mobile_chart_wrapper.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:deriv_chart/deriv_chart.dart';
import 'package:deriv_mobile_chart_wrapper/src/constants.dart';
import 'package:deriv_mobile_chart_wrapper/src/extensions.dart';
import 'package:deriv_mobile_chart_wrapper/src/indicator_event_service.dart';
import 'package:deriv_mobile_chart_wrapper/src/mobile_tools_ui/drawing_tools/drawing_tools_selector.dart';
Expand All @@ -19,7 +20,8 @@ class MobileChartWrapper extends StatefulWidget {
const MobileChartWrapper({
required this.mainSeries,
required this.granularity,
this.toolsStoreKey = 'default',
this.indicatorsStoreKey = defaultIndicatorsStoreKey,
this.drawingToolsStoreKey = defaultDrawingToolsStoreKey,
this.toolsController,
this.markerSeries,
this.controller,
Expand Down Expand Up @@ -60,11 +62,21 @@ class MobileChartWrapper extends StatefulWidget {
/// Open position marker series.
final MarkerSeries? markerSeries;

/// The key which is used to store selected indicators/tools.
/// The key used to store the selected indicators in shared preferences.
/// If no key is provided, the default key `'default'` is used.
///
/// When you pass the same key that was passed before when user selected some
/// tools, by passing the same key, the tools will be restored.
final String toolsStoreKey;
/// By using the same key when selecting indicators, the previously saved
/// state will be restored, ensuring the tools are in the same configuration
/// as before.
final String indicatorsStoreKey;

/// The key used to store the selected drawing tools in shared preferences.
/// If no key is provided, the default key `'default'` is used.
///
/// By using the same key when applying drawing tools, the previously applied
/// tools state will be restored, ensuring the tools are in the same
/// configuration as before.
final String drawingToolsStoreKey;

/// Chart's controller
final ChartController? controller;
Expand Down Expand Up @@ -186,8 +198,14 @@ class MobileChartWrapperState extends State<MobileChartWrapper> {
void didUpdateWidget(covariant MobileChartWrapper oldWidget) {
super.didUpdateWidget(oldWidget);

if (widget.toolsStoreKey != oldWidget.toolsStoreKey) {
loadSavedIndicatorsAndDrawingTools();
// Reload indicators if the indicators key has changed
if (widget.indicatorsStoreKey != oldWidget.indicatorsStoreKey) {
_loadSavedIndicators();
}

// Reload drawing tools if the drawing tools key has changed
if (widget.drawingToolsStoreKey != oldWidget.drawingToolsStoreKey) {
_loadSavedDrawingTools();
}
}

Expand Down Expand Up @@ -216,51 +234,58 @@ class MobileChartWrapperState extends State<MobileChartWrapper> {
createAddOn: (Map<String, dynamic> map) =>
IndicatorConfig.fromJson(map),
onEditCallback: (_) => _showIndicatorsSheet(_indicatorsRepo!),
sharedPrefKey: widget.toolsStoreKey,
sharedPrefKey: widget.indicatorsStoreKey,
);

await _loadSavedIndicators();
}

if (widget.toolsController?.drawingToolsEnabled ?? false) {
_drawingToolsRepo = AddOnsRepository<DrawingToolConfig>(
createAddOn: (Map<String, dynamic> map) =>
DrawingToolConfig.fromJson(map),
onEditCallback: (_) => _showDrawingToolsSheet(_drawingToolsRepo!),
sharedPrefKey: widget.toolsStoreKey,
sharedPrefKey: widget.drawingToolsStoreKey,
);

await _loadSavedDrawingTools();
}

await loadSavedIndicatorsAndDrawingTools();
_setupController();
}

Future<void> loadSavedIndicatorsAndDrawingTools() async {
Future<void> _loadSavedIndicators() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
final List<AddOnsRepository<AddOnConfig>> stateRepos =
<AddOnsRepository<AddOnConfig>>[
if (_indicatorsRepo != null) _indicatorsRepo!,
if (_drawingToolsRepo != null) _drawingToolsRepo!,
];

stateRepos
.asMap()
.forEach((int index, AddOnsRepository<AddOnConfig> element) {
if (_indicatorsRepo != null) {
try {
element.loadFromPrefs(prefs, widget.toolsStoreKey);
_indicatorsRepo!.loadFromPrefs(prefs, widget.indicatorsStoreKey);
} on Exception {
// ignore: unawaited_futures
showDialog<void>(
context: context,
builder: (BuildContext context) => AnimatedPopupDialog(
child: Center(
child: element is Repository<IndicatorConfig>
// TODO(Ramin): use localization.
? const Text('Failed loading indicators')
: const Text('Failed loading drawing tools'),
),
),
);
_showLoadErrorDialog(message: 'Failed loading indicators');
}
});
}
}

Future<void> _loadSavedDrawingTools() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
if (_drawingToolsRepo != null) {
try {
_drawingToolsRepo!.loadFromPrefs(prefs, widget.drawingToolsStoreKey);
} on Exception {
_showLoadErrorDialog(message: 'Failed loading drawing tools');
}
}
}

void _showLoadErrorDialog({required String message}) {
// Show error dialog
showDialog<void>(
context: context,
builder: (BuildContext context) => AnimatedPopupDialog(
child: Center(
child: Text(message),
),
),
);
}

void _showIndicatorsSheet(AddOnsRepository<IndicatorConfig> indicatorsRepo) {
Expand Down Expand Up @@ -325,13 +350,13 @@ class MobileChartWrapperState extends State<MobileChartWrapper> {
: AddOnsRepository<IndicatorConfig>(
createAddOn: (Map<String, dynamic> map) =>
IndicatorConfig.fromJson(map),
sharedPrefKey: widget.toolsStoreKey,
sharedPrefKey: widget.indicatorsStoreKey,
),
drawingToolsRepo: _drawingToolsRepo ??
AddOnsRepository<DrawingToolConfig>(
createAddOn: (Map<String, dynamic> map) =>
DrawingToolConfig.fromJson(map),
sharedPrefKey: widget.toolsStoreKey,
sharedPrefKey: widget.drawingToolsStoreKey,
),
drawingTools: _drawingTools,
controller: widget.controller,
Expand All @@ -345,7 +370,11 @@ class MobileChartWrapperState extends State<MobileChartWrapper> {
opacity: widget.opacity,
chartAxisConfig: widget.chartAxisConfig,
annotations: widget.annotations,
activeSymbol: widget.toolsStoreKey,
// TODO: The 'activeSymbol' property will be deprecated in a future
// release. It is currently irrelevant in the current chart package
// implementation, as the AddOnsRepository is initialized externally
// in the implementation.
activeSymbol: 'default',
);

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/deriv_mobile_chart_wrapper/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: deriv_mobile_chart_wrapper
description: A new Flutter package project.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 0.1.8
version: 0.1.8+1
homepage:

environment:
Expand Down

0 comments on commit 664b8a3

Please sign in to comment.