Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enforce linter rules #336

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 2 additions & 45 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,60 +1,17 @@
include: package:lint/analysis_options.yaml
# package: flutter_lints/flutter.yaml

linter:
rules:
avoid_deprecated_members: false
file_names: false
curly_braces_in_flow_control_structures: false
avoid_classes_with_only_static_members: false
sort_constructors_first: true
prefer_single_quotes: true
avoid_void_async: false
sized_box_for_whitespace: false
prefer_interpolation_to_compose_strings: false
avoid_print: false
# always_specify_types: true
# const_initialized_with_non_constant_value: false
# import_of_legacy_library_into_null_safe: false
avoid_positional_boolean_parameters: false
use_string_buffers: false
use_build_context_synchronously: false
depend_on_referenced_packages: false
join_return_with_assignment: false
unnecessary_string_escapes: false
avoid_classes_with_only_static_members: false
avoid_dynamic_calls: false
non_constant_identifier_names: false
no_wildcard_variable_uses: false



analyzer:
errors:
deprecated_member_use: ignore
# enable-experiment:
# - inline-class
# - records
exclude:
- lib/**/*.g.dart
- lib/**/*.freezed.dart
# - test/
- maintainance/**
- pubspec.yaml




# include: package:flutter_lints/flutter.yaml

# linter:

# rules:
# depend_on_referenced_packages:false

# analyzer:
# exclude:
# - "**/*.g.dart"
# # strong-mode:
# # implicit-casts: false
# # implicit-dynamic: false
# errors:
# invalid_annotation_target: ignore
8 changes: 4 additions & 4 deletions integration_test/boltz_dart_test.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import 'package:boltz_dart/boltz_dart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('Swap Fees test', () async {
try {
const boltzUrl = 'https://api.testnet.boltz.exchange';
// const amount = 100000;
// const fees = Fees(boltzUrl: boltzUrl);
// final submarineFees = await fees.submarine();
// print('FEES:${submarineFees.lbtcFees}');
// print('FEES:${fees.lbtcSubmarine.lockupFeesEstimate}');
} catch (e) {
print(e);
debugPrint(e.toString());
if (e is BoltzError) {
print(e.kind);
print(e.message);
debugPrint(e.kind);
debugPrint(e.message);
}
}
});
Expand Down
12 changes: 3 additions & 9 deletions lib/_model/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,15 @@ class Address with _$Address {
}

String miniString() {
return address.substring(0, 6) +
'[...]' +
address.substring(address.length - 6);
return '${address.substring(0, 6)}[...]${address.substring(address.length - 6)}';
}

String largeString() {
return address.substring(0, 10) +
'[...]' +
address.substring(address.length - 10);
return '${address.substring(0, 10)}[...]${address.substring(address.length - 10)}';
}

String toShortString() {
return address.substring(0, 5) +
'...' +
address.substring(address.length - 5);
return '${address.substring(0, 5)}...${address.substring(address.length - 5)}';
}

String getKindString() {
Expand Down
26 changes: 20 additions & 6 deletions lib/_model/bip329_label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Bip329Label with _$Bip329Label {
}) = _Bip329Label;
const Bip329Label._();

factory Bip329Label.fromJson(Map<String, dynamic> json) => _$Bip329LabelFromJson(json);
factory Bip329Label.fromJson(Map<String, dynamic> json) =>
_$Bip329LabelFromJson(json);

/// TAG LIKE LABELLING SYSTEM
/// To stay within the BIP329 standard and support multiple labels per ref:
Expand All @@ -57,7 +58,10 @@ class Bip329Label with _$Bip329Label {
}

extension Bip329LabelHelpers on Bip329Label {
static Future<(List<Bip329Label>?, Err?)> decryptRead(String fileName, String key) async {
static Future<(List<Bip329Label>?, Err?)> decryptRead(
String fileName,
String key,
) async {
final directory = await getApplicationDocumentsDirectory();
final file = File('${directory.path}/$fileName.export.bip329');
if (await file.exists()) {
Expand All @@ -71,16 +75,26 @@ extension Bip329LabelHelpers on Bip329Label {
final decryptedContents = _decrypt(encryptedContents, key);
final lines = LineSplitter.split(decryptedContents);
return (
lines.map((line) => Bip329Label.fromJson(jsonDecode(line) as Map<String, dynamic>)).toList(),
lines
.map(
(line) =>
Bip329Label.fromJson(jsonDecode(line) as Map<String, dynamic>),
)
.toList(),
null
);
}

static Future<Err?> encryptWrite(String fileName, List<Bip329Label> labels, String key) async {
static Future<Err?> encryptWrite(
String fileName,
List<Bip329Label> labels,
String key,
) async {
if (labels.isEmpty) return Err('No Labels To Write.');
final directory = await getApplicationDocumentsDirectory();
final file = File('${directory.path}/$fileName.export.bip329');
final dataToEncrypt = labels.map((label) => jsonEncode(label.toJson())).join('\n');
final dataToEncrypt =
labels.map((label) => jsonEncode(label.toJson())).join('\n');
final encryptedData = _encrypt(dataToEncrypt, key);
await file.writeAsString(encryptedData);
return null;
Expand All @@ -103,7 +117,7 @@ String _encrypt(String plainText, String key) {
final input = Uint8List.fromList(utf8.encode(plainText));
final encrypted = paddedBlockCipher.process(input);

return base64Encode(iv) + ',' + base64Encode(encrypted);
return '${base64Encode(iv)},${base64Encode(encrypted)}';
}

String _decrypt(String encryptedBase64Text, String key) {
Expand Down
7 changes: 6 additions & 1 deletion lib/_model/currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ class Currency with _$Currency {
required double? price,
required String shortName,
}) = _Currency;

factory Currency.fromJson(Map<String, dynamic> json) =>
_$CurrencyFromJson(json);
const Currency._();

factory Currency.fromJson(Map<String, dynamic> json) => _$CurrencyFromJson(json);
static int get satsInBtc => 100000000;
static int get btcDecimalPoints => 8;
static int get fiatDecimalPoints => 2;

String getSymbol() {
switch (name) {
Expand Down
16 changes: 6 additions & 10 deletions lib/_model/currency_new.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import 'package:bb_mobile/_model/currency.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'currency_new.freezed.dart';
part 'currency_new.g.dart';

const SATS_IN_BTC = 100000000;

const BTC_DECIMAL_POINTS = 8;
const FIAT_DECIMAL_POINTS = 2;

@freezed
class CurrencyNew with _$CurrencyNew {
const factory CurrencyNew({
Expand All @@ -27,16 +23,16 @@ int calcualteSats(double price, CurrencyNew currency) {
int sats;

if (currency.isFiat) {
final int oneBTCInSmallFiatUnit = ((currency.price ?? 0.0) * 100).toInt();
final int oneBTCInSmallFiatUnit = ((currency.price) * 100).toInt();
final int totalFiatSmallUnitsInvested = (price * 100).toInt();

final double btcBought =
totalFiatSmallUnitsInvested / oneBTCInSmallFiatUnit;
sats = (btcBought * SATS_IN_BTC).toInt();
sats = (btcBought * Currency.satsInBtc).toInt();
} else {
if (currency.code == btcCurrency.code ||
currency.code == lbtcCurrency.code) {
sats = (price * SATS_IN_BTC).toInt();
sats = (price * Currency.satsInBtc).toInt();
} else {
// Should be sats
sats = price.toInt();
Expand All @@ -47,8 +43,8 @@ int calcualteSats(double price, CurrencyNew currency) {
}

double getFiatValueFromSats(int sats, CurrencyNew fiatCurrency) {
final double oneBTCInFiat = fiatCurrency.price ?? 0.0;
final double oneSatInFiat = oneBTCInFiat / SATS_IN_BTC;
final double oneBTCInFiat = fiatCurrency.price;
final double oneSatInFiat = oneBTCInFiat / Currency.satsInBtc;
final double fiatValue = sats * oneSatInFiat;

return fiatValue;
Expand Down
10 changes: 6 additions & 4 deletions lib/_model/network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class ElectrumNetwork with _$ElectrumNetwork {

String getNetworkUrl(bool isTestnet, {bool split = false}) {
String url;
if (isTestnet)
if (isTestnet) {
url = testnet;
else
} else {
url = mainnet;
}

if (split) {
final spliturl = url.split('://');
Expand Down Expand Up @@ -97,10 +98,11 @@ class LiquidElectrumNetwork with _$LiquidElectrumNetwork {

String getNetworkUrl(bool isTestnet, {bool split = true}) {
String url;
if (isTestnet)
if (isTestnet) {
url = testnet;
else
} else {
url = mainnet;
}

// if (split) url = url.split('://')[1];

Expand Down
Loading