Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions lib/pages/exchange_view/exchange_step_views/step_4_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../../../models/exchange/incomplete_exchange.dart';
import '../../../notifications/show_flush_bar.dart';
import '../../../providers/providers.dart';
import '../../../route_generator.dart';
import '../../../services/wallets.dart';
import '../../../themes/stack_colors.dart';
import '../../../utilities/amount/amount.dart';
import '../../../utilities/amount/amount_formatter.dart';
Expand All @@ -34,6 +35,8 @@ import '../../../wallets/crypto_currency/crypto_currency.dart';
import '../../../wallets/isar/providers/wallet_info_provider.dart';
import '../../../wallets/models/tx_data.dart';
import '../../../wallets/wallet/impl/firo_wallet.dart';
import '../../../wallets/wallet/intermediate/external_wallet.dart';
import '../../../wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart';
import '../../../widgets/background.dart';
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../../widgets/desktop/secondary_button.dart';
Expand Down Expand Up @@ -65,20 +68,28 @@ class Step4View extends ConsumerStatefulWidget {
}

class _Step4ViewState extends ConsumerState<Step4View> {
late final bool isWalletCoinAndCanSend;
late final IncompleteExchangeModel model;
late final ClipboardInterface clipboard;

String _statusString = "New";

Timer? _statusTimer;

bool _isWalletCoinAndHasWallet(String ticker, WidgetRef ref) {
bool isWalletCoinAndCanSendWithoutWalletOpened(
String ticker,
Wallets walletsInstance,
) {
try {
final coin = AppConfig.getCryptoCurrencyForTicker(ticker);
return ref
.read(pWallets)
.wallets
.where((e) => e.info.coin == coin)
return walletsInstance.wallets
.where(
(e) =>
e.info.coin == coin &&
(e is! ExternalWallet ||
e is MwebInterface), // ltc mweb is external but swaps
// should not use mweb, hence the odd logic check here
)
.isNotEmpty;
} catch (_) {
return false;
Expand Down Expand Up @@ -111,6 +122,11 @@ class _Step4ViewState extends ConsumerState<Step4View> {
model = widget.model;
clipboard = widget.clipboard;

isWalletCoinAndCanSend = isWalletCoinAndCanSendWithoutWalletOpened(
model.trade!.payInCurrency,
ref.read(pWallets),
);

_statusTimer = Timer.periodic(const Duration(seconds: 60), (_) {
_updateStatus();
});
Expand Down Expand Up @@ -339,10 +355,6 @@ class _Step4ViewState extends ConsumerState<Step4View> {

@override
Widget build(BuildContext context) {
final bool isWalletCoin = _isWalletCoinAndHasWallet(
model.trade!.payInCurrency,
ref,
);
return WillPopScope(
onWillPop: () async {
await _close();
Expand Down Expand Up @@ -791,8 +803,9 @@ class _Step4ViewState extends ConsumerState<Step4View> {
style: STextStyles.button(context),
),
),
if (isWalletCoin) const SizedBox(height: 12),
if (isWalletCoin)
if (isWalletCoinAndCanSend)
const SizedBox(height: 12),
if (isWalletCoinAndCanSend)
Builder(
builder: (context) {
String buttonTitle =
Expand Down
33 changes: 27 additions & 6 deletions lib/pages/exchange_view/trade_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import '../../services/exchange/exchange.dart';
import '../../services/exchange/nanswap/nanswap_exchange.dart';
import '../../services/exchange/simpleswap/simpleswap_exchange.dart';
import '../../services/exchange/trocador/trocador_exchange.dart';
import '../../services/wallets.dart';
import '../../themes/stack_colors.dart';
import '../../themes/theme_providers.dart';
import '../../utilities/amount/amount.dart';
Expand All @@ -43,6 +44,8 @@ import '../../utilities/format.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
import '../../wallets/crypto_currency/crypto_currency.dart';
import '../../wallets/wallet/intermediate/external_wallet.dart';
import '../../wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart';
import '../../widgets/background.dart';
import '../../widgets/conditional_parent.dart';
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
Expand Down Expand Up @@ -152,6 +155,26 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
}
}

bool isWalletCoinAndCanSendWithoutWalletOpened(
String ticker,
Wallets walletsInstance,
) {
try {
final coin = AppConfig.getCryptoCurrencyForTicker(ticker);
return walletsInstance.wallets
.where(
(e) =>
e.info.coin == coin &&
(e is! ExternalWallet ||
e is MwebInterface), // ltc mweb is external but swaps
// should not use mweb, hence the odd logic check here
)
.isNotEmpty;
} catch (_) {
return false;
}
}

@override
Widget build(BuildContext context) {
final bool sentFromStack =
Expand Down Expand Up @@ -193,13 +216,11 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {

final showSendFromStackButton =
!hasTx &&
![
"xmr",
"monero",
"wow",
"wownero",
].contains(trade.payInCurrency.toLowerCase()) &&
AppConfig.isStackCoin(trade.payInCurrency) &&
isWalletCoinAndCanSendWithoutWalletOpened(
trade.payInCurrency,
ref.read(pWallets),
) &&
(trade.status == "New" ||
trade.status == "new" ||
trade.status == "waiting" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ import '../../../models/exchange/response_objects/trade.dart';
import '../../../pages/exchange_view/send_from_view.dart';
import '../../../providers/exchange/exchange_form_state_provider.dart';
import '../../../providers/global/trades_service_provider.dart';
import '../../../providers/global/wallets_provider.dart';
import '../../../route_generator.dart';
import '../../../services/exchange/exchange_response.dart';
import '../../../services/notifications_api.dart';
import '../../../services/wallets.dart';
import '../../../themes/stack_colors.dart';
import '../../../utilities/amount/amount.dart';
import '../../../utilities/assets.dart';
import '../../../utilities/enums/exchange_rate_type_enum.dart';
import '../../../utilities/text_styles.dart';
import '../../../wallets/wallet/intermediate/external_wallet.dart';
import '../../../wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart';
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../../widgets/custom_loading_overlay.dart';
import '../../../widgets/desktop/desktop_dialog.dart';
Expand Down Expand Up @@ -241,6 +245,26 @@ class _StepScaffoldState extends ConsumerState<StepScaffold> {
);
}

bool isWalletCoinAndCanSendWithoutWalletOpened(
String ticker,
Wallets walletsInstance,
) {
try {
final coin = AppConfig.getCryptoCurrencyForTicker(ticker);
return walletsInstance.wallets
.where(
(e) =>
e.info.coin == coin &&
(e is! ExternalWallet ||
e is MwebInterface), // ltc mweb is external but swaps
// should not use mweb, hence the odd logic check here
)
.isNotEmpty;
} catch (_) {
return false;
}
}

@override
void initState() {
duration = const Duration(milliseconds: 250);
Expand All @@ -251,6 +275,18 @@ class _StepScaffoldState extends ConsumerState<StepScaffold> {
@override
Widget build(BuildContext context) {
final model = ref.watch(desktopExchangeModelProvider);

final bool canSendFromStack;
if (currentStep != 4) {
// set to true anyways to show back button
canSendFromStack = true;
} else {
canSendFromStack = isWalletCoinAndCanSendWithoutWalletOpened(
model?.sendTicker ?? "",
ref.read(pWallets),
);
}

return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expand Down Expand Up @@ -307,25 +343,27 @@ class _StepScaffoldState extends ConsumerState<StepScaffold> {
),
child: Row(
children: [
Expanded(
child: AnimatedCrossFade(
duration: const Duration(milliseconds: 250),
crossFadeState:
currentStep == 4
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
firstChild: SecondaryButton(
label: "Back",
buttonHeight: ButtonHeight.l,
onPressed: onBack,
),
secondChild: SecondaryButton(
label: "Send from ${AppConfig.appName}",
buttonHeight: ButtonHeight.l,
onPressed: sendFromStack,
),
),
),
canSendFromStack
? Expanded(
child: AnimatedCrossFade(
duration: const Duration(milliseconds: 250),
crossFadeState:
currentStep == 4
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
firstChild: SecondaryButton(
label: "Back",
buttonHeight: ButtonHeight.l,
onPressed: onBack,
),
secondChild: SecondaryButton(
label: "Send from ${AppConfig.appName}",
buttonHeight: ButtonHeight.l,
onPressed: sendFromStack,
),
),
)
: const Spacer(),
const SizedBox(width: 16),
Expanded(
child: AnimatedCrossFade(
Expand Down
Loading
Loading