From a0f86df9a69d36211ae6c38dff21db5ef269fe9c Mon Sep 17 00:00:00 2001 From: Serhii Date: Sun, 26 Mar 2023 20:32:10 +0300 Subject: [PATCH] add block explorer --- .../unspent_coins_details_page.dart | 9 ++++++ .../unspent_coins_details_view_model.dart | 32 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/src/screens/unspent_coins/unspent_coins_details_page.dart b/lib/src/screens/unspent_coins/unspent_coins_details_page.dart index dd194c4fd..d686bf992 100644 --- a/lib/src/screens/unspent_coins/unspent_coins_details_page.dart +++ b/lib/src/screens/unspent_coins/unspent_coins_details_page.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/src/screens/transaction_details/blockexplorer_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/textfield_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/widgets/textfield_list_row.dart'; import 'package:cake_wallet/src/screens/unspent_coins/widgets/unspent_coins_switch_row.dart'; @@ -60,6 +61,14 @@ class UnspentCoinsDetailsPage extends BasePage { )); } + if (item is BlockExplorerListItem) { + return GestureDetector( + onTap: item.onTap, + child: + ListRow(title: '${item.title}:', value: item.value), + ); + } + return Container(); }); } diff --git a/lib/view_model/unspent_coins/unspent_coins_details_view_model.dart b/lib/view_model/unspent_coins/unspent_coins_details_view_model.dart index ed8687c87..e43ada6d7 100644 --- a/lib/view_model/unspent_coins/unspent_coins_details_view_model.dart +++ b/lib/view_model/unspent_coins/unspent_coins_details_view_model.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/src/screens/transaction_details/blockexplorer_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/textfield_list_item.dart'; import 'package:cake_wallet/src/screens/transaction_details/transaction_details_list_item.dart'; @@ -5,7 +6,9 @@ import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_list_view_model.dart'; import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_switch_item.dart'; +import 'package:cw_core/wallet_type.dart'; import 'package:mobx/mobx.dart'; +import 'package:url_launcher/url_launcher.dart'; part 'unspent_coins_details_view_model.g.dart'; @@ -47,10 +50,37 @@ abstract class UnspentCoinsDetailsViewModelBase with Store { } await unspentCoinsListViewModel.saveUnspentCoinInfo(unspentCoinsItem); } - ) + ), + BlockExplorerListItem( + title: S.current.view_in_block_explorer, + value: _explorerDescription(unspentCoinsListViewModel.wallet.type), + onTap: () => launch(_explorerUrl(unspentCoinsListViewModel.wallet.type, + unspentCoinsItem.hash))) ]; } + String _explorerUrl(WalletType type, String txId) { + switch (type) { + case WalletType.bitcoin: + return 'https://ordinals.com/tx/${txId}'; + case WalletType.litecoin: + return 'https://litecoin.earlyordies.com/tx/${txId}'; + default: + return ''; + } + } + + String _explorerDescription(WalletType type) { + switch (type) { + case WalletType.bitcoin: + return S.current.view_transaction_on + 'Ordinals.com'; + case WalletType.litecoin: + return S.current.view_transaction_on + 'Earlyordies.com'; + default: + return ''; + } + } + @observable bool isFrozen;