From 5a6b0eb15d6cc21902eaf99dbb6779fb3ddadcdf Mon Sep 17 00:00:00 2001 From: shawn Date: Fri, 11 Sep 2020 18:24:08 +0800 Subject: [PATCH] fix setNominees role --- ios/Runner.xcodeproj/project.pbxproj | 6 +- lib/common/consts/settings.dart | 4 +- lib/page/staking/actions/actions.dart | 7 +-- lib/page/staking/validators/overview.dart | 68 +++++++++++++++-------- lib/service/substrateApi/apiStaking.dart | 2 +- lib/store/staking/staking.dart | 4 +- pubspec.yaml | 2 +- 7 files changed, 57 insertions(+), 36 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 51388751..c5130180 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -383,7 +383,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = WQ5H736A22; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -518,7 +518,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = WQ5H736A22; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -548,7 +548,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = WQ5H736A22; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( diff --git a/lib/common/consts/settings.dart b/lib/common/consts/settings.dart index 3e72f929..8bdeb27c 100644 --- a/lib/common/consts/settings.dart +++ b/lib/common/consts/settings.dart @@ -148,8 +148,8 @@ const String cross_chain_transfer_address_laminar = '5CLaminarAUSDCrossChainTransferxxxxxxxxxxxxxwisu'; /// app versions -const String app_beta_version = 'v1.0.1-beta.2'; -const int app_beta_version_code = 1012; +const String app_beta_version = 'v1.0.1-beta.3'; +const int app_beta_version_code = 1013; /// js code versions const Map js_code_version_map = { diff --git a/lib/page/staking/actions/actions.dart b/lib/page/staking/actions/actions.dart index 55db12ad..113507b9 100644 --- a/lib/page/staking/actions/actions.dart +++ b/lib/page/staking/actions/actions.dart @@ -229,12 +229,7 @@ class _StakingActions extends State child: !hasData ? Container( padding: EdgeInsets.only(top: 80, bottom: 80), - child: Column( - children: [ - CupertinoActivityIndicator(), - Text(I18n.of(context).assets['node.connecting']), - ], - ), + child: CupertinoActivityIndicator(), ) : Column( children: [ diff --git a/lib/page/staking/validators/overview.dart b/lib/page/staking/validators/overview.dart index a60b8f5a..9e00225a 100644 --- a/lib/page/staking/validators/overview.dart +++ b/lib/page/staking/validators/overview.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:polka_wallet/common/components/textTag.dart'; import 'package:polka_wallet/page/account/txConfirmPage.dart'; +import 'package:polka_wallet/page/staking/actions/bondExtraPage.dart'; import 'package:polka_wallet/page/staking/actions/bondPage.dart'; import 'package:polka_wallet/page/staking/validators/nominatePage.dart'; import 'package:polka_wallet/page/staking/validators/validatorDetailPage.dart'; @@ -63,7 +64,9 @@ class _StakingOverviewPageState extends State } } - void _goToBond() { + void _goToBond({bondExtra = false}) { + if (store.staking.ownStashInfo == null) return; + var dic = I18n.of(context).staking; showCupertinoDialog( context: context, @@ -80,7 +83,8 @@ class _StakingOverviewPageState extends State child: Text(I18n.of(context).home['ok']), onPressed: () { Navigator.of(context).pop(); - Navigator.pushNamed(context, BondPage.route); + Navigator.pushNamed( + context, bondExtra ? BondExtraPage.route : BondPage.route); }, ), ], @@ -90,6 +94,8 @@ class _StakingOverviewPageState extends State } void _onSetPayee() { + if (store.staking.ownStashInfo == null) return; + var dic = I18n.of(context).staking; showCupertinoModalPopup( context: context, @@ -146,20 +152,20 @@ class _StakingOverviewPageState extends State bool hashData = store.staking.ownStashInfo != null && store.staking.ownStashInfo.stakingLedger != null; - String controllerId = store.account.currentAddress; int bonded = 0; List nominators = []; double nominatorListHeight = 48; + bool isController = false; if (hashData) { - controllerId = store.staking.ownStashInfo.controllerId; bonded = store.staking.ownStashInfo.stakingLedger['active']; nominators = store.staking.ownStashInfo.nominating.toList(); if (nominators.length > 0) { nominatorListHeight = double.parse((nominators.length * 56).toString()); } + isController = store.staking.ownStashInfo.isOwnController; } - bool isController = - store.staking.ownStashInfo?.account?.accountId == controllerId; + final isStash = store.staking.ownStashInfo?.stashId == + store.staking.ownStashInfo?.account?.accountId; Color actionButtonColor = Theme.of(context).primaryColor; Color disabledColor = Theme.of(context).disabledColor; @@ -195,7 +201,7 @@ class _StakingOverviewPageState extends State subtitle: Text(dic['nominating']), trailing: Container( width: 100, - child: isController + child: store.staking.ownStashInfo?.controllerId == null && isStash ? GestureDetector( child: Column( children: [ @@ -204,27 +210,45 @@ class _StakingOverviewPageState extends State color: actionButtonColor, ), Text( - dic[nominators.length > 0 - ? 'action.nominee' - : 'action.nominate'], + dic['action.nominate'], style: TextStyle(color: actionButtonColor), ) ], ), - onTap: bonded > 0 ? _onSetPayee : _goToBond, + onTap: _goToBond, ) - : Column( - children: [ - OutlinedCircle( - icon: Icons.add, - color: disabledColor, - ), - Text( - dic['action.nominate'], - style: TextStyle(color: disabledColor), + : isStash && !isController + ? Column( + children: [ + OutlinedCircle( + icon: Icons.add, + color: disabledColor, + ), + Text( + dic['action.nominate'], + style: TextStyle(color: disabledColor), + ) + ], ) - ], - ), + : GestureDetector( + child: Column( + children: [ + OutlinedCircle( + icon: Icons.add, + color: actionButtonColor, + ), + Text( + dic[nominators.length > 0 + ? 'action.nominee' + : 'action.nominate'], + style: TextStyle(color: actionButtonColor), + ) + ], + ), + onTap: bonded > 0 + ? _onSetPayee + : () => _goToBond(bondExtra: true), + ), ), ), AnimatedContainer( diff --git a/lib/service/substrateApi/apiStaking.dart b/lib/service/substrateApi/apiStaking.dart index 47a90939..f673a1f3 100644 --- a/lib/service/substrateApi/apiStaking.dart +++ b/lib/service/substrateApi/apiStaking.dart @@ -123,7 +123,7 @@ class ApiStaking { store.staking.setOwnStashInfo(pubKey, data); final List addressesNeedIcons = - store.staking.ownStashInfo.nominating != null + store.staking.ownStashInfo?.nominating != null ? store.staking.ownStashInfo.nominating.toList() : []; final List addressesNeedDecode = []; diff --git a/lib/store/staking/staking.dart b/lib/store/staking/staking.dart index c002c7b0..d4f4b677 100644 --- a/lib/store/staking/staking.dart +++ b/lib/store/staking/staking.dart @@ -164,7 +164,9 @@ abstract class _StakingStore with Store { List ls = List(); data['info'].forEach((i) { - i['points'] = overview['eraPoints']['individual'][i['accountId']]; + i['points'] = overview['eraPoints'] != null + ? overview['eraPoints']['individual'][i['accountId']] + : 0; ValidatorData data = ValidatorData.fromJson(i); totalStaked += data.total; data.nominators.forEach((n) { diff --git a/pubspec.yaml b/pubspec.yaml index 28500c76..39f9cf93 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: PolkaWallet made with Flutter. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.1+1012 +version: 1.0.1+1013 environment: sdk: ">=2.1.0 <3.0.0"