Skip to content

Commit 9859e52

Browse files
committed
fix: use tor, display showLoading and use primary node
1 parent 0606d1e commit 9859e52

2 files changed

Lines changed: 42 additions & 47 deletions

File tree

lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ import '../../../utilities/barcode_scanner_interface.dart';
3232
import '../../../utilities/constants.dart';
3333
import '../../../utilities/default_eth_tokens.dart';
3434
import '../../../utilities/logger.dart';
35+
import '../../../utilities/show_loading.dart';
3536
import '../../../utilities/text_styles.dart';
3637
import '../../../utilities/util.dart';
3738
import '../../../wallets/crypto_currency/crypto_currency.dart';
39+
import '../../../wallets/wallet/wallet.dart';
3840
import '../../../widgets/background.dart';
3941
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
4042
import '../../../widgets/desktop/desktop_app_bar.dart';
@@ -139,50 +141,21 @@ class _AddWalletViewState extends ConsumerState<AddWalletView> {
139141

140142
if (results != null) {
141143
if (mounted) {
142-
unawaited(showModalBottomSheet<dynamic>(
143-
backgroundColor: Colors.transparent,
144+
final Wallet<CryptoCurrency>? wallet = await showLoading(
145+
whileFuture: results.coin.importPaperWallet(results, ref),
144146
context: context,
145-
shape: const RoundedRectangleBorder(
146-
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
147-
),
148-
builder: (_) {
149-
return Container(
150-
decoration: BoxDecoration(
151-
color: Theme.of(context).extension<StackColors>()!.popupBG,
152-
borderRadius: const BorderRadius.vertical(
153-
top: Radius.circular(20),
154-
),
155-
),
156-
child: Padding(
157-
padding: const EdgeInsets.all(20),
158-
child: Column(
159-
mainAxisSize: MainAxisSize.min,
160-
crossAxisAlignment: CrossAxisAlignment.center,
161-
children: [
162-
const CircularProgressIndicator(),
163-
const SizedBox(
164-
height: 16,
165-
),
166-
Text(
167-
"Importing ${results.coin.prettyName} Paper Wallet",
168-
style: STextStyles.field(context).copyWith(
169-
fontSize: 16,
170-
height: 1.5,
171-
),
172-
textAlign: TextAlign.center,
173-
),
174-
],
175-
)
176-
),
177-
);
178-
},
179-
));
180-
final wallet = await results.coin.importPaperWallet(results, ref);
147+
message: "Importing paper wallet...",
148+
);
149+
if (wallet == null) {
150+
throw Exception(
151+
"Failed to import paper wallet because wallet from importPaperWallet is null: ${results.coin.prettyName}",
152+
);
153+
}
181154
if (mounted) {
182155
Navigator.pop(context);
183156
await Navigator.of(context).pushNamed(
184157
WalletView.routeName,
185-
arguments: wallet.walletId,
158+
arguments: wallet!.walletId,
186159
);
187160
}
188161
}

lib/wallets/crypto_currency/coins/monero.dart

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import 'dart:io';
22

3-
import 'package:compat/old_cw_core/wallet_type.dart';
4-
import 'package:cs_monero/cs_monero.dart' as cs_monero;
53
import 'package:cs_monero/src/ffi_bindings/monero_wallet_bindings.dart'
64
as xmr_wallet_ffi;
75
import 'package:flutter_riverpod/flutter_riverpod.dart';
86
import 'package:http/io_client.dart';
97
import 'package:monero_rpc/monero_rpc.dart';
8+
import 'package:socks5_proxy/socks.dart';
109

11-
import '../../../models/isar/models/isar_models.dart';
1210
import '../../../models/node_model.dart';
1311
import '../../../providers/db/main_db_provider.dart';
1412
import '../../../providers/global/node_service_provider.dart';
1513
import '../../../providers/global/prefs_provider.dart';
1614
import '../../../providers/global/secure_store_provider.dart';
1715
import '../../../providers/global/wallets_provider.dart';
16+
import '../../../services/event_bus/events/global/tor_connection_status_changed_event.dart';
1817
import '../../../services/node_service.dart';
18+
import '../../../services/tor_service.dart';
1919
import '../../../utilities/address_utils.dart';
2020
import '../../../utilities/default_nodes.dart';
2121
import '../../../utilities/enums/derive_path_type_enum.dart';
2222
import '../../../utilities/enums/fee_rate_type_enum.dart';
23+
import '../../../utilities/logger.dart';
24+
import '../../../utilities/prefs.dart';
2325
import '../../isar/models/wallet_info.dart';
24-
import '../../isar/providers/wallet_info_provider.dart';
2526
import '../../models/tx_data.dart';
2627
import '../../wallet/impl/monero_wallet.dart';
27-
import '../../wallet/intermediate/lib_monero_wallet.dart';
2828
import '../../wallet/wallet.dart';
2929
import '../crypto_currency.dart';
3030
import '../intermediate/cryptonote_currency.dart';
@@ -147,6 +147,7 @@ class Monero extends CryptonoteCurrency {
147147
@override
148148
Future<Wallet<CryptoCurrency>> importPaperWallet(WalletUriData walletData, WidgetRef ref) async {
149149
if (walletData.txids != null) {
150+
// If the walletData contains txids, we need to create a temporary wallet to sweep the gift wallet
150151
final wallet = await Wallet.create(
151152
walletInfo: WalletInfo.createNew(
152153
coin: walletData.coin,
@@ -164,10 +165,31 @@ class Monero extends CryptonoteCurrency {
164165
await (wallet as MoneroWallet).init(isRestore: true);
165166
await wallet.recover(isRescan: false);
166167

167-
// Scan the blocks with given txids
168-
final primaryNode = defaultNode;
168+
final primaryNode = NodeService(secureStorageInterface: ref.read(secureStoreProvider))
169+
.getPrimaryNodeFor(currency: walletData.coin) ?? defaultNode;
170+
171+
// Create an HTTP client with Tor support if enabled
172+
final torService = TorService.sharedInstance;
173+
final prefs = Prefs.instance;
174+
final httpClient = HttpClient();
175+
if (prefs.useTor) {
176+
if (torService.status != TorConnectionStatus.connected) {
177+
if (prefs.torKillSwitch) {
178+
throw Exception("Tor is not connected, and the kill switch is enabled. Can't sweep gift wallet");
179+
} else {
180+
// If Tor is not connected, we can still proceed with the request
181+
Logging.instance.w("Tor is not connected, proceeding without Tor.");
182+
}
183+
} else {
184+
SocksTCPClient.assignToHttpClient(httpClient, [ProxySettings(torService.getProxyInfo().host, torService.getProxyInfo().port)]);
185+
}
186+
}
187+
188+
// Create a DaemonRpc instance to interact with the Monero node
169189
final daemonRpc = DaemonRpc(
170-
IOClient(HttpClient()), "${primaryNode.host}:${primaryNode.port}");
190+
IOClient(httpClient), "${primaryNode.host}:${primaryNode.port}");
191+
192+
// Scan the blocks with given txids
171193
final txs = await daemonRpc.postToEndpoint("/get_transactions", {
172194
"txs_hashes": walletData.txids,
173195
"decode_as_json": true,

0 commit comments

Comments
 (0)