stack_wallet/lib/models/paynym/paynym_account.dart

91 lines
2.2 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'paynym_account_lite.dart';
import 'paynym_code.dart';
2022-12-21 16:17:53 +00:00
class PaynymAccount {
final String nymID;
final String nymName;
2023-04-25 21:06:12 +00:00
final bool segwit;
2022-12-21 16:17:53 +00:00
final List<PaynymCode> codes;
/// list of nymId
2022-12-21 23:24:08 +00:00
final List<PaynymAccountLite> followers;
2022-12-21 16:17:53 +00:00
/// list of nymId
2022-12-21 23:24:08 +00:00
final List<PaynymAccountLite> following;
2022-12-21 16:17:53 +00:00
PaynymCode get nonSegwitPaymentCode =>
codes.firstWhere((element) => !element.segwit);
2022-12-21 16:17:53 +00:00
PaynymAccount(
this.nymID,
this.nymName,
2023-04-25 21:06:12 +00:00
this.segwit,
2022-12-21 16:17:53 +00:00
this.codes,
this.followers,
this.following,
);
PaynymAccount.fromMap(Map<String, dynamic> map)
: nymID = map["nymID"] as String,
nymName = map["nymName"] as String,
2023-04-25 21:06:12 +00:00
segwit = map["segwit"] as bool,
2022-12-21 16:17:53 +00:00
codes = (map["codes"] as List<dynamic>)
.map((e) => PaynymCode.fromMap(Map<String, dynamic>.from(e as Map)))
.toList(),
2022-12-21 23:24:08 +00:00
followers = (map["followers"] as List<dynamic>)
2024-05-27 23:56:22 +00:00
.map(
(e) => PaynymAccountLite.fromMap(
Map<String, dynamic>.from(e as Map)),
)
2022-12-21 23:24:08 +00:00
.toList(),
following = (map["following"] as List<dynamic>)
2024-05-27 23:56:22 +00:00
.map(
(e) => PaynymAccountLite.fromMap(
Map<String, dynamic>.from(e as Map)),
)
2022-12-21 23:24:08 +00:00
.toList();
2022-12-21 16:17:53 +00:00
PaynymAccount copyWith({
String? nymID,
String? nymName,
2023-04-25 21:06:12 +00:00
bool? segwit,
List<PaynymCode>? codes,
List<PaynymAccountLite>? followers,
List<PaynymAccountLite>? following,
}) {
return PaynymAccount(
nymID ?? this.nymID,
nymName ?? this.nymName,
2023-04-25 21:06:12 +00:00
segwit ?? this.segwit,
codes ?? this.codes,
followers ?? this.followers,
following ?? this.following,
);
}
2022-12-21 16:17:53 +00:00
Map<String, dynamic> toMap() => {
"nymID": nymID,
"nymName": nymName,
2023-04-25 21:06:12 +00:00
"segwit": segwit,
2022-12-21 16:17:53 +00:00
"codes": codes.map((e) => e.toMap()),
2022-12-21 23:24:08 +00:00
"followers": followers.map((e) => e.toMap()),
"following": followers.map((e) => e.toMap()),
2022-12-21 16:17:53 +00:00
};
@override
String toString() {
return toMap().toString();
}
}