From 16fbd9250dc55724efaab678530a1ea5d108e88f Mon Sep 17 00:00:00 2001 From: M Date: Wed, 9 Sep 2020 17:13:44 +0300 Subject: [PATCH] Merge redesign part 4. --- lib/bitcoin/electrum.dart | 24 +++++++++++++++---- lib/src/screens/dashboard/dashboard_page.dart | 15 +++--------- .../dashboard/widgets/action_button.dart | 23 +++++++----------- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/bitcoin/electrum.dart b/lib/bitcoin/electrum.dart index 5f034bc6a..69d1c332f 100644 --- a/lib/bitcoin/electrum.dart +++ b/lib/bitcoin/electrum.dart @@ -6,6 +6,16 @@ import 'package:cake_wallet/bitcoin/script_hash.dart'; import 'package:flutter/foundation.dart'; import 'package:rxdart/rxdart.dart'; +class UriParseException implements Exception { + UriParseException(this.uri); + + final String uri; + + @override + String toString() => + 'Cannot parse host and port from uri. Invalid uri format. Uri: $uri'; +} + String jsonrpcparams(List params) { final _params = params?.map((val) => '"${val.toString()}"')?.join(','); return '[$_params]'; @@ -40,9 +50,14 @@ class ElectrumClient { Timer _aliveTimer; Future connectToUri(String uri) async { - final _uri = Uri.parse(uri); - final host = _uri.scheme; - final port = int.parse(_uri.path); + final splittedUri = uri.split(':'); + + if (splittedUri.length != 2) { + throw UriParseException(uri); + } + + final host = splittedUri.first; + final port = int.parse(splittedUri.last); await connect(host: host, port: port); } @@ -51,7 +66,8 @@ class ElectrumClient { await socket?.close(); } catch (_) {} - socket = await SecureSocket.connect(host, port, timeout: connectionTimeout); + socket = await SecureSocket.connect(host, port, + timeout: connectionTimeout, onBadCertificate: (_) => true); _setIsConnected(true); socket.listen((Uint8List event) { diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index df93362b4..d3ae08cbe 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -88,9 +88,7 @@ class DashboardPage extends BasePage { child: PageView.builder( controller: controller, itemCount: pages.length, - itemBuilder: (context, index) { - return pages[index]; - })), + itemBuilder: (context, index) => pages[index])), Padding( padding: EdgeInsets.only(bottom: 24), child: SmoothPageIndicator( @@ -106,8 +104,9 @@ class DashboardPage extends BasePage { )), Container( width: double.infinity, - padding: EdgeInsets.only(left: 45, right: 45, bottom: 24), + padding: EdgeInsets.only(left: 44, right: 0, bottom: 24), child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible( child: ActionButton( @@ -122,14 +121,6 @@ class DashboardPage extends BasePage { image: exchangeImage, title: S.of(context).exchange, route: Routes.exchange), - ), - Flexible( - child: ActionButton( - image: receiveImage, - title: S.of(context).receive, - route: Routes.receive, - alignment: Alignment.centerRight, - ), ) ], ), diff --git a/lib/src/screens/dashboard/widgets/action_button.dart b/lib/src/screens/dashboard/widgets/action_button.dart index 4ab08d97e..3cf1d6ded 100644 --- a/lib/src/screens/dashboard/widgets/action_button.dart +++ b/lib/src/screens/dashboard/widgets/action_button.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; -class ActionButton extends StatelessWidget{ - ActionButton({ - @required this.image, - @required this.title, - @required this.route, - this.alignment = Alignment.center - }); +class ActionButton extends StatelessWidget { + ActionButton( + {@required this.image, + @required this.title, + @required this.route, + this.alignment = Alignment.center}); final Image image; final String title; @@ -35,20 +34,16 @@ class ActionButton extends StatelessWidget{ width: 60, alignment: Alignment.center, decoration: BoxDecoration( - color: Theme.of(context).buttonColor, - shape: BoxShape.circle), + color: Theme.of(context).buttonColor, shape: BoxShape.circle), child: image, ), ), Text( title, - style: TextStyle( - fontSize: 14, - color: Colors.white - ), + style: TextStyle(fontSize: 14, color: Colors.white), ) ], ), ); } -} \ No newline at end of file +}