From 6fdcc0dd9ecad18373ccfa1b541745032fa5da2a Mon Sep 17 00:00:00 2001 From: OmarHatem28 Date: Mon, 4 Jul 2022 21:15:03 +0200 Subject: [PATCH] Calculate purchase amount with current wallet currency --- assets/images/flags/czk.png | Bin 915 -> 0 bytes .../phone_number_product_page.dart | 93 +++++++++++++++--- 2 files changed, 81 insertions(+), 12 deletions(-) delete mode 100644 assets/images/flags/czk.png diff --git a/assets/images/flags/czk.png b/assets/images/flags/czk.png deleted file mode 100644 index a6c13a7738cb9601c3f9279ec6e887dd752ac6cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 915 zcmV;E18n?>P)xL4tec=q1VIa} zirU&@32CWX14&boCQXyP>-jD{kC#Up(=h7l4*u@$t`Ut!mFFL$;o)ID zM^8_WlK5OMXLNRUDtV7_=o=dwQsVvEiDxd!_X2F zv$wXlw*zazD?ga?Ao}i2g}Gg(c7d0Fb7ErR0=vaXBvR73!P1-i`}?Ml1RlPK(8Z}I z^ewtW?EtGd$g5`|4e@Ns3(hIa8@%;5MdLST>Hh3%+RGeJtKsHk)-vGf!bcjvHB0Zm z#;Dc6M+oZ>MG{vV0Clh3eb!QS6Nv=L?%@!{S6<6tQFrdmXKFUOy1E=rH7>Pb# zn%4FswH=~;eSMUmljH1Rh8}Fbqf41T z)M!AwKp;@AXg#it44uF~b|!4i(+tt;y!XS^HX1 zK7iR98yh9gf-MPZmx=;g(H5WKN}QG`OjOz7j;${qkNfzrWg->ar62s`(!+f?LtaTS z;hn=9>xRT)yk%J`o6Q!7hK6un0#Vzko|vf3oduRV&jWINbk!D(Cq|{5g++7sAH`v^J(Q&yFoC^c*rGY#jT}YVT pca<&~JeL { contentWidget: Column( mainAxisSize: MainAxisSize.min, children: [ - cakePayReceiptRow(S.of(context).amount, phonePlanViewModel.totalPrice), - cakePayReceiptRow(S.of(context).cake_pay_balance, 100), + receiptRow(S.of(context).amount, amountText(phonePlanViewModel.totalPrice)), + receiptRow(S.of(context).cake_pay_balance, amountText(100)), ], ), isDividerExists: true, @@ -350,7 +354,38 @@ class PhoneNumberProductBodyState extends State { ), const SizedBox(height: 8), PrimaryButton( - onPressed: () {}, + onPressed: () { + showPopUp( + context: context, + builder: (dialogContext) { + return AlertWithTwoActions( + alertTitle: S.of(context).confirm_payment, + alertContent: S.of(context).confirm_delete_template, + contentWidget: Column( + mainAxisSize: MainAxisSize.min, + children: [ + receiptRow(S.of(context).amount, cryptoAmount(phonePlanViewModel.totalPrice)), + receiptRow( + S.of(context).send_fee, + cryptoAmount(getIt + .get() + .wallet + .calculateEstimatedFee( + getIt.get().settingsStore.priority[getIt.get().wallet.type], + phonePlanViewModel.totalPrice.floor(), + ) + .toDouble())), + ], + ), + isDividerExists: true, + rightButtonText: S.of(context).ok, + leftButtonText: S.of(context).cancel, + actionRightButton: () { + Navigator.of(dialogContext).pop(); + }, + actionLeftButton: () => Navigator.of(dialogContext).pop()); + }); + }, text: "${S.of(context).pay_with} ${getIt.get().wallet.currency.toString()}", color: Theme.of(context).accentTextTheme.body2.color, textColor: Colors.white, @@ -410,7 +445,7 @@ class PhoneNumberProductBodyState extends State { ); } - Widget cakePayReceiptRow(String title, double amount) { + Widget receiptRow(String title, Widget value) { return Padding( padding: const EdgeInsets.only(top: 24), child: Row( @@ -424,16 +459,50 @@ class PhoneNumberProductBodyState extends State { color: Theme.of(context).accentTextTheme.subhead.color, ), ), - Text( - "\$${amount.roundToDouble() == amount ? amount.round() : amount}", - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.w700, - color: Theme.of(context).primaryTextTheme.title.color, - ), - ), + value, ], ), ); } + + Widget amountText(double amount) { + return Text( + "\$${amount.roundToDouble() == amount ? amount.round() : amount}", + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w700, + color: Theme.of(context).primaryTextTheme.title.color, + ), + ); + } + + Widget cryptoAmount(double totalPrice) { + return FutureBuilder( + future: MoonPayBuyProvider(wallet: getIt.get().wallet) + .calculateAmount(totalPrice.toString(), FiatCurrency.usd.title), + builder: (context, AsyncSnapshot snapshot) { + double sourceAmount; + double destAmount; + double achAmount; + int minAmount; + + if (snapshot.hasData) { + sourceAmount = snapshot.data.sourceAmount; + destAmount = snapshot.data.destAmount; + minAmount = snapshot.data.minAmount; + achAmount = snapshot.data.achSourceAmount; + } else { + sourceAmount = 0.0; + destAmount = 0.0; + minAmount = 0; + } + + return Column( + children: [ + Text(sourceAmount.toString()), + Text(destAmount.toString()), + ], + ); + }); + } }