Files
hash-wallet/lib/exchange/trade_currency_snapshot.dart
9f6396f5d8 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>
2026-05-07 00:02:04 +02:00

46 lines
982 B
Dart

import 'package:cw_core/crypto_currency.dart';
class TradeCurrencySnapshot {
TradeCurrencySnapshot._();
static CryptoCurrency? fromLegacyHive({
required int raw,
String? displayTitleTag,
}) {
if (raw >= 0) {
final curr = CryptoCurrency.safeDeserialize(raw: raw);
if (curr != null) return curr;
}
return _parseLegacyTitleTag(displayTitleTag);
}
static CryptoCurrency? _parseLegacyTitleTag(String? titleTag) {
if (titleTag == null || titleTag.isEmpty) return null;
final idx = titleTag.indexOf('_');
if (idx < 0) {
return CryptoCurrency(
title: titleTag,
name: '',
raw: -1,
decimals: 1,
);
}
final title = titleTag.substring(0, idx);
var tag = titleTag.substring(idx + 1);
if (tag.contains('ARB')) tag = 'ARB';
return CryptoCurrency(
title: title,
tag: tag.isNotEmpty ? tag : null,
name: '',
raw: -1,
decimals: 1,
);
}
}