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
13 changes: 9 additions & 4 deletions lib/pages/buy_view/buy_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import '../../widgets/stack_dialog.dart';
import '../../widgets/stack_text_field.dart';
import '../../widgets/textfield_icon_button.dart';
import '../address_book_views/address_book_view.dart';
import '../exchange_view/choose_from_stack_view.dart';
import '../exchange_view/choose_address_from_stack_view.dart';
import 'buy_quote_preview.dart';
import 'sub_widgets/crypto_selection_view.dart';
import 'sub_widgets/fiat_selection_view.dart';
Expand Down Expand Up @@ -1172,14 +1172,19 @@ class _BuyFormState extends ConsumerState<BuyForm> {
);
Navigator.of(context)
.pushNamed(
ChooseFromStackView.routeName,
ChooseAddressFromStackView.routeName,
arguments: coin,
)
.then((value) async {
if (value is String) {
if (value
is ({
String walletId,
String address,
String walletName,
})) {
final wallet = ref
.read(pWallets)
.getWallet(value);
.getWallet(value.walletId);

// _toController.text = manager.walletName;
// model.recipientAddress =
Expand Down
344 changes: 344 additions & 0 deletions lib/pages/exchange_view/choose_address_from_stack_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,344 @@
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';

import '../../providers/providers.dart';
import '../../themes/stack_colors.dart';
import '../../utilities/assets.dart';
import '../../utilities/constants.dart';
import '../../utilities/show_loading.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
import '../../wallets/crypto_currency/crypto_currency.dart';
import '../../wallets/isar/providers/wallet_info_provider.dart';
import '../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
import '../../widgets/background.dart';
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
import '../../widgets/rounded_white_container.dart';
import '../../widgets/stack_dialog.dart';
import '../../widgets/wallet_info_row/sub_widgets/wallet_info_row_balance.dart';
import '../../widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart';

class ChooseAddressFromStackView extends ConsumerStatefulWidget {
const ChooseAddressFromStackView({super.key, required this.coin});

final CryptoCurrency coin;

static const String routeName = "/chooseFromStack";

@override
ConsumerState<ChooseAddressFromStackView> createState() =>
_ChooseFromStackViewState();
}

class _ChooseFromStackViewState
extends ConsumerState<ChooseAddressFromStackView> {
late final CryptoCurrency coin;

@override
void initState() {
coin = widget.coin;
super.initState();
}

@override
Widget build(BuildContext context) {
final walletIds = ref
.watch(pWallets)
.wallets
.where((e) => e.info.coin == coin)
.map((e) => e.walletId)
.toList();

return Background(
child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: const AppBarBackButton(),
title: Text(
"Choose your ${coin.ticker.toUpperCase()} wallet",
style: STextStyles.navBarTitle(context),
),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: walletIds.isEmpty
? Column(
children: [
RoundedWhiteContainer(
child: Center(
child: Text(
"No ${coin.ticker.toUpperCase()} wallets",
style: STextStyles.itemSubtitle(context),
),
),
),
],
)
: ListView.builder(
itemCount: walletIds.length,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: _WalletAddressSelectCard(
walletId: walletIds[index],
),
),
),
),
),
),
);
}
}

class _WalletAddressSelectCard extends ConsumerStatefulWidget {
const _WalletAddressSelectCard({required this.walletId});

final String walletId;

@override
ConsumerState<_WalletAddressSelectCard> createState() =>
_WalletAddressSelectCardState();
}

class _WalletAddressSelectCardState
extends ConsumerState<_WalletAddressSelectCard> {
@override
Widget build(BuildContext context) {
final coin = ref.watch(pWalletCoin(widget.walletId));

if (coin is! Firo) {
return RawMaterialButton(
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
padding: const EdgeInsets.all(0),
elevation: 0,
onPressed: () async {
final wallet = ref.read(pWallets).getWallet(widget.walletId);

final data = (
walletId: widget.walletId,
address:
(await wallet.getCurrentReceivingAddress())?.value ??
wallet.info.cachedReceivingAddress,
walletName: wallet.info.name,
);

if (context.mounted) {
Navigator.of(context).pop(data);
}
},
child: RoundedWhiteContainer(
child: Row(
children: [
WalletInfoCoinIcon(coin: coin),
const SizedBox(width: 12),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
ref.watch(pWalletName(widget.walletId)),
style: STextStyles.titleBold12(context),
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 2),
WalletInfoRowBalance(walletId: widget.walletId),
],
),
),
],
),
),
);
}

return RoundedWhiteContainer(
child: Column(
mainAxisSize: .min,
crossAxisAlignment: .start,
children: [
Row(
children: [
WalletInfoCoinIcon(coin: coin),
const SizedBox(width: 12),
Expanded(
child: Text(
ref.watch(pWalletName(widget.walletId)),
style: STextStyles.titleBold12(context),
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 10),
RawMaterialButton(
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
padding: const EdgeInsets.all(0),
elevation: 0,
onPressed: () async {
Future<String?> _future() async {
final wallet =
ref.read(pWallets).getWallet(widget.walletId)
as SparkInterface;
final sparkAddress = await wallet
.getCurrentReceivingSparkAddress();
if (sparkAddress != null) {
return sparkAddress.value;
}

return (await wallet.generateNextSparkAddress(
saveToDB: true,
)).value;
}

Exception? ex;
final sparkAddress = await showLoading(
context: context,
message: "Fetching Spark address",
rootNavigator: Util.isDesktop,
delay: const Duration(milliseconds: 1200),
whileFutureAlt: _future,
onException: (e) => ex = e,
);

if (context.mounted) {
if (ex != null) {
await showDialog<void>(
context: context,
builder: (context) => StackOkDialog(
title: "Error",
message: ex
.toString()
.replaceFirst("Exception:", "")
.trim(),
),
);
} else {
Navigator.of(context).pop((
walletId: widget.walletId,
address: sparkAddress,
walletName:
"${ref.read(pWalletName(widget.walletId))} (Spark)",
));
}
}
},
child: Row(
crossAxisAlignment: .center,
mainAxisAlignment: .spaceBetween,
children: [
Column(
mainAxisSize: .min,
crossAxisAlignment: .start,
children: [
Text("Spark address", style: STextStyles.w500_12(context)),
const SizedBox(height: 2),
WalletInfoRowBalance(
walletId: widget.walletId,
balanceType: .private,
),
],
),
SizedBox(
width: 25,
height: 25,
child: SvgPicture.asset(
Assets.svg.chevronRight,
colorFilter: ColorFilter.mode(
Theme.of(context).extension<StackColors>()!.textDark,
BlendMode.srcIn,
),
),
),
],
),
),
const SizedBox(height: 8),
RawMaterialButton(
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
padding: const EdgeInsets.all(0),
elevation: 0,
onPressed: () async {
final wallet = ref.read(pWallets).getWallet(widget.walletId);

final data = (
walletId: widget.walletId,
address:
(await wallet.getCurrentReceivingAddress())?.value ??
wallet.info.cachedReceivingAddress,
walletName: "${wallet.info.name} (Transparent)",
);

if (context.mounted) {
Navigator.of(context).pop(data);
}
},

child: Row(
crossAxisAlignment: .center,
mainAxisAlignment: .spaceBetween,
children: [
Column(
mainAxisSize: .min,
crossAxisAlignment: .start,
children: [
Text(
"Transparent address",
style: STextStyles.w500_12(context),
),
const SizedBox(height: 2),
WalletInfoRowBalance(
walletId: widget.walletId,
balanceType: .public,
),
],
),
SizedBox(
width: 25,
height: 25,
child: SvgPicture.asset(
Assets.svg.chevronRight,
colorFilter: ColorFilter.mode(
Theme.of(context).extension<StackColors>()!.textDark,
BlendMode.srcIn,
),
),
),
],
),
),
],
),
);
}
}
Loading
Loading