1
1
import 'dart:math' ;
2
2
3
+ import 'package:encointer_wallet/config/consts.dart' ;
3
4
import 'package:encointer_wallet/l10n/l10.dart' ;
4
5
import 'package:encointer_wallet/models/communities/community_identifier.dart' ;
5
6
import 'package:encointer_wallet/service/service.dart' ;
6
7
import 'package:encointer_wallet/service/substrate_api/encointer/encointer_api.dart' ;
7
8
import 'package:encointer_wallet/store/app.dart' ;
9
+ import 'package:encointer_wallet/utils/format.dart' ;
10
+ import 'package:ew_keyring/ew_keyring.dart' ;
8
11
import 'package:ew_substrate_fixed/substrate_fixed.dart' ;
9
12
import 'package:flutter/material.dart' ;
10
13
import 'package:provider/provider.dart' ;
@@ -14,10 +17,12 @@ import 'package:ew_polkadart/encointer_types.dart' as et;
14
17
import 'package:ew_polkadart/ew_polkadart.dart'
15
18
show
16
19
AddLocation,
20
+ Petition,
17
21
Proposal,
18
22
ProposalAction,
19
23
RemoveLocation,
20
24
SetInactivityTimeout,
25
+ SpendNative,
21
26
Tally,
22
27
UpdateDemurrage,
23
28
UpdateNominalIncome;
@@ -27,6 +32,7 @@ import 'package:ew_polkadart/ew_polkadart.dart'
27
32
/// Todo: add localization for all variants.
28
33
String getProposalActionTitle (BuildContext context, ProposalAction action) {
29
34
final l10n = context.l10n;
35
+ final store = context.read <AppStore >();
30
36
31
37
switch (action.runtimeType) {
32
38
case UpdateNominalIncome :
@@ -52,11 +58,32 @@ String getProposalActionTitle(BuildContext context, ProposalAction action) {
52
58
return 'Remove Location (unsupported)' ;
53
59
case SetInactivityTimeout :
54
60
return 'SetInactivity Timeout (unsupported)' ;
61
+ case Petition :
62
+ final cidPolkadart = getCommunityIdentifierFromProposal (action);
63
+ final cidStr = cidOrGlobal (cidPolkadart, store);
64
+ final demand = String .fromCharCodes ((action as Petition ).value1);
65
+ return l10n.proposalPetition (cidStr, demand);
66
+ case SpendNative :
67
+ final cidPolkadart = getCommunityIdentifierFromProposal (action);
68
+ final cidStr = cidOrGlobal (cidPolkadart, store);
69
+ final beneficiary = Fmt .address (
70
+ AddressUtils .pubKeyToAddress ((action as SpendNative ).value1, prefix: store.settings.currentNetwork.ss58 ()))! ;
71
+ final amount = Fmt .token (action.value2, ertDecimals);
72
+ return l10n.proposalSpendNative (cidStr, amount, beneficiary);
55
73
default :
56
74
throw Exception ('ProposalAction: Invalid Type: "${action .runtimeType }"' );
57
75
}
58
76
}
59
77
78
+ String cidOrGlobal (et.CommunityIdentifier ? cidPolkadart, AppStore store) {
79
+ final cidStr = cidPolkadart == null
80
+ ? 'global'
81
+ : (store.encointer.communityStores! [CommunityIdentifier (cidPolkadart.geohash, cidPolkadart.digest).toFmtString ()]
82
+ ? .symbol ??
83
+ CommunityIdentifier (cidPolkadart.geohash, cidPolkadart.digest).toFmtString ());
84
+ return cidStr;
85
+ }
86
+
60
87
double demurragePerMonth (double demurrage, BigInt blockProductionTime) {
61
88
return (1 - exp (- 1 * demurrage * blocksPerMonth (blockProductionTime))) * 100 ;
62
89
}
@@ -81,6 +108,12 @@ et.CommunityIdentifier? getCommunityIdentifierFromProposal(ProposalAction action
81
108
case SetInactivityTimeout :
82
109
// This is a global action hence all communities can vote for it.
83
110
return null ;
111
+ case Petition :
112
+ // can be global or local
113
+ return (action as Petition ).value0;
114
+ case SpendNative :
115
+ // can be global or local
116
+ return (action as SpendNative ).value0;
84
117
default :
85
118
throw Exception ('ProposalAction: Invalid Type: "${action .runtimeType }"' );
86
119
}
0 commit comments