Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: subscribing on wallets #44

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ mixin TonWalletRepositoryImpl implements TonWalletRepository {
Future<void> updateSubscriptions(List<TonWalletAsset> assets) async {
final last = lastUpdatedAssets;
final toSubscribe = <TonWalletAsset>[];
final toUnsubscribe = <TonWalletAsset>[];
final toUnsubscribe = <TonWallet>[];

// Stop last created operation if possible
final oldOperation = _lastOperation;
Expand All @@ -183,11 +183,11 @@ mixin TonWalletRepositoryImpl implements TonWalletRepository {
if (last != null) {
toUnsubscribe.addAll(
// pick all elements from old list, which is not contains in a new list
last.where((l) => !assets.any((a) => a.address == l.address)),
wallets.where((l) => !assets.any((a) => a.address == l.address)),
);
toSubscribe.addAll(
// pick all elements from new list, which is not contains in old list
assets.where((a) => !last.any((l) => l.address == a.address)),
assets.where((a) => !wallets.any((l) => l.address == a.address)),
);
} else {
toSubscribe.addAll(assets);
Expand All @@ -197,8 +197,6 @@ mixin TonWalletRepositoryImpl implements TonWalletRepository {
unsubscribe(asset.address);
}

lastUpdatedAssets = assets;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't updatelastUpdatedAssets, then you mustn't use last != null expression. Imho, it's better to remove lastUpdatedAssets, trying to use wallets for all checks. Look through the same behaviour in TokenWalletrepositoryImpl


late CancelableOperation<void> operation;

operation = CancelableOperation.fromFuture(() async {
Expand All @@ -217,6 +215,7 @@ mixin TonWalletRepositoryImpl implements TonWalletRepository {
// stop subscribing.
if (operation.isCanceled) return;
}
lastUpdatedAssets = assets;
}());
_lastOperation = operation;

Expand Down
Loading