add follower/following entity

This commit is contained in:
julian 2022-12-21 17:24:08 -06:00
parent 7631d3f3c6
commit b11bd0c20c
4 changed files with 63 additions and 30 deletions

View file

@ -1,3 +1,4 @@
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
import 'package:stackwallet/models/paynym/paynym_code.dart';
class PaynymAccount {
@ -7,10 +8,10 @@ class PaynymAccount {
final List<PaynymCode> codes;
/// list of nymId
final List<String> followers;
final List<PaynymAccountLite> followers;
/// list of nymId
final List<String> following;
final List<PaynymAccountLite> following;
PaynymAccount(
this.nymID,
@ -26,27 +27,21 @@ class PaynymAccount {
codes = (map["codes"] as List<dynamic>)
.map((e) => PaynymCode.fromMap(Map<String, dynamic>.from(e as Map)))
.toList(),
followers = [],
following = [] {
final f1 = map["followers"] as List<dynamic>;
for (final item in f1) {
followers.add(Map<String, dynamic>.from(item as Map)["nymId"] as String);
}
final f2 = map["following"] as List<dynamic>;
for (final item in f2) {
final nymId = Map<String, dynamic>.from(item as Map)["nymId"] as String;
print(nymId + "DDDDDDDDDDDDD");
following.add(nymId);
}
}
followers = (map["followers"] as List<dynamic>)
.map((e) =>
PaynymAccountLite.fromMap(Map<String, dynamic>.from(e as Map)))
.toList(),
following = (map["following"] as List<dynamic>)
.map((e) =>
PaynymAccountLite.fromMap(Map<String, dynamic>.from(e as Map)))
.toList();
Map<String, dynamic> toMap() => {
"nymID": nymID,
"nymName": nymName,
"codes": codes.map((e) => e.toMap()),
"followers": followers.map((e) => {"nymId": e}).toList(),
"following": followers.map((e) => {"nymId": e}).toList(),
"followers": followers.map((e) => e.toMap()),
"following": followers.map((e) => e.toMap()),
};
@override

View file

@ -0,0 +1,31 @@
class PaynymAccountLite {
final String nymId;
final String nymName;
final String code;
final bool segwit;
PaynymAccountLite(
this.nymId,
this.nymName,
this.code,
this.segwit,
);
PaynymAccountLite.fromMap(Map<String, dynamic> map)
: nymId = map["nymId"] as String,
nymName = map["nymName"] as String,
code = map["code"] as String,
segwit = map["segwit"] as bool;
Map<String, dynamic> toMap() => {
"nymId": nymId,
"nymName": nymName,
"code": code,
"segwit": segwit,
};
@override
String toString() {
return toMap().toString();
}
}

View file

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/paynym/paynym_home_view.dart';
import 'package:stackwallet/pages/paynym/subwidgets/paynym_bot.dart';
@ -154,11 +155,14 @@ class _PaynymFollowToggleButtonState
context: context,
),
);
ref
.read(myPaynymAccountStateProvider.state)
.state!
.following
.add(followedAccount.codes.first.code);
ref.read(myPaynymAccountStateProvider.state).state!.following.add(
PaynymAccountLite(
followedAccount.nymID,
followedAccount.nymName,
followedAccount.codes.first.code,
followedAccount.codes.first.segwit,
),
);
setState(() {
isFollowing = true;
@ -232,7 +236,7 @@ class _PaynymFollowToggleButtonState
.read(myPaynymAccountStateProvider.state)
.state!
.following
.remove(followedAccount.codes.first.code);
.removeWhere((e) => e.nymId == followedAccount.nymID);
setState(() {
isFollowing = false;
@ -265,7 +269,8 @@ class _PaynymFollowToggleButtonState
.read(myPaynymAccountStateProvider.state)
.state!
.following
.contains(widget.paymentCodeStringToFollow);
.where((e) => e.code == widget.paymentCodeStringToFollow)
.isNotEmpty;
super.initState();
}

View file

@ -11,6 +11,7 @@ import 'package:stackwallet/services/coins/coin_paynym_extension.dart';
import 'package:stackwallet/services/coins/dogecoin/dogecoin_wallet.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/loading_indicator.dart';
@ -124,15 +125,16 @@ class _WalletNavigationBarState extends State<WalletNavigationBar> {
.read(paynymAPIProvider)
.nym(code.toString());
Logging.instance.log(
"my nym account: $account",
level: LogLevel.Info,
);
if (mounted) {
Navigator.of(context).pop();
// check if account exists and for matching code to see if claimed
if (account != null &&
account.codes
.where((e) =>
e.code == code.toString() && e.claimed)
.isNotEmpty) {
if (account != null && account.codes.first.claimed) {
ref.read(myPaynymAccountStateProvider.state).state =
account;