feat: migrate Trade data to SQLite with TradeLegacy for backward compatibility (#3106)

* feat: migrate Trade data to SQLite with TradeLegacy for backward compatibility

* feat: persist full currency snapshots in sql storage, not raw-only [WIP]

* feat: persist full trade currency snapshots in sql storage

* refactor trade and currency handling for migration

* Minor fixes

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
David Adegoke
2026-05-07 00:02:04 +02:00
committed by GitHub
co-authored by Omar Hatem
parent 813aa348bc
commit 9f6396f5d8
39 changed files with 1011 additions and 833 deletions
+16 -14
View File
@@ -1,9 +1,7 @@
import 'dart:async';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
part 'trades_store.g.dart';
@@ -11,14 +9,11 @@ part 'trades_store.g.dart';
class TradesStore = TradesStoreBase with _$TradesStore;
abstract class TradesStoreBase with Store {
TradesStoreBase({required this.tradesSource, required this.appStore})
: trades = <TradeListItem>[] {
_onTradesChanged = tradesSource.watch().listen((_) async => await updateTradeList());
TradesStoreBase({required this.appStore}) : trades = <TradeListItem>[] {
Trade.onChanged.stream.listen((_) => updateTradeList());
updateTradeList();
}
Box<Trade> tradesSource;
StreamSubscription<BoxEvent>? _onTradesChanged;
AppStore appStore;
@observable
@@ -31,11 +26,18 @@ abstract class TradesStoreBase with Store {
void setTrade(Trade trade) => this.trade = trade;
@action
Future<void> updateTradeList() async => trades = tradesSource.values
.map((trade) => TradeListItem(
trade: trade,
appStore: appStore,
key: ValueKey('trade_list_item_${trade.id}_key'),
))
.toList();
Future<void> updateTradeList() async {
try {
final allTrades = await Trade.getAll();
runInAction(() {
trades = allTrades
.map((trade) => TradeListItem(
trade: trade,
appStore: appStore,
key: ValueKey('trade_list_item_${trade.id}_key'),
))
.toList();
});
} catch (_) {}
}
}