stack_wallet/lib/utilities/block_explorers.dart

42 lines
1.1 KiB
Dart
Raw Normal View History

/*
2023-05-26 21:21:16 +00:00
* This file is part of Stack Wallet.
*
2023-05-26 21:21:16 +00:00
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'package:stackwallet/db/isar/main_db.dart';
import 'package:stackwallet/models/isar/models/block_explorer.dart';
2024-05-15 21:20:45 +00:00
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
2023-05-04 18:10:37 +00:00
2023-05-26 19:25:59 +00:00
// Returns internal Isar ID for the inserted object/record
Future<int> setBlockExplorerForCoin({
2024-05-15 21:20:45 +00:00
required CryptoCurrency coin,
required Uri url,
}) async {
return await MainDB.instance.putTransactionBlockExplorer(
TransactionBlockExplorer(
ticker: coin.ticker,
url: url.toString(),
),
);
2023-05-04 18:10:37 +00:00
}
2023-05-26 19:25:59 +00:00
// Returns the block explorer URL for the given coin and txid
2023-05-04 18:10:37 +00:00
Uri getBlockExplorerTransactionUrlFor({
2024-05-15 21:20:45 +00:00
required CryptoCurrency coin,
2023-05-04 18:10:37 +00:00
required String txid,
}) {
2024-05-15 21:20:45 +00:00
String? url =
MainDB.instance.getTransactionBlockExplorer(cryptoCurrency: coin)?.url;
2023-05-04 18:10:37 +00:00
if (url == null) {
2024-05-15 21:20:45 +00:00
return coin.defaultBlockExplorer(txid);
2023-05-04 18:10:37 +00:00
} else {
url = url.replaceAll("%5BTXID%5D", txid);
2023-05-05 17:30:22 +00:00
return Uri.parse(url);
2023-05-04 18:10:37 +00:00
}
}