Skip to content

Commit

Permalink
Merge branch 'master' into f-droid
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Dec 8, 2023
2 parents 641b845 + 28a6343 commit ce0c3f5
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
28 changes: 27 additions & 1 deletion app/lib/service/substrate_api/encointer/encointer_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class EncointerApi {
getReputations();
getMeetupTimeOverride();
store.encointer.communityAccount?.getNumberOfNewbieTicketsForBootstrapper();
store.encointer.account?.getNumberOfNewbieTicketsForReputable();
}

/// Queries the Scheduler pallet: encointerScheduler.currentPhase().
Expand Down Expand Up @@ -476,7 +477,7 @@ class EncointerApi {

if (cid != null && pubKey != null && pubKey.isNotEmpty) {
final address = store.account.currentAddress;
final data = await getAggregatedAccountData(cid, pubKey);
final data = await pollAggregatedAccountDataUntilNextPhase(phase, cid, pubKey);
store.encointer.setAggregatedAccountData(cid, address, data);
}

Expand All @@ -486,6 +487,31 @@ class EncointerApi {
});
}

/// Polls the aggregated account data until its ceremony phase field equals [nextPhase].
///
/// This is needed because because the latestHash slightly lags behind, as it involves a
/// network request based on the `bestHead` subscription.
Future<AggregatedAccountData> pollAggregatedAccountDataUntilNextPhase(
CeremonyPhase nextPhase,
CommunityIdentifier cid,
String pubKey,
) async {
while (true) {
final data = await getAggregatedAccountData(cid, pubKey, at: store.chain.latestHash);
final phase = data.global.ceremonyPhase;

if (nextPhase == phase) {
Log.d('[EncointerApi] received account data valid for the new ceremony phase', 'EncointerApi');
return data;
} else {
await Future.delayed(
const Duration(seconds: 3),
() => Log.d('[EncointerApi] polling account data until next phase is reached...', 'EncointerApi'),
);
}
}
}

/// Subscribes to new community identifies.
Future<void> subscribeCommunityIdentifiers() async {
// contrary to the JS subscriptions, we don't get the current
Expand Down
4 changes: 2 additions & 2 deletions app/lib/service/tx/lib/src/submit_tx_wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ Future<void> submitEndorseNewcomer(
api,
txParams,
onFinish: (BuildContext txPageContext, ExtrinsicReport report) {
store.encointer.account!.getNumberOfNewbieTicketsForReputable();
store.encointer.communityAccount!.getNumberOfNewbieTicketsForBootstrapper();
store.encointer.account!.getNumberOfNewbieTicketsForReputable(at: report.blockHashBytes);
store.encointer.communityAccount!.getNumberOfNewbieTicketsForBootstrapper(at: report.blockHashBytes);
},
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:encointer_wallet/service/substrate_api/api.dart';
import 'package:json_annotation/json_annotation.dart';
Expand Down Expand Up @@ -171,10 +172,10 @@ abstract class _CommunityAccountStore with Store {
}

@action
Future<void> getNumberOfNewbieTicketsForBootstrapper() async {
// Todo: #923 This returns 5 for non-bootstrappers as it naively calculates the amount of tickes based on
Future<void> getNumberOfNewbieTicketsForBootstrapper({Uint8List? at}) async {
// Todo: #923 This returns 5 for non-bootstrappers as it naively calculates the amount of tickets based on
// the amount of burned tickets. This is essentially wrong and leads to workarounds that we need to do on dart side.
numberOfNewbieTicketsForBootstrapper = await webApi.encointer.getNumberOfNewbieTicketsForBootstrapper();
numberOfNewbieTicketsForBootstrapper = await webApi.encointer.getNumberOfNewbieTicketsForBootstrapper(at: at);
}

void initStore(Function? cacheFn) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:json_annotation/json_annotation.dart';
import 'package:mobx/mobx.dart';
Expand Down Expand Up @@ -143,8 +144,8 @@ abstract class _EncointerAccountStore with Store {
}

@action
Future<void> getNumberOfNewbieTicketsForReputable() async {
numberOfNewbieTicketsForReputable = await webApi.encointer.getNumberOfNewbieTicketsForReputable();
Future<void> getNumberOfNewbieTicketsForReputable({Uint8List? at}) async {
numberOfNewbieTicketsForReputable = await webApi.encointer.getNumberOfNewbieTicketsForReputable(at: at);
}

void initStore(Function? cacheFn) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description: EncointerWallet made with Flutter.

# bump version already while working on new release, bumping build number at the same time
# bump build number even more, if needed to clarify what's deployed
version: 1.11.5+876
version: 1.11.6+877

publish_to: none

Expand Down

0 comments on commit ce0c3f5

Please sign in to comment.