Skip to content

Commit

Permalink
fix #162 & #163 & #166, staking actions role
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Sep 10, 2020
1 parent 4904495 commit f37bc03
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 105 deletions.
6 changes: 3 additions & 3 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = WQ5H736A22;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -518,7 +518,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = WQ5H736A22;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -548,7 +548,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = WQ5H736A22;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
4 changes: 2 additions & 2 deletions lib/common/consts/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ const String cross_chain_transfer_address_laminar =
'5CLaminarAUSDCrossChainTransferxxxxxxxxxxxxxwisu';

/// app versions
const String app_beta_version = 'v1.0.0-beta.3';
const int app_beta_version_code = 1003;
const String app_beta_version = 'v1.0.0-beta.4';
const int app_beta_version_code = 1004;

/// js code versions
const Map<String, int> js_code_version_map = {
Expand Down
11 changes: 10 additions & 1 deletion lib/page/governance/govEntry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ class GovEntry extends StatelessWidget {
? 'polkadot'
: 'kusama';
if (store.settings.loading) {
return CupertinoActivityIndicator();
return Container(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.width / 2),
child: Column(
children: [
CupertinoActivityIndicator(),
Text(I18n.of(context).assets['node.connecting']),
],
),
);
}
return ListView(
padding: EdgeInsets.all(16),
Expand Down
114 changes: 78 additions & 36 deletions lib/page/staking/actions/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class _StakingActions extends State<StakingActions>
setState(() {
_rewardLoading = true;
});
Map res = await webApi.staking.updateStakingRewards();
await webApi.staking.updateStakingRewards();
if (mounted) {
setState(() {
_rewardLoading = false;
Expand Down Expand Up @@ -188,16 +188,23 @@ class _StakingActions extends State<StakingActions>
if (hasData) {
store.account.pubKeyAddressMap[store.settings.endpoint.ss58]
.forEach((k, v) {
if (v == store.staking.ownStashInfo.controllerId) {
if (store.staking.ownStashInfo.isOwnStash &&
v == store.staking.ownStashInfo.controllerId) {
account02PubKey = k;
return;
}
if (store.staking.ownStashInfo.isOwnController &&
v == store.staking.ownStashInfo.stashId) {
account02PubKey = k;
return;
}
});
}
AccountData acc02;
int acc02Index = store.account.accountList
int acc02Index = store.account.accountListAll
.indexWhere((i) => i.pubKey == account02PubKey);
if (acc02Index >= 0) {
acc02 = store.account.accountList[acc02Index];
acc02 = store.account.accountListAll[acc02Index];
}

final symbol = store.settings.networkState.tokenSymbol;
Expand All @@ -220,7 +227,15 @@ class _StakingActions extends State<StakingActions>
margin: EdgeInsets.fromLTRB(16, 12, 16, 24),
padding: EdgeInsets.all(16),
child: !hasData
? CupertinoActivityIndicator()
? Container(
padding: EdgeInsets.only(top: 80, bottom: 80),
child: Column(
children: [
CupertinoActivityIndicator(),
Text(I18n.of(context).assets['node.connecting']),
],
),
)
: Column(
children: <Widget>[
Row(
Expand Down Expand Up @@ -333,9 +348,6 @@ class _StakingActions extends State<StakingActions>

return Observer(
builder: (_) {
if (store.settings.loading) {
return CupertinoActivityIndicator();
}
List<Widget> list = <Widget>[
_buildActionCard(),
Container(
Expand Down Expand Up @@ -396,8 +408,8 @@ class RowAccount02 extends StatelessWidget {

void _showActions(BuildContext context) {
var dic = I18n.of(context).staking;
final isStash = stashInfo.stashId == accountId;
String actionAccountTitle = isStash ? dic['controller'] : dic['stash'];
String actionAccountTitle =
stashInfo.isOwnStash ? dic['controller'] : dic['stash'];
String importAccountText = '${dic['action.import']}$actionAccountTitle';
String changeAccountText =
dic['action.use'] + actionAccountTitle + dic['action.operate'];
Expand Down Expand Up @@ -493,16 +505,18 @@ class RowAccount02 extends StatelessWidget {
],
),
),
controllerId == stashId
? Container()
: GestureDetector(
child: Container(
width: 80,
height: 18,
child: Image.asset('assets/images/staking/set.png'),
Expanded(
child: controllerId == stashId
? Container()
: GestureDetector(
child: Container(
width: 80,
height: 18,
child: Image.asset('assets/images/staking/set.png'),
),
onTap: () => _showActions(context),
),
onTap: () => _showActions(context),
)
)
],
)
: Container(),
Expand Down Expand Up @@ -674,24 +688,28 @@ class StakingActionsPanel extends StatelessWidget {
bool setControllerDisabled = true;
Function onSetControllerTap = () => null;
if (isStash) {
if (bonded > BigInt.zero) {
if (stashInfo.controllerId != null) {
setControllerDisabled = false;
onSetControllerTap = () => Navigator.of(context)
.pushNamed(SetControllerPage.route, arguments: controller);

if (stashInfo.isOwnStash) {
if (stashInfo.isOwnController) {
setPayeeDisabled = false;
onSetPayeeTap =
() => Navigator.of(context).pushNamed(SetPayeePage.route);
onSetPayeeTap = () => Navigator.of(context).pushNamed(
SetPayeePage.route,
arguments: stashInfo.destinationId,
);
}
} else {
bondButtonString = dic['action.bond'];
}
} else {
if (bonded > BigInt.zero) {
setPayeeDisabled = false;
onSetPayeeTap =
() => Navigator.of(context).pushNamed(SetPayeePage.route);
onSetPayeeTap = () => Navigator.of(context).pushNamed(
SetPayeePage.route,
arguments: stashInfo.destinationId,
);
}
}

Expand All @@ -718,27 +736,51 @@ class StakingActionsPanel extends StatelessWidget {
],
),
onTap: () {
if (isStash && bonded == BigInt.zero) {
/// if not bonded, we can go to bond page.
/// 1. it has no controller
/// 2. it's stash is itself(it's not controller of another acc)
if (stashInfo.controllerId == null && isStash) {
Navigator.of(context).pushNamed(BondPage.route);
return;
}
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) => CupertinoActionSheet(
actions: <Widget>[
/// disable bondExtra button if account is not stash
CupertinoActionSheetAction(
child: Text(dic['action.bondExtra']),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(BondExtraPage.route);
},
child: Text(
dic['action.bondExtra'],
style: TextStyle(
color: !isStash ? disabledColor : actionButtonColor,
),
),
onPressed: !isStash
? () => {}
: () {
Navigator.of(context).pop();
Navigator.of(context)
.pushNamed(BondExtraPage.route);
},
),

/// disable unbond button if account is not controller
CupertinoActionSheetAction(
child: Text(dic['action.unbond']),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(UnBondPage.route);
},
child: Text(
dic['action.unbond'],
style: TextStyle(
color: isStash && !stashInfo.isOwnController
? disabledColor
: actionButtonColor,
),
),
onPressed: isStash && !stashInfo.isOwnController
? () => {}
: () {
Navigator.of(context).pop();
Navigator.of(context)
.pushNamed(UnBondPage.route);
},
),
],
cancelButton: CupertinoActionSheetAction(
Expand Down
13 changes: 7 additions & 6 deletions lib/page/staking/actions/setPayeePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _SetPayeePageState extends State<SetPayeePage> {

final _rewardToOptions = ['Staked', 'Stash', 'Controller'];

int _rewardTo = 0;
int _rewardTo;

void _onSubmit() {
var dic = I18n.of(context).staking;
Expand Down Expand Up @@ -73,10 +73,10 @@ class _SetPayeePageState extends State<SetPayeePage> {

@override
Widget build(BuildContext context) {
var dic = I18n.of(context).staking;
String address = store.account.currentAddress;
final dic = I18n.of(context).staking;
final defaultValue = ModalRoute.of(context).settings.arguments ?? 0;

var rewardToOptions =
final rewardToOptions =
_rewardToOptions.map((i) => dic['reward.$i']).toList();

return Scaffold(
Expand All @@ -100,7 +100,8 @@ class _SetPayeePageState extends State<SetPayeePage> {
),
ListTile(
title: Text(dic['bond.reward']),
subtitle: Text(rewardToOptions[_rewardTo]),
subtitle:
Text(rewardToOptions[_rewardTo ?? defaultValue]),
trailing: Icon(Icons.arrow_forward_ios, size: 18),
onTap: () {
showCupertinoModalPopup(
Expand All @@ -113,7 +114,7 @@ class _SetPayeePageState extends State<SetPayeePage> {
backgroundColor: Colors.white,
itemExtent: 56,
scrollController: FixedExtentScrollController(
initialItem: _rewardTo),
initialItem: defaultValue),
children: rewardToOptions
.map((i) => Padding(
padding: EdgeInsets.all(12),
Expand Down
39 changes: 21 additions & 18 deletions lib/page/staking/validators/nominatePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,28 @@ class _NominatePageState extends State<NominatePage> {
void initState() {
super.initState();

setState(() {
store.staking.validatorsAll.forEach((i) {
_notSelected.add(i);
_selectedMap[i.accountId] = false;
});
store.staking.nominatingList.forEach((i) {
_selected.add(i);
_notSelected.removeWhere((item) => item.accountId == i.accountId);
_selectedMap[i.accountId] = true;
});
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
store.staking.validatorsAll.forEach((i) {
_notSelected.add(i);
_selectedMap[i.accountId] = false;
});
print(store.staking.nominatingList.length);
store.staking.nominatingList.forEach((i) {
_selected.add(i);
_notSelected.removeWhere((item) => item.accountId == i.accountId);
_selectedMap[i.accountId] = true;
});

// set recommended selected
List<ValidatorData> recommended = _notSelected.toList();
recommended.retainWhere((i) =>
store.staking.recommendedValidatorList.indexOf(i.accountId) > -1);
recommended.forEach((i) {
_selected.add(i);
_notSelected.removeWhere((item) => item.accountId == i.accountId);
_selectedMap[i.accountId] = true;
// set recommended selected
List<ValidatorData> recommended = _notSelected.toList();
recommended.retainWhere((i) =>
store.staking.recommendedValidatorList.indexOf(i.accountId) > -1);
recommended.forEach((i) {
_selected.add(i);
_notSelected.removeWhere((item) => item.accountId == i.accountId);
_selectedMap[i.accountId] = true;
});
});
});
}
Expand Down
Loading

0 comments on commit f37bc03

Please sign in to comment.