Cw 45 implement yat sending (#269)

* resolve YAT emoji

* remove animation in route builder

change YAT api

* remove yat sending page

* fix crypto address resolving

* check if text is emoji

* use getter for string extension hasOnlyEmojis

* refactor parsed domain from address

* update PR based on changes from code review

* import missing dependencies
This commit is contained in:
Godwin Asuquo
2022-03-15 12:11:53 +03:00
committed by GitHub
parent 23913c01dc
commit d2cc812884
15 changed files with 178 additions and 363 deletions
@@ -178,24 +178,6 @@ class DashboardPage extends BasePage {
pages.add(TransactionsPage(dashboardViewModel: walletViewModel));
_isEffectsInstalled = true;
//if (walletViewModel.shouldShowYatPopup) {
// await Future<void>.delayed(Duration(seconds: 1));
// if (currentRouteSettings.name == Routes.preSeed
// || currentRouteSettings.name == Routes.seed) {
// return;
// }
// await showPopUp<void>(
// context: context,
// builder: (BuildContext context) {
// return YatPopup(
// dashboardViewModel: walletViewModel,
// onClose: () => Navigator.of(context).pop());
// });
// walletViewModel.furtherShowYatPopup(false);
//}
autorun((_) async {
if (!walletViewModel.isOutdatedElectrumWallet) {
return;
+2 -2
View File
@@ -1,5 +1,5 @@
import 'dart:ui';
import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/utils/debounce.dart';
import 'package:cw_core/sync_status.dart';
import 'package:cw_core/wallet_type.dart';
@@ -790,7 +790,7 @@ class ExchangePage extends BasePage {
Future<String> fetchParsedAddress(
BuildContext context, String domain, String ticker) async {
final parsedAddress = await parseAddressFromDomain(domain, ticker);
final parsedAddress = await getIt.get<AddressResolver>().resolve(domain, ticker);
final address = await extractAddressFromParsed(context, parsedAddress);
return address;
}
+2 -10
View File
@@ -1,6 +1,6 @@
import 'dart:ui';
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.dart';
import 'package:cake_wallet/src/screens/send/widgets/send_card.dart';
import 'package:cake_wallet/src/screens/yat/widgets/yat_close_button.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/src/widgets/template_tile.dart';
import 'package:cake_wallet/view_model/send/output.dart';
@@ -22,9 +22,6 @@ import 'package:dotted_border/dotted_border.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:cake_wallet/src/screens/yat/yat_sending.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.dart';
class SendPage extends BasePage {
SendPage({@required this.sendViewModel}) : _formKey = GlobalKey<FormState>();
@@ -304,11 +301,6 @@ class SendPage extends BasePage {
await sendViewModel.createTransaction();
if (!sendViewModel.isBatchSending &&
sendViewModel.hasYat) {
Navigator.of(context)
.push<void>(YatSending.createRoute(sendViewModel));
}
},
text: S.of(context).send,
color: Theme.of(context).accentTextTheme.body2.color,
@@ -345,7 +337,7 @@ class SendPage extends BasePage {
}
if (state is ExecutedSuccessfullyState &&
!(!sendViewModel.isBatchSending && sendViewModel.hasYat)) {
!sendViewModel.isBatchSending) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showPopUp<void>(
context: context,
-15
View File
@@ -1,15 +0,0 @@
import 'package:flutter/material.dart';
class CircleClipper extends CustomClipper<Path> {
CircleClipper(this.center, this.radius);
final Offset center;
final double radius;
@override
Path getClip(Size size) =>
Path()..addOval(Rect.fromCircle(radius: radius, center: center));
@override
bool shouldReclip(covariant CustomClipper<Path> oldClipper) => true;
}
-124
View File
@@ -1,124 +0,0 @@
import 'package:cake_wallet/src/screens/yat/widgets/yat_bar.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/palette.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:lottie/lottie.dart';
class YatAlert extends StatelessWidget {
YatAlert(this.yatStore);
final YatStore yatStore;
static const aspectRatioImage = 1.133;
final animation = Lottie.asset('assets/animation/anim1.json');
@override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
final screenWidth = MediaQuery.of(context).size.width;
return Container(
height: screenHeight,
width: screenWidth,
color: Colors.white,
child: ScrollableWithBottomSection(
contentPadding: EdgeInsets.only(top: 40, bottom: 40),
content: Column(
children: [
Container(
height: 45,
padding: EdgeInsets.only(left: 24, right: 24),
child: YatBar(onClose: () => Navigator.of(context).pop())
),
animation,
Container(
padding: EdgeInsets.only(left: 30, right: 30),
child: Column(
children: [
Text(
S.of(context).yat_alert_title,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
fontFamily: 'Lato',
color: Colors.black,
decoration: TextDecoration.none,
)
),
Padding(
padding: EdgeInsets.only(top: 20),
child: Text(
S.of(context).yat_alert_content,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Colors.black,
decoration: TextDecoration.none,
)
)
)
]
)
)
]
),
bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 40),
bottomSection: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
PrimaryIconButton(
text: S.of(context).get_your_yat,
textColor: Colors.white,
color: Palette.protectiveBlue,
borderColor: Palette.protectiveBlue,
iconColor: Colors.white,
iconBackgroundColor: Colors.transparent,
iconData: CupertinoIcons
.arrow_up_right_square,
mainAxisAlignment: MainAxisAlignment.end,
onPressed: () {
var createNewYatUrl = YatLink.startFlowUrl;
final createNewYatUrlParameters =
yatStore.defineQueryParameters();
if (createNewYatUrlParameters.isNotEmpty) {
createNewYatUrl += '?sub1=' + createNewYatUrlParameters;
}
launch(createNewYatUrl, forceSafariVC: false);
}),
Padding(
padding: EdgeInsets.only(top: 24),
child: PrimaryIconButton(
text: S.of(context).connect_an_existing_yat,
textColor: Colors.black,
color: Palette.blueAlice,
borderColor: Palette.blueAlice,
iconColor: Colors.black,
iconBackgroundColor: Colors.transparent,
iconData: CupertinoIcons
.arrow_up_right_square,
mainAxisAlignment: MainAxisAlignment.end,
onPressed: () {
String url = YatLink.baseUrl + YatLink.signInSuffix;
final parameters =
yatStore.defineQueryParameters();
if (parameters.isNotEmpty) {
url += YatLink.queryParameter + parameters;
}
launch(url, forceSafariVC: false);
})
)
]
),
)
);
}
}
-141
View File
@@ -1,141 +0,0 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/src/screens/yat/widgets/yat_close_button.dart';
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
import 'package:cake_wallet/src/screens/yat/circle_clipper.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/view_model/send/send_view_model.dart';
class YatSending extends BasePage {
YatSending(this.sendViewModel);
static Route createRoute(SendViewModel sendViewModel) {
return PageRouteBuilder<void>(
transitionDuration: Duration(seconds: 1),
reverseTransitionDuration: Duration(seconds: 1),
opaque: false,
barrierDismissible: false,
pageBuilder: (context, animation, secondaryAnimation) => YatSending(sendViewModel),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
final screenSize = MediaQuery.of(context).size;
final center = Offset(screenSize.width / 2, screenSize.height / 2);
final endRadius = screenSize.height * 1.2;
final tween = Tween(begin: 0.0, end: endRadius);
return ClipPath(
clipper: CircleClipper(center, animation.drive(tween).value),
child: child,
);
},
);
}
final SendViewModel sendViewModel;
@override
Color get titleColor => Colors.white;
@override
bool get resizeToAvoidBottomInset => false;
@override
bool get extendBodyBehindAppBar => true;
@override
AppBarStyle get appBarStyle => AppBarStyle.transparent;
@override
Widget trailing(context) =>
YatCloseButton(onClose: () => Navigator.of(context).pop());
@override
Widget leading(BuildContext context) => Container();
@override
Widget body(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
return Container(
color: Colors.black,
child: Stack(
children: [
//Center(
// child:FutureBuilder<String>(
// future: visualisationForEmojiId(sendViewModel.outputs.first.address),
// builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
// switch (snapshot.connectionState) {
// case ConnectionState.done:
// if (snapshot.hasError || snapshot.data.isEmpty) {
// return Image.asset('assets/images/yat_logo.png', width: screenWidth, color: Colors.white);
// }
// return Image.network(
// snapshot.data,
// scale: 0.7,
// loadingBuilder: (Object z, Widget child, ImageChunkEvent loading)
// => loading != null
// ? CupertinoActivityIndicator(animating: true)
// : child);
// default:
// return Image.asset('assets/images/yat_logo.png', width: screenWidth, color: Colors.white);
// }
// }),
// ),
Positioned(
bottom: 20,
child: Container(
width: screenWidth,
padding: EdgeInsets.fromLTRB(20, 0, 20, 10),
child: Column(children: [
Text(
'You are sending ${sendViewModel.outputs.first.cryptoAmount} ${sendViewModel.currency.title} to ${sendViewModel.outputs.first.address}'.toUpperCase(),
style: TextStyle(
fontSize: 28,
decoration: TextDecoration.none,
color: Theme.of(context).accentTextTheme.display3.backgroundColor),
textAlign: TextAlign.center),
Container(height: 30),
LoadingPrimaryButton(
onPressed: () {
sendViewModel.commitTransaction();
showPopUp<void>(
context: context,
builder: (BuildContext popContext) {
return Observer(builder: (_) {
final state = sendViewModel.state;
if (state is FailureState) {
Navigator.of(context).pop();
}
if (state is TransactionCommitted) {
return AlertWithOneAction(
alertTitle: '',
alertContent: S.of(popContext).send_success(
sendViewModel.currency
.toString()),
buttonText: S.of(popContext).ok,
buttonAction: () {
Navigator.of(popContext).pop();
Navigator.of(context).pop();
});
}
return Offstage();
});
});
},
text: S.of(context).confirm_sending,
color: Theme.of(context).accentTextTheme.body2.color,
textColor: Colors.white,
isLoading: sendViewModel.state is IsExecutingState ||
sendViewModel.state is TransactionCommitting)])))]));
}
}