From 493f9ddede93bb2eed9ccbcc629fe3711123c032 Mon Sep 17 00:00:00 2001 From: shawn Date: Fri, 25 Sep 2020 17:38:30 +0800 Subject: [PATCH] update nominating list & acala faucet api --- ios/Runner.xcodeproj/project.pbxproj | 12 +-- lib/common/consts/settings.dart | 4 +- lib/page/assets/index.dart | 18 ++-- lib/page/staking/validators/overview.dart | 106 ++++++++++++------- lib/service/faucet.dart | 29 +++++ lib/service/substrateApi/acala/apiAcala.dart | 2 +- lib/utils/i18n/staking.dart | 2 + pubspec.yaml | 2 +- 8 files changed, 119 insertions(+), 56 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index d8f56c86..ecbc2310 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 = 3; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = WQ5H736A22; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -396,7 +396,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - MARKETING_VERSION = 1.0.3; + MARKETING_VERSION = 1.0.4; PRODUCT_BUNDLE_IDENTIFIER = io.polkawallet.polkawallet; PRODUCT_NAME = Runner; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -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 = 1; DEVELOPMENT_TEAM = WQ5H736A22; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -531,7 +531,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - MARKETING_VERSION = 1.0.3; + MARKETING_VERSION = 1.0.4; PRODUCT_BUNDLE_IDENTIFIER = io.polkawallet.polkawallet; PRODUCT_NAME = Runner; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -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 = 1; DEVELOPMENT_TEAM = WQ5H736A22; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -561,7 +561,7 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - MARKETING_VERSION = 1.0.3; + MARKETING_VERSION = 1.0.4; PRODUCT_BUNDLE_IDENTIFIER = io.polkawallet.polkawallet; PRODUCT_NAME = Runner; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; diff --git a/lib/common/consts/settings.dart b/lib/common/consts/settings.dart index 8a9d8705..27661445 100644 --- a/lib/common/consts/settings.dart +++ b/lib/common/consts/settings.dart @@ -141,8 +141,8 @@ const String cross_chain_transfer_address_laminar = '5CLaminarAUSDCrossChainTransferxxxxxxxxxxxxxwisu'; /// app versions -const String app_beta_version = 'v1.0.3-beta.3'; -const int app_beta_version_code = 1033; +const String app_beta_version = 'v1.0.4-beta.1'; +const int app_beta_version_code = 1041; /// js code versions const Map js_code_version_map = { diff --git a/lib/page/assets/index.dart b/lib/page/assets/index.dart index af93d4b4..11266118 100644 --- a/lib/page/assets/index.dart +++ b/lib/page/assets/index.dart @@ -187,12 +187,10 @@ class _AssetsState extends State { final String res = await webApi.acala.fetchFaucet(); String dialogContent = I18n.of(context).acala['faucet.ok']; bool isOK = false; - if (res == null || res == "ERROR") { - dialogContent = I18n.of(context).acala['faucet.error']; - } else if (res == "LIMIT") { - dialogContent = I18n.of(context).acala['faucet.limit']; - } else { + if (res != null && res == "success") { isOK = true; + } else { + dialogContent = res ?? I18n.of(context).acala['faucet.error']; } Timer(Duration(seconds: 3), () { @@ -213,11 +211,11 @@ class _AssetsState extends State { Navigator.of(context).pop(); if (isOK) { globalBalanceRefreshKey.currentState.show(); - NotificationPlugin.showNotification( - int.parse(res.substring(0, 6)), - I18n.of(context).assets['notify.receive'], - '{"ACA": 2, "aUSD": 2, "DOT": 2, "XBTC": 0.2}', - ); + // NotificationPlugin.showNotification( + // int.parse(res.substring(0, 6)), + // I18n.of(context).assets['notify.receive'], + // '{"ACA": 2, "aUSD": 2, "DOT": 2, "XBTC": 0.2}', + // ); } }, ), diff --git a/lib/page/staking/validators/overview.dart b/lib/page/staking/validators/overview.dart index 38c5b939..72e89ff9 100644 --- a/lib/page/staking/validators/overview.dart +++ b/lib/page/staking/validators/overview.dart @@ -278,54 +278,61 @@ class _StakingOverviewPageState extends State } Widget _buildNominatingList() { - final dic = I18n.of(context).staking; if (store.staking.ownStashInfo == null || store.staking.validatorsInfo.length == 0) { return Container(); } + final stashId = store.staking.ownStashInfo.stashId; final NomineesInfoData nomineesInfo = store.staking.ownStashInfo.inactives; - final List list = nomineesInfo.nomsActive.map((e) { - int validatorIndex = - store.staking.validatorsInfo.indexWhere((i) => i.accountId == e); + final List list = nomineesInfo.nomsActive.map((id) { return Expanded( - child: validatorIndex < 0 - ? Container() - : _NomineeItem( - store.staking.validatorsInfo[validatorIndex], - true, - store.account.addressIndexMap, - ), + child: _NomineeItem( + id, + store.staking.validatorsInfo, + stashId, + NomStatus.active, + store.settings.networkState.tokenDecimals, + store.account.addressIndexMap, + ), ); }).toList(); - list.addAll(nomineesInfo.nomsInactive.map((e) { - final validatorIndex = - store.staking.validatorsInfo.indexWhere((i) => i.accountId == e); - final validator = validatorIndex < 0 - ? ValidatorData.fromJson({'accountId': e}) - : store.staking.validatorsInfo[validatorIndex]; + list.addAll(nomineesInfo.nomsOver.map((id) { + return Expanded( + child: _NomineeItem( + id, + store.staking.validatorsInfo, + stashId, + NomStatus.over, + store.settings.networkState.tokenDecimals, + store.account.addressIndexMap, + ), + ); + }).toList()); + + list.addAll(nomineesInfo.nomsInactive.map((id) { return Expanded( child: _NomineeItem( - validator, - false, + id, + store.staking.validatorsInfo, + stashId, + NomStatus.inactive, + store.settings.networkState.tokenDecimals, store.account.addressIndexMap, ), ); }).toList()); list.addAll(nomineesInfo.nomsWaiting.map((id) { - final validatorIndex = - store.staking.validatorsInfo.indexWhere((i) => i.accountId == id); - final validator = validatorIndex < 0 - ? ValidatorData.fromJson({'accountId': id}) - : store.staking.validatorsInfo[validatorIndex]; return Expanded( child: _NomineeItem( - validator, - false, + id, + store.staking.validatorsInfo, + stashId, + NomStatus.waiting, + store.settings.networkState.tokenDecimals, store.account.addressIndexMap, - waiting: true, ), ); }).toList()); @@ -504,26 +511,53 @@ class _StakingOverviewPageState extends State } } -class _NomineeItem extends StatelessWidget { - _NomineeItem(this.validator, this.active, this.accInfoMap, - {this.waiting = false}); +enum NomStatus { active, over, inactive, waiting } - final ValidatorData validator; - final bool active; - final bool waiting; +class _NomineeItem extends StatelessWidget { + _NomineeItem( + this.id, + this.validators, + this.stashId, + this.nomStatus, + this.decimals, + this.accInfoMap, + ); + + final String id; + final List validators; + final String stashId; + final NomStatus nomStatus; + final int decimals; final Map accInfoMap; @override Widget build(BuildContext context) { final dic = I18n.of(context).staking; + + final validatorIndex = validators.indexWhere((i) => i.accountId == id); + final validator = validatorIndex < 0 + ? ValidatorData.fromJson({'accountId': id}) + : validators[validatorIndex]; + final accInfo = accInfoMap[validator.accountId]; + final status = nomStatus.toString().split('.')[1]; + + BigInt meStaked; + int meIndex = validator.nominators.indexWhere((i) => i['who'] == stashId); + if (meIndex >= 0) { + meStaked = + BigInt.parse(validator.nominators[meIndex]['value'].toString()); + } + String subtitle = dic['nominate.$status']; + if (nomStatus == NomStatus.active) { + subtitle += ' ${Fmt.token(meStaked ?? BigInt.zero, decimals)}'; + } + return ListTile( dense: true, leading: AddressIcon(validator.accountId, size: 32), title: Fmt.accountDisplayName(validator.accountId, accInfo), - subtitle: Text(waiting - ? dic['nominate.waiting'] - : active ? dic['nominate.active'] : dic['nominate.inactive']), + subtitle: Text(subtitle), trailing: Container( width: 100, child: Column( diff --git a/lib/service/faucet.dart b/lib/service/faucet.dart index d9137b1a..08cb10d3 100644 --- a/lib/service/faucet.dart +++ b/lib/service/faucet.dart @@ -4,6 +4,7 @@ import 'package:http/http.dart'; class FaucetApi { static const String _endpoint = 'https://api.polkawallet.io/faucet'; + static const String _endpointV2 = 'https://api.polkawallet.io/v2/faucet'; static Future getAcalaTokens(String address, String deviceId) async { Map headers = {"Content-type": "application/json"}; @@ -24,6 +25,34 @@ class FaucetApi { } } + static Future getAcalaTokensV2( + String address, String deviceId) async { + Map headers = {"Content-type": "application/json"}; + String body = jsonEncode({ + "address": address, + "account": deviceId, + }); + try { + Response res = + await post('$_endpointV2/faucet', headers: headers, body: body); + if (res.statusCode == 200) { + try { + final body = jsonDecode(res.body); + if (body['code'] == 200) { + return 'success'; + } + return body['message']; + } catch (_) { + return null; + } + } + return null; + } catch (err) { + print(err); + return null; + } + } + static Future getLaminarTokens(String address) async { try { Response res = await post( diff --git a/lib/service/substrateApi/acala/apiAcala.dart b/lib/service/substrateApi/acala/apiAcala.dart index f712047d..e87a0e76 100644 --- a/lib/service/substrateApi/acala/apiAcala.dart +++ b/lib/service/substrateApi/acala/apiAcala.dart @@ -27,7 +27,7 @@ class ApiAcala { IosDeviceInfo info = await deviceInfo.iosInfo; deviceId = info.identifierForVendor; } - String res = await FaucetApi.getAcalaTokens(address, deviceId); + String res = await FaucetApi.getAcalaTokensV2(address, deviceId); return res; } diff --git a/lib/utils/i18n/staking.dart b/lib/utils/i18n/staking.dart index 22e3da21..0635b3c2 100644 --- a/lib/utils/i18n/staking.dart +++ b/lib/utils/i18n/staking.dart @@ -69,6 +69,7 @@ const Map enStaking = { 'filter': 'Filter with Address/Name', 'sort': 'Sort by', 'nominate.active': 'Active', + 'nominate.over': 'Oversubscribed', 'nominate.inactive': 'Inactive', 'nominate.waiting': 'Waiting', 'phala': 'Phala Airdrop', @@ -143,6 +144,7 @@ const Map zhStaking = { 'filter': '地址/名称筛选', 'sort': '排序', 'nominate.active': '活跃', + 'nominate.over': '超额认购', 'nominate.inactive': '不活跃', 'nominate.waiting': '等待', 'phala': 'Phala 空投', diff --git a/pubspec.yaml b/pubspec.yaml index f53f7224..da2a890a 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.3+1033 +version: 1.0.4+1041 environment: sdk: ">=2.7.0 <3.0.0"