Skip to content

Commit

Permalink
[encointer-api] getAggregatedAccountData does now use th pubKey ins…
Browse files Browse the repository at this point in the history
…tead of the address.
  • Loading branch information
clangenb committed Apr 3, 2023
1 parent d1b6975 commit 38fa884
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/lib/mocks/substrate_api/mock_encointer_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MockEncointerApi extends EncointerApi {
}

@override
Future<AggregatedAccountData> getAggregatedAccountData(CommunityIdentifier cid, String address) {
Future<AggregatedAccountData> getAggregatedAccountData(CommunityIdentifier cid, String pubKey) {
// ignore: null_argument_to_non_null_type
return Future.value();
}
Expand Down
1 change: 0 additions & 1 deletion app/lib/service/substrate_api/account_api.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';

import 'package:encointer_wallet/config/consts.dart';
import 'package:encointer_wallet/service/log/log_service.dart';
import 'package:encointer_wallet/service/notification/lib/notification.dart';
import 'package:encointer_wallet/service/substrate_api/core/js_api.dart';
Expand Down
15 changes: 11 additions & 4 deletions app/lib/service/substrate_api/encointer/encointer_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ class EncointerApi {

/// Queries the rpc 'encointer_getAggregatedAccountData' with the dart api.
///
Future<AggregatedAccountData> getAggregatedAccountData(CommunityIdentifier cid, String address) async {
/// Todo: Be able to handle pubKey and any address and transform it to the
/// address with prefix 42. Needs #1105.
Future<AggregatedAccountData> getAggregatedAccountData(CommunityIdentifier cid, String pubKey) async {
final address = Fmt.ss58Encode(pubKey);

try {
final accountData = await _dartApi.getAggregatedAccountData(cid, address);
Log.d(
Expand Down Expand Up @@ -330,13 +334,16 @@ class EncointerApi {
await jsApi.subscribeMessage(
'encointer.subscribeCurrentPhase("$_currentPhaseSubscribeChannel")', _currentPhaseSubscribeChannel,
(String data) async {
if (store.account.currentAccountPubKey == null) return;
final phase = ceremonyPhaseFromString(data.toUpperCase())!;

final cid = store.encointer.chosenCid;
final address = store.account.currentAddress;

final pubKey = store.account.currentAccountPubKey!;

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

Expand All @@ -352,10 +359,10 @@ class EncointerApi {
Future<AggregatedAccountData> pollAggregatedAccountDataUntilNextPhase(
CeremonyPhase nextPhase,
CommunityIdentifier cid,
String address,
String pubKey,
) async {
while (true) {
final data = await getAggregatedAccountData(cid, address);
final data = await getAggregatedAccountData(cid, pubKey);
final phase = data.global!.ceremonyPhase;

if (nextPhase == phase) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/service/tx/lib/src/submit_tx_wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Future<void> submitRegisterParticipant(BuildContext context, AppStore store, Api

final data = await webApi.encointer.getAggregatedAccountData(
store.encointer.chosenCid!,
store.account.currentAddress,
store.account.currentAccountPubKey!,
);
Log.d('$data', 'AggregatedAccountData from register participant');
final registrationType = data.personal?.participantType;
Expand Down
3 changes: 2 additions & 1 deletion app/lib/store/encointer/encointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ abstract class _EncointerStore with Store {
Future<void> updateAggregatedAccountData() async {
try {
if (chosenCid != null) {
final data = await webApi.encointer.getAggregatedAccountData(chosenCid!, _rootStore.account.currentAddress);
if (_rootStore.account.currentAccountPubKey == null) return;
final data = await webApi.encointer.getAggregatedAccountData(chosenCid!, _rootStore.account.currentAccountPubKey!);
setAggregatedAccountData(chosenCid!, _rootStore.account.currentAddress, data);
} else {
Log.d('chosenCid is null', 'Encointer updateAggregatedAccountData');
Expand Down

0 comments on commit 38fa884

Please sign in to comment.