Fixes and changed build versions for ios and android projects.

M committed Jan 6, 2021 at 22:53 UTC 6a9720d5d64f23de352b9fac101d26c0060bcbbb
7 files changed +68 -39
ios/Runner.xcodeproj/project.pbxproj
+3 -3
@@ -354,7 +354,7 @@
354 buildSettings = {
355 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
356 CLANG_ENABLE_MODULES = YES;
357 - CURRENT_PROJECT_VERSION = 11;
357 + CURRENT_PROJECT_VERSION = 12;
358 DEVELOPMENT_TEAM = 32J6BB6VUS;
359 ENABLE_BITCODE = NO;
360 FRAMEWORK_SEARCH_PATHS = (
@@ -494,7 +494,7 @@
494 buildSettings = {
495 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
496 CLANG_ENABLE_MODULES = YES;
497 - CURRENT_PROJECT_VERSION = 11;
497 + CURRENT_PROJECT_VERSION = 12;
498 DEVELOPMENT_TEAM = 32J6BB6VUS;
499 ENABLE_BITCODE = NO;
500 FRAMEWORK_SEARCH_PATHS = (
@@ -528,7 +528,7 @@
528 buildSettings = {
529 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
530 CLANG_ENABLE_MODULES = YES;
531 - CURRENT_PROJECT_VERSION = 11;
531 + CURRENT_PROJECT_VERSION = 12;
532 DEVELOPMENT_TEAM = 32J6BB6VUS;
533 ENABLE_BITCODE = NO;
534 FRAMEWORK_SEARCH_PATHS = (
lib/bitcoin/bitcoin_balance.dart
+3 -3
@@ -27,10 +27,10 @@ class BitcoinBalance extends Balance {
27 final int confirmed;
28 final int unconfirmed;
29
30 - int get total =>
31 - confirmed + (unconfirmed < 0 ? unconfirmed * -1 : unconfirmed);
30 + int get total => confirmed + unconfirmed;
31
33 - int get availableBalance => confirmed + (unconfirmed < 0 ? unconfirmed : 0);
32 + int get availableBalance =>
33 + (confirmed ?? 0) + (unconfirmed < 0 ? unconfirmed : 0);
34
35 String get confirmedFormatted => bitcoinAmountToString(amount: confirmed);
36
lib/bitcoin/electrum.dart
+50 -29
@@ -22,9 +22,8 @@ String jsonrpcparams(List<Object> params) {
22 }
23
24 String jsonrpc(
25 - {String method, List<Object> params, int id, double version = 2.0}) =>
26 - '{"jsonrpc": "$version", "method": "$method", "id": "$id", "params": ${json
27 - .encode(params)}}\n';
25 + {String method, List<Object> params, int id, double version = 2.0}) =>
26 + '{"jsonrpc": "$version", "method": "$method", "id": "$id", "params": ${json.encode(params)}}\n';
27
28 class SocketTask {
29 SocketTask({this.completer, this.isSubscription, this.subject});
@@ -75,7 +74,9 @@ class ElectrumClient {
74
75 socket.listen((Uint8List event) {
76 try {
78 - _handleResponse(utf8.decode(event.toList()));
77 + final response =
78 + json.decode(utf8.decode(event.toList())) as Map<String, Object>;
79 + _handleResponse(response);
80 } on FormatException catch (e) {
81 final msg = e.message.toLowerCase();
82
@@ -87,12 +88,33 @@ class ElectrumClient {
88 unterminatedString += e.source as String;
89 }
90
91 + if (msg.contains("not a subtype of type")) {
92 + unterminatedString += e.source as String;
93 + return;
94 + }
95 +
96 if (isJSONStringCorrect(unterminatedString)) {
91 - _handleResponse(unterminatedString);
97 + final response =
98 + json.decode(unterminatedString) as Map<String, Object>;
99 + _handleResponse(response);
100 + unterminatedString = null;
101 + }
102 + } on TypeError catch (e) {
103 + if (!e.toString().contains('Map<String, Object>')) {
104 + return;
105 + }
106 +
107 + final source = utf8.decode(event.toList());
108 + unterminatedString += source;
109 +
110 + if (isJSONStringCorrect(unterminatedString)) {
111 + final response =
112 + json.decode(unterminatedString) as Map<String, Object>;
113 + _handleResponse(response);
114 unterminatedString = null;
115 }
116 } catch (e) {
95 - print(e);
117 + print(e.toString());
118 }
119 }, onError: (Object error) {
120 print(error.toString());
@@ -153,7 +175,7 @@ class ElectrumClient {
175 });
176
177 Future<List<Map<String, dynamic>>> getListUnspentWithAddress(
156 - String address) =>
178 + String address) =>
179 call(
180 method: 'blockchain.scripthash.listunspent',
181 params: [scriptHash(address)]).then((dynamic result) {
@@ -204,7 +226,7 @@ class ElectrumClient {
226 });
227
228 Future<Map<String, Object>> getTransactionRaw(
207 - {@required String hash}) async =>
229 + {@required String hash}) async =>
230 call(method: 'blockchain.transaction.get', params: [hash, true])
231 .then((dynamic result) {
232 if (result is Map<String, Object>) {
@@ -233,25 +255,25 @@ class ElectrumClient {
255 }
256
257 Future<String> broadcastTransaction(
236 - {@required String transactionRaw}) async =>
258 + {@required String transactionRaw}) async =>
259 call(method: 'blockchain.transaction.broadcast', params: [transactionRaw])
260 .then((dynamic result) {
261 if (result is String) {
262 return result;
263 }
242 -
264 + print(result);
265 return '';
266 });
267
268 Future<Map<String, dynamic>> getMerkle(
247 - {@required String hash, @required int height}) async =>
269 + {@required String hash, @required int height}) async =>
270 await call(
271 method: 'blockchain.transaction.get_merkle',
272 params: [hash, height]) as Map<String, dynamic>;
273
274 Future<Map<String, dynamic>> getHeader({@required int height}) async =>
275 await call(method: 'blockchain.block.get_header', params: [height])
254 - as Map<String, dynamic>;
276 + as Map<String, dynamic>;
277
278 Future<double> estimatefee({@required int p}) =>
279 call(method: 'blockchain.estimatefee', params: [p])
@@ -275,9 +297,10 @@ class ElectrumClient {
297 params: [scripthash]);
298 }
299
278 - BehaviorSubject<T> subscribe<T>({@required String id,
279 - @required String method,
280 - List<Object> params = const []}) {
300 + BehaviorSubject<T> subscribe<T>(
301 + {@required String id,
302 + @required String method,
303 + List<Object> params = const []}) {
304 final subscription = BehaviorSubject<T>();
305 _regisrySubscription(id, subscription);
306 socket.write(jsonrpc(method: method, id: _id, params: params));
@@ -296,9 +319,10 @@ class ElectrumClient {
319 return completer.future;
320 }
321
299 - Future<dynamic> callWithTimeout({String method,
300 - List<Object> params = const [],
301 - int timeout = 2000}) async {
322 + Future<dynamic> callWithTimeout(
323 + {String method,
324 + List<Object> params = const [],
325 + int timeout = 2000}) async {
326 final completer = Completer<dynamic>();
327 _id += 1;
328 final id = _id;
@@ -325,9 +349,8 @@ class ElectrumClient {
349 onConnectionStatusChange = null;
350 }
351
328 - void _regisryTask(int id, Completer completer) =>
329 - _tasks[id.toString()] =
330 - SocketTask(completer: completer, isSubscription: false);
352 + void _regisryTask(int id, Completer completer) => _tasks[id.toString()] =
353 + SocketTask(completer: completer, isSubscription: false);
354
355 void _regisrySubscription(String id, BehaviorSubject subject) =>
356 _tasks[id] = SocketTask(subject: subject, isSubscription: true);
@@ -371,22 +394,20 @@ class ElectrumClient {
394 _isConnected = isConnected;
395 }
396
374 - void _handleResponse(String response) {
375 - print('Response: $response');
376 - final jsoned = json.decode(response) as Map<String, Object>;
377 - // print(jsoned);
378 - final method = jsoned['method'];
379 - final id = jsoned['id'] as String;
380 - final result = jsoned['result'];
397 + void _handleResponse(Map<String, Object> response) {
398 + final method = response['method'];
399 + final id = response['id'] as String;
400 + final result = response['result'];
401
402 if (method is String) {
383 - _methodHandler(method: method, request: jsoned);
403 + _methodHandler(method: method, request: response);
404 return;
405 }
406
407 _finish(id, result);
408 }
409 }
410 +
411 // FIXME: move me
412 bool isJSONStringCorrect(String source) {
413 try {
lib/main.dart
-1
@@ -1,4 +1,3 @@
1 -import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
1 import 'package:cake_wallet/themes/theme_base.dart';
2 import 'package:flutter/material.dart';
3 import 'package:flutter/services.dart';
lib/src/screens/exchange_trade/exchange_trade_page.dart
+10 -1
@@ -358,7 +358,16 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
358 });
359 });
360 },
361 - actionLeftButton: () => Navigator.of(context).pop());
361 + actionLeftButton: () => Navigator.of(context).pop(),
362 + feeFiatAmount: widget.exchangeTradeViewModel.sendViewModel
363 + .pendingTransaction.feeFormatted,
364 + fiatAmountValue: widget.exchangeTradeViewModel.sendViewModel
365 + .pendingTransactionFeeFiatAmount +
366 + ' ' +
367 + widget.exchangeTradeViewModel.sendViewModel.fiat.title,
368 + recipientTitle: S.of(context).recipient_address,
369 + recipientAddress:
370 + widget.exchangeTradeViewModel.sendViewModel.address);
371 });
372 });
373 }
lib/view_model/exchange/exchange_view_model.dart
+1 -1
@@ -310,7 +310,7 @@ abstract class ExchangeViewModelBase with Store {
310 }
311
312 final amount = availableBalance - fee;
313 - depositAmount = bitcoinAmountToString(amount: amount);
313 + changeDepositAmount(amount: bitcoinAmountToString(amount: amount));
314 }
315 }
316
pubspec.yaml
+1 -1
@@ -11,7 +11,7 @@ description: Cake Wallet.
11 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
12 # Read more about iOS versioning at
13 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14 -version: 4.1.0+27
14 +version: 4.1.0+28
15
16 environment:
17 sdk: ">=2.7.0 <3.0.0"