LCOV - code coverage report
Current view: top level - lib/_classes/integration/starling - starling_settings.dart Coverage Total Hit
Test: lcov.info Lines: 0.0 % 25 0
Test Date: 2026-12-05 10:54:13 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2026 The terCAD team. All rights reserved.
       2              : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3              : 
       4              : import 'dart:convert';
       5              : 
       6              : import 'package:app_finance/_classes/controller/encryption_handler.dart';
       7              : import 'package:app_finance/_classes/storage/app_preferences.dart';
       8              : 
       9              : class StarlingSettings {
      10              :   // Starling account uid to the uuid of the application's account
      11              :   final Map<String, String> links;
      12              : 
      13              :   // Starling account uid to the last day transactions were imported for
      14              :   final Map<String, DateTime> imported;
      15              : 
      16            0 :   StarlingSettings({Map<String, String>? links, Map<String, DateTime>? imported})
      17            0 :       : links = links ?? {},
      18            0 :         imported = imported ?? {};
      19              : 
      20            0 :   Map<String, dynamic> toJson() => {
      21            0 :         'links': links,
      22            0 :         'imported': imported.map((key, value) => MapEntry(key, value.toIso8601String())),
      23              :       };
      24              : 
      25            0 :   factory StarlingSettings.fromJson(Map<String, dynamic> json) => StarlingSettings(
      26            0 :         links: (json['links'] as Map<String, dynamic>? ?? {}).map((key, value) => MapEntry(key, value.toString())),
      27            0 :         imported: (json['imported'] as Map<String, dynamic>? ?? {}).map(
      28            0 :           (key, value) => MapEntry(key, DateTime.parse(value.toString())),
      29              :         ),
      30              :       );
      31              : 
      32            0 :   static StarlingSettings load() {
      33            0 :     final value = AppPreferences.get(AppPreferences.prefStarling);
      34            0 :     if (value == null || value.isEmpty) {
      35            0 :       return StarlingSettings();
      36              :     }
      37              :     try {
      38            0 :       return StarlingSettings.fromJson(jsonDecode(value));
      39            0 :     } on FormatException {
      40            0 :       return StarlingSettings();
      41              :     }
      42              :   }
      43              : 
      44            0 :   Future<void> save() => AppPreferences.set(AppPreferences.prefStarling, jsonEncode(toJson()));
      45              : 
      46            0 :   static String? loadToken() {
      47            0 :     final value = AppPreferences.get(AppPreferences.prefStarlingToken);
      48            0 :     if (value == null || value.isEmpty) {
      49              :       return null;
      50              :     }
      51              :     try {
      52            0 :       return EncryptionHandler.decrypt(value);
      53              :     } catch (_) {
      54              :       return null;
      55              :     }
      56              :   }
      57              : 
      58            0 :   static Future<void> saveToken(String token) =>
      59            0 :       AppPreferences.set(AppPreferences.prefStarlingToken, EncryptionHandler.encrypt(token));
      60              : 
      61            0 :   static Future<void> clearToken() => AppPreferences.clear(AppPreferences.prefStarlingToken);
      62              : }
        

Generated by: LCOV version 2.0-1