-
Notifications
You must be signed in to change notification settings - Fork 251
fix(app): finalize SIA integration and Trezor guards #3449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8e87464
e1dcd7d
cb56887
94b36cf
7a6b462
36eaecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import 'package:web_dex/mm2/mm2_api/rpc/withdraw/withdraw_request.dart'; | |
| import 'package:web_dex/model/cex_price.dart'; | ||
| import 'package:web_dex/model/coin.dart'; | ||
| import 'package:web_dex/model/kdf_auth_metadata_extension.dart'; | ||
| import 'package:web_dex/model/wallet.dart'; | ||
| import 'package:web_dex/model/text_error.dart'; | ||
| import 'package:web_dex/model/withdraw_details/withdraw_details.dart'; | ||
| import 'package:web_dex/services/arrr_activation/arrr_activation_service.dart'; | ||
|
|
@@ -67,6 +68,8 @@ class CoinsRepo { | |
| final ArrrActivationService _arrrActivationService; | ||
|
|
||
| final _log = Logger('CoinsRepo'); | ||
| static const _unsupportedTrezorSiaMessage = | ||
| 'SIA is not supported for Trezor wallets in this release.'; | ||
|
|
||
| /// { acc: { abbr: address }}, used in Fiat Page | ||
| final Map<String, Map<String, String>> _addressCache = {}; | ||
|
|
@@ -383,6 +386,31 @@ class CoinsRepo { | |
| return; | ||
| } | ||
|
|
||
| final walletType = (await _kdfSdk.currentWallet())?.config.type; | ||
| if (walletType == WalletType.trezor) { | ||
| final unsupportedSiaAssets = | ||
| assets.where((asset) => asset.id.subClass == CoinSubClass.sia); | ||
| if (unsupportedSiaAssets.isNotEmpty) { | ||
| _log.warning( | ||
| 'Skipping unsupported Trezor SIA activation for ' | ||
| '${unsupportedSiaAssets.map((a) => a.id.id).join(', ')}: ' | ||
| '$_unsupportedTrezorSiaMessage', | ||
| ); | ||
| for (final siaAsset in unsupportedSiaAssets) { | ||
| _broadcastAsset( | ||
| _assetToCoinWithoutAddress(siaAsset) | ||
| .copyWith(state: CoinState.suspended), | ||
| ); | ||
| } | ||
| } | ||
| assets = assets | ||
| .where((asset) => asset.id.subClass != CoinSubClass.sia) | ||
| .toList(); | ||
| if (assets.isEmpty) { | ||
| return; | ||
|
Comment on lines
+406
to
+410
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a Trezor wallet already has SIA in Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
|
|
||
| // Debug logging for activation | ||
| if (kDebugElectrumLogs) { | ||
| final coinIdList = assets.map((e) => e.id.id).join(', '); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import 'package:web_dex/bloc/settings/settings_repository.dart'; | |
| import 'package:web_dex/blocs/trading_entities_bloc.dart'; | ||
| import 'package:web_dex/model/coin.dart'; | ||
| import 'package:web_dex/model/coin_utils.dart'; | ||
| import 'package:web_dex/model/wallet.dart'; | ||
| import 'package:web_dex/shared/utils/extensions/kdf_user_extensions.dart'; | ||
| import 'package:web_dex/router/state/wallet_state.dart'; | ||
| import 'package:web_dex/views/wallet/coins_manager/coins_manager_helpers.dart'; | ||
|
|
@@ -68,13 +69,17 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| ) async { | ||
| final List<FilterFunction> filters = []; | ||
|
|
||
| final mergedCoinsList = _mergeCoinLists( | ||
| final originalCoins = await _filterUnsupportedHardwareCoins( | ||
| await _getOriginalCoinList( | ||
| _coinsRepo, | ||
| event.action, | ||
| cachedKnownCoinsMap: _cachedKnownCoinsMap, | ||
| cachedWalletCoins: _cachedWalletCoins, | ||
| ), | ||
| event.action, | ||
| ); | ||
| final mergedCoinsList = _mergeCoinLists( | ||
| originalCoins, | ||
| state.coins, | ||
| ).toList(); | ||
|
|
||
|
|
@@ -86,8 +91,15 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| state.selectedCoins, | ||
| event.action, | ||
| ); | ||
| final visibleSelectedCoins = await _filterUnsupportedHardwareCoins( | ||
| selectedCoins, | ||
| event.action, | ||
| ); | ||
|
|
||
| final uniqueCombinedList = <Coin>{...mergedCoinsList, ...selectedCoins}; | ||
| final uniqueCombinedList = <Coin>{ | ||
| ...mergedCoinsList, | ||
| ...visibleSelectedCoins, | ||
| }; | ||
|
|
||
| final testFilteredCoins = await _filterTestCoinsIfNeeded( | ||
| uniqueCombinedList.toList(), | ||
|
|
@@ -111,7 +123,7 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| state.copyWith( | ||
| coins: sortedCoins.unique((coin) => coin.id), | ||
| action: event.action, | ||
| selectedCoins: selectedCoins, | ||
| selectedCoins: visibleSelectedCoins, | ||
| ), | ||
| ); | ||
| } | ||
|
|
@@ -147,11 +159,14 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| _cachedTestCoinsEnabled = | ||
| (await _settingsRepository.loadSettings()).testCoinsEnabled; | ||
|
|
||
| final List<Coin> coins = await _getOriginalCoinList( | ||
| _coinsRepo, | ||
| final List<Coin> coins = await _filterUnsupportedHardwareCoins( | ||
| await _getOriginalCoinList( | ||
| _coinsRepo, | ||
| event.action, | ||
| cachedKnownCoinsMap: _cachedKnownCoinsMap, | ||
| cachedWalletCoins: _cachedWalletCoins, | ||
| ), | ||
| event.action, | ||
| cachedKnownCoinsMap: _cachedKnownCoinsMap, | ||
| cachedWalletCoins: _cachedWalletCoins, | ||
| ); | ||
|
|
||
| // Add wallet coins to selected coins if in add mode so that they | ||
|
|
@@ -164,17 +179,21 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| : <Coin>[], | ||
| event.action, | ||
| ); | ||
| final visibleSelectedCoins = await _filterUnsupportedHardwareCoins( | ||
| selectedCoins, | ||
| event.action, | ||
| ); | ||
|
Comment on lines
+182
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This second filter removes wallet-owned SIA coins from Useful? React with 👍 / 👎. |
||
|
|
||
| final filteredCoins = await _filterTestCoinsIfNeeded( | ||
| {...coins, ...selectedCoins}.toList(), | ||
| {...coins, ...visibleSelectedCoins}.toList(), | ||
| ); | ||
| final sortedCoins = _sortCoins(filteredCoins, event.action, state.sortData); | ||
|
|
||
| emit( | ||
| state.copyWith( | ||
| coins: sortedCoins.unique((coin) => coin.id), | ||
| action: event.action, | ||
| selectedCoins: selectedCoins, | ||
| selectedCoins: visibleSelectedCoins, | ||
| ), | ||
| ); | ||
| } | ||
|
|
@@ -185,9 +204,7 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| ) { | ||
| final List<CoinSubClass> newTypes = | ||
| state.selectedCoinTypes.contains(event.type) | ||
| ? state.selectedCoinTypes | ||
| .where((type) => type != event.type) | ||
| .toList() | ||
| ? state.selectedCoinTypes.where((type) => type != event.type).toList() | ||
| : [...state.selectedCoinTypes, event.type]; | ||
|
|
||
| emit(state.copyWith(selectedCoinTypes: newTypes)); | ||
|
|
@@ -249,10 +266,12 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| } on ZhtlcActivationCancelled { | ||
| // Revert optimistic selection and show a friendly message | ||
| selectedCoins.remove(coin); | ||
| emit(state.copyWith( | ||
| selectedCoins: selectedCoins.toList(), | ||
| errorMessage: 'Activation canceled.', | ||
| )); | ||
| emit( | ||
| state.copyWith( | ||
| selectedCoins: selectedCoins.toList(), | ||
| errorMessage: 'Activation canceled.', | ||
| ), | ||
| ); | ||
| return; | ||
| } | ||
| } else { | ||
|
|
@@ -358,12 +377,26 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
|
|
||
| List<Coin> _filterByType(List<Coin> coins) { | ||
| return coins | ||
| .where( | ||
| (coin) => state.selectedCoinTypes.contains(coin.id.subClass), | ||
| ) | ||
| .where((coin) => state.selectedCoinTypes.contains(coin.id.subClass)) | ||
| .toList(); | ||
| } | ||
|
|
||
| Future<List<Coin>> _filterUnsupportedHardwareCoins( | ||
| List<Coin> coins, | ||
| CoinsManagerAction action, | ||
| ) async { | ||
| if (action != CoinsManagerAction.add) { | ||
| return coins; | ||
| } | ||
|
|
||
| final currentWalletType = (await _sdk.auth.currentUser)?.wallet.config.type; | ||
| if (currentWalletType != WalletType.trezor) { | ||
| return coins; | ||
| } | ||
|
|
||
| return coins.where((coin) => coin.id.subClass != CoinSubClass.sia).toList(); | ||
| } | ||
|
|
||
| /// Merges wallet coins into selected coins list when in add mode | ||
| Future<List<Coin>> _mergeWalletCoinsIfNeeded( | ||
| List<Coin> selectedCoins, | ||
|
|
@@ -383,8 +416,9 @@ class CoinsManagerBloc extends Bloc<CoinsManagerEvent, CoinsManagerState> { | |
| // This ensures toggles remain OFF if auto-activation was bypassed. | ||
| if (walletCoin.id.subClass == CoinSubClass.zhtlc) { | ||
| try { | ||
| final saved = | ||
| await _sdk.activationConfigService.getSavedZhtlc(walletCoin.id); | ||
| final saved = await _sdk.activationConfigService.getSavedZhtlc( | ||
| walletCoin.id, | ||
| ); | ||
| if (saved == null) { | ||
| continue; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the requested set is only SIA assets on a Trezor,
activateAssetsSync()now filters them out and returns successfully. Callers such asactivateCoinIfNeeded()inlib/views/dex/dex_helpers.dart:226-255only surface a guardrail from thecatchpath, and that helper is reused by maker/taker/bridge/NFT entry points, so those flows will still let a Trezor user pick SIA and continue with an inactive coin instead of showing the intended unsupported-asset message.Useful? React with 👍 / 👎.