ignore invalid account data
This commit is contained in:
parent
3754bc2feb
commit
401b527714
1 changed files with 13 additions and 22 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import "dart:convert";
|
||||
|
||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter/foundation.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/models/account_data.dart";
|
||||
|
||||
|
|
@ -9,11 +10,16 @@ class AccountDataController extends Notifier<AccountData> {
|
|||
AccountData build() => .new();
|
||||
|
||||
void update(IMap<String, IMap<String, dynamic>> newAccountData) =>
|
||||
state = .fromJson({
|
||||
...json.decode(json.encode(state.toJson())),
|
||||
...newAccountData
|
||||
.map((key, value) => MapEntry(key, value["content"]))
|
||||
.unlock,
|
||||
state = newAccountData.entries.fold(state, (data, entry) {
|
||||
try {
|
||||
return .fromJson({
|
||||
...json.decode(json.encode(data.toJson())),
|
||||
entry.key: entry.value["content"],
|
||||
});
|
||||
} catch (error) {
|
||||
debugPrint("Ignoring invalid ${entry.key} account data: $error");
|
||||
return data;
|
||||
}
|
||||
});
|
||||
|
||||
static final provider = NotifierProvider<AccountDataController, AccountData>(
|
||||
|
|
|
|||
Loading…
Reference in a new issue