diff --git a/lib/models/paynym/created_paynym.dart b/lib/models/paynym/created_paynym.dart new file mode 100644 index 000000000..4efdcb85b --- /dev/null +++ b/lib/models/paynym/created_paynym.dart @@ -0,0 +1,35 @@ +class CreatedPaynym { + final bool claimed; + final String nymAvatar; + final String? nymId; + final String? nymName; + final String? token; + + CreatedPaynym( + this.claimed, + this.nymAvatar, + this.nymId, + this.nymName, + this.token, + ); + + CreatedPaynym.fromMap(Map map) + : claimed = map["claimed"] as bool, + nymAvatar = map["nymAvatar"] as String, + nymId = map["nymId"] as String?, + nymName = map["nymName"] as String?, + token = map["token"] as String?; + + Map toMap() => { + "claimed": claimed, + "nymAvatar": nymAvatar, + "nymId": nymId, + "nymName": nymName, + "token": token, + }; + + @override + String toString() { + return toMap().toString(); + } +} diff --git a/lib/utilities/paynym_api.dart b/lib/utilities/paynym_api.dart index 9cc7d42e9..e2ef33a96 100644 --- a/lib/utilities/paynym_api.dart +++ b/lib/utilities/paynym_api.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:http/http.dart' as http; +import 'package:stackwallet/models/paynym/created_paynym.dart'; class PaynymAPI { static const String baseURL = "https://paynym.is/api"; @@ -73,8 +74,9 @@ class PaynymAPI { // // // ------ - Future> create(String code) async { - return _post("/create", {"code": code}); + Future create(String code) async { + final map = await _post("/create", {"code": code}); + return CreatedPaynym.fromMap(map); } // ### `/api/v1/token`