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

support system.remark on account manage page #1698

Merged
merged 11 commits into from
Sep 18, 2024
7 changes: 7 additions & 0 deletions app/lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@
"registerUntil": "Register before",
"remainingNewbieTicketsAsBootStrapper": "Remaining newbie tickets as bootsrapper:",
"remainingNewbieTicketsAsReputable": "Remaining newbie tickets as reputable:",
"remarkNotificationTitle": "note submitted",
"remarkNotificationBody": "You have submitted a note.",
"remarks": "Remarks",
"remarksButton": "Add note",
"remarksExplain": "You can submit a note to the network. This note will be public and immutable. It can be read and authenticated by everyone as it will be digitally signed by you.",
"remarksNote": "Note",
"remarksSubmit": "Submit note",
"reputableContent": "You used your reputation to get a guaranteed seat. Caution: Should you register, but not show up at the cycle, you become a newbie again.",
"reputableTitle": "Registered as reputable - your seat is guaranteed",
"reputationAlreadyCommittedTitle": "Reputation already used",
Expand Down
22 changes: 22 additions & 0 deletions app/lib/page/profile/account/account_manage_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:encointer_wallet/page/profile/account/remark.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
Expand Down Expand Up @@ -192,6 +193,26 @@ class _AccountManagePageState extends State<AccountManagePage> {
);
}

// Not an ideal practice, but we only release a dev-version of the faucet, and cleanup can be later ;-)
Widget remarks() {
if (faucets == null) {
return appConfig.isIntegrationTest ? const SizedBox.shrink() : const CupertinoActivityIndicator();
}

if (store.account.currentAccountPubKey! != accountToBeEditedPubKey) {
return Column(children: [
Text(l10n.remarks, style: h3Grey, textAlign: TextAlign.left),
]);
}

return Remarks(
store,
userAddress: Address(
pubkey: AddressUtils.pubKeyHexToPubKey(accountToBeEditedPubKey),
prefix: store.settings.currentNetwork.ss58(),
),
);
}
return Observer(
builder: (_) => Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -277,6 +298,7 @@ class _AccountManagePageState extends State<AccountManagePage> {
),
),
benefits(),
remarks(),
const Spacer(),
DecoratedBox(
// width: double.infinity,
Expand Down
95 changes: 95 additions & 0 deletions app/lib/page/profile/account/remark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:encointer_wallet/store/app.dart';
import 'package:encointer_wallet/config/consts.dart';
import 'package:encointer_wallet/l10n/l10.dart';
import 'package:encointer_wallet/theme/theme.dart';
import 'package:encointer_wallet/utils/format.dart';
import 'package:ew_keyring/ew_keyring.dart';

import '../../../common/components/submit_button.dart';
import '../../../service/substrate_api/api.dart';
import '../../../service/tx/lib/tx.dart';

class Remarks extends StatelessWidget {
const Remarks(
this.store, {
required this.userAddress,
super.key,
});

final AppStore store;

final Address userAddress;

@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final titleLarge = context.titleLarge.copyWith(fontSize: 19, color: AppColors.encointerGrey);
final titleMedium = context.titleMedium.copyWith(color: AppColors.encointerGrey);

return Column(
children: [
Text(l10n.remarks, style: titleLarge, textAlign: TextAlign.left),
Text(
l10n.remarksExplain,
textAlign: TextAlign.left,
),
ElevatedButton(
onPressed: () => _showRemarkDialog(context),
child: Text(l10n.remarksButton),
),
],
);
}

void _showRemarkDialog(BuildContext context) {
final TextEditingController _remarkController = TextEditingController();

showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(context.l10n.remarksNote),
content: TextField(
controller: _remarkController,
decoration: InputDecoration(hintText: context.l10n.remarksNote),
),
actions: <Widget>[
TextButton(
child: Text(context.l10n.cancel),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text(context.l10n.remarksSubmit),
onPressed: () async {
final remark = _remarkController.text;
if (remark.isNotEmpty) {
await _submitRemarkTx(
context,
remark);
Navigator.of(context).pop();
}
},
),
],
);
},
);
}

Future<void> _submitRemarkTx(BuildContext context, String remark) async {
return submitRemark(
context,
store,
webApi,
store.account.getKeyringAccount(store.account.currentAccountPubKey!),
remark,
txPaymentAsset: store.encointer.getTxPaymentAsset(store.encointer.chosenCid),
);
}
}
34 changes: 34 additions & 0 deletions app/lib/service/tx/lib/src/submit_tx_wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,40 @@ Future<void> submitClaimRewards(
);
}

Future<void> submitRemark(
BuildContext context,
AppStore store,
Api api,
KeyringAccount signer,
String remark,
{
required CommunityIdentifier? txPaymentAsset,
}
) async {
final List<int> remarkList = remark.codeUnits;
final call = api.encointer.encointerKusama.tx.system.remarkWithEvent(remark: remarkList);
final xt = await TxBuilder(api.provider).createSignedExtrinsic(
signer.pair,
call,
paymentAsset: txPaymentAsset?.toPolkadart(),
);

return submitTx(
context,
store,
api,
OpaqueExtrinsic(xt),
TxNotification.claimRewards(context.l10n),
onFinish: (BuildContext txPageContext, ExtrinsicReport report) {
// Claiming the rewards creates a new reputation if successful.
// Hence, we should update the state afterwards.
store.encointer.getEncointerBalance();
webApi.encointer.getReputations();
return report;
},
);
}

Future<void> submitEndorseNewcomer(
BuildContext context,
AppStore store,
Expand Down
5 changes: 5 additions & 0 deletions app/lib/service/tx/lib/src/tx_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class TxNotification {
body: l10n.claimRewardsNotificationBody,
);

factory TxNotification.remark(AppLocalizations l10n) => TxNotification(
title: l10n.remarkNotificationTitle,
body: l10n.remarkNotificationBody,
);

factory TxNotification.democracyVote(AppLocalizations l10n) => TxNotification(
title: l10n.democracyVotedNotificationTitle,
body: l10n.democracyVotedNotificationTitle,
Expand Down
Loading