|
1 | | -import 'dart:convert'; |
2 | 1 | import 'package:flutter/material.dart'; |
3 | 2 | import 'package:flutter/services.dart'; |
4 | | -import 'package:http/http.dart' as http; |
5 | 3 | import 'package:threebotlogin/models/wallet.dart'; |
6 | 4 | import 'package:threebotlogin/helpers/logger.dart'; |
7 | 5 | import 'package:threebotlogin/services/signing_service.dart'; |
@@ -41,7 +39,26 @@ mixin SigningMixin<T extends StatefulWidget> on State<T> { |
41 | 39 | ); |
42 | 40 | final destinationUrl = destUrlController.text.trim(); |
43 | 41 | if (destinationUrl.isNotEmpty) { |
44 | | - await sendSignedData(destinationUrl, signedData!); |
| 42 | + final success = await sendSignedData(destinationUrl, signedData!); |
| 43 | + if (mounted) { |
| 44 | + ScaffoldMessenger.of(context).showSnackBar( |
| 45 | + SnackBar( |
| 46 | + content: Text( |
| 47 | + success |
| 48 | + ? 'Signature sent successfully' |
| 49 | + : 'Failed to send signature to destination', |
| 50 | + style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 51 | + color: success |
| 52 | + ? Theme.of(context).colorScheme.onPrimaryContainer |
| 53 | + : Theme.of(context).colorScheme.onErrorContainer, |
| 54 | + ), |
| 55 | + ), |
| 56 | + backgroundColor: success |
| 57 | + ? Theme.of(context).colorScheme.primary |
| 58 | + : Theme.of(context).colorScheme.error, |
| 59 | + ), |
| 60 | + ); |
| 61 | + } |
45 | 62 | } |
46 | 63 | } catch (e) { |
47 | 64 | logger.e('Failed to sign data: $e'); |
@@ -113,43 +130,6 @@ mixin SigningMixin<T extends StatefulWidget> on State<T> { |
113 | 130 | } |
114 | 131 | } |
115 | 132 |
|
116 | | - Future<void> sendSignedData(String destUrl, String signature) async { |
117 | | - try { |
118 | | - final response = await http.post( |
119 | | - Uri.parse(destUrl), |
120 | | - headers: {'Content-Type': 'application/json'}, |
121 | | - body: json.encode({'signature': signature}), |
122 | | - ); |
123 | | - |
124 | | - if (response.statusCode != 200) { |
125 | | - throw Exception('Failed to send signature to destination'); |
126 | | - } |
127 | | - |
128 | | - if (mounted) { |
129 | | - ScaffoldMessenger.of(context).showSnackBar( |
130 | | - SnackBar( |
131 | | - content: Text('Signature sent successfully', |
132 | | - style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
133 | | - color: Theme.of(context).colorScheme.onPrimaryContainer)), |
134 | | - backgroundColor: Theme.of(context).colorScheme.primary, |
135 | | - ), |
136 | | - ); |
137 | | - } |
138 | | - } catch (e) { |
139 | | - logger.e('Error sending signature to destination: $e'); |
140 | | - if (mounted) { |
141 | | - ScaffoldMessenger.of(context).showSnackBar( |
142 | | - SnackBar( |
143 | | - content: Text('Failed to send signature to destination', |
144 | | - style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
145 | | - color: Theme.of(context).colorScheme.onErrorContainer)), |
146 | | - backgroundColor: Theme.of(context).colorScheme.error, |
147 | | - ), |
148 | | - ); |
149 | | - } |
150 | | - } |
151 | | - } |
152 | | - |
153 | 133 | Widget buildWalletSelector(List<Wallet> wallets) { |
154 | 134 | return Column( |
155 | 135 | crossAxisAlignment: CrossAxisAlignment.stretch, |
|
0 commit comments