Skip to content

Commit 56ff04f

Browse files
committed
move sendSignedData to signing_service file
1 parent 095237d commit 56ff04f

2 files changed

Lines changed: 41 additions & 40 deletions

File tree

app/lib/screens/signing/signing_mixin.dart

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import 'dart:convert';
21
import 'package:flutter/material.dart';
32
import 'package:flutter/services.dart';
4-
import 'package:http/http.dart' as http;
53
import 'package:threebotlogin/models/wallet.dart';
64
import 'package:threebotlogin/helpers/logger.dart';
75
import 'package:threebotlogin/services/signing_service.dart';
@@ -41,7 +39,26 @@ mixin SigningMixin<T extends StatefulWidget> on State<T> {
4139
);
4240
final destinationUrl = destUrlController.text.trim();
4341
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+
}
4562
}
4663
} catch (e) {
4764
logger.e('Failed to sign data: $e');
@@ -113,43 +130,6 @@ mixin SigningMixin<T extends StatefulWidget> on State<T> {
113130
}
114131
}
115132

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-
153133
Widget buildWalletSelector(List<Wallet> wallets) {
154134
return Column(
155135
crossAxisAlignment: CrossAxisAlignment.stretch,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import 'package:crypto/crypto.dart';
2+
import 'package:threebotlogin/helpers/logger.dart';
23
import 'package:threebotlogin/services/tfchain_service.dart';
4+
import 'package:http/http.dart' as http;
5+
import 'dart:convert';
36

47
Future<String> md5Sign(
58
{required String data, required String walletSecretSeed}) async {
69
final contentHash = md5.convert(data.codeUnits).toString();
710
final signer = await getSignerFromSeed(walletSecretSeed);
811
return signer.sign(contentHash);
912
}
13+
14+
Future<bool> sendSignedData(String destUrl, String signature) async {
15+
try {
16+
final response = await http.post(
17+
Uri.parse(destUrl),
18+
headers: {'Content-Type': 'application/json'},
19+
body: json.encode({'signature': signature}),
20+
);
21+
22+
if (response.statusCode != 200) {
23+
throw Exception('Failed to send signature to destination');
24+
}
25+
return true;
26+
} catch (e) {
27+
logger.e('Error sending signature to destination: $e');
28+
return false;
29+
}
30+
}

0 commit comments

Comments
 (0)