mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-29 21:55:58 +00:00
open exchange view, receive view, and WIP buy view from within token wallet
This commit is contained in:
parent
1f4ba55828
commit
7a177a6616
6 changed files with 122 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/pages/buy_view/buy_view.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -10,11 +11,13 @@ class BuyInWalletView extends StatefulWidget {
|
|||
const BuyInWalletView({
|
||||
Key? key,
|
||||
required this.coin,
|
||||
this.contract,
|
||||
}) : super(key: key);
|
||||
|
||||
static const String routeName = "/stackBuyInWalletView";
|
||||
|
||||
final Coin? coin;
|
||||
final EthContract? contract;
|
||||
|
||||
@override
|
||||
State<BuyInWalletView> createState() => _BuyInWalletViewState();
|
||||
|
@ -41,7 +44,11 @@ class _BuyInWalletViewState extends State<BuyInWalletView> {
|
|||
style: STextStyles.navBarTitle(context),
|
||||
),
|
||||
),
|
||||
body: BuyView(coin: widget.coin),
|
||||
body: BuyView(
|
||||
coin: widget.coin,
|
||||
tokenContract,
|
||||
widget.contract,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,19 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/pages/buy_view/buy_form.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
||||
class BuyView extends StatefulWidget {
|
||||
class BuyView extends StatelessWidget {
|
||||
const BuyView({
|
||||
Key? key,
|
||||
this.coin,
|
||||
this.tokenContract,
|
||||
}) : super(key: key);
|
||||
|
||||
static const String routeName = "/stackBuyView";
|
||||
|
||||
final Coin? coin;
|
||||
|
||||
@override
|
||||
State<BuyView> createState() => _BuyViewState();
|
||||
}
|
||||
|
||||
class _BuyViewState extends State<BuyView> {
|
||||
late final Coin? coin;
|
||||
final EthContract? tokenContract;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -30,7 +26,10 @@ class _BuyViewState extends State<BuyView> {
|
|||
right: 16,
|
||||
top: 16,
|
||||
),
|
||||
child: BuyForm(coin: widget.coin),
|
||||
child: BuyForm(
|
||||
coin: coin,
|
||||
tokenContract: tokenContract,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:stackwallet/models/exchange/aggregate_currency.dart';
|
|||
import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
|
||||
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
|
||||
import 'package:stackwallet/models/isar/exchange_cache/pair.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_1_view.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_2_view.dart';
|
||||
|
@ -43,10 +44,12 @@ class ExchangeForm extends ConsumerStatefulWidget {
|
|||
Key? key,
|
||||
this.walletId,
|
||||
this.coin,
|
||||
this.contract,
|
||||
}) : super(key: key);
|
||||
|
||||
final String? walletId;
|
||||
final Coin? coin;
|
||||
final EthContract? contract;
|
||||
|
||||
@override
|
||||
ConsumerState<ExchangeForm> createState() => _ExchangeFormState();
|
||||
|
@ -161,10 +164,16 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
final type = (ref.read(exchangeFormStateProvider).exchangeRateType);
|
||||
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "";
|
||||
|
||||
if (walletInitiated &&
|
||||
fromTicker.toLowerCase() == coin!.ticker.toLowerCase()) {
|
||||
// do not allow changing away from wallet coin
|
||||
return;
|
||||
if (walletInitiated) {
|
||||
if (widget.contract != null &&
|
||||
fromTicker.toLowerCase() == widget.contract!.symbol.toLowerCase()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fromTicker.toLowerCase() == coin!.ticker.toLowerCase()) {
|
||||
// do not allow changing away from wallet coin
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final selectedCurrency = await _showCurrencySelectionSheet(
|
||||
|
@ -620,7 +629,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
|||
ref.read(exchangeFormStateProvider).reset(shouldNotifyListeners: true);
|
||||
ExchangeDataLoadingService.instance
|
||||
.getAggregateCurrency(
|
||||
coin!.ticker,
|
||||
widget.contract == null ? coin!.ticker : widget.contract!.symbol,
|
||||
ExchangeRateType.estimated,
|
||||
)
|
||||
.then((value) {
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/exchange_form.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart';
|
||||
import 'package:stackwallet/providers/exchange/exchange_form_state_provider.dart';
|
||||
|
@ -20,12 +21,14 @@ class WalletInitiatedExchangeView extends ConsumerStatefulWidget {
|
|||
Key? key,
|
||||
required this.walletId,
|
||||
required this.coin,
|
||||
this.contract,
|
||||
}) : super(key: key);
|
||||
|
||||
static const String routeName = "/walletInitiatedExchange";
|
||||
|
||||
final String walletId;
|
||||
final Coin coin;
|
||||
final EthContract? contract;
|
||||
|
||||
@override
|
||||
ConsumerState<WalletInitiatedExchangeView> createState() =>
|
||||
|
@ -172,6 +175,7 @@ class _WalletInitiatedExchangeViewState
|
|||
ExchangeForm(
|
||||
walletId: walletId,
|
||||
coin: coin,
|
||||
contract: widget.contract,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/pages/buy_view/buy_in_wallet_view.dart';
|
||||
import 'package:stackwallet/pages/exchange_view/wallet_initiated_exchange_view.dart';
|
||||
import 'package:stackwallet/pages/receive_view/receive_view.dart';
|
||||
import 'package:stackwallet/pages/token_view/token_view.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
|
@ -9,6 +15,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/widgets/rounded_container.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class TokenSummary extends ConsumerWidget {
|
||||
const TokenSummary({
|
||||
|
@ -84,7 +91,10 @@ class TokenSummary extends ConsumerWidget {
|
|||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
const TokenWalletOptions(),
|
||||
TokenWalletOptions(
|
||||
walletId: walletId,
|
||||
tokenContract: token,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -92,7 +102,39 @@ class TokenSummary extends ConsumerWidget {
|
|||
}
|
||||
|
||||
class TokenWalletOptions extends StatelessWidget {
|
||||
const TokenWalletOptions({Key? key}) : super(key: key);
|
||||
const TokenWalletOptions({
|
||||
Key? key,
|
||||
required this.walletId,
|
||||
required this.tokenContract,
|
||||
}) : super(key: key);
|
||||
|
||||
final String walletId;
|
||||
final EthContract tokenContract;
|
||||
|
||||
void _onExchangePressed(BuildContext context) async {
|
||||
unawaited(
|
||||
Navigator.of(context).pushNamed(
|
||||
WalletInitiatedExchangeView.routeName,
|
||||
arguments: Tuple3(
|
||||
walletId,
|
||||
Coin.ethereum,
|
||||
tokenContract,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onBuyPressed(BuildContext context) {
|
||||
unawaited(
|
||||
Navigator.of(context).pushNamed(
|
||||
BuyInWalletView.routeName,
|
||||
arguments: Tuple2(
|
||||
Coin.ethereum,
|
||||
tokenContract,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -100,7 +142,15 @@ class TokenWalletOptions extends StatelessWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
TokenOptionsButton(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
ReceiveView.routeName,
|
||||
arguments: Tuple2(
|
||||
walletId,
|
||||
Coin.ethereum,
|
||||
),
|
||||
);
|
||||
},
|
||||
subLabel: "Receive",
|
||||
iconAssetSVG: Assets.svg.receive(context),
|
||||
),
|
||||
|
@ -116,15 +166,15 @@ class TokenWalletOptions extends StatelessWidget {
|
|||
width: 16,
|
||||
),
|
||||
TokenOptionsButton(
|
||||
onPressed: () {},
|
||||
subLabel: "Exchange",
|
||||
onPressed: () => _onExchangePressed(context),
|
||||
subLabel: "Swap",
|
||||
iconAssetSVG: Assets.svg.exchange(context),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
TokenOptionsButton(
|
||||
onPressed: () {},
|
||||
onPressed: () => _onBuyPressed(context),
|
||||
subLabel: "Buy",
|
||||
iconAssetSVG: Assets.svg.creditCard,
|
||||
),
|
||||
|
|
|
@ -1088,6 +1088,26 @@ class RouteGenerator {
|
|||
),
|
||||
);
|
||||
}
|
||||
if (args is Tuple3<String, Coin, EthContract?>) {
|
||||
return getRoute(
|
||||
shouldUseMaterialRoute: useMaterialPageRoute,
|
||||
builder: (_) => Stack(
|
||||
children: [
|
||||
WalletInitiatedExchangeView(
|
||||
walletId: args.item1,
|
||||
coin: args.item2,
|
||||
contract: args.item3,
|
||||
),
|
||||
// ExchangeLoadingOverlayView(
|
||||
// unawaitedLoad: args.item3,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
settings: RouteSettings(
|
||||
name: settings.name,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||
|
||||
case NotificationsView.routeName:
|
||||
|
@ -1350,6 +1370,18 @@ class RouteGenerator {
|
|||
),
|
||||
);
|
||||
}
|
||||
if (args is Tuple2<Coin, EthContract?>) {
|
||||
return getRoute(
|
||||
shouldUseMaterialRoute: useMaterialPageRoute,
|
||||
builder: (_) => BuyInWalletView(
|
||||
coin: args.item1,
|
||||
contract: args.item2,
|
||||
),
|
||||
settings: RouteSettings(
|
||||
name: settings.name,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||
|
||||
case DesktopBuyView.routeName:
|
||||
|
|
Loading…
Reference in a new issue