feat: use isar instead of hive

This commit is contained in:
detherminal 2023-05-05 20:30:22 +03:00
parent bf6e378fbc
commit 47df2a8a7a
2 changed files with 11 additions and 16 deletions

View file

@ -88,8 +88,9 @@ class _ManageExplorerViewState extends ConsumerState<ManageExplorerView> {
.getPrimaryEnabledButtonStyle(context), .getPrimaryEnabledButtonStyle(context),
onPressed: () { onPressed: () {
textEditingController.text = textEditingController.text.trim(); textEditingController.text = textEditingController.text.trim();
setBlockExplorerForCoin(coin: widget.coin, url: Uri.parse(textEditingController.text)); setBlockExplorerForCoin(coin: widget.coin, url: Uri.parse(textEditingController.text)).then((value) =>
Navigator.of(context).pop(); Navigator.of(context).pop()
);
}, },
child: Text( child: Text(
"Save", "Save",

View file

@ -3,6 +3,8 @@ import 'dart:ffi';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import '../db/hive/db.dart'; import '../db/hive/db.dart';
import '../db/isar/main_db.dart';
import '../models/isar/models/block_explorer.dart';
Uri getDefaultBlockExplorerUrlFor({ Uri getDefaultBlockExplorerUrlFor({
required Coin coin, required Coin coin,
@ -46,14 +48,10 @@ Uri getDefaultBlockExplorerUrlFor({
} }
} }
int setBlockExplorerForCoin( Future<int> setBlockExplorerForCoin(
{required Coin coin, required Uri url} {required Coin coin, required Uri url}
) { ) async {
var ticker = coin.ticker; await MainDB.instance.putTransactionBlockExplorer(TransactionBlockExplorer(ticker: coin.ticker, url: url.toString()));
DB.instance.put<dynamic>(
boxName: DB.boxNameAllWalletsData,
key: "${ticker}blockExplorerUrl",
value: url);
return 0; return 0;
} }
@ -61,15 +59,11 @@ Uri getBlockExplorerTransactionUrlFor({
required Coin coin, required Coin coin,
required String txid, required String txid,
}) { }) {
var ticker = coin.ticker; var url = MainDB.instance.getTransactionBlockExplorer(coin: coin)?.url.toString();
var url = DB.instance.get<dynamic>(
boxName: DB.boxNameAllWalletsData,
key: "${ticker}blockExplorerUrl",
);
if (url == null) { if (url == null) {
return getDefaultBlockExplorerUrlFor(coin: coin, txid: txid); return getDefaultBlockExplorerUrlFor(coin: coin, txid: txid);
} else { } else {
url = url.replace("%5BTXID%5D", txid); url = url.replaceAll("%5BTXID%5D", txid);
return Uri.parse(url.toString()); return Uri.parse(url);
} }
} }