mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-23 02:54:30 +00:00
commit
70f474fd82
6 changed files with 134 additions and 31 deletions
|
@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:stackwallet/models/exchange/aggregate_currency.dart';
|
import 'package:stackwallet/models/exchange/aggregate_currency.dart';
|
||||||
import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
|
import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
|
||||||
|
@ -152,10 +151,22 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final numFromLocalised = NumberFormat.decimalPattern(
|
// wtf Dart?????
|
||||||
ref.read(localeServiceChangeNotifierProvider).locale)
|
// This turns "99999999999999999999" into 100000000000000000000.0
|
||||||
.parse(value);
|
// final numFromLocalised = NumberFormat.decimalPattern(
|
||||||
return Decimal.tryParse(numFromLocalised.toString());
|
// 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 (_) {
|
} catch (_) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -953,12 +964,20 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
onChanged: onRateTypeChanged,
|
onChanged: onRateTypeChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
AnimatedSize(
|
||||||
padding: EdgeInsets.only(top: isDesktop ? 20 : 12),
|
duration: const Duration(milliseconds: 300),
|
||||||
child: ExchangeProviderOptions(
|
child: ref.watch(efSendAmountProvider) == null &&
|
||||||
fixedRate: rateType == ExchangeRateType.fixed,
|
ref.watch(efReceiveAmountProvider) == null
|
||||||
reversed: ref.watch(efReversedProvider),
|
? const SizedBox(
|
||||||
),
|
height: 0,
|
||||||
|
)
|
||||||
|
: Padding(
|
||||||
|
padding: EdgeInsets.only(top: isDesktop ? 20 : 12),
|
||||||
|
child: ExchangeProviderOptions(
|
||||||
|
fixedRate: rateType == ExchangeRateType.fixed,
|
||||||
|
reversed: ref.watch(efReversedProvider),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: isDesktop ? 20 : 12,
|
height: isDesktop ? 20 : 12,
|
||||||
|
|
|
@ -150,10 +150,14 @@ class _DesktopExchangeViewState extends ConsumerState<DesktopExchangeView> {
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Expanded(
|
Expanded(
|
||||||
child: RoundedWhiteContainer(
|
child: ListView(
|
||||||
padding: EdgeInsets.all(24),
|
children: const [
|
||||||
child: ExchangeForm(),
|
RoundedWhiteContainer(
|
||||||
|
padding: EdgeInsets.all(24),
|
||||||
|
child: ExchangeForm(),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
|
|
|
@ -34,7 +34,7 @@ final efSendAmountStringProvider = StateProvider<String>((ref) {
|
||||||
if (refreshing && reversed) {
|
if (refreshing && reversed) {
|
||||||
return "-";
|
return "-";
|
||||||
} else {
|
} else {
|
||||||
return ref.watch(efSendAmountProvider)?.toStringAsFixed(8) ?? "";
|
return ref.watch(efSendAmountProvider)?.toString() ?? "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final efReceiveAmountStringProvider = StateProvider<String>((ref) {
|
final efReceiveAmountStringProvider = StateProvider<String>((ref) {
|
||||||
|
@ -44,7 +44,7 @@ final efReceiveAmountStringProvider = StateProvider<String>((ref) {
|
||||||
if (refreshing && reversed == false) {
|
if (refreshing && reversed == false) {
|
||||||
return "-";
|
return "-";
|
||||||
} else {
|
} else {
|
||||||
return ref.watch(efReceiveAmountProvider)?.toStringAsFixed(8) ?? "";
|
return ref.watch(efReceiveAmountProvider)?.toString() ?? "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -100,12 +100,18 @@ class ChangeNowAPI {
|
||||||
body: jsonEncode(body),
|
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) {
|
} catch (e, s) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
.log("_makePostRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,10 +302,32 @@ abstract class TrocadorAPI {
|
||||||
final json = await _makeGetRequest(uri);
|
final json = await _makeGetRequest(uri);
|
||||||
final map = Map<String, dynamic>.from(json as Map);
|
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) {
|
} catch (e, s) {
|
||||||
Logging.instance
|
Logging.instance.log(
|
||||||
.log("_getNewTrade exception: $e\n$s", level: LogLevel.Error);
|
"_getNewTrade exception: $e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
return ExchangeResponse(
|
return ExchangeResponse(
|
||||||
exception: ExchangeException(
|
exception: ExchangeException(
|
||||||
e.toString(),
|
e.toString(),
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
||||||
|
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
|
||||||
|
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
import 'package:stackwallet/widgets/exchange/trocador/trocador_kyc_icon.dart';
|
import 'package:stackwallet/widgets/exchange/trocador/trocador_kyc_icon.dart';
|
||||||
import 'package:stackwallet/widgets/exchange/trocador/trocador_rating_type_enum.dart';
|
import 'package:stackwallet/widgets/exchange/trocador/trocador_rating_type_enum.dart';
|
||||||
|
@ -12,9 +15,56 @@ class TrocadorKYCRatingInfo extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final small = MediaQuery.of(context).size.width <= 500;
|
final small = MediaQuery.of(context).size.width <= 500;
|
||||||
|
|
||||||
return ConditionalParent(
|
return ConditionalParent(
|
||||||
condition: !small,
|
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(
|
child: ConditionalParent(
|
||||||
condition: small,
|
condition: small,
|
||||||
builder: (child) {
|
builder: (child) {
|
||||||
|
@ -24,13 +74,15 @@ class TrocadorKYCRatingInfo extends StatelessWidget {
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
if (small)
|
||||||
"Trocador KYC Rating",
|
Text(
|
||||||
style: STextStyles.pageTitleH2(context),
|
"Trocador KYC Rating",
|
||||||
),
|
style: STextStyles.pageTitleH2(context),
|
||||||
const SizedBox(
|
),
|
||||||
height: 16,
|
if (small)
|
||||||
),
|
const SizedBox(
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
const _Rating(
|
const _Rating(
|
||||||
kycType: TrocadorKYCType.a,
|
kycType: TrocadorKYCType.a,
|
||||||
text: "Never asks for user verification.",
|
text: "Never asks for user verification.",
|
||||||
|
|
Loading…
Reference in a new issue