Skip to content

Commit

Permalink
Merge branch 'master' into ab/remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi authored Sep 14, 2024
2 parents e4c7b27 + 0d032ac commit 725b09d
Show file tree
Hide file tree
Showing 67 changed files with 2,410 additions and 763 deletions.
30 changes: 30 additions & 0 deletions app/lib/l10n/arb/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,36 @@
}
}
},
"proposalPetition": "{cid} Petition: {value}",
"@proposalPetition": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"value": {
"type": "String",
"example": "Peace to the World"
}
}
},
"proposalSpendNative": "{cid} Kasse soll {amount} KSM an {beneficiary} senden",
"@proposalSpendNative": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"amount": {
"type": "String",
"example": "0.00"
},
"beneficiary": {
"type": "String",
"example": "HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F"
}
}
},
"proposalSupersededBy": "Verdrängt durch: {id}",
"@proposalSupersededBy": {
"placeholders": {
Expand Down
30 changes: 30 additions & 0 deletions app/lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,36 @@
}
}
},
"proposalPetition": "{cid} petition: {value}",
"@proposalPetition": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"value": {
"type": "String",
"example": "Peace to the World"
}
}
},
"proposalSpendNative": "{cid} treasury shall spend {amount} KSM to {beneficiary}",
"@proposalSpendNative": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"amount": {
"type": "String",
"example": "0.00"
},
"beneficiary": {
"type": "String",
"example": "HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F"
}
}
},
"proposalSupersededBy": "Superseded by: {id}",
"@proposalSupersededBy": {
"placeholders": {
Expand Down
30 changes: 30 additions & 0 deletions app/lib/l10n/arb/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,36 @@
}
}
},
"proposalPetition": "{cid} petition: {value}",
"@proposalPetition": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"value": {
"type": "String",
"example": "Peace to the World"
}
}
},
"proposalSpendNative": "{cid} trèsor enverra {amount} KSM à {beneficiary}",
"@proposalSpendNative": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"amount": {
"type": "String",
"example": "0.00"
},
"beneficiary": {
"type": "String",
"example": "HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F"
}
}
},
"proposalSupersededBy": "Epargné par: {id}",
"@proposalSupersededBy": {
"placeholders": {
Expand Down
30 changes: 30 additions & 0 deletions app/lib/l10n/arb/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,36 @@
}
}
},
"proposalPetition": "{cid} петиция: {value}",
"@proposalPetition": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"value": {
"type": "String",
"example": "Peace to the World"
}
}
},
"proposalSpendNative": "{cid} Казначейство отправит {amount} KSM {beneficiary}",
"@proposalSpendNative": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"amount": {
"type": "String",
"example": "0.00"
},
"beneficiary": {
"type": "String",
"example": "HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F"
}
}
},
"proposalSupersededBy": "заменен на: {id}",
"@proposalSupersededBy": {
"placeholders": {
Expand Down
30 changes: 30 additions & 0 deletions app/lib/l10n/arb/app_sw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,36 @@
}
}
},
"proposalPetition": "{cid} petitioni: {value}",
"@proposalPetition": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"value": {
"type": "String",
"example": "Peace to the World"
}
}
},
"proposalSpendNative": "{cid} hazina itatuma {amount} KSM kwa {beneficiary}",
"@proposalSpendNative": {
"placeholders": {
"cid": {
"type": "String",
"example": "global"
},
"amount": {
"type": "String",
"example": "0.00"
},
"beneficiary": {
"type": "String",
"example": "HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F"
}
}
},
"proposalSupersededBy": "Imetanguliwa na: {id}",
"@proposalSupersededBy": {
"placeholders": {
Expand Down
9 changes: 6 additions & 3 deletions app/lib/page-encointer/democracy/democracy_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ class _DemocracyPageState extends State<DemocracyPage> {
}

Future<void> _init() async {
final proposalIds = await webApi.encointer.getHistoricProposalIds(count: BigInt.from(50));
final maybeProposalIds = await webApi.encointer.getHistoricProposalIds(count: BigInt.from(50));

final allProposals = await webApi.encointer.getProposals(proposalIds);
final allProposals = await webApi.encointer.getProposals(maybeProposalIds);
// Reduce proposalIds to the entries which also exist in allProposals
// this is necessary, because migrations may purge incompatible (non-decodable) proposals,
// but never the index
final proposalIds = maybeProposalIds.where(allProposals.containsKey).toList();
final allTallies = await webApi.encointer.getTallies(proposalIds);
final allPurposeIds = await webApi.encointer.getProposalPurposeIds(proposalIds);

democracyParams = webApi.encointer.democracyParams();

proposals = allProposals;
Expand Down
33 changes: 33 additions & 0 deletions app/lib/page-encointer/democracy/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:math';

import 'package:encointer_wallet/config/consts.dart';
import 'package:encointer_wallet/l10n/l10.dart';
import 'package:encointer_wallet/models/communities/community_identifier.dart';
import 'package:encointer_wallet/service/service.dart';
import 'package:encointer_wallet/service/substrate_api/encointer/encointer_api.dart';
import 'package:encointer_wallet/store/app.dart';
import 'package:encointer_wallet/utils/format.dart';
import 'package:ew_keyring/ew_keyring.dart';
import 'package:ew_substrate_fixed/substrate_fixed.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand All @@ -14,10 +17,12 @@ import 'package:ew_polkadart/encointer_types.dart' as et;
import 'package:ew_polkadart/ew_polkadart.dart'
show
AddLocation,
Petition,
Proposal,
ProposalAction,
RemoveLocation,
SetInactivityTimeout,
SpendNative,
Tally,
UpdateDemurrage,
UpdateNominalIncome;
Expand All @@ -27,6 +32,7 @@ import 'package:ew_polkadart/ew_polkadart.dart'
/// Todo: add localization for all variants.
String getProposalActionTitle(BuildContext context, ProposalAction action) {
final l10n = context.l10n;
final store = context.read<AppStore>();

switch (action.runtimeType) {
case UpdateNominalIncome:
Expand All @@ -52,11 +58,32 @@ String getProposalActionTitle(BuildContext context, ProposalAction action) {
return 'Remove Location (unsupported)';
case SetInactivityTimeout:
return 'SetInactivity Timeout (unsupported)';
case Petition:
final cidPolkadart = getCommunityIdentifierFromProposal(action);
final cidStr = cidOrGlobal(cidPolkadart, store);
final demand = String.fromCharCodes((action as Petition).value1);
return l10n.proposalPetition(cidStr, demand);
case SpendNative:
final cidPolkadart = getCommunityIdentifierFromProposal(action);
final cidStr = cidOrGlobal(cidPolkadart, store);
final beneficiary = Fmt.address(
AddressUtils.pubKeyToAddress((action as SpendNative).value1, prefix: store.settings.currentNetwork.ss58()))!;
final amount = Fmt.token(action.value2, ertDecimals);
return l10n.proposalSpendNative(cidStr, amount, beneficiary);
default:
throw Exception('ProposalAction: Invalid Type: "${action.runtimeType}"');
}
}

String cidOrGlobal(et.CommunityIdentifier? cidPolkadart, AppStore store) {
final cidStr = cidPolkadart == null
? 'global'
: (store.encointer.communityStores![CommunityIdentifier(cidPolkadart.geohash, cidPolkadart.digest).toFmtString()]
?.symbol ??
CommunityIdentifier(cidPolkadart.geohash, cidPolkadart.digest).toFmtString());
return cidStr;
}

double demurragePerMonth(double demurrage, BigInt blockProductionTime) {
return (1 - exp(-1 * demurrage * blocksPerMonth(blockProductionTime))) * 100;
}
Expand All @@ -81,6 +108,12 @@ et.CommunityIdentifier? getCommunityIdentifierFromProposal(ProposalAction action
case SetInactivityTimeout:
// This is a global action hence all communities can vote for it.
return null;
case Petition:
// can be global or local
return (action as Petition).value0;
case SpendNative:
// can be global or local
return (action as SpendNative).value0;
default:
throw Exception('ProposalAction: Invalid Type: "${action.runtimeType}"');
}
Expand Down
22 changes: 13 additions & 9 deletions app/lib/service/substrate_api/encointer/encointer_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -734,21 +734,25 @@ class EncointerApi {

Future<Map<BigInt, Proposal>> getProposals(List<BigInt> proposalIds, {BlockHash? at}) async {
try {
// Keys including storage prefix.
Log.d("[getProposals] ProposalIds: $proposalIds')}");
Log.d('[getProposals] ProposalIds: $proposalIds');

final proposals = await Future.wait(proposalIds.map(
(key) => encointerKusama.query.encointerDemocracy
.proposals(key, at: at ?? store.chain.latestHash)
.then((maybeProposal) => maybeProposal!),
(key) => encointerKusama.query.encointerDemocracy.proposals(key, at: at ?? store.chain.latestHash),
));

final proposalMap = Map.fromIterables(proposalIds, proposals);
Log.d('[getProposals] proposals: $proposalMap');
return proposalMap;
// We need to assume that old proposals have been purged from the state. So we need to filter out null values.
final validProposals = <BigInt, Proposal>{};
for (var i = 0; i < proposalIds.length; i++) {
if (proposals[i] != null) {
validProposals[proposalIds[i]] = proposals[i]!;
}
}

Log.d('[getProposals] valid proposals: $validProposals');
return validProposals;
} catch (e, s) {
Log.e('[getProposals]', '$e', s);
return Map.of({});
return {};
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/ew_polkadart/lib/ew_polkadart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ export 'package:polkadart/polkadart.dart';
// encointer democracy exports
export 'generated/encointer_kusama/types/encointer_primitives/democracy/proposal.dart' show Proposal;
export 'generated/encointer_kusama/types/encointer_primitives/democracy/proposal_action.dart'
show ProposalAction, AddLocation, RemoveLocation, UpdateDemurrage, UpdateNominalIncome, SetInactivityTimeout;
show
ProposalAction,
AddLocation,
RemoveLocation,
UpdateDemurrage,
UpdateNominalIncome,
SetInactivityTimeout,
Petition,
SpendNative;
export 'generated/encointer_kusama/types/encointer_primitives/democracy/proposal_action_identifier.dart'
show ProposalActionIdentifier;
export 'generated/encointer_kusama/types/encointer_primitives/democracy/proposal_state.dart'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i21;
import 'dart:async' as _i23;

import 'package:polkadart/polkadart.dart' as _i1;

import 'pallets/aura.dart' as _i21;
import 'pallets/balances.dart' as _i6;
import 'pallets/encointer_balances.dart' as _i15;
import 'pallets/encointer_bazaar.dart' as _i16;
Expand All @@ -12,6 +13,7 @@ import 'pallets/encointer_democracy.dart' as _i19;
import 'pallets/encointer_faucet.dart' as _i18;
import 'pallets/encointer_reputation_commitments.dart' as _i17;
import 'pallets/encointer_scheduler.dart' as _i12;
import 'pallets/encointer_treasuries.dart' as _i22;
import 'pallets/grandpa.dart' as _i8;
import 'pallets/proxy.dart' as _i9;
import 'pallets/randomness_collective_flip.dart' as _i3;
Expand Down Expand Up @@ -130,6 +132,8 @@ class Constants {

final _i7.Constants transactionPayment = _i7.Constants();

final _i21.Constants aura = _i21.Constants();

final _i8.Constants grandpa = _i8.Constants();

final _i20.Constants utility = _i20.Constants();
Expand All @@ -151,6 +155,8 @@ class Constants {
final _i18.Constants encointerFaucet = _i18.Constants();

final _i19.Constants encointerDemocracy = _i19.Constants();

final _i22.Constants encointerTreasuries = _i22.Constants();
}

class Rpc {
Expand Down Expand Up @@ -215,11 +221,11 @@ class EncointerKusama {

final Registry registry;

_i21.Future connect() async {
_i23.Future connect() async {
return await _provider.connect();
}

_i21.Future disconnect() async {
_i23.Future disconnect() async {
return await _provider.disconnect();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Constants {
Constants();

/// The slot duration Aura should run with, expressed in milliseconds.
/// The effective value of this type should not change while the chain is running.
///
/// For backwards compatibility either use [`MinimumPeriodTimesTwo`] or a const.
final BigInt slotDuration = BigInt.from(6000);
}
Loading

0 comments on commit 725b09d

Please sign in to comment.