@@ -46,6 +46,7 @@ class ReapVoucherPage extends StatefulWidget {
46
46
}
47
47
48
48
class _ReapVoucherPageState extends State <ReapVoucherPage > {
49
+ late KeyringAccount _voucherKeyringAccount;
49
50
String ? _voucherAddress;
50
51
double ? _voucherBalance;
51
52
@@ -56,8 +57,8 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {
56
57
Log .d ('Fetching voucher data...' , 'ReapVoucherPage' );
57
58
final store = context.read <AppStore >();
58
59
59
- final voucherPair = await KeyringAccount .fromUri ('Voucher' , voucherUri);
60
- _voucherAddress = voucherPair .address (prefix: store.settings.endpoint.ss58 ?? 42 ).encode ();
60
+ _voucherKeyringAccount = await KeyringAccount .fromUri ('Voucher' , voucherUri);
61
+ _voucherAddress = _voucherKeyringAccount .address (prefix: store.settings.endpoint.ss58 ?? 42 ).encode ();
61
62
62
63
setState (() {});
63
64
@@ -96,12 +97,12 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {
96
97
@override
97
98
Widget build (BuildContext context) {
98
99
final l10n = context.l10n;
99
- final store = context.watch <AppStore >();
100
+ final store = context.read <AppStore >();
100
101
final h2Grey = context.titleLarge.copyWith (color: AppColors .encointerGrey);
101
102
final h4Grey = context.bodyLarge.copyWith (color: AppColors .encointerGrey);
102
103
103
104
final voucher = widget.voucher;
104
- final recipient = store.account.currentAddress;
105
+ final recipient = Address . decode ( store.account.currentAddress) ;
105
106
106
107
return Scaffold (
107
108
appBar: AppBar (title: Text (l10n.voucher)),
@@ -156,7 +157,7 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {
156
157
SubmitButton (
157
158
key: const Key (EWTestKeys .submitVoucher),
158
159
onPressed: _isReady
159
- ? (context) => _submitReapVoucher (context, voucher.voucherUri , voucher.cid, recipient)
160
+ ? (context) => _submitReapVoucher (context, _voucherKeyringAccount , voucher.cid, recipient)
160
161
: null ,
161
162
child: Row (
162
163
mainAxisAlignment: MainAxisAlignment .center,
@@ -175,24 +176,28 @@ class _ReapVoucherPageState extends State<ReapVoucherPage> {
175
176
176
177
Future <void > _submitReapVoucher (
177
178
BuildContext context,
178
- String voucherUri ,
179
+ KeyringAccount voucherKeyringAccount ,
179
180
CommunityIdentifier cid,
180
- String recipientAddress,
181
+ Address recipientAddress,
181
182
) async {
182
183
// Fixme, use proper threshold here: #589
183
184
if (_voucherBalance! < 0.04 ) return showRedeemFailedDialog (context, context.l10n.voucherBalanceTooLow);
184
185
185
- final res = await submitReapVoucher (widget.api, voucherUri, recipientAddress, cid);
186
-
187
- if (res['hash' ] == null ) {
188
- Log .d ('Error redeeming voucher: ${res ['error' ]}' , 'ReapVoucherPage' );
189
- await showRedeemFailedDialog (context, res['error' ] as String ? );
190
- } else {
191
- await VoucherDialogs .showRedeemSuccessDialog (
192
- context: context,
193
- onOK: () => Navigator .of (context).popUntil ((route) => route.isFirst),
194
- );
195
- }
186
+ await submitEncointerTransferAll (
187
+ context, context.read <AppStore >(), widget.api, voucherKeyringAccount, recipientAddress, cid,
188
+ // the voucher obviously has tokens in cid.
189
+ txPaymentAsset: cid,
190
+ onError: (report) async {
191
+ Log .d ('Error redeeming voucher: ${report .toJson ()}' , 'ReapVoucherPage' );
192
+ await showRedeemFailedDialog (context, report.toJson ().toString ());
193
+ },
194
+ onFinish: (context, report) async {
195
+ await VoucherDialogs .showRedeemSuccessDialog (
196
+ context: context,
197
+ onOK: () => Navigator .of (context).popUntil ((route) => route.isFirst),
198
+ );
199
+ },
200
+ );
196
201
}
197
202
198
203
Future <ChangeResult ?> _changeNetworkAndCommunityIfNeeded (
0 commit comments