mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-24 12:29:37 +00:00
put buy quote preview in floating sheet on desktop
TODO check if this breaks mobile
This commit is contained in:
parent
7eefe196c9
commit
0dff63d9ac
2 changed files with 153 additions and 22 deletions
|
@ -7,6 +7,15 @@ import 'package:stackwallet/models/buy/response_objects/quote.dart';
|
||||||
class Simplex {
|
class Simplex {
|
||||||
List<Crypto> supportedCryptos = [];
|
List<Crypto> supportedCryptos = [];
|
||||||
List<Fiat> supportedFiats = [];
|
List<Fiat> supportedFiats = [];
|
||||||
|
SimplexQuote quote = SimplexQuote(
|
||||||
|
crypto: Crypto.fromJson({'ticker': 'BTC', 'name': 'Bitcoin', 'image': ''}),
|
||||||
|
fiat: Fiat.fromJson(
|
||||||
|
{'ticker': 'USD', 'name': 'United States Dollar', 'image': ''}),
|
||||||
|
youPayFiatPrice: Decimal.parse("100"),
|
||||||
|
youReceiveCryptoAmount: Decimal.parse("1.0238917"),
|
||||||
|
purchaseId: "someID",
|
||||||
|
receivingAddress: '',
|
||||||
|
);
|
||||||
|
|
||||||
void updateSupportedCryptos(List<Crypto> newCryptos) {
|
void updateSupportedCryptos(List<Crypto> newCryptos) {
|
||||||
supportedCryptos = newCryptos;
|
supportedCryptos = newCryptos;
|
||||||
|
@ -15,4 +24,8 @@ class Simplex {
|
||||||
void updateSupportedFiats(List<Fiat> newFiats) {
|
void updateSupportedFiats(List<Fiat> newFiats) {
|
||||||
supportedFiats = newFiats;
|
supportedFiats = newFiats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateQuote(SimplexQuote newQuote) {
|
||||||
|
quote = newQuote;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
||||||
|
|
||||||
Fiat? selectedFiat;
|
Fiat? selectedFiat;
|
||||||
Crypto? selectedCrypto;
|
Crypto? selectedCrypto;
|
||||||
|
SimplexQuote? quote;
|
||||||
|
|
||||||
bool buyWithFiat = true;
|
bool buyWithFiat = true;
|
||||||
bool _addressToggleFlag = false;
|
bool _addressToggleFlag = false;
|
||||||
|
@ -322,6 +323,111 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> previewQuote() async {
|
||||||
|
// if (ref.read(simplexProvider).estimate.isEmpty) {
|
||||||
|
// bool shouldPop = false;
|
||||||
|
// unawaited(
|
||||||
|
// showDialog(
|
||||||
|
// context: context,
|
||||||
|
// builder: (context) => WillPopScope(
|
||||||
|
// child: const CustomLoadingOverlay(
|
||||||
|
// message: "Loading quote data",
|
||||||
|
// eventBus: null,
|
||||||
|
// ),
|
||||||
|
// onWillPop: () async => shouldPop,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// await _loadQuote();
|
||||||
|
// shouldPop = true;
|
||||||
|
// if (mounted) {
|
||||||
|
// Navigator.of(context).pop();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
await _showFloatingBuyQuotePreviewSheet(
|
||||||
|
quote: ref.read(simplexProvider).quote,
|
||||||
|
onSelected: (quote) {
|
||||||
|
// setState(() {
|
||||||
|
// selectedFiat = fiat;
|
||||||
|
// });
|
||||||
|
// TODO launch URL
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _showFloatingBuyQuotePreviewSheet({
|
||||||
|
required SimplexQuote quote,
|
||||||
|
required void Function(SimplexQuote) onSelected,
|
||||||
|
}) async {
|
||||||
|
_fiatFocusNode.unfocus();
|
||||||
|
_cryptoFocusNode.unfocus();
|
||||||
|
|
||||||
|
final result = isDesktop
|
||||||
|
? await showDialog<Fiat?>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return DesktopDialog(
|
||||||
|
maxHeight: 700,
|
||||||
|
maxWidth: 580,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 32,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
"Choose a fiat with which to pay",
|
||||||
|
style: STextStyles.desktopH3(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const DesktopDialogCloseButton(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 32,
|
||||||
|
right: 32,
|
||||||
|
bottom: 32,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: RoundedWhiteContainer(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
borderColor: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.background,
|
||||||
|
child: BuyQuotePreviewView(
|
||||||
|
quote: quote,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
: await Navigator.of(context).push(
|
||||||
|
MaterialPageRoute<dynamic>(
|
||||||
|
builder: (_) => BuyQuotePreviewView(
|
||||||
|
quote: quote,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (mounted && result is SimplexQuote) {
|
||||||
|
onSelected(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_receiveAddressController = TextEditingController();
|
_receiveAddressController = TextEditingController();
|
||||||
|
@ -332,6 +438,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
||||||
|
|
||||||
coins = ref.read(simplexProvider).supportedCryptos;
|
coins = ref.read(simplexProvider).supportedCryptos;
|
||||||
fiats = ref.read(simplexProvider).supportedFiats;
|
fiats = ref.read(simplexProvider).supportedFiats;
|
||||||
|
quote = ref.read(simplexProvider).quote;
|
||||||
|
|
||||||
// TODO set initial crypto to open wallet if a wallet is open
|
// TODO set initial crypto to open wallet if a wallet is open
|
||||||
|
|
||||||
|
@ -869,29 +976,40 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: isDesktop ? 20 : 12,
|
height: isDesktop ? 20 : 12,
|
||||||
),
|
),
|
||||||
PrimaryButton(
|
MouseRegion(
|
||||||
buttonHeight: isDesktop ? ButtonHeight.l : null,
|
cursor: SystemMouseCursors.click,
|
||||||
enabled: _receiveAddressController.text.isNotEmpty &&
|
onEnter: (_) => setState(() => _hovering1 = true),
|
||||||
_buyAmountController.text.isNotEmpty,
|
onExit: (_) => setState(() => _hovering1 = false),
|
||||||
onPressed: () {
|
child: GestureDetector(
|
||||||
// preview buy quote
|
onTap: () {
|
||||||
// TODO: show loading while fetching quote
|
previewQuote();
|
||||||
final quote = SimplexQuote(
|
},
|
||||||
crypto: selectedCrypto!,
|
child: PrimaryButton(
|
||||||
fiat: selectedFiat!,
|
buttonHeight: isDesktop ? ButtonHeight.l : null,
|
||||||
youPayFiatPrice: Decimal.parse("100"),
|
enabled: _receiveAddressController.text.isNotEmpty &&
|
||||||
youReceiveCryptoAmount: Decimal.parse("1.0238917"),
|
_buyAmountController.text.isNotEmpty,
|
||||||
purchaseId: "someID",
|
onPressed: () {
|
||||||
receivingAddress: _receiveAddressController.text,
|
previewQuote(); // ??
|
||||||
);
|
|
||||||
|
|
||||||
Navigator.of(context).pushNamed(
|
// // preview buy quote
|
||||||
BuyQuotePreviewView.routeName,
|
// // TODO: show loading while fetching quote
|
||||||
arguments: quote,
|
// final quote = SimplexQuote(
|
||||||
);
|
// crypto: selectedCrypto!,
|
||||||
},
|
// fiat: selectedFiat!,
|
||||||
label: "Preview quote",
|
// youPayFiatPrice: Decimal.parse("100"),
|
||||||
)
|
// youReceiveCryptoAmount: Decimal.parse("1.0238917"),
|
||||||
|
// purchaseId: "someID",
|
||||||
|
// receivingAddress: _receiveAddressController.text,
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// Navigator.of(context).pushNamed(
|
||||||
|
// BuyQuotePreviewView.routeName,
|
||||||
|
// arguments: quote,
|
||||||
|
// );
|
||||||
|
},
|
||||||
|
label: "Preview quote",
|
||||||
|
)),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue