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

Upgrades from stack #27

Merged
merged 7 commits into from
May 5, 2023
Merged
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
41 changes: 30 additions & 11 deletions lib/pages/exchange_view/exchange_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_svg/svg.dart';
import 'package:intl/intl.dart';
import 'package:isar/isar.dart';
import 'package:stackduo/models/exchange/aggregate_currency.dart';
import 'package:stackduo/models/exchange/incomplete_exchange.dart';
Expand Down Expand Up @@ -148,10 +147,22 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
return null;
}
try {
final numFromLocalised = NumberFormat.decimalPattern(
ref.read(localeServiceChangeNotifierProvider).locale)
.parse(value);
return Decimal.tryParse(numFromLocalised.toString());
// wtf Dart?????
// This turns "99999999999999999999" into 100000000000000000000.0
// final numFromLocalised = NumberFormat.decimalPattern(
// ref.read(localeServiceChangeNotifierProvider).locale)
// .parse(value);
// return Decimal.tryParse(numFromLocalised.toString());

try {
return Decimal.parse(value);
} catch (_) {
try {
return Decimal.parse(value.replaceAll(",", "."));
} catch (_) {
rethrow;
}
}
} catch (_) {
return null;
}
Expand Down Expand Up @@ -941,12 +952,20 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
onChanged: onRateTypeChanged,
),
),
Padding(
padding: EdgeInsets.only(top: isDesktop ? 20 : 12),
child: ExchangeProviderOptions(
fixedRate: rateType == ExchangeRateType.fixed,
reversed: ref.watch(efReversedProvider),
),
AnimatedSize(
duration: const Duration(milliseconds: 300),
child: ref.watch(efSendAmountProvider) == null &&
ref.watch(efReceiveAmountProvider) == null
? const SizedBox(
height: 0,
)
: Padding(
padding: EdgeInsets.only(top: isDesktop ? 20 : 12),
child: ExchangeProviderOptions(
fixedRate: rateType == ExchangeRateType.fixed,
reversed: ref.watch(efReversedProvider),
),
),
),
SizedBox(
height: isDesktop ? 20 : 12,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ class _DesktopExchangeViewState extends ConsumerState<DesktopExchangeView> {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Expanded(
child: RoundedWhiteContainer(
padding: EdgeInsets.all(24),
child: ExchangeForm(),
Expanded(
child: ListView(
children: const [
RoundedWhiteContainer(
padding: EdgeInsets.all(24),
child: ExchangeForm(),
),
],
),
),
const SizedBox(
Expand Down
4 changes: 2 additions & 2 deletions lib/providers/exchange/exchange_form_state_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final efSendAmountStringProvider = StateProvider<String>((ref) {
if (refreshing && reversed) {
return "-";
} else {
return ref.watch(efSendAmountProvider)?.toStringAsFixed(8) ?? "";
return ref.watch(efSendAmountProvider)?.toString() ?? "";
}
});
final efReceiveAmountStringProvider = StateProvider<String>((ref) {
Expand All @@ -44,7 +44,7 @@ final efReceiveAmountStringProvider = StateProvider<String>((ref) {
if (refreshing && reversed == false) {
return "-";
} else {
return ref.watch(efReceiveAmountProvider)?.toStringAsFixed(8) ?? "";
return ref.watch(efReceiveAmountProvider)?.toString() ?? "";
}
});

Expand Down
12 changes: 9 additions & 3 deletions lib/services/exchange/change_now/change_now_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@ class ChangeNowAPI {
body: jsonEncode(body),
);

final parsed = jsonDecode(response.body);
try {
final parsed = jsonDecode(response.body);

return parsed;
return parsed;
} catch (_) {
Logging.instance.log("ChangeNOW api failed to parse: ${response.body}",
level: LogLevel.Error);
rethrow;
}
} catch (e, s) {
Logging.instance
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
.log("_makePostRequest($uri) threw: $e\n$s", level: LogLevel.Error);
rethrow;
}
}
Expand Down
28 changes: 25 additions & 3 deletions lib/services/exchange/trocador/trocador_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,32 @@ abstract class TrocadorAPI {
final json = await _makeGetRequest(uri);
final map = Map<String, dynamic>.from(json as Map);

return ExchangeResponse(value: TrocadorTradeNew.fromMap(map));
try {
return ExchangeResponse(value: TrocadorTradeNew.fromMap(map));
} catch (e, s) {
String error = map["error"] as String? ?? json.toString();
if (error ==
"trade could not be generated, some unknown error happened") {
error =
"This trade couldn't be completed. Please select another provider.";
}

Logging.instance.log(
"_getNewTrade failed to parse response: $json\n$e\n$s",
level: LogLevel.Error,
);
return ExchangeResponse(
exception: ExchangeException(
error,
ExchangeExceptionType.serializeResponseError,
),
);
}
} catch (e, s) {
Logging.instance
.log("_getNewTrade exception: $e\n$s", level: LogLevel.Error);
Logging.instance.log(
"_getNewTrade exception: $e\n$s",
level: LogLevel.Error,
);
return ExchangeResponse(
exception: ExchangeException(
e.toString(),
Expand Down
68 changes: 60 additions & 8 deletions lib/widgets/trocador_kyc_rating_info.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:stackduo/utilities/text_styles.dart';
import 'package:stackduo/widgets/conditional_parent.dart';
import 'package:stackduo/widgets/desktop/desktop_dialog.dart';
import 'package:stackduo/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackduo/widgets/desktop/primary_button.dart';
import 'package:stackduo/widgets/desktop/secondary_button.dart';
import 'package:stackduo/widgets/exchange/trocador/trocador_kyc_icon.dart';
import 'package:stackduo/widgets/exchange/trocador/trocador_rating_type_enum.dart';
Expand All @@ -12,9 +15,56 @@ class TrocadorKYCRatingInfo extends StatelessWidget {
@override
Widget build(BuildContext context) {
final small = MediaQuery.of(context).size.width <= 500;

return ConditionalParent(
condition: !small,
builder: (child) => child,
builder: (child) => DesktopDialog(
maxHeight: double.infinity,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 32),
child: Text(
"Trocador KYC Rating",
style: STextStyles.desktopH3(context),
),
),
const DesktopDialogCloseButton(),
],
),
const SizedBox(
height: 16,
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 32,
),
child: child,
),
Padding(
padding: const EdgeInsets.all(32),
child: Row(
children: [
const Spacer(),
const SizedBox(
width: 16,
),
Expanded(
child: PrimaryButton(
label: "Ok",
buttonHeight: ButtonHeight.l,
onPressed: Navigator.of(context).pop,
),
),
],
),
)
],
),
),
child: ConditionalParent(
condition: small,
builder: (child) {
Expand All @@ -24,13 +74,15 @@ class TrocadorKYCRatingInfo extends StatelessWidget {
},
child: Column(
children: [
Text(
"Trocador KYC Rating",
style: STextStyles.pageTitleH2(context),
),
const SizedBox(
height: 16,
),
if (small)
Text(
"Trocador KYC Rating",
style: STextStyles.pageTitleH2(context),
),
if (small)
const SizedBox(
height: 16,
),
const _Rating(
kycType: TrocadorKYCType.a,
text: "Never asks for user verification.",
Expand Down