mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-28 06:28:41 +01:00
Catches up from the May 12 fork point (v6.1.2+23) through v6.5.0: 535 upstream commits, including the Monero silent-open fix, Monero on Trezor, Ledger/Trezor BLE fixes, the new seed and history screens, quick Bitcoin sync, git-pinned dependencies (pubspec_overrides.yaml), frozen Hive adapters (*.part.dart), monero_c v0.18.4.6-RC2 and Flutter 3.41.9. Merged with both sides normalized first (import rename, 100-column format), which took the conflict count from 614 paths to 322. The procedure is now scripts/upstream_sync.sh. Kept from Hash Bags: - WalletType enum order and Hive IDs. SQLite stores WalletType.index and our order differs from upstream's; taking theirs would reread saved wallets as other chains. Our frozen adapter keeps the shipped IDs. - The 1.0.2 legacy PIN and wallet-password decode and self-heal. - Removed chains (Solana, Tron, Zano, Zcash, Decred, Haven) and the new Robinhood chain stay out; Cake Pay and non-Trocador swaps stay out. - Default nodes (node.wownero.org, sethforprivacy, Blockstream, bysh.me), converted to upstream's isDefault node-list key; Wownero is back in the node reset list. - Privacy: address resolvers limited to domain-anchored sources again; prices.neroswap.com for fiat; upstream's charts tab, which reads prices.cakewallet.com, sits behind FeatureFlag.isChartsEnabled = false. - Lightning stays behind FeatureFlag.isLightningEnabled, including upstream's new post-seed Lightning username step. - Our icon pipeline, branding and bundle identifiers. Twelve new upstream widget tests are skipped: test and code are unchanged from v6.5.0 apart from renames (not rerun on a pristine upstream checkout; upstream's top_bar_test does not compile against its own TopBar). flutter analyze lib: 0 errors; flutter test: 345 passed, 12 skipped; flutter build bundle compiles. Built with Flutter 3.41.9.
187 lines
6.8 KiB
Dart
187 lines
6.8 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:hash_wallet/exchange/exchange_provider_description.dart';
|
|
import 'package:hash_wallet/exchange/provider/exchange_provider.dart';
|
|
import 'package:hash_wallet/exchange/provider/near_Intents_exchange_provider.dart';
|
|
import 'package:hash_wallet/exchange/provider/trocador_exchange_provider.dart';
|
|
import 'package:hash_wallet/exchange/trade.dart';
|
|
import 'package:hash_wallet/generated/i18n.dart';
|
|
import 'package:hash_wallet/src/screens/trade_details/track_trade_list_item.dart';
|
|
import 'package:hash_wallet/src/screens/trade_details/trade_details_list_card.dart';
|
|
import 'package:hash_wallet/src/screens/trade_details/trade_details_status_item.dart';
|
|
import 'package:hash_wallet/src/screens/trade_details/trade_provider_unsupported_item.dart';
|
|
import 'package:hash_wallet/src/screens/transaction_details/standart_list_item.dart';
|
|
import 'package:hash_wallet/store/app_store.dart';
|
|
import 'package:hash_wallet/utils/date_formatter.dart';
|
|
import 'package:hash_wallet/utils/show_bar.dart';
|
|
import 'package:cw_core/currencies_with_memo.dart';
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
part 'trade_details_view_model.g.dart';
|
|
|
|
class TradeDetailsViewModel = TradeDetailsViewModelBase with _$TradeDetailsViewModel;
|
|
|
|
abstract class TradeDetailsViewModelBase with Store {
|
|
TradeDetailsViewModelBase({
|
|
required Trade tradeForDetails,
|
|
required this.appStore,
|
|
}) : items = ObservableList<StandartListItem>(),
|
|
trade = tradeForDetails {
|
|
// Trades from providers whose implementations were removed keep a null
|
|
// _provider and show the "provider unsupported" item with stored data.
|
|
switch (trade.provider) {
|
|
case ExchangeProviderDescription.trocador:
|
|
_provider = TrocadorExchangeProvider();
|
|
break;
|
|
case ExchangeProviderDescription.nearIntents:
|
|
_provider = NearIntentsExchangeProvider();
|
|
break;
|
|
}
|
|
|
|
_updateItems();
|
|
|
|
if (_provider != null) {
|
|
_updateTrade();
|
|
timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateTrade());
|
|
}
|
|
}
|
|
|
|
static String? getTrackUrl(ExchangeProviderDescription provider, Trade trade) {
|
|
switch (provider) {
|
|
case ExchangeProviderDescription.changeNow:
|
|
return 'https://changenow.io/exchange/txs/${trade.id}';
|
|
case ExchangeProviderDescription.sideShift:
|
|
return 'https://sideshift.ai/orders/${trade.id}';
|
|
case ExchangeProviderDescription.simpleSwap:
|
|
return 'https://simpleswap.io/exchange?id=${trade.id}';
|
|
case ExchangeProviderDescription.trocador:
|
|
return 'https://trocador.app/en/checkout/${trade.id}';
|
|
case ExchangeProviderDescription.exolix:
|
|
return 'https://exolix.com/transaction/${trade.id}';
|
|
case ExchangeProviderDescription.thorChain:
|
|
return 'https://track.ninerealms.com/${trade.id}';
|
|
case ExchangeProviderDescription.swapTrade:
|
|
return 'https://swaptrade.io/send/${trade.id}';
|
|
case ExchangeProviderDescription.letsExchange:
|
|
return 'https://letsexchange.io/?transactionId=${trade.id}';
|
|
case ExchangeProviderDescription.stealthEx:
|
|
return 'https://stealthex.io/exchange/?id=${trade.id}';
|
|
case ExchangeProviderDescription.chainflip:
|
|
return 'https://scan.chainflip.io/channels/${trade.id}';
|
|
case ExchangeProviderDescription.xoSwap:
|
|
return 'https://orders.xoswap.com/${trade.id}';
|
|
case ExchangeProviderDescription.swapsXyz:
|
|
return 'https://scan.swaps.xyz/transactions/${trade.id}';
|
|
case ExchangeProviderDescription.nearIntents:
|
|
return 'https://explorer.near-intents.org/transactions/${trade.id}';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@observable
|
|
Trade trade;
|
|
|
|
@observable
|
|
ObservableList<StandartListItem> items;
|
|
|
|
ExchangeProvider? _provider;
|
|
|
|
Timer? timer;
|
|
|
|
final AppStore appStore;
|
|
|
|
@action
|
|
Future<void> _updateTrade() async {
|
|
try {
|
|
final updatedTrade = await _provider!.findTradeById(id: trade.id);
|
|
|
|
trade.mergeFindTradeByIdResult(updatedTrade);
|
|
await trade.save();
|
|
|
|
_updateItems();
|
|
} catch (e) {
|
|
printV(e.toString());
|
|
}
|
|
}
|
|
|
|
void _updateItems() {
|
|
final dateFormat = DateFormatter.withCurrentLocal(reverse: true);
|
|
|
|
items.clear();
|
|
|
|
if (_provider == null)
|
|
items.add(TradeProviderUnsupportedItem(
|
|
error: S.current.exchange_provider_unsupported(trade.provider.title)));
|
|
|
|
items.add(
|
|
DetailsListStatusItem(title: S.current.trade_details_state, value: trade.state.toString()));
|
|
|
|
final tradeFrom = trade.from;
|
|
final tradeTo = trade.to;
|
|
|
|
if (tradeFrom != null && tradeTo != null) {
|
|
items.add(TradeDetailsListCardItem.tradeDetails(
|
|
id: trade.id,
|
|
extraId: trade.extraId,
|
|
createdAt: trade.createdAt != null ? dateFormat.format(trade.createdAt!) : '',
|
|
from: tradeFrom,
|
|
to: tradeTo,
|
|
onTap: (context) {
|
|
Clipboard.setData(ClipboardData(text: trade.id));
|
|
showBar<void>(context, S.of(context).copied_to_clipboard);
|
|
},
|
|
));
|
|
}
|
|
|
|
final destinationMemo = trade.toAddressExtraId;
|
|
final destinationCurrency = trade.to;
|
|
if (destinationMemo != null && destinationMemo.isNotEmpty && destinationCurrency != null) {
|
|
final isDestinationTag =
|
|
memoLabelTypeFor(destinationCurrency) == MemoLabelType.destinationTag;
|
|
items.add(StandartListItem(
|
|
title: isDestinationTag ? S.current.destination_tag : S.current.memo,
|
|
value: destinationMemo));
|
|
}
|
|
|
|
items.add(StandartListItem(
|
|
title: S.current.trade_details_provider, value: trade.provider.toString()));
|
|
|
|
final trackUrl = TradeDetailsViewModelBase.getTrackUrl(trade.provider, trade);
|
|
if (trackUrl != null) {
|
|
items.add(TrackTradeListItem(
|
|
title: S.current.track, value: trackUrl, onTap: () => _launchUrl(trackUrl)));
|
|
}
|
|
|
|
if (trade.isRefund == true) {
|
|
items.add(StandartListItem(title: 'Refund', value: trade.refundAddress ?? ''));
|
|
}
|
|
|
|
if (trade.provider == ExchangeProviderDescription.trocador) {
|
|
items.add(StandartListItem(
|
|
title: '${trade.providerName} ${S.current.id.toUpperCase()}',
|
|
value: trade.providerId ?? ''));
|
|
|
|
if (trade.password != null && trade.password!.isNotEmpty) {
|
|
items.add(StandartListItem(
|
|
title: '${trade.providerName} ${S.current.password}', value: trade.password ?? ''));
|
|
}
|
|
}
|
|
|
|
if (trade.provider == ExchangeProviderDescription.swapsXyz &&
|
|
trade.txId != null &&
|
|
trade.txId!.isNotEmpty) {
|
|
items.add(StandartListItem(title: 'Transaction ID', value: trade.txId!));
|
|
}
|
|
}
|
|
|
|
void _launchUrl(String url) {
|
|
final uri = Uri.parse(url);
|
|
try {
|
|
launchUrl(uri, mode: LaunchMode.externalApplication);
|
|
} catch (e) {}
|
|
}
|
|
}
|