mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
add follower/following entity
This commit is contained in:
parent
7631d3f3c6
commit
b11bd0c20c
4 changed files with 63 additions and 30 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:stackwallet/models/paynym/paynym_account_lite.dart';
|
||||||
import 'package:stackwallet/models/paynym/paynym_code.dart';
|
import 'package:stackwallet/models/paynym/paynym_code.dart';
|
||||||
|
|
||||||
class PaynymAccount {
|
class PaynymAccount {
|
||||||
|
@ -7,10 +8,10 @@ class PaynymAccount {
|
||||||
final List<PaynymCode> codes;
|
final List<PaynymCode> codes;
|
||||||
|
|
||||||
/// list of nymId
|
/// list of nymId
|
||||||
final List<String> followers;
|
final List<PaynymAccountLite> followers;
|
||||||
|
|
||||||
/// list of nymId
|
/// list of nymId
|
||||||
final List<String> following;
|
final List<PaynymAccountLite> following;
|
||||||
|
|
||||||
PaynymAccount(
|
PaynymAccount(
|
||||||
this.nymID,
|
this.nymID,
|
||||||
|
@ -26,27 +27,21 @@ class PaynymAccount {
|
||||||
codes = (map["codes"] as List<dynamic>)
|
codes = (map["codes"] as List<dynamic>)
|
||||||
.map((e) => PaynymCode.fromMap(Map<String, dynamic>.from(e as Map)))
|
.map((e) => PaynymCode.fromMap(Map<String, dynamic>.from(e as Map)))
|
||||||
.toList(),
|
.toList(),
|
||||||
followers = [],
|
followers = (map["followers"] as List<dynamic>)
|
||||||
following = [] {
|
.map((e) =>
|
||||||
final f1 = map["followers"] as List<dynamic>;
|
PaynymAccountLite.fromMap(Map<String, dynamic>.from(e as Map)))
|
||||||
for (final item in f1) {
|
.toList(),
|
||||||
followers.add(Map<String, dynamic>.from(item as Map)["nymId"] as String);
|
following = (map["following"] as List<dynamic>)
|
||||||
}
|
.map((e) =>
|
||||||
|
PaynymAccountLite.fromMap(Map<String, dynamic>.from(e as Map)))
|
||||||
final f2 = map["following"] as List<dynamic>;
|
.toList();
|
||||||
for (final item in f2) {
|
|
||||||
final nymId = Map<String, dynamic>.from(item as Map)["nymId"] as String;
|
|
||||||
print(nymId + "DDDDDDDDDDDDD");
|
|
||||||
following.add(nymId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toMap() => {
|
Map<String, dynamic> toMap() => {
|
||||||
"nymID": nymID,
|
"nymID": nymID,
|
||||||
"nymName": nymName,
|
"nymName": nymName,
|
||||||
"codes": codes.map((e) => e.toMap()),
|
"codes": codes.map((e) => e.toMap()),
|
||||||
"followers": followers.map((e) => {"nymId": e}).toList(),
|
"followers": followers.map((e) => e.toMap()),
|
||||||
"following": followers.map((e) => {"nymId": e}).toList(),
|
"following": followers.map((e) => e.toMap()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
31
lib/models/paynym/paynym_account_lite.dart
Normal file
31
lib/models/paynym/paynym_account_lite.dart
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.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/notifications/show_flush_bar.dart';
|
||||||
import 'package:stackwallet/pages/paynym/paynym_home_view.dart';
|
import 'package:stackwallet/pages/paynym/paynym_home_view.dart';
|
||||||
import 'package:stackwallet/pages/paynym/subwidgets/paynym_bot.dart';
|
import 'package:stackwallet/pages/paynym/subwidgets/paynym_bot.dart';
|
||||||
|
@ -154,11 +155,14 @@ class _PaynymFollowToggleButtonState
|
||||||
context: context,
|
context: context,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
ref
|
ref.read(myPaynymAccountStateProvider.state).state!.following.add(
|
||||||
.read(myPaynymAccountStateProvider.state)
|
PaynymAccountLite(
|
||||||
.state!
|
followedAccount.nymID,
|
||||||
.following
|
followedAccount.nymName,
|
||||||
.add(followedAccount.codes.first.code);
|
followedAccount.codes.first.code,
|
||||||
|
followedAccount.codes.first.segwit,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
isFollowing = true;
|
isFollowing = true;
|
||||||
|
@ -232,7 +236,7 @@ class _PaynymFollowToggleButtonState
|
||||||
.read(myPaynymAccountStateProvider.state)
|
.read(myPaynymAccountStateProvider.state)
|
||||||
.state!
|
.state!
|
||||||
.following
|
.following
|
||||||
.remove(followedAccount.codes.first.code);
|
.removeWhere((e) => e.nymId == followedAccount.nymID);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
isFollowing = false;
|
isFollowing = false;
|
||||||
|
@ -265,7 +269,8 @@ class _PaynymFollowToggleButtonState
|
||||||
.read(myPaynymAccountStateProvider.state)
|
.read(myPaynymAccountStateProvider.state)
|
||||||
.state!
|
.state!
|
||||||
.following
|
.following
|
||||||
.contains(widget.paymentCodeStringToFollow);
|
.where((e) => e.code == widget.paymentCodeStringToFollow)
|
||||||
|
.isNotEmpty;
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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/services/coins/dogecoin/dogecoin_wallet.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.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/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||||
|
@ -124,15 +125,16 @@ class _WalletNavigationBarState extends State<WalletNavigationBar> {
|
||||||
.read(paynymAPIProvider)
|
.read(paynymAPIProvider)
|
||||||
.nym(code.toString());
|
.nym(code.toString());
|
||||||
|
|
||||||
|
Logging.instance.log(
|
||||||
|
"my nym account: $account",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
// check if account exists and for matching code to see if claimed
|
// check if account exists and for matching code to see if claimed
|
||||||
if (account != null &&
|
if (account != null && account.codes.first.claimed) {
|
||||||
account.codes
|
|
||||||
.where((e) =>
|
|
||||||
e.code == code.toString() && e.claimed)
|
|
||||||
.isNotEmpty) {
|
|
||||||
ref.read(myPaynymAccountStateProvider.state).state =
|
ref.read(myPaynymAccountStateProvider.state).state =
|
||||||
account;
|
account;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue