Skip to content

Commit

Permalink
Use compression
Browse files Browse the repository at this point in the history
  • Loading branch information
hhanh00 committed Jun 22, 2022
1 parent 811e5cd commit 72d2d1d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
30 changes: 29 additions & 1 deletion lib/animated_qr.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:warp_api/warp_api.dart';
import 'generated/l10n.dart';
Expand All @@ -15,7 +18,8 @@ class AnimatedQR extends StatefulWidget {
final List<String> chunks;

AnimatedQR.init(String title, String caption, String data):
this(title, caption, data, WarpApi.splitData(DateTime.now().millisecondsSinceEpoch ~/ 1000, base64Encode(utf8.encode(data))));
this(title, caption, data, WarpApi.splitData(DateTime.now().millisecondsSinceEpoch ~/ 1000,
base64Encode(ZLibCodec().encode(utf8.encode(data)))));

AnimatedQR(this.title, this.caption, this.data, this.chunks);

Expand Down Expand Up @@ -90,3 +94,27 @@ class ShowRawTx extends StatelessWidget {
}
}

Future<String?> scanMultiCode(BuildContext context) async {
if (!isMobile()) {
showSnackBar(S.of(context).barcodeScannerIsNotAvailableOnDesktop);
return null;
}
else {
final player = AudioPlayer();
final ding = AssetSource("ding.mp3");
final dropStream = FlutterBarcodeScanner.getBarcodeStreamReceiver('#FF0000', S.of(context).cancel, true, ScanMode.QR);
var f = Completer<String>();
StreamSubscription? sub;
sub = dropStream?.listen((barcode) async {
await player.play(ding);
final res = WarpApi.mergeData(barcode);
if (res.isNotEmpty) {
FlutterBarcodeScanner.dismiss();
final decoded = utf8.decode(ZLibCodec().decode(base64Decode(res)));
sub?.cancel();
f.complete(decoded);
}
});
return f.future;
}
}
1 change: 1 addition & 0 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:upgrader/upgrader.dart';
import 'about.dart';
import 'account.dart';
import 'account_manager.dart';
import 'animated_qr.dart';
import 'budget.dart';
import 'contact.dart';
import 'history.dart';
Expand Down
25 changes: 0 additions & 25 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -575,31 +575,6 @@ Future<String?> scanCode(BuildContext context) async {
}
}

Future<String?> scanMultiCode(BuildContext context) async {
if (!isMobile()) {
showSnackBar(S.of(context).barcodeScannerIsNotAvailableOnDesktop);
return null;
}
else {
final player = AudioPlayer();
final ding = AssetSource("ding.mp3");
final dropStream = FlutterBarcodeScanner.getBarcodeStreamReceiver('#FF0000', S.of(context).cancel, true, ScanMode.QR);
var f = Completer<String>();
StreamSubscription? sub;
sub = dropStream?.listen((barcode) async {
await player.play(ding);
final res = WarpApi.mergeData(barcode);
if (res.isNotEmpty) {
FlutterBarcodeScanner.dismiss();
final decoded = utf8.decode(base64Decode(res));
sub?.cancel();
f.complete(decoded);
}
});
return f.future;
}
}

String centerTrim(String v) =>
v.length >= 16 ? v.substring(0, 8) + "..." +
v.substring(v.length - 16) : v;
Expand Down
6 changes: 5 additions & 1 deletion lib/sign.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ class Sign extends StatelessWidget {
}

_sign(BuildContext context) async {
final rawTransactionLabel = S.of(context).rawTransaction;
final s = S.of(context);
final rawTransactionLabel = s.rawTransaction;
final paymentInProgressLabel = s.paymentInProgress;
Navigator.of(context).pop();

if (txStr != null) {
active.setBanner(paymentInProgressLabel);
final res = await WarpApi.signOnly(
active.coin, active.id, txStr, (progress) {
progressPort.sendPort.send(progress);
});
progressPort.sendPort.send(0);
active.setBanner("");
final isError = WarpApi.getError();
if (isError) {
final snackBar = SnackBar(content: Text(res));
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.8+243
version: 1.2.8+244

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit 72d2d1d

Please sign in to comment.