handle refund address support

This commit is contained in:
julian 2023-02-06 13:45:22 -06:00
parent b19a3dbbf8
commit 8061f0811d
2 changed files with 285 additions and 250 deletions

View file

@ -8,6 +8,7 @@ import 'package:stackwallet/pages/exchange_view/choose_from_stack_view.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_3_view.dart'; import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_3_view.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart'; import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart';
import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart';
import 'package:stackwallet/utilities/address_utils.dart'; import 'package:stackwallet/utilities/address_utils.dart';
import 'package:stackwallet/utilities/barcode_scanner_interface.dart'; import 'package:stackwallet/utilities/barcode_scanner_interface.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/clipboard_interface.dart';
@ -123,6 +124,10 @@ class _Step2ViewState extends ConsumerState<Step2View> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final supportsRefund =
ref.watch(currentExchangeNameStateProvider.state).state !=
MajesticBankExchange.exchangeName;
return Background( return Background(
child: Scaffold( child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background, backgroundColor: Theme.of(context).extension<StackColors>()!.background,
@ -217,8 +222,9 @@ class _Step2ViewState extends ConsumerState<Step2View> {
setState(() { setState(() {
enableNext = enableNext =
_toController.text.isNotEmpty && _toController.text.isNotEmpty &&
_refundController (_refundController
.text.isNotEmpty; .text.isNotEmpty ||
!supportsRefund);
}); });
} }
}); });
@ -291,8 +297,9 @@ class _Step2ViewState extends ConsumerState<Step2View> {
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text.isNotEmpty && .text.isNotEmpty &&
_refundController (_refundController.text
.text.isNotEmpty; .isNotEmpty ||
!supportsRefund);
}); });
}, },
child: const XIcon(), child: const XIcon(),
@ -318,8 +325,10 @@ class _Step2ViewState extends ConsumerState<Step2View> {
enableNext = _toController enableNext = _toController
.text .text
.isNotEmpty && .isNotEmpty &&
_refundController (_refundController
.text.isNotEmpty; .text
.isNotEmpty ||
!supportsRefund);
}); });
} }
}, },
@ -367,8 +376,9 @@ class _Step2ViewState extends ConsumerState<Step2View> {
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text.isNotEmpty && .text.isNotEmpty &&
_refundController (_refundController.text
.text.isNotEmpty; .isNotEmpty ||
!supportsRefund);
}); });
}); });
}, },
@ -396,8 +406,9 @@ class _Step2ViewState extends ConsumerState<Step2View> {
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text.isNotEmpty && .text.isNotEmpty &&
_refundController (_refundController.text
.text.isNotEmpty; .isNotEmpty ||
!supportsRefund);
}); });
} else { } else {
_toController.text = _toController.text =
@ -408,8 +419,9 @@ class _Step2ViewState extends ConsumerState<Step2View> {
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text.isNotEmpty && .text.isNotEmpty &&
_refundController (_refundController.text
.text.isNotEmpty; .isNotEmpty ||
!supportsRefund);
}); });
} }
} on PlatformException catch (e, s) { } on PlatformException catch (e, s) {
@ -440,6 +452,7 @@ class _Step2ViewState extends ConsumerState<Step2View> {
const SizedBox( const SizedBox(
height: 24, height: 24,
), ),
if (supportsRefund)
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -474,22 +487,25 @@ class _Step2ViewState extends ConsumerState<Step2View> {
.currentReceivingAddress; .currentReceivingAddress;
} }
setState(() { setState(() {
enableNext = _toController enableNext =
.text.isNotEmpty && _toController.text.isNotEmpty &&
_refundController.text.isNotEmpty; _refundController
.text.isNotEmpty;
}); });
}); });
} catch (e, s) { } catch (e, s) {
Logging.instance Logging.instance.log("$e\n$s",
.log("$e\n$s", level: LogLevel.Info); level: LogLevel.Info);
} }
}, },
), ),
], ],
), ),
if (supportsRefund)
const SizedBox( const SizedBox(
height: 4, height: 4,
), ),
if (supportsRefund)
ClipRRect( ClipRRect(
borderRadius: BorderRadius.circular( borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius, Constants.size.circularBorderRadius,
@ -546,7 +562,8 @@ class _Step2ViewState extends ConsumerState<Step2View> {
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text.isNotEmpty && .text
.isNotEmpty &&
_refundController _refundController
.text.isNotEmpty; .text.isNotEmpty;
}); });
@ -559,23 +576,27 @@ class _Step2ViewState extends ConsumerState<Step2View> {
onTap: () async { onTap: () async {
final ClipboardData? data = final ClipboardData? data =
await clipboard.getData( await clipboard.getData(
Clipboard.kTextPlain); Clipboard
.kTextPlain);
if (data?.text != null && if (data?.text != null &&
data!.text!.isNotEmpty) { data!
.text!.isNotEmpty) {
final content = final content =
data.text!.trim(); data.text!.trim();
_refundController.text = _refundController.text =
content; content;
model.refundAddress = model.refundAddress =
_refundController.text; _refundController
.text;
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text .text
.isNotEmpty && .isNotEmpty &&
_refundController _refundController
.text.isNotEmpty; .text
.isNotEmpty;
}); });
} }
}, },
@ -640,13 +661,15 @@ class _Step2ViewState extends ConsumerState<Step2View> {
if (results.isNotEmpty) { if (results.isNotEmpty) {
// auto fill address // auto fill address
_refundController.text = _refundController.text =
results["address"] ?? ""; results["address"] ??
"";
model.refundAddress = model.refundAddress =
_refundController.text; _refundController.text;
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text.isNotEmpty && .text
.isNotEmpty &&
_refundController _refundController
.text.isNotEmpty; .text.isNotEmpty;
}); });
@ -658,7 +681,8 @@ class _Step2ViewState extends ConsumerState<Step2View> {
setState(() { setState(() {
enableNext = _toController enableNext = _toController
.text.isNotEmpty && .text
.isNotEmpty &&
_refundController _refundController
.text.isNotEmpty; .text.isNotEmpty;
}); });
@ -679,9 +703,11 @@ class _Step2ViewState extends ConsumerState<Step2View> {
), ),
), ),
), ),
if (supportsRefund)
const SizedBox( const SizedBox(
height: 6, height: 6,
), ),
if (supportsRefund)
RoundedWhiteContainer( RoundedWhiteContainer(
child: Text( child: Text(
"In case something goes wrong during the exchange, we might need a refund address so we can return your coins back to you.", "In case something goes wrong during the exchange, we might need a refund address so we can return your coins back to you.",

View file

@ -7,9 +7,11 @@ import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_4_view.dart'; import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_4_view.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart'; import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart'; import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart';
import 'package:stackwallet/providers/exchange/current_exchange_name_state_provider.dart';
import 'package:stackwallet/providers/exchange/exchange_provider.dart'; import 'package:stackwallet/providers/exchange/exchange_provider.dart';
import 'package:stackwallet/providers/global/trades_service_provider.dart'; import 'package:stackwallet/providers/global/trades_service_provider.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart'; import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart';
import 'package:stackwallet/services/notifications_api.dart'; import 'package:stackwallet/services/notifications_api.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/clipboard_interface.dart';
@ -51,6 +53,10 @@ class _Step3ViewState extends ConsumerState<Step3View> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final supportsRefund =
ref.watch(currentExchangeNameStateProvider.state).state !=
MajesticBankExchange.exchangeName;
return Background( return Background(
child: Scaffold( child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background, backgroundColor: Theme.of(context).extension<StackColors>()!.background,
@ -174,9 +180,11 @@ class _Step3ViewState extends ConsumerState<Step3View> {
], ],
), ),
), ),
if (supportsRefund)
const SizedBox( const SizedBox(
height: 8, height: 8,
), ),
if (supportsRefund)
RoundedWhiteContainer( RoundedWhiteContainer(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -259,8 +267,9 @@ class _Step3ViewState extends ConsumerState<Step3View> {
addressTo: addressTo:
model.recipientAddress!, model.recipientAddress!,
extraId: null, extraId: null,
addressRefund: addressRefund: supportsRefund
model.refundAddress!, ? model.refundAddress!
: "",
refundExtraId: "", refundExtraId: "",
rateId: model.rateId, rateId: model.rateId,
reversed: model.reversed, reversed: model.reversed,