mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
add tokenInfo to migration and a couple other eth token related tweaks
This commit is contained in:
parent
7bf817ca66
commit
6942a9b3dd
5 changed files with 40 additions and 36 deletions
|
@ -350,5 +350,4 @@ abstract class DBKeys {
|
|||
static const String isFavorite = "isFavorite";
|
||||
static const String id = "id";
|
||||
static const String storedChainHeight = "storedChainHeight";
|
||||
static const String ethTokenContracts = "ethTokenContracts";
|
||||
}
|
||||
|
|
|
@ -4,9 +4,10 @@ import 'package:hive_flutter/hive_flutter.dart';
|
|||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/db/hive/db.dart';
|
||||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/transaction_note.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/token_wallet_info.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/wallet_info_meta.dart';
|
||||
import 'package:stackwallet/wallets/wallet/supporting/epiccash_wallet_info_extension.dart';
|
||||
|
@ -49,6 +50,7 @@ Future<void> migrateWalletsToIsar({
|
|||
(await Hive.openBox<String>(DB.boxNameFavoriteWallets)).values.toList();
|
||||
|
||||
final List<(WalletInfo, WalletInfoMeta)> newInfo = [];
|
||||
final List<TokenWalletInfo> tokenInfo = [];
|
||||
final List<TransactionNote> migratedNotes = [];
|
||||
|
||||
//
|
||||
|
@ -89,10 +91,30 @@ Future<void> migrateWalletsToIsar({
|
|||
//
|
||||
Map<String, dynamic> otherData = {};
|
||||
|
||||
otherData[WalletInfoKeys.tokenContractAddresses] = walletBox.get(
|
||||
DBKeys.ethTokenContracts,
|
||||
final List<String>? tokenContractAddresses = walletBox.get(
|
||||
"ethTokenContracts",
|
||||
) as List<String>?;
|
||||
|
||||
if (tokenContractAddresses?.isNotEmpty == true) {
|
||||
otherData[WalletInfoKeys.tokenContractAddresses] = tokenContractAddresses;
|
||||
|
||||
for (final address in tokenContractAddresses!) {
|
||||
final contract = await MainDB.instance.isar.ethContracts
|
||||
.where()
|
||||
.addressEqualTo(address)
|
||||
.findFirst();
|
||||
if (contract != null) {
|
||||
tokenInfo.add(
|
||||
TokenWalletInfo(
|
||||
walletId: old.walletId,
|
||||
tokenAddress: address,
|
||||
tokenFractionDigits: contract.decimals,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// epiccash specifics
|
||||
if (old.coin == Coin.epicCash) {
|
||||
final epicWalletInfo = ExtraEpiccashWalletInfo.fromMap({
|
||||
|
@ -149,12 +171,18 @@ Future<void> migrateWalletsToIsar({
|
|||
});
|
||||
}
|
||||
|
||||
await MainDB.instance.isar.writeTxn(() async {
|
||||
await MainDB.instance.isar.walletInfo
|
||||
.putAll(newInfo.map((e) => e.$1).toList());
|
||||
await MainDB.instance.isar.walletInfoMeta
|
||||
.putAll(newInfo.map((e) => e.$2).toList());
|
||||
});
|
||||
if (newInfo.isNotEmpty) {
|
||||
await MainDB.instance.isar.writeTxn(() async {
|
||||
await MainDB.instance.isar.walletInfo
|
||||
.putAll(newInfo.map((e) => e.$1).toList());
|
||||
await MainDB.instance.isar.walletInfoMeta
|
||||
.putAll(newInfo.map((e) => e.$2).toList());
|
||||
|
||||
if (tokenInfo.isNotEmpty) {
|
||||
await MainDB.instance.isar.tokenWalletInfo.putAll(tokenInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await _cleanupOnSuccess(
|
||||
walletIds: newInfo.map((e) => e.$1.walletId).toList());
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/db/hive/db.dart';
|
||||
import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/coin_entity.dart';
|
||||
import 'package:stackwallet/models/add_wallet_list_entity/sub_classes/eth_token_entity.dart';
|
||||
import 'package:stackwallet/pages/add_wallet_views/add_token_view/edit_wallet_tokens_view.dart';
|
||||
|
@ -20,6 +19,7 @@ import 'package:stackwallet/themes/stack_colors.dart';
|
|||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/wallets/isar/providers/all_wallets_info_provider.dart';
|
||||
import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart';
|
||||
import 'package:stackwallet/widgets/background.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
|
@ -85,13 +85,8 @@ class _SelectWalletForTokenViewState
|
|||
|
||||
final List<String> ethWalletIds = [];
|
||||
|
||||
// TODO: proper wallet data class instead of this Hive silliness
|
||||
for (final walletId in ethWalletInfos.map((e) => e.walletId).toList()) {
|
||||
final walletContracts = DB.instance.get<dynamic>(
|
||||
boxName: walletId,
|
||||
key: DBKeys.ethTokenContracts,
|
||||
) as List<String>? ??
|
||||
[];
|
||||
final walletContracts = ref.read(pWalletTokenAddresses(walletId));
|
||||
if (!walletContracts.contains(widget.entity.token.address)) {
|
||||
ethWalletIds.add(walletId);
|
||||
}
|
||||
|
|
|
@ -127,22 +127,4 @@ mixin WalletCache {
|
|||
value: balance.toJsonIgnoreCoin(),
|
||||
);
|
||||
}
|
||||
|
||||
// Ethereum specific
|
||||
List<String> getWalletTokenContractAddresses() {
|
||||
return DB.instance.get<dynamic>(
|
||||
boxName: _walletId,
|
||||
key: DBKeys.ethTokenContracts,
|
||||
) as List<String>? ??
|
||||
[];
|
||||
}
|
||||
|
||||
Future<void> updateWalletTokenContractAddresses(
|
||||
List<String> contractAddresses) async {
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: _walletId,
|
||||
key: DBKeys.ethTokenContracts,
|
||||
value: contractAddresses,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class TokenWalletInfo implements IsarId {
|
|||
// // ensure we are updating using the latest entry of this in the db
|
||||
final thisEntry = await isar.tokenWalletInfo
|
||||
.where()
|
||||
.walletIdEqualToTokenAddressNotEqualTo(walletId, tokenAddress)
|
||||
.walletIdTokenAddressEqualTo(walletId, tokenAddress)
|
||||
.findFirst();
|
||||
if (thisEntry == null) {
|
||||
throw Exception(
|
||||
|
|
Loading…
Reference in a new issue