mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-09-29 18:01:06 +00:00
clean up db migrate
This commit is contained in:
parent
58deb850f2
commit
649ebd1987
2 changed files with 8 additions and 27 deletions
|
@ -36,7 +36,7 @@ abstract class Constants {
|
||||||
// Enable Logger.print statements
|
// Enable Logger.print statements
|
||||||
static const bool disableLogger = false;
|
static const bool disableLogger = false;
|
||||||
|
|
||||||
static const int currentHiveDbVersion = 1;
|
static const int currentHiveDbVersion = 2;
|
||||||
|
|
||||||
static List<int> possibleLengthsForCoin(Coin coin) {
|
static List<int> possibleLengthsForCoin(Coin coin) {
|
||||||
final List<int> values = [];
|
final List<int> values = [];
|
||||||
|
|
|
@ -21,6 +21,10 @@ class DbVersionMigrator {
|
||||||
FlutterSecureStorage(),
|
FlutterSecureStorage(),
|
||||||
),
|
),
|
||||||
}) async {
|
}) async {
|
||||||
|
Logging.instance.log(
|
||||||
|
"Running migrate fromVersion $fromVersion",
|
||||||
|
level: LogLevel.Warning,
|
||||||
|
);
|
||||||
switch (fromVersion) {
|
switch (fromVersion) {
|
||||||
case 0:
|
case 0:
|
||||||
await Hive.openBox<dynamic>(DB.boxNameAllWalletsData);
|
await Hive.openBox<dynamic>(DB.boxNameAllWalletsData);
|
||||||
|
@ -117,37 +121,14 @@ class DbVersionMigrator {
|
||||||
return await migrate(1);
|
return await migrate(1);
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
await Hive.openBox<dynamic>(DB.boxNameTrades);
|
await Hive.openBox<ExchangeTransaction>(DB.boxNameTrades);
|
||||||
await Hive.openBox<dynamic>(DB.boxNameTradesV2);
|
await Hive.openBox<Trade>(DB.boxNameTradesV2);
|
||||||
final trades =
|
final trades =
|
||||||
DB.instance.values<ExchangeTransaction>(boxName: DB.boxNameTrades);
|
DB.instance.values<ExchangeTransaction>(boxName: DB.boxNameTrades);
|
||||||
|
|
||||||
for (final old in trades) {
|
for (final old in trades) {
|
||||||
if (old.statusObject != null) {
|
if (old.statusObject != null) {
|
||||||
final trade = Trade(
|
final trade = Trade.fromExchangeTransaction(old);
|
||||||
uuid: old.uuid,
|
|
||||||
tradeId: old.id,
|
|
||||||
rateType: "",
|
|
||||||
direction: "direct",
|
|
||||||
timestamp: old.date,
|
|
||||||
updatedAt: DateTime.tryParse(old.statusObject?.updatedAt ?? "") ??
|
|
||||||
old.date,
|
|
||||||
payInCurrency: old.fromCurrency,
|
|
||||||
payInAmount: old.statusObject!.expectedSendAmountDecimal,
|
|
||||||
payInAddress: old.payinAddress,
|
|
||||||
payInNetwork: "",
|
|
||||||
payInExtraId: old.payinExtraId,
|
|
||||||
payInTxid: "",
|
|
||||||
payOutCurrency: old.toCurrency,
|
|
||||||
payOutAmount: old.amount,
|
|
||||||
payOutAddress: old.payoutAddress,
|
|
||||||
payOutNetwork: "",
|
|
||||||
payOutExtraId: old.payoutExtraId,
|
|
||||||
payOutTxid: "",
|
|
||||||
refundAddress: old.refundAddress,
|
|
||||||
refundExtraId: old.refundExtraId,
|
|
||||||
status: old.statusObject!.status.name,
|
|
||||||
);
|
|
||||||
await DB.instance.put<Trade>(
|
await DB.instance.put<Trade>(
|
||||||
boxName: DB.boxNameTradesV2,
|
boxName: DB.boxNameTradesV2,
|
||||||
key: trade.uuid,
|
key: trade.uuid,
|
||||||
|
|
Loading…
Reference in a new issue